1 /* configfile.c: parsing of config files
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
9 #include <git-compat-util.h>
10 #include "configfile.h"
12 static int next_char(FILE *f)
25 static void skip_line(FILE *f)
29 while ((c = next_char(f)) && c != '\n' && c != EOF)
33 static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value)
40 /* Skip comments and preceding spaces. */
42 if (c == '#' || c == ';')
49 /* Read variable name. */
51 if (c == '\n' || c == EOF)
53 strbuf_addch(name, c);
57 /* Read variable value. */
59 while (c != '\n' && c != EOF) {
60 strbuf_addch(value, c);
67 int parse_configfile(const char *filename, configfile_value_fn fn)
70 struct strbuf name = STRBUF_INIT;
71 struct strbuf value = STRBUF_INIT;
74 /* cancel deeply nested include-commands */
77 if (!(f = fopen(filename, "r")))
80 while (read_config_line(f, &name, &value))
81 fn(name.buf, value.buf);
84 strbuf_release(&name);
85 strbuf_release(&value);