Logo Search packages:      
Sourcecode: freetds version File versions

int tds_read_conf_section ( FILE *  in,
const char *  section,
TDSCONFPARSE  tds_conf_parse,
void *  param 
)

Read a section of configuration file (INI style file)

Parameters:
in configuration file
section section to read
tds_conf_parse callback that receive every entry in section
param parameter to pass to callback function

Definition at line 302 of file config.c.

References tds_read_conf_section().

Referenced by tds_get_locale(), and tds_read_conf_section().

{
      char line[256], option[256], value[256];
      char *s;
      char p;
      int i;
      int insection = 0;
      int found = 0;

      tdsdump_log(TDS_DBG_INFO1, "%L Looking for section %s.\n", section);
      while (fgets(line, 256, in)) {
            s = line;

            /* skip leading whitespace */
            while (*s && isspace(*s))
                  s++;

            /* skip it if it's a comment line */
            if (*s == ';' || *s == '#')
                  continue;

            /* read up to the = ignoring duplicate spaces */
            p = 0;
            i = 0;
            while (*s && *s != '=') {
                  if (!isspace(*s) && isspace(p))
                        option[i++] = ' ';
                  if (!isspace(*s))
                        option[i++] = tolower(*s);
                  p = *s;
                  s++;
            }
            option[i] = '\0';

            /* skip the = */
            if (*s)
                  s++;

            /* skip leading whitespace */
            while (*s && isspace(*s))
                  s++;

            /* read up to a # ; or null ignoring duplicate spaces */
            p = 0;
            i = 0;
            while (*s && *s != ';' && *s != '#') {
                  if (!isspace(*s) && isspace(p))
                        value[i++] = ' ';
                  if (!isspace(*s))
                        value[i++] = *s;
                  p = *s;
                  s++;
            }
            value[i] = '\0';

            if (!strlen(option))
                  continue;

            if (option[0] == '[') {
                  s = &option[1];
                  while (*s) {
                        if (*s == ']')
                              *s = '\0';
                        *s = tolower(*s);
                        s++;
                  }
                  tdsdump_log(TDS_DBG_INFO1, "%L ... Found section %s.\n", &option[1]);

                  if (!strcasecmp(section, &option[1])) {
                        tdsdump_log(TDS_DBG_INFO1, "%L Got a match.\n");
                        insection = 1;
                        found = 1;
                  } else {
                        insection = 0;
                  }
            } else if (insection) {
                  tds_conf_parse(option, value, param);
            }

      }
      return found;
}


Generated by  Doxygen 1.6.0   Back to index