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. */
44 else if (c == '#' || c == ';')
51 /* Read variable name. */
53 if (c == '\n' || c == EOF)
55 strbuf_addch(name, c);
59 /* Read variable value. */
61 while (c != '\n' && c != EOF) {
62 strbuf_addch(value, c);
69 int parse_configfile(const char *filename, configfile_value_fn fn)
72 struct strbuf name = STRBUF_INIT;
73 struct strbuf value = STRBUF_INIT;
76 /* cancel deeply nested include-commands */
79 if (!(f = fopen(filename, "r")))
82 while (read_config_line(f, &name, &value))
83 fn(name.buf, value.buf);
86 strbuf_release(&name);
87 strbuf_release(&value);