Config files

Allegro supports reading and writing of configuration files with a simple, INI file-like format.

A configuration file consists of key-value pairs separated by newlines. Keys are separated from values by an equals sign (=).  All whitespace before the key, after the value and immediately adjacent to the equals sign is ignored.  Keys and values may have whitespace characters within them.  Keys do not need to be unique, but all but the last one are ignored.

The hash (#) character is used a comment when it is the first non-whitespace character on the line.  All characters following that character are ignored to the end of the line.  The hash character anywhere else on the line has no special significance.

Key-value pairs can be optionally grouped into sections, which are declared by surrounding a section name with square brackets ([ and ]) on a single line.  Whitespace before the opening bracket is ignored.  All characters after the trailing bracket are also ignored.

All key-value pairs that follow a section declaration belong to the last declared section.  Key-value pairs that don't follow any section declarations belong to the global section. Sections do not nest.

Here is an example configuration file:

#  Monster description
monster name = Allegro Developer

[weapon 0]
damage = 443

[weapon 1]
damage = 503

It can then be accessed like this (make sure to check for errors in an actual program):

  cfg := al_load_config_file ('test.cfg');
  WriteLn (al_get_config_value (Cfg, '', 'monster name')); { Prints: Allegro Developer }
  WriteLn (al_get_config_value (Cfg, 'weapon 0', "damage')); { Prints: 443 }
  WriteLn (al_get_config_value (Cfg, 'weapon 1', 'damage')); { Prints: 503 }
  al_destroy_config (Cfg)

See also: al_load_config_file