- /* Read in the config file one line at a time and parse it
- XXX doesn't deal with lines longer than MAXLINE */
- while (fgets(buf, MAXLINE, fp)) {
- /* skip comments */
- if (buf[0] == '#')
- continue;
- /* look for the = in the line */
- if (!(tmp = strchr(buf, '=')))
- continue;
-
- /* split the line into parameter (before =, in buf) and
- value (after =, in value) */
- if (!(value = calloc(strlen(tmp+1)+1, sizeof(char))))
- goto out;
- strncpy(value, tmp+1, strlen(tmp+1));
- value[strlen(tmp+1)] = '\0';
- /* scribble over the = in buf with a \0 -- that makes buf
- just the parameter name */
- *tmp = '\0';
- /* if we find a newline in value, replace that with a \0 too */
- if ((tmp = strchr(value, '\n')))
- *tmp = '\0';
-
- if (!strcmp(buf, "continuous_mode")) {
- ctx.continuous_mode = atoi(value);
- free(value);
- } else if (!strcmp(buf, "default_browser")) {
- if (!default_browser)
- default_browser = value;
- } else if (!strcmp(buf, "other_browser_cmd")) {
- if (!ctx.other_browser_cmd)
- ctx.other_browser_cmd = value;
- } else {
- /* Don't need this line's contents */
- free(value);
+ /* Parse the config file
+ TODO: should we handle errors differently than EOF? */
+ if (!parse_config_file_begin())
+ goto out;
+ while (!parse_config_file_line(fp, &line)) {
+ if (line.parsed) {
+ if (!strcmp(line.key, "continuous_mode")) {
+ if (!continuous_mode_seen) {
+ ctx.continuous_mode = atoi(line.value);
+ continuous_mode_seen = 1;
+ }
+ free(line.value);
+ } else if (!strcmp(line.key, "default_browser")) {
+ if (!default_browser)
+ default_browser = line.value;
+ } else if (!strcmp(line.key, "other_browser_cmd")) {
+ if (!ctx.other_browser_cmd)
+ ctx.other_browser_cmd = line.value;
+ } else {
+ /* Don't need this line's contents */
+ free(line.value);
+ }