summaryrefslogtreecommitdiffabout
path: root/config.c
Unidiff
Diffstat (limited to 'config.c') (more/less context) (show whitespace changes)
-rw-r--r--config.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/config.c b/config.c
index ee49b62..871edf2 100644
--- a/config.c
+++ b/config.c
@@ -1,48 +1,56 @@
1/* config.c: parsing of config files
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
1#include "cgit.h" 9#include "cgit.h"
2 10
3int next_char(FILE *f) 11int next_char(FILE *f)
4{ 12{
5 int c = fgetc(f); 13 int c = fgetc(f);
6 if (c=='\r') { 14 if (c=='\r') {
7 c = fgetc(f); 15 c = fgetc(f);
8 if (c!='\n') { 16 if (c!='\n') {
9 ungetc(c, f); 17 ungetc(c, f);
10 c = '\r'; 18 c = '\r';
11 } 19 }
12 } 20 }
13 return c; 21 return c;
14} 22}
15 23
16void skip_line(FILE *f) 24void skip_line(FILE *f)
17{ 25{
18 int c; 26 int c;
19 27
20 while((c=next_char(f)) && c!='\n' && c!=EOF) 28 while((c=next_char(f)) && c!='\n' && c!=EOF)
21 ; 29 ;
22} 30}
23 31
24int read_config_line(FILE *f, char *line, const char **value, int bufsize) 32int read_config_line(FILE *f, char *line, const char **value, int bufsize)
25{ 33{
26 int i = 0, isname = 0; 34 int i = 0, isname = 0;
27 35
28 *value = NULL; 36 *value = NULL;
29 while(i<bufsize-1) { 37 while(i<bufsize-1) {
30 int c = next_char(f); 38 int c = next_char(f);
31 if (!isname && (c=='#' || c==';')) { 39 if (!isname && (c=='#' || c==';')) {
32 skip_line(f); 40 skip_line(f);
33 continue; 41 continue;
34 } 42 }
35 if (!isname && isspace(c)) 43 if (!isname && isspace(c))
36 continue; 44 continue;
37 45
38 if (c=='=' && !*value) { 46 if (c=='=' && !*value) {
39 line[i] = 0; 47 line[i] = 0;
40 *value = &line[i+1]; 48 *value = &line[i+1];
41 } else if (c=='\n' && !isname) { 49 } else if (c=='\n' && !isname) {
42 i = 0; 50 i = 0;
43 continue; 51 continue;
44 } else if (c=='\n' || c==EOF) { 52 } else if (c=='\n' || c==EOF) {
45 line[i] = 0; 53 line[i] = 0;
46 break; 54 break;
47 } else { 55 } else {
48 line[i]=c; 56 line[i]=c;