1 /* $Id: map.c 6135 2003-01-19 01:15:40Z rra $
15 typedef struct _PAIR {
33 for (mp = MAPdata; mp < MAPend; mp++) {
46 MAPread(const char *name)
57 /* Open file, count lines. */
58 if ((F = fopen(name, "r")) == NULL) {
59 fprintf(stderr, "Can't open %s, %s\n", name, strerror(errno));
62 for (i = 0; fgets(buff, sizeof buff, F) != NULL; i++)
64 mp = MAPdata = xmalloc((i + 1) * sizeof(PAIR));
66 /* Read each line; ignore blank and comment lines. */
67 fseeko(F, 0, SEEK_SET);
68 while (fgets(buff, sizeof buff, F) != NULL) {
69 if ((p = strchr(buff, '\n')) != NULL)
73 || (p = strchr(buff, ':')) == NULL)
77 mp->Key = xstrdup(buff);
78 mp->Value = xstrdup(p);
87 ** Look up a name in the map, return original value if not found.
95 for (c = *p, mp = MAPdata; mp < MAPend; mp++)
96 if (c == mp->First && strcmp(p, mp->Key) == 0)