| iMatix home page | << | < | > | >> |
![]() Version 1.91 |
#include "sflini.h" Bool ini_scan_section ( FILE *inifile, char **keyword, char **value)
Scans the current section of the ini file, and returns a keyword and value if such was found. Returns the address of these values in the supplied arguments. The addresses point to static values that are overwritten with each call. Returns TRUE when a keyword/value pair is found. Returns FALSE if a new section name or end of file is found. In the first case, sets the keyword to the section name; in the second case sets the keyword to NULL. Ignores blank and comment lines, and lines that look like junk. Keyword and section names are returned as lower-case; values are returned exactly as specified in the ini file. Hyphens in keywords and section names are replaced by underlines.
{ char *first; /* 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) { *keyword = strlwc (ini_section); *value = NULL; strconvch (*keyword, '-', '_'); return (FALSE); /* New section name */ } else if (streq (first, "[]")) /* Allow empty section names */ { strcpy (ini_section, ""); *keyword = ini_section; *value = NULL; return (FALSE); /* New section name */ } else if (sscanf (first, "%[^=] = \"%[^\"]\"", ini_keyword, ini_value) == 2 || sscanf (first, "%[^=] = '%[^\']'", ini_keyword, ini_value) == 2 || sscanf (first, "%[^=] = %[^;#]", ini_keyword, ini_value) == 2) { strconvch (ini_keyword, '-', '_'); strcrop (strlwc (ini_keyword)); strcrop (ini_value); /* sscanf can't handle "" or '' as an empty value, so we do this * ourselves. Note that this breaks '""' and "''". :-( */ if (streq (ini_value, "\"\"") || streq (ini_value, "''")) strclr (ini_value); *keyword = ini_keyword; *value = ini_value; return (TRUE); /* Found keyword = value */ } } *keyword = NULL; return (FALSE); /* End of file */ }
| << | < | > | >> |
![]() |