fileio/
mg_read_config.pro
includes main-level programRoutines
top mg_read_config
result = mg_read_config(filename [, defaults=hash] [, error=long] [, /fold_case])
Reads a configuration file and returns an MGffOptions
object with the
results.
Options and their values are listed one option per line, though the value can extend over multiple lines by indenting at least one space on the continued lined. There must be either a ":" or an "=" after the option name. Leading space before the first character in the value is ignored. For example:
option1: value1
option2 = value2
option3 : a very long
value3
Comments have "#" or ";" as the first character on a line and are ignored.
Sections break a configuration file into namespaces. They are specified by placing a name in square brackets, such as:
[ section_name ]
Interpolation can be used to substitute values from one option into another.
Only options from the default section or the current section can be used.
Interpolation uses MG_SUBS
and hence its syntax, in this case:
%(option_name)s
MG_SUBS
can substitute numeric quantities
and uses the C format codes, but options are always strings so "s" is always
used in this case).
Return value
MGffOptions
object
Parameters
- filename in required type=string
filename of configuration file to read
Keywords
- defaults in optional type=hash
hash containing default values for items to be specified in configuration file
- error out optional type=long
set to a named variable to retrieve any error code from attempting to read the configuration file; 0 for OK, -1 for file not found, -2 for invalid syntax in configuration file
- fold_case in optional type=boolean
set for case-insensitive results (for section and option names, but not for values)
Examples
For example, suppose the following configuration file is in config.ini
:
[My Section]
foodir: %(dir)s/whatever
dir=frob
long: this value continues
in the next line
MGffOptions
object with:
IDL> config = mg_read_config('config.ini')
IDL> print, config->has_option('foodir', section='My Section')
1
IDL> print, config->get('foodir', section='My Section')
frob/whatever
IDL> .run mg_read_config
File attributes
Modification date: | Mon Jun 16 12:49:40 2014 |
Lines: | 92 |
Docformat: | rst rst |
Contact me if you have enhancement requests or bug fixes.