]>
git.cameronkatri.com Git - cgit.git/blob - parsing.c
1 /* config.c: parsing of config files
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 int next_char(FILE *f
)
24 void skip_line(FILE *f
)
28 while((c
=next_char(f
)) && c
!='\n' && c
!=EOF
)
32 int read_config_line(FILE *f
, char *line
, const char **value
, int bufsize
)
34 int i
= 0, isname
= 0;
39 if (!isname
&& (c
=='#' || c
==';')) {
43 if (!isname
&& isspace(c
))
46 if (c
=='=' && !*value
) {
49 } else if (c
=='\n' && !isname
) {
52 } else if (c
=='\n' || c
==EOF
) {
65 int cgit_read_config(const char *filename
, configfn fn
)
70 FILE *f
= fopen(filename
, "r");
75 while((len
= read_config_line(f
, line
, &value
, sizeof(line
))) > 0)
82 int cgit_parse_query(char *txt
, configfn fn
)
84 char *t
, *value
= NULL
, c
;
89 t
= txt
= xstrdup(txt
);
91 while((c
=*t
) != '\0') {
110 char *substr(const char *head
, const char *tail
)
114 buf
= xmalloc(tail
- head
+ 1);
115 strncpy(buf
, head
, tail
- head
);
116 buf
[tail
- head
] = '\0';
120 struct commitinfo
*cgit_parse_commit(struct commit
*commit
)
122 struct commitinfo
*ret
;
123 char *p
= commit
->buffer
, *t
= commit
->buffer
;
125 ret
= xmalloc(sizeof(*ret
));
126 ret
->commit
= commit
;
128 if (strncmp(p
, "tree ", 5))
129 die("Bad commit: %s", sha1_to_hex(commit
->object
.sha1
));
131 p
+= 46; // "tree " + hex[40] + "\n"
133 while (!strncmp(p
, "parent ", 7))
134 p
+= 48; // "parent " + hex[40] + "\n"
136 if (!strncmp(p
, "author ", 7)) {
138 t
= strchr(p
, '<') - 1;
139 ret
->author
= substr(p
, t
);
141 t
= strchr(t
, '>') + 1;
142 ret
->author_email
= substr(p
, t
);
143 ret
->author_date
= atol(++t
);
144 p
= strchr(t
, '\n') + 1;
147 if (!strncmp(p
, "committer ", 9)) {
149 t
= strchr(p
, '<') - 1;
150 ret
->committer
= substr(p
, t
);
152 t
= strchr(t
, '>') + 1;
153 ret
->committer_email
= substr(p
, t
);
154 ret
->committer_date
= atol(++t
);
155 p
= strchr(t
, '\n') + 1;
159 p
= strchr(p
, '\n') + 1;
162 ret
->subject
= substr(p
, t
);
166 p
= strchr(p
, '\n') + 1;