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
|
/*
** Each entry looks like this:
*/
typedef struct Entry {
int eType;
char *zFunc;
char *zPath;
} Entry;
/*
** Maximum number of entries
*/
#define N_ENTRY 500
/*
** Table of entries
*/
Entry aEntry[N_ENTRY];
/*
** How many entries are used
*/
int nUsed;
int nFixed;
/*
|
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
/*
** Each entry looks like this:
*/
typedef struct Entry {
int eType;
char *zFunc;
char *zPath;
char *zHelp;
} Entry;
/*
** Maximum number of entries
*/
#define N_ENTRY 500
/*
** Maximum size of a help message
*/
#define MX_HELP 10000
/*
** Table of entries
*/
Entry aEntry[N_ENTRY];
/*
** Current help message accumulator
*/
char zHelp[MX_HELP];
int nHelp;
/*
** How many entries are used
*/
int nUsed;
int nFixed;
/*
|
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
|
nUsed++;
}
/*
** Scan a line for a function that implements a web page or command.
*/
void scan_for_func(char *zLine){
int i,j,k;
if( nUsed<=nFixed ) return;
for(i=0; isspace(zLine[i]); i++){}
if( zLine[i]==0 ) return;
if( strncmp(&zLine[i],"void",4)!=0 ){
if( zLine[i]!='*' ) goto page_skip;
return;
}
i += 4;
if( !isspace(zLine[i]) ) goto page_skip;
while( isspace(zLine[i]) ){ i++; }
for(j=0; isalnum(zLine[i+j]) || zLine[i+j]=='_'; j++){}
if( j==0 ) goto page_skip;
for(k=nFixed; k<nUsed; k++){
aEntry[k].zFunc = string_dup(&zLine[i], j);
}
i+=j;
while( isspace(zLine[i]) ){ i++; }
if( zLine[i]!='(' ) goto page_skip;
nFixed = nUsed;
return;
page_skip:
for(i=nFixed; i<nUsed; i++){
fprintf(stderr,"%s:%d: skipping page \"%s\"\n",
zFile, nLine, aEntry[i].zPath);
}
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
nUsed++;
}
/*
** Scan a line for a function that implements a web page or command.
*/
void scan_for_func(char *zLine){
int i,j,k;
char *z;
if( nUsed<=nFixed ) return;
if( strncmp(zLine, "**", 2)==0 && isspace(zLine[2])
&& strlen(zLine)<sizeof(zHelp)-nHelp-1 && nUsed>nFixed ){
if( zLine[2]=='\n' ){
zHelp[nHelp++] = '\n';
}else{
if( strncmp(&zLine[3], "Usage: ", 6)==0 ) nHelp = 0;
strcpy(&zHelp[nHelp], &zLine[3]);
nHelp += strlen(&zHelp[nHelp]);
}
return;
}
for(i=0; isspace(zLine[i]); i++){}
if( zLine[i]==0 ) return;
if( strncmp(&zLine[i],"void",4)!=0 ){
if( zLine[i]!='*' ) goto page_skip;
return;
}
i += 4;
if( !isspace(zLine[i]) ) goto page_skip;
while( isspace(zLine[i]) ){ i++; }
for(j=0; isalnum(zLine[i+j]) || zLine[i+j]=='_'; j++){}
if( j==0 ) goto page_skip;
for(k=nHelp-1; k>=0 && isspace(zHelp[k]); k--){}
nHelp = k+1;
zHelp[nHelp] = 0;
for(k=0; k<nHelp && isspace(zHelp[k]); k++){}
if( k<nHelp ){
z = string_dup(&zHelp[k], nHelp-k);
}else{
z = 0;
}
for(k=nFixed; k<nUsed; k++){
aEntry[k].zFunc = string_dup(&zLine[i], j);
aEntry[k].zHelp = z;
}
i+=j;
while( isspace(zLine[i]) ){ i++; }
if( zLine[i]!='(' ) goto page_skip;
nFixed = nUsed;
nHelp = 0;
return;
page_skip:
for(i=nFixed; i<nUsed; i++){
fprintf(stderr,"%s:%d: skipping page \"%s\"\n",
zFile, nLine, aEntry[i].zPath);
}
|
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
201
202
203
204
205
206
207
|
}
/*
** Build the binary search table.
*/
void build_table(void){
int i;
qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
for(i=0; i<nFixed; i++){
printf("extern void %s(void);\n", aEntry[i].zFunc);
}
printf(
"typedef struct NameMap NameMap;\n"
"struct NameMap {\n"
" const char *zName;\n"
" void (*xFunc)(void);\n"
"};\n"
"static const NameMap aWebpage[] = {\n"
);
for(i=0; i<nFixed && aEntry[i].eType==0; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
printf(
"static const NameMap aCommand[] = {\n"
);
for(; i<nFixed && aEntry[i].eType==1; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
}
/*
** Process a single file of input
*/
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
}
/*
** Build the binary search table.
*/
void build_table(void){
int i;
int nType0;
qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
for(i=0; i<nFixed; i++){
printf("extern void %s(void);\n", aEntry[i].zFunc);
}
printf(
"typedef struct NameMap NameMap;\n"
"struct NameMap {\n"
" const char *zName;\n"
" void (*xFunc)(void);\n"
"};\n"
"static const NameMap aWebpage[] = {\n"
);
for(i=0; i<nFixed && aEntry[i].eType==0; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
nType0 = i;
printf(
"static const NameMap aCommand[] = {\n"
);
for(i=nType0; i<nFixed && aEntry[i].eType==1; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
for(i=nType0; i<nFixed; i++){
char *z = aEntry[i].zHelp;
if( z && z[0] ){
printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
printf(" \"");
while( *z ){
if( *z=='\n' ){
printf("\\n\"\n \"");
}else if( *z=='"' ){
printf("\\\"");
}else{
putchar(*z);
}
z++;
}
printf("\";\n");
aEntry[i].zHelp[0] = 0;
}
}
printf(
"static const char * const aCmdHelp[] = {\n"
);
for(i=nType0; i<nFixed; i++){
if( aEntry[i].zHelp==0 ){
printf(" 0,\n");
}else{
printf(" zHelp_%s,\n", aEntry[i].zFunc);
}
}
printf("};\n");
}
/*
** Process a single file of input
*/
|