Unidiff1 files changed, 2 insertions, 2 deletions
|
diff --git a/config.c b/config.c index 858ab69..ee49b62 100644 --- a/ config.c+++ b/ config.c |
|
@@ -1,73 +1,73 @@ |
1 | #include "cgit.h" |
1 | #include "cgit.h" |
2 | |
2 | |
3 | int next_char(FILE *f) |
3 | int next_char(FILE *f) |
4 | { |
4 | { |
5 | int c = fgetc(f); |
5 | int c = fgetc(f); |
6 | if (c=='\r') { |
6 | if (c=='\r') { |
7 | c = fgetc(f); |
7 | c = fgetc(f); |
8 | if (c!='\n') { |
8 | if (c!='\n') { |
9 | ungetc(c, f); |
9 | ungetc(c, f); |
10 | c = '\r'; |
10 | c = '\r'; |
11 | } |
11 | } |
12 | } |
12 | } |
13 | return c; |
13 | return c; |
14 | } |
14 | } |
15 | |
15 | |
16 | void skip_line(FILE *f) |
16 | void skip_line(FILE *f) |
17 | { |
17 | { |
18 | int c; |
18 | int c; |
19 | |
19 | |
20 | while((c=next_char(f)) && c!='\n' && c!=EOF) |
20 | while((c=next_char(f)) && c!='\n' && c!=EOF) |
21 | ; |
21 | ; |
22 | } |
22 | } |
23 | |
23 | |
24 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) |
24 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) |
25 | { |
25 | { |
26 | int i = 0, isname = 0; |
26 | int i = 0, isname = 0; |
27 | |
27 | |
28 | *value = NULL; |
28 | *value = NULL; |
29 | while(i<bufsize-1) { |
29 | while(i<bufsize-1) { |
30 | int c = next_char(f); |
30 | int c = next_char(f); |
31 | if (!isname && (c=='#' || c==';')) { |
31 | if (!isname && (c=='#' || c==';')) { |
32 | skip_line(f); |
32 | skip_line(f); |
33 | continue; |
33 | continue; |
34 | } |
34 | } |
35 | if (!isname && isblank(c)) |
35 | if (!isname && isspace(c)) |
36 | continue; |
36 | continue; |
37 | |
37 | |
38 | if (c=='=' && !*value) { |
38 | if (c=='=' && !*value) { |
39 | line[i] = 0; |
39 | line[i] = 0; |
40 | *value = &line[i+1]; |
40 | *value = &line[i+1]; |
41 | } else if (c=='\n' && !isname) { |
41 | } else if (c=='\n' && !isname) { |
42 | i = 0; |
42 | i = 0; |
43 | continue; |
43 | continue; |
44 | } else if (c=='\n' || c==EOF) { |
44 | } else if (c=='\n' || c==EOF) { |
45 | line[i] = 0; |
45 | line[i] = 0; |
46 | break; |
46 | break; |
47 | } else { |
47 | } else { |
48 | line[i]=c; |
48 | line[i]=c; |
49 | } |
49 | } |
50 | isname = 1; |
50 | isname = 1; |
51 | i++; |
51 | i++; |
52 | } |
52 | } |
53 | line[i+1] = 0; |
53 | line[i+1] = 0; |
54 | return i; |
54 | return i; |
55 | } |
55 | } |
56 | |
56 | |
57 | int cgit_read_config(const char *filename, configfn fn) |
57 | int cgit_read_config(const char *filename, configfn fn) |
58 | { |
58 | { |
59 | int ret = 0, len; |
59 | int ret = 0, len; |
60 | char line[256]; |
60 | char line[256]; |
61 | const char *value; |
61 | const char *value; |
62 | FILE *f = fopen(filename, "r"); |
62 | FILE *f = fopen(filename, "r"); |
63 | |
63 | |
64 | if (!f) |
64 | if (!f) |
65 | return -1; |
65 | return -1; |
66 | |
66 | |
67 | while(len = read_config_line(f, line, &value, sizeof(line))) |
67 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) |
68 | (*fn)(line, value); |
68 | (*fn)(line, value); |
69 | |
69 | |
70 | fclose(f); |
70 | fclose(f); |
71 | return ret; |
71 | return ret; |
72 | } |
72 | } |
73 | |
73 | |
|