author | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 21:40:33 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 21:40:33 (UTC) |
commit | 5ec6e02bd1cc0c05b7cfd0d53371e7d176daec39 (patch) (unidiff) | |
tree | 5c844c0ba53cfd2e838368ffbbd4583ac63d3608 /parsing.c | |
parent | 9ecde6568a9e39c942f4c5585ffa494c5df870e4 (diff) | |
download | cgit-5ec6e02bd1cc0c05b7cfd0d53371e7d176daec39.zip cgit-5ec6e02bd1cc0c05b7cfd0d53371e7d176daec39.tar.gz cgit-5ec6e02bd1cc0c05b7cfd0d53371e7d176daec39.tar.bz2 |
Add include-parameter to config files
This parameter can be used to include another config-file, like
a standalone repository listing.
Suggested in a patch by Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | parsing.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -43,61 +43,63 @@ int read_config_line(FILE *f, char *line, const char **value, int bufsize) | |||
43 | if (!isname && isspace(c)) | 43 | if (!isname && isspace(c)) |
44 | continue; | 44 | continue; |
45 | 45 | ||
46 | if (c=='=' && !*value) { | 46 | if (c=='=' && !*value) { |
47 | line[i] = 0; | 47 | line[i] = 0; |
48 | *value = &line[i+1]; | 48 | *value = &line[i+1]; |
49 | } else if (c=='\n' && !isname) { | 49 | } else if (c=='\n' && !isname) { |
50 | i = 0; | 50 | i = 0; |
51 | continue; | 51 | continue; |
52 | } else if (c=='\n' || c==EOF) { | 52 | } else if (c=='\n' || c==EOF) { |
53 | line[i] = 0; | 53 | line[i] = 0; |
54 | break; | 54 | break; |
55 | } else { | 55 | } else { |
56 | line[i]=c; | 56 | line[i]=c; |
57 | } | 57 | } |
58 | isname = 1; | 58 | isname = 1; |
59 | i++; | 59 | i++; |
60 | } | 60 | } |
61 | line[i+1] = 0; | 61 | line[i+1] = 0; |
62 | return i; | 62 | return i; |
63 | } | 63 | } |
64 | 64 | ||
65 | int cgit_read_config(const char *filename, configfn fn) | 65 | int cgit_read_config(const char *filename, configfn fn) |
66 | { | 66 | { |
67 | int ret = 0, len; | 67 | static int nesting; |
68 | int len; | ||
68 | char line[256]; | 69 | char line[256]; |
69 | const char *value; | 70 | const char *value; |
70 | FILE *f = fopen(filename, "r"); | 71 | FILE *f; |
71 | 72 | ||
72 | if (!f) | 73 | /* cancel the reading of yet another configfile after 16 invocations */ |
74 | if (nesting++ > 16) | ||
75 | return -1; | ||
76 | if (!(f = fopen(filename, "r"))) | ||
73 | return -1; | 77 | return -1; |
74 | |||
75 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) | 78 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) |
76 | (*fn)(line, value); | 79 | (*fn)(line, value); |
77 | |||
78 | fclose(f); | 80 | fclose(f); |
79 | return ret; | 81 | return 0; |
80 | } | 82 | } |
81 | 83 | ||
82 | char *convert_query_hexchar(char *txt) | 84 | char *convert_query_hexchar(char *txt) |
83 | { | 85 | { |
84 | int d1, d2; | 86 | int d1, d2; |
85 | if (strlen(txt) < 3) { | 87 | if (strlen(txt) < 3) { |
86 | *txt = '\0'; | 88 | *txt = '\0'; |
87 | return txt-1; | 89 | return txt-1; |
88 | } | 90 | } |
89 | d1 = hextoint(*(txt+1)); | 91 | d1 = hextoint(*(txt+1)); |
90 | d2 = hextoint(*(txt+2)); | 92 | d2 = hextoint(*(txt+2)); |
91 | if (d1<0 || d2<0) { | 93 | if (d1<0 || d2<0) { |
92 | strcpy(txt, txt+3); | 94 | strcpy(txt, txt+3); |
93 | return txt-1; | 95 | return txt-1; |
94 | } else { | 96 | } else { |
95 | *txt = d1 * 16 + d2; | 97 | *txt = d1 * 16 + d2; |
96 | strcpy(txt+1, txt+3); | 98 | strcpy(txt+1, txt+3); |
97 | return txt; | 99 | return txt; |
98 | } | 100 | } |
99 | } | 101 | } |
100 | 102 | ||
101 | int cgit_parse_query(char *txt, configfn fn) | 103 | int cgit_parse_query(char *txt, configfn fn) |
102 | { | 104 | { |
103 | char *t, *value = NULL, c; | 105 | char *t, *value = NULL, c; |