void inifile (char *execex, char *filename) { char exec [1024]; int cline = 0; char section [1024]; char base [1024], *line; int length; FILE *file; file = fopen (filename, "rt"); if (file == NULL) return; strcpy (exec, execex); length = strlen (exec); while (length >= 0) { if (exec [length - 1] == '/' || exec [length - 1] == '\\') { exec [length - 1] = '\0';//'/'; break; } exec [-- length] = '\0'; } while (fgets (base, sizeof (base), file) != NULL) { cline += 1; line = base; while (isspace (*line)) line ++; length = strlen (line); if (line [length - 1] != '\n') fail_at (filename, cline, "ini file line is too long"); while (length && isspace (line [length - 1])) line [-- length] = '\0'; if (!length) continue; if (line [0] == ';') ; else if (line [0] == '[') { if (line [length - 1] != ']') fail_at (filename, cline, "expected \"]\" at the end of the section line"); memmove (section, line + 1, length - 2); section [length - 2] = '\0'; if (strcasecmp (section, "Version") && strcasecmp (section, "Environment")) fail_at (filename, cline, "unknown section %s in ini file", section); } else { char word [1024]; char value [1024]; char *sep, *beg; /* Get the = separator and the word */ sep = strchr (line, '='); if (sep == NULL) fail_at (filename, cline, "badly formed value set"); for (beg = sep; beg > line && isspace (beg [-1]); beg --) { } memmove (word, line, (int) (beg - line)); word [(int) (beg - line)] = '\0'; /* Find the value */ for (beg = sep + 1; isspace (*beg); beg ++) { } strcpy (value, beg); /* Remove the double quote if any */ length = strlen (value); if (value [0] == '\"') { if (value [length - 1] != '\"') fail_at (filename, cline, "unterminated string constant"); value [length - 1] = '\0'; strcpy (value, value + 1); } /* Expand %@P% */ for (beg = value; *beg != '\0'; beg ++) { if (memcmp (beg, "%@P%", 4)) continue; int elen = strlen (exec); memmove (beg + elen + (elen <= 4 ? 0 : 4), beg + 4, strlen (beg) - 3); memmove (beg, exec, elen); } if (!strcasecmp (section, "version")) { if (!strcasecmp (word, "version")) { } else fail_at (filename, cline, "unhandled section %s command %s = \"%s\"", section, word, value); } else if (!strcasecmp (section, "environment")) { if (!strcasecmp (word, "dflags")) setenv ("DFLAGS", value, 1); else fail_at (filename, cline, "unhandled section %s command %s = \"%s\"", section, word, value); } else fail_at (filename, cline, "unhandled section %s command %s = \"%s\"", section, word, value); } } }