| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

ini_find_section

#include "sflini.h"
Bool
ini_find_section (
    FILE *inifile,
    char *section,
    Bool top)

Synopsis

Finds a specific section in the ini file. An ini file contains lines as shown below. The section name can be any mix of upper or lowercase. You should open the ini file using file_open before you call this function. If the 'top' argument is TRUE, repositions to the start of the file before reading, else reads from the current file offset. Returns TRUE if the section was found, and positions on the line that follows the section. Returns FALSE if the section was not found, and positions at the end of the file.

Examples

    ;   comments like this, or
    #   comments like this if you prefer
    !   Text is echoed to console using trace()
    [Section]
        keyword = key_value; comments
        keyword = "key_value"; comments
        keyword = 'key_value'; comments
        ...
    [Section]
        keyword = key_value; comments
        ...

Source Code - (sflini.c)

{
    char
        *first;

    ASSERT (inifile != NULL);
    ASSERT (section != NULL);

    if (top)                            /*  Reposition at top if wanted      */
        fseek (inifile, 0, SEEK_SET);

    /*  Read through file until we find what we are looking for              */
    while (file read (inifile, iniline))
      {
        first = strskp (iniline);       /*  Skip leading spaces              */

        if (*first == ';' || *first == '#' || *first == 0)
            continue;                   /*  Comment line                     */
        else
        if (*first == '!')
          {
            first = strskp (first + 1);
            trace (first);
          }
        else
        if (sscanf (first, "[%[^]]", ini_section) == 1
        &&  lexcmp (ini_section, section) == 0)
            return (TRUE);
      }
    return (FALSE);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation