+#define SWM_CONF_WS "\n= \t"
+#define SWM_CONF_FILE "scrotwm.conf"
+int
+conf_load(char *filename)
+{
+ FILE *config;
+ char *line, *cp, *var, *val;
+ size_t len, lineno = 0;
+
+ DNPRINTF(SWM_D_MISC, "conf_load: filename %s\n", filename);
+
+ if (filename == NULL)
+ return (1);
+
+ if ((config = fopen(filename, "r")) == NULL)
+ return (1);
+
+ for (;;) {
+ if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
+ if (feof(config))
+ break;
+
+ cp = line;
+ cp += (long)strspn(cp, SWM_CONF_WS);
+ if (cp[0] == '\0') {
+ /* empty line */
+ free(line);
+ continue;
+ }
+
+ if ((var = strsep(&cp, SWM_CONF_WS)) == NULL || cp == NULL)
+ break;
+
+ cp += (long)strspn(cp, SWM_CONF_WS);
+ if ((val = strsep(&cp, SWM_CONF_WS)) == NULL)
+ break;
+
+ DNPRINTF(SWM_D_MISC, "conf_load: %s=%s\n",var ,val);
+ switch (var[0]) {
+ case 'b':
+ if (!strncmp(var, "bar_enabled", strlen("bar_enabled")))
+ bar_enabled = atoi(val);
+ else if (!strncmp(var, "bar_border",
+ strlen("bar_border")))
+ bar_border = strtol(val, NULL, 16);
+ else if (!strncmp(var, "bar_color",
+ strlen("bar_color")))
+ bar_color = strtol(val, NULL, 16);
+ else if (!strncmp(var, "bar_font_color",
+ strlen("bar_font_color")))
+ bar_font_color = strtol(val, NULL, 16);
+ else if (!strncmp(var, "bar_font", strlen("bar_font")))
+ asprintf(&bar_fonts[0], "%s", val);
+ else
+ goto bad;
+ break;
+
+ case 'c':
+ if (!strncmp(var, "color_focus", strlen("color_focus")))
+ color_focus = strtol(val, NULL, 16);
+ else if (!strncmp(var, "color_unfocus",
+ strlen("color_unfocus")))
+ color_unfocus = strtol(val, NULL, 16);
+ else
+ goto bad;
+ break;
+
+ case 's':
+ if (!strncmp(var, "spawn_term", strlen("spawn_term")))
+ asprintf(&spawn_term[0], "%s", val); /* XXX args? */
+ break;
+ default:
+ goto bad;
+ }
+
+ free(line);
+ }
+
+ fclose(config);
+ return (0);
+bad:
+ errx(1, "invalid conf file entry: %s=%s", var, val);
+}
+