1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
static const config_opt config_opts[] = {
{"git-root", "Root of git server (can also be a url).", TYPE_STRING, &get_git_root},
{"socket-type", "Socket type to use (options: unix, network. default: network).", TYPE_STRING, &get_sock_type},
{"socket", "Path, IP address, or domain name of socket.", TYPE_STRING, &get_sock},
{"port", "Port to listen on (network socket only).", TYPE_INT, &get_sock_port},
{"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", TYPE_INT, &get_merge_type},
{"pr-root", "Directory to store pull requests in.", TYPE_STRING, &pr_root},
{"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", TYPE_STRING, &get_key_path},
};
char *read_file(const char *filename, long *size) {
FILE *fp = fopen(filename, "r");
long filesize = 0;
char *buf;
if (fp == NULL) {
fclose(fp);
return NULL;
}
if (fseek(fp, 0L, SEEK_END)) {
fclose(fp);
return NULL;
}
filesize = ftell(fp);
if (filesize < 0) {
fclose(fp);
return NULL;
}
buf = malloc(filesize+1);
if (buf == NULL) {
fclose(fp);
free(cfg);
return NULL;
}
memset(buf, 0, filesize+1);
rewind(fp);
fread(buf, sizeof(char), filesize, fp);
fclose(fp);
*size = filesize;
return buf;
}
char *find_line(char *str) {
for (; *str != '\n' && *str != '\0'; str++);
return str;
}
config *parse_config(const char *filename) {
long filesize = 0;
config *cfg;
char *buf = read_file(filename, &filesize);
if (buf == NULL) {
return NULL;
}
cfg = malloc(sizeof(config));
if (cfg == NULL) {
free(buf);
return NULL;
}
for (; *buf != '\0'; buf = find_line(buf)) {
char *value;
char *name = strtok_r(buf, "=", &value);
}
}
|