static char * get_map_value ( char *map_file, /* Name of map file */ char *request_point /* Point coordinates */ ) { static char buffer [LINE_MAX], /* Buffer for map file line */ url [LINE_MAX], /* Buffer to store URL */ default_url [LINE_MAX]; /* Default URL value for the map */ char *full_uri; /* Full URI */ FILE *file; int point_x = 0, /* Used only for sscanf */ point_y = 0; ASSERT (map_file); strclr (url); strclr (default_url); file = file_open (map_file, 'r'); if (file) { /* Get the coodinates of point */ if (request_point) sscanf (request_point, "%d,%d", &point_x, &point_y); /* Note: The first line of map sets the value url_def */ while (file_readn (file, buffer, LINE_MAX)) { /* Ignore comments and blank lines */ if ((buffer [0] == '#') || strnull (buffer)) continue; point_in_map_element (buffer, url, point_x, point_y, default_url); if (strused (url)) break; } /* If not found a URL, set the return with the default value */ if (strnull (url)) strcpy (url, default_url); file_close (file); } /* Return final URL string, or NULL if we did not find anything */ if (strused (url)) { full_uri = build_full_url (url, map_file); strcpy (url, full_uri); mem_free (full_uri); return (url); } else return (NULL); }
Bool ini_scan_section ( FILE *inifile, char **keyword, char **value) { int remaining; /* Space remaining in line buffer */ char *first, *valueptr, *lineptr; /* Read through file until we find what we are looking for */ while (file_read (inifile, iniline)) { strcrop (iniline); if (strnull (iniline)) continue; /* Skip empty lines */ /* Calculate space remaining in buffer after this line; we need to * know this later if we start reading continuation lines. */ remaining = LINE_MAX - strlen (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 /* Have name = value */ if (sscanf (first, "[%[^]]", ini_section) == 1) { *keyword = strlwc (ini_section); *value = NULL; 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 (*first == '"') { /* Name in quotes */ valueptr = strchr (first + 1, '"'); if (valueptr) { first++; *valueptr = ' '; valueptr = strchr (valueptr + 1, '='); } } else valueptr = strchr (first, '='); if (valueptr == NULL) { coprintf ("E: illegal definition in ini file"); return (FALSE); } *valueptr++ = '\0'; strcpy (ini_keyword, strcrop (strlwc (first))); while (*valueptr == ' ') valueptr++; /* and leading spaces */ if (*valueptr == '"') { /* Have value in quotes */ /* Get continuation lines as necessary and possible */ first = &strlast (valueptr); while (*first == '-' && remaining > 0) { if (!file_readn (inifile, first, remaining)) break; /* Abrubt end of file */ strcrop (first); remaining -= strlen (first) - 1; first += strlen (first) - 1; } /* Now find closing quote and terminate value there */ for (lineptr = valueptr + 1; *lineptr; lineptr++) { if (*lineptr == '\\') lineptr++; /* Ignore next char */ else if (*lineptr == '"') { lineptr [1] = '\0'; break; /* Closing quote, end of value */ } } } else { /* Have unquoted value */ strconvch (valueptr, ';', '\0'); strconvch (valueptr, '#', '\0'); } strcrop (valueptr); strcpy (ini_value, valueptr); *keyword = ini_keyword; *value = ini_value; return (TRUE); /* Found keyword = value */ } } *keyword = NULL; return (FALSE); /* End of file */ }