Description |
Special text files are configuration files and templates. tdbengine supports configuration files of the following style:
Configuration files
[Group 1]
Entry1=...
Entry2=...
...
[Group 2]
Entry1=...
Entry2=...
...
Every entry can be composed of 255 chars.
To work with such files EASY has two functions: SETIDENT and GETIDENT:
SETIDENT(config_file,entry,value)
writes an entry=value to config_file
GETIDENT(config_file,entry)
returns the value of entry
Entries are specified in that way: »group.entry«
Example:
PROCEDURE Main
VAR ini : STRING
ini:='test.ini'
cgiwriteln('content-type: text/html')
cgiwriteln('')
SETIDENT(ini,'Administrator.Name','Hans Huber')
SETIDENT(ini,'Administrator.Password','secret')
SETIDENT(ini,'Database.Addresses','database/address.dat')
cgiclosebuffer
copyfile(ini,'con')
ENDPROC
Dieses kleine Programm legt die Datei »test.ini« mit folgendem Inhalt an:
[Administrator]
Name=Hans Huber
Password=secret
[Database]
Addresses=database/address.dat
Note: Then the created file is outputted to the screen too. Here the use of »CGICLOSEBUFFER« is important, that the internal buffer is outputted before the copying.
With GETIDENT the single entries can be read.
Example:
GETIDENT('test.ini','Administrator.Name) -> 'Hans Huber'
GETIDENT('test.ini',Database.Addresses) -> 'database/address.dat'
Note: Within the first access to a configuration file, it is completely read to the memory of the computer and is provided to the programm via a tree structure. That is why the access is very fast.
Configuration files replaces databases in many cases!
|