Libini

From KolibriOS wiki

Jump to: navigation, search

libINI explained

Contents

[edit] General info

This article assume's you know the basics of programming applications for KolibriOS in fasm, if not, start by reading this article programming applications. A general intro to libraries in KolibriOS can be found here: Libraries

All strings are asciiz strings! (zero terminated)

for example:

string db 'This is an asciiz string',0

There's no extended error reporting possibilities. if error occurs, write functions and string read function will return -1, integer read function will simply return default value supplied. Enumeration functions will also return -1 on error. Read functions always return default value on error.

[edit] Intro on ini files

Common ini file structure is following:

[section1]
key1=value1
key2=value2

[section2]
key3=value3

Section names are embraced with square braces and are one-line strings which may contain any characters. Sections divide file into parts, where keys and their corresponding values are specified. In the begining of file (before the first section) there may also be keys and values found which aren't in any section. Keys and values are also one-line strings which are separated from each other with equality sign '='. Key name of course can't contain '=' character. Key value is the string after first '=' character found in line till the end on line.

Section names, key names and key values are trimmed i.e. space characters are deleted from the beginning and end of the strings during comparison.

If each section identifies the set of keys, each key in turn identifies one value. Section and key names don't have to be unique, but if there're two keys (within a section) with the same name, value will be read and written from the one which appears earlier in the file.

[edit] Exported functions

[edit] ini.enum_sections

This procedure will call the "callback" procedure (wich you should write in your app) for every section in the .ini file where f_name points to. parameters: filename, callback function

An example:

 invoke ini.enum_sections ini_filename, section_callback_function

;... you may put some other code here...

proc section_callback_function ini_filename, section_name
    ; now in this function we can use [ini_filename] wich points to an ascii string
    ; and [section_name] wich also point to an ascii string

  ret
endp 

;... the next should be in your 'data' section of your code (almost at the end of the file usually)  

ini_filename db '/hd0/1/file.ini',0

[edit] ini.enum_keys

Enumerates keys within given section, calling _callback function for each of them, passing filename, section name ,key name and a key value (string) on each call

[edit] ini.get_str

Reads string value. Parameters: filename, section name, key name, buffer for result, buffer size, default value to return if key section or file wasn't found


[edit] ini.set_str

Writes string value. Parameters: filename, section name, key name, buffer with string to write, string length (string in buffer may not be zero-terminated or you don't want to write it all, so you need to pass the length)


[edit] ini.get_int

Reads integer value. Parameters: filename, section name, key name, default integer if key section or file wasn't found Returns: integer in eax


[edit] ini.set_int

Write integer value. Parameters: filename, section name, key name, integer value to write





						
			
Personal tools
Select language