]>
git.cameronkatri.com Git - cgit.git/blob - configfile.c
1 /* configfile.c: parsing of config files
3 * Copyright (C) 2008 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 #include "configfile.h"
13 int next_char(FILE *f
)
26 void skip_line(FILE *f
)
30 while((c
=next_char(f
)) && c
!='\n' && c
!=EOF
)
34 int read_config_line(FILE *f
, char *line
, const char **value
, int bufsize
)
36 int i
= 0, isname
= 0;
41 if (!isname
&& (c
=='#' || c
==';')) {
45 if (!isname
&& isspace(c
))
48 if (c
=='=' && !*value
) {
51 } else if (c
=='\n' && !isname
) {
54 } else if (c
=='\n' || c
==EOF
) {
67 int parse_configfile(const char *filename
, configfile_value_fn fn
)
75 /* cancel deeply nested include-commands */
78 if (!(f
= fopen(filename
, "r")))
81 while((len
= read_config_line(f
, line
, &value
, sizeof(line
))) > 0)