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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#include "gen.h"
#include "version.h"
#include "parse.h"
#include "opt.h"
#include <time.h>
#include <assert.h>
#include "gen-consts.h"
void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar)
{
time_t t;
struct tm *ti;
struct parse_deftype_s *dcur, *dtmp;
struct parse_var_s *vcur, *vtmp;
unsigned i;
time(&t);
ti = localtime(&t);
/********
* HEAD *
********/
fprintf(f, "/* generated by %s on %04d-%02d-%02d */\n",
VERSION, ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday);
fprintf(f, sheadp1);
fprintf(f, sheadp2);
if (ar.uses_type[PARSE_TYPE_BOOL])
fprintf(f, sbool);
if (ar.uses_type[PARSE_TYPE_STRING])
fprintf(f, sstring);
if (ar.uses_type[PARSE_TYPE_INT])
fprintf(f, sint);
if (ar.uses_type[PARSE_TYPE_INTL])
fprintf(f, sintl);
if (ar.uses_type[PARSE_TYPE_INTLL])
fprintf(f, sintll);
if (ar.uses_type[PARSE_TYPE_UINT])
fprintf(f, suint);
if (ar.uses_type[PARSE_TYPE_UINTL])
fprintf(f, suintl);
if (ar.uses_type[PARSE_TYPE_UINTLL])
fprintf(f, suintll);
if (ar.uses_type[PARSE_TYPE_FLOAT])
fprintf(f, sfloat);
if (ar.uses_type[PARSE_TYPE_DOUBLE])
fprintf(f, sdouble);
if (ar.uses_type[PARSE_TYPE_DOUBLEL])
fprintf(f, sdoublel);
/* if (ar.uses_array) */
/* fprintf(f, sarray); */
if (ar.uses_hash)
fprintf(f, shash, (opt_header_str() ? opt_header_str() : pr.header));
/********
* BODY *
********/
fprintf(f,
"#ifndef CONFCONF_BODY_%s_H\n"
"#define CONFCONF_BODY_%s_H\n\n",
(opt_suffix_str() ? opt_suffix_str() : pr.suffix),
(opt_suffix_str() ? opt_suffix_str() : pr.suffix)
);
/* deftypes */
HASH_ITER(hh, pr.deftypes, dcur, dtmp) {
if (!dcur->is_used)
continue;
fprintf(f, "%s confconf_type_%s_%s {\n",
(dcur->type == PARSE_DEFTYPE_ENUM ? "enum" :
(dcur->type == PARSE_DEFTYPE_UNION ?
"union" : "struct")
),
dcur->name,
(opt_suffix_str() ? opt_suffix_str() : pr.suffix)
);
for (i = 0; i < dcur->member_list_len; i++) {
if (dcur->type == PARSE_DEFTYPE_ENUM) {
fprintf(f, " CONFCONF_TYPE_%s_%s_%s,\n",
dcur->name,
dcur->member_name_list[i],
(opt_suffix_str() ? opt_suffix_str() : pr.suffix)
);
continue;
}
switch (dcur->member_type_list[i]) {
case PARSE_TYPE_BOOL:
fprintf(f, " bool ");
break;
case PARSE_TYPE_STRING:
fprintf(f, " char *");
break;
case PARSE_TYPE_ID:
fprintf(f, " char *");
break;
case PARSE_TYPE_INT:
fprintf(f, " int ");
break;
case PARSE_TYPE_INTL:
fprintf(f, " long int ");
break;
case PARSE_TYPE_INTLL:
fprintf(f, " long long int ");
break;
case PARSE_TYPE_UINT:
fprintf(f, " unsigned ");
break;
case PARSE_TYPE_UINTL:
fprintf(f, " long unsigned ");
break;
case PARSE_TYPE_UINTLL:
fprintf(f, " long long unsigned ");
break;
case PARSE_TYPE_FLOAT:
fprintf(f, " float ");
break;
case PARSE_TYPE_DOUBLE:
fprintf(f, " double ");
break;
case PARSE_TYPE_DOUBLEL:
fprintf(f, " long double ");
break;
default:
assert(0);
}
fprintf(f, "%s;\n", dcur->member_name_list[i]);
}
fprintf(f, "};\n\n");
}
/* hash type */
if (ar.uses_hash) {
fprintf(f,
"#include %s\n\n"
"struct confconf_hash_%s {\n"
" char *key;\n"
" union {\n"
"%s%s%s%s%s%s%s%s%s%s%s",
(opt_header_str() ? opt_header_str() : pr.header),
(opt_suffix_str() ? opt_suffix_str() : pr.suffix),
(ar.uses_type[PARSE_TYPE_HASH_BOOL]
? " bool b;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_STRING]
? " char *s;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_INT]
? " int i;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_INTL]
? " long int il;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_INTLL]
? " long long int ill;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_UINT]
? " unsigned u;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_UINTL]
? " long unsigned ul;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_UINTLL]
? " long long unsigned ull;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_FLOAT]
? " float f;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_DOUBLE]
? " double d;\n" : ""),
(ar.uses_type[PARSE_TYPE_HASH_DOUBLEL]
? " long double dl;\n" : "")
);
HASH_ITER(hh, pr.deftypes, dcur, dtmp) {
if (dcur->is_used && dcur->is_in_hash) {
fprintf(f, " %s confconf_type_%s_%s type_%s;\n",
(dcur->type == PARSE_DEFTYPE_ENUM ? "enum" :
(dcur->type == PARSE_DEFTYPE_UNION ?
"union" : "struct")
),
dcur->name,
(opt_suffix_str() ? opt_suffix_str() : pr.suffix),
dcur->name
);
}
}
fprintf(f,
" } val;\n"
" UT_hash_handle hh;\n"
"};\n\n"
);
}
fprintf(f, "#endif\n");
}
|