INI functions

These functions are used for reading and writing from/to "*.ini" files, that usually contains initalization information such as the "seal.ini" file.


getini_fromfile ()
     Description:
       Reads the value of a key from a structure in a "*.ini" file.

     Syntax:
       char *getini_fromfile ( char *filename, char *ininame, char *ixname );

     Parameters:
       filename    Name of the "*.ini" file.
       ininame     Name of the structure where the value is located.
       ixname      Name of the key to read.

     Returns:
       The value.


     Example:
       In the "seal.ini" file:

          ...
          [SEAL]
          info = "desktop environment"
          version = 1
          ...

       To get the value of [info] set in the [SEAL] section, line call:

          char *i = getini_fromfile("seal.ini", "SEAL", "info");


       To get the value of [version] set in the [SEAL] section, line call:

          long  v = *((long *)getini_fromfile("seal.ini", "SEAL", "version"));


       Now "i" contains the string "desktop environment" and "v" the number 1.



setini_tofile ()
     Description:
       Sets a value of a key in a "*.ini" file.

     Syntax:
       void  setini_tofile ( char *filename, char *ininame, char *ixname, 
                             char *value, int type );

     Parameters:
       filename    Name of the "*.ini" file.
       ininame     Structure where the value will get stored.
       ixname      Name of the key to set.
       value       A pointer to the value to set.
       type        The type of the "value" pointer. May be one of:

                      INI_DECANUM - Decimal number.
                      INI_HEXANUM - Hexadecimal number.
                      INI_STRING  - String.

     Returns:
       -


     Example:
          int i = 1;

          setini_tofile("seal.ini", "SEAL", "info", "FREE desktop environment", INI_STRING);
          setini_tofile("seal.ini", "SEAL", "version", &i, INI_DECANUM);
          setini_tofile("seal.ini", "SEAL", "hexa version", &i, INI_HEXANUM);

       The "seal.ini" file now contains:

          ...
          [SEAL]
          info = "FREE desktop environment"
          version = 1
          hexa version = 0x1
          ...



getinidata_fromfile ()
     Description:
       Reads all data from a structure in a "*.ini" file.
       Reads all values until next structure or end of file is reached.

     Syntax:
       ini_data  *getinidata_fromfile ( char *filename, char *ininame );

     Parameters:
       filename    Name of the "*.ini" file.
       ininame     Structure where the value will be located.

     Returns:
       An ini_data structure containing the values.



getini_value ()
     Description:
       Reads a value from a "ini_data" structure previously
       returned by the getinidata_fromfile() function.

     Syntax:
       char *getini_value ( ini_data *dat, char *ixname );

     Parameters:
       dat         The structure to read the value from.
       ixname      Name of the key to set.

     Returns:
       The value.



getini_linenum ()
     Description:
       Gets the number of values in a "ini_data" structure.

     Syntax:
       int   getini_linenum ( ini_data *dat );

     Parameters:
       dat         The structure to count the lines in.

     Returns:
       The number of lines.


     Example:
       The "seal.ini" file contains:
          ...
          [SEAL]
          info = "desktop environment"
          version = 1
          ...

          ini_data *d = getinidata_fromfile("seal.ini", "SEAL");
          int lines = getini_linenum(d);

       Now "lines" equals 2 = number of lines in "[SEAL]" structure.



getini_line ()
     Description:
       Gets the data from a line in a structure.

     Syntax:
       char  *getini_line ( char **def, ini_data *dat, int line );

     Parameters:
       def         Pointer to a variable that will contain the
                   name of the key.
       dat         The structure to get the data from.
       line        Number of the line to read.

     Returns:
       The value of the line.


     Example:
       In the "seal.ini" file:

          ...
          [SEAL]
          info = "desktop environment"
          version = 1
          ...

          ini_data *d = getinidata_fromfile("seal.ini", "SEAL");
          char *head = NULL;
          char *def = getini_line ( &head, d, 1);

       Now "def" contains the string "desktop environment" and "head"
       contains the name of the key, which is "info".



getini_color ()
     Description:
       Reads a color value from a "*.ini" file.

     Syntax:
       ini_rgb  getini_color ( char *filename, char *ininame, char *ixname );

     Parameters:
       filename    Name of the "*.ini" file.
       ininame     The structure where the color is located.
       ixname      Name of the key to read.

     Returns:
       A ini_rgb structure containing the color values.


     Example:

       In the "seal.ini" file:

          ...
          [colors]
          desktop = "255, 0, 128"
          ...


          ini_rgb rgb = geini_color("seal.ini", "colors", "desktop");

       Now rgb.r = 255, rgb.g = 0 and rgb.b = 128. 




The ini_rgb structure

Variables

     Name:         int r

     Description:  The amount of red color (0-255).



     Name:         int g

     Description:  The amount of green color (0-255).



     Name:         int b

     Description:  The amount of blue color (0-255).



     Name:         int x

     Description:  Reserved for future versions.