Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/bx-conf/load.c
1069 views
1
2
3
void init_default()
4
{
5
int i;
6
for (i = 0; compile_default[i].option; i++)
7
compile_default[i].integer = 0;
8
for (i = 0; dcc_default[i].option; i++)
9
dcc_default[i].integer = 0;
10
for (i = 0; server_default[i].option; i++)
11
server_default[i].integer = 0;
12
for (i = 0; userlist_default[i].option; i++)
13
userlist_default[i].integer = 0;
14
for (i = 0; flood_default[i].option; i++)
15
flood_default[i].integer = 0;
16
for (i = 0; various_default[i].option; i++)
17
various_default[i].integer = 0;
18
19
}
20
21
char def[] = "#define ";
22
int load_file(char *filename)
23
{
24
FILE *out = NULL;
25
char buf[200];
26
int dlen = strlen(def);
27
char *p, *value, *define;
28
int i, found = 0;
29
int init = 0;
30
if (!(out = fopen(filename, "r")))
31
return 0;
32
while(!feof(out))
33
{
34
found = 0;
35
if (!(fgets(buf, 100, out)))
36
break;
37
if ((p = strchr(buf, '\n')))
38
*p = 0;
39
if ((p = strchr(buf, '\r')))
40
*p = 0;
41
if (!buf[0])
42
continue;
43
if (!init)
44
{
45
init_default();
46
init++;
47
}
48
if (strncmp(buf, def, dlen))
49
continue;
50
/* got a #define lets break it down. */
51
define = buf;
52
if ((p = strchr(buf, ' ')))
53
*p++ = 0;
54
define = p;
55
if ((p = strchr(define, ' ')))
56
*p++ = 0;
57
while (p && strchr(" \t", *p))
58
p++;
59
value = p;
60
if (!value || !define || !*define || !*value)
61
continue;
62
for (i = 0; compile_default[i].option; i++)
63
{
64
if (!strcmp(compile_default[i].out, define))
65
{
66
if (isdigit(*value))
67
compile_default[i].integer = strtoul(value, NULL, 10);
68
found++;
69
break;
70
}
71
}
72
if (found) continue;
73
for (i = 0; dcc_default[i].option; i++)
74
{
75
if (!strcmp(dcc_default[i].out, define))
76
{
77
if (isdigit(*value))
78
dcc_default[i].integer = strtoul(value, NULL, 10);
79
found++;
80
break;
81
}
82
}
83
if (found) continue;
84
for (i = 0; server_default[i].option; i++)
85
{
86
if (!strcmp(server_default[i].out, define))
87
{
88
if (isdigit(*value))
89
server_default[i].integer = strtoul(value, NULL, 10);
90
found++;
91
break;
92
}
93
}
94
if (found) continue;
95
for (i = 0; userlist_default[i].option; i++)
96
{
97
if (!strcmp(userlist_default[i].out, define))
98
{
99
if (isdigit(*value))
100
userlist_default[i].integer = strtoul(value, NULL, 10);
101
found++;
102
break;
103
}
104
}
105
if (found) continue;
106
for (i = 0; flood_default[i].option; i++)
107
{
108
if (!strcmp(flood_default[i].out, define))
109
{
110
if (isdigit(*value))
111
flood_default[i].integer = strtoul(value, NULL, 10);
112
found++;
113
break;
114
}
115
}
116
if (found) continue;
117
for (i = 0; various_default[i].option; i++)
118
{
119
if (!strcmp(various_default[i].out, define))
120
{
121
if (isdigit(*value))
122
various_default[i].integer = strtoul(value, NULL, 10);
123
found++;
124
break;
125
}
126
}
127
}
128
fclose(out);
129
return TRUE;
130
}
131
132