OBJECT:
/lib/config
AUTHOR:
Softbyte
VERSION:
V1.0
LAST UPDATE:
Fri Nov 14 00:14:24 1997
SYNOPSIS:
"/lib/config"->fun()
or
inherit "/lib/config"
DESCRIPTION:
This file allows you to read in windows like ini files, i.e. getting
information out of ascii files in key=data pairs. The data can be
Arranged in sections as well
Functions:
..... mixed GetKeyValue(string file,string section,string key)
..... [Read data belonging to 'key' from 'file' in a certain 'section'
..... string *GetSections(string file)
..... [Returns an array holding all section names of the ini file]
..... string *GetKeys(string file,string section)
..... [Returns an array holding all keynames of a given section]
Optional functions:
..... int LoadIni(string file)
..... [Forces the reload of the inifile]
..... int UnloadIni(string file)
..... [Unloads the inifile from memory to save memory; will be done
..... automatically after a certain time]
Inifile format:
Lines starting with ';' or '*' are ignored (comments)
Lines with '[mysection]' are considered a section named 'mysection'
Lines with 'mykey=mydata' are key-data pairs to the corresponding
. section if following lines have the same keyword their arguments
. are concatted
Data format:
Integer: a single number, e.g. '1'
String: text or text in "", e.g. Hello or "Hello"
............ "\n" are expanded correctly
Integerarray: numbers seprated by ',', e.g. 1,2,3,4
Stringarray: strings separated by ',', e.g. a,b,c,d
mappings: key:data pairs separated by ',', e.g. red:1,blue:2
PUBLIC FUNCTIONS
int LoadIni(string file)
Explicitely load an ini file
Parameter:
string file: Filename of the inifile, if the file does not exists
".ini"is appended to the filename and its tried again
Return Value:
0: Error, 1: Ok
int UnloadIni(string file)
Unload an ini file to free memory [Optional]
Parameter:
string file: The name of the inifile, exactely as given to LoadIni
Return Value:
1: Ok, 0: Error
mixed GetKeyValue(string file,string section,string key)
Gets the data from an inifile. When the inifile is already readin
it is cached. This means that you have to explecitely "LoadIni"
your inifile if you have changed it after usage. Otherwise no
the loading of the inifile is performed automatically
Parameter:
string file: The name of the inifile [with or without *.ini
string section: The section of the inifile, "[section]
string key: The key in the section "key=blabla
Return Value:
string data: Any data corresponding to the key,section pair
0: key or section or file not found
string *GetSections(string file)
Returns the names of all sections found in the ini file
Parameter:
file: The name of the inifile [with or without *.ini]
Return Value:
Array holding all section names or 0 for error
string *GetKeys(string file,string section)
Returns the names of all keys found in the given section of the ini file
Parameter:
string file: The name of the inifile [with or without *.ini]
string section: the section to be searched
Return Value:
Array holding all key names or 0 for error
KNOWN BUGS
Not known
INHERITANCE
config
|-lib/config
|-std/base
EXAMPLES
Example ini file
; This is a test data file
[section1]
item1=1
item2=Hello
[section2]
item1=2
item2=Hello world
item3=1,2,3,4
item4=Hello this is a test!
item5="12323"
item6=a,b,c,d
item7=a:1,b:2,c:hello
SEE ALSO