]>
git.cameronkatri.com Git - cgit.git/blob - parsing.c
6cab0e94701fe12f8e0fd6e48d05004d761f113f
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') {
108 char *substr(const char *head
, const char *tail
)
112 buf
= xmalloc(tail
- head
+ 1);
113 strncpy(buf
, head
, tail
- head
);
114 buf
[tail
- head
] = '\0';
118 struct commitinfo
*cgit_parse_commit(struct commit
*commit
)
120 struct commitinfo
*ret
;
121 char *p
= commit
->buffer
, *t
= commit
->buffer
;
123 ret
= xmalloc(sizeof(*ret
));
124 ret
->commit
= commit
;
126 if (strncmp(p
, "tree ", 5))
127 die("Bad commit: %s", sha1_to_hex(commit
->object
.sha1
));
129 p
+= 46; // "tree " + hex[40] + "\n"
131 while (!strncmp(p
, "parent ", 7))
132 p
+= 48; // "parent " + hex[40] + "\n"
134 if (!strncmp(p
, "author ", 7)) {
136 t
= strchr(p
, '<') - 1;
137 ret
->author
= substr(p
, t
);
138 p
= strchr(p
, '\n') + 1;
141 if (!strncmp(p
, "committer ", 9)) {
143 t
= strchr(p
, '<') - 1;
144 ret
->committer
= substr(p
, t
);
145 p
= strchr(p
, '\n') + 1;
149 p
= strchr(p
, '\n') + 1;
152 ret
->subject
= substr(p
, t
);
155 p
= strchr(p
, '\n') + 1;