Fossil SCM

Enhance the mkindex.c utility so that it honors #if statements in the source code.

drh 2011-11-04 18:55 trunk
Commit 1e3cae806885d1ed0d02e1da421e37d28c7bf195
--- src/mkindex.c
+++ src/mkindex.c
@@ -61,10 +61,11 @@
6161
/*
6262
** Each entry looks like this:
6363
*/
6464
typedef struct Entry {
6565
int eType;
66
+ char *zIf;
6667
char *zFunc;
6768
char *zPath;
6869
char *zHelp;
6970
} Entry;
7071
@@ -87,10 +88,15 @@
8788
** Current help message accumulator
8889
*/
8990
char zHelp[MX_HELP];
9091
int nHelp;
9192
93
+/*
94
+** Most recently encountered #if
95
+*/
96
+char zIf[200];
97
+
9298
/*
9399
** How many entries are used
94100
*/
95101
int nUsed;
96102
int nFixed;
@@ -135,10 +141,30 @@
135141
aEntry[nUsed].eType = eType;
136142
aEntry[nUsed].zPath = string_dup(&zLine[i], j);
137143
aEntry[nUsed].zFunc = 0;
138144
nUsed++;
139145
}
146
+
147
+/*
148
+** Check to see if the current line is an #if and if it is, add it to
149
+** the zIf[] string. If the current line is an #endif or #else or #elif
150
+** then cancel the current zIf[] string.
151
+*/
152
+void scan_for_if(const char *zLine){
153
+ int i;
154
+ int len;
155
+ if( zLine[0]!='#' ) return;
156
+ for(i=1; isspace(zLine[i]); i++){}
157
+ if( zLine[i]==0 ) return;
158
+ len = strlen(&zLine[i]);
159
+ if( memcmp(&zLine[i],"if",2)==0 ){
160
+ zIf[0] = '#';
161
+ memcpy(&zIf[1], &zLine[i], len+1);
162
+ }else if( zLine[i]=='e' ){
163
+ zIf[0] = 0;
164
+ }
165
+}
140166
141167
/*
142168
** Scan a line for a function that implements a web page or command.
143169
*/
144170
void scan_for_func(char *zLine){
@@ -179,10 +205,11 @@
179205
z = string_dup(&zHelp[k], nHelp-k);
180206
}else{
181207
z = 0;
182208
}
183209
for(k=nFixed; k<nUsed; k++){
210
+ aEntry[k].zIf = zIf[0] ? string_dup(zIf, -1) : 0;
184211
aEntry[k].zFunc = string_dup(&zLine[i], j);
185212
aEntry[k].zHelp = z;
186213
}
187214
i+=j;
188215
while( isspace(zLine[i]) ){ i++; }
@@ -219,11 +246,13 @@
219246
int i;
220247
int nType0;
221248
222249
qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
223250
for(i=0; i<nFixed; i++){
251
+ if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
224252
printf("extern void %s(void);\n", aEntry[i].zFunc);
253
+ if( aEntry[i].zIf ) printf("#endif\n");
225254
}
226255
printf(
227256
"typedef struct NameMap NameMap;\n"
228257
"struct NameMap {\n"
229258
" const char *zName;\n"
@@ -236,16 +265,18 @@
236265
"static const NameMap aWebpage[] = {\n"
237266
);
238267
for(i=0; i<nFixed && aEntry[i].eType==0; i++){
239268
const char *z = aEntry[i].zPath;
240269
int n = strlen(z);
270
+ if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
241271
printf(" { \"%s\",%*s %s,%*s 1 },\n",
242272
z,
243273
25-n, "",
244274
aEntry[i].zFunc,
245275
(int)(35-strlen(aEntry[i].zFunc)), ""
246276
);
277
+ if( aEntry[i].zIf ) printf("#endif\n");
247278
}
248279
printf("};\n");
249280
nType0 = i;
250281
printf(
251282
"static const NameMap aCommand[] = {\n"
@@ -258,22 +289,25 @@
258289
n--;
259290
cmdFlags = 0x02;
260291
}else if( memcmp(z, "test-", 5)==0 ){
261292
cmdFlags = 0x04;
262293
}
294
+ if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
263295
printf(" { \"%.*s\",%*s %s,%*s %d },\n",
264296
n, z,
265297
25-n, "",
266298
aEntry[i].zFunc,
267299
(int)(35-strlen(aEntry[i].zFunc)), "",
268300
cmdFlags
269301
);
302
+ if( aEntry[i].zIf ) printf("#endif\n");
270303
}
271304
printf("};\n");
272305
for(i=nType0; i<nFixed; i++){
273306
char *z = aEntry[i].zHelp;
274307
if( z && z[0] ){
308
+ if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
275309
printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
276310
printf(" \"");
277311
while( *z ){
278312
if( *z=='\n' ){
279313
printf("\\n\"\n \"");
@@ -283,22 +317,25 @@
283317
putchar(*z);
284318
}
285319
z++;
286320
}
287321
printf("\";\n");
322
+ if( aEntry[i].zIf ) printf("#endif\n");
288323
aEntry[i].zHelp[0] = 0;
289324
}
290325
}
291326
printf(
292327
"static const char * const aCmdHelp[] = {\n"
293328
);
294329
for(i=nType0; i<nFixed; i++){
330
+ if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
295331
if( aEntry[i].zHelp==0 ){
296332
printf(" 0,\n");
297333
}else{
298334
printf(" zHelp_%s,\n", aEntry[i].zFunc);
299335
}
336
+ if( aEntry[i].zIf ) printf("#endif\n");
300337
}
301338
printf("};\n");
302339
}
303340
304341
/*
@@ -312,10 +349,11 @@
312349
return;
313350
}
314351
nLine = 0;
315352
while( fgets(zLine, sizeof(zLine), in) ){
316353
nLine++;
354
+ scan_for_if(zLine);
317355
scan_for_label("WEBPAGE:",zLine,0);
318356
scan_for_label("COMMAND:",zLine,1);
319357
scan_for_func(zLine);
320358
}
321359
fclose(in);
322360
--- src/mkindex.c
+++ src/mkindex.c
@@ -61,10 +61,11 @@
61 /*
62 ** Each entry looks like this:
63 */
64 typedef struct Entry {
65 int eType;
 
66 char *zFunc;
67 char *zPath;
68 char *zHelp;
69 } Entry;
70
@@ -87,10 +88,15 @@
87 ** Current help message accumulator
88 */
89 char zHelp[MX_HELP];
90 int nHelp;
91
 
 
 
 
 
92 /*
93 ** How many entries are used
94 */
95 int nUsed;
96 int nFixed;
@@ -135,10 +141,30 @@
135 aEntry[nUsed].eType = eType;
136 aEntry[nUsed].zPath = string_dup(&zLine[i], j);
137 aEntry[nUsed].zFunc = 0;
138 nUsed++;
139 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141 /*
142 ** Scan a line for a function that implements a web page or command.
143 */
144 void scan_for_func(char *zLine){
@@ -179,10 +205,11 @@
179 z = string_dup(&zHelp[k], nHelp-k);
180 }else{
181 z = 0;
182 }
183 for(k=nFixed; k<nUsed; k++){
 
184 aEntry[k].zFunc = string_dup(&zLine[i], j);
185 aEntry[k].zHelp = z;
186 }
187 i+=j;
188 while( isspace(zLine[i]) ){ i++; }
@@ -219,11 +246,13 @@
219 int i;
220 int nType0;
221
222 qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
223 for(i=0; i<nFixed; i++){
 
224 printf("extern void %s(void);\n", aEntry[i].zFunc);
 
225 }
226 printf(
227 "typedef struct NameMap NameMap;\n"
228 "struct NameMap {\n"
229 " const char *zName;\n"
@@ -236,16 +265,18 @@
236 "static const NameMap aWebpage[] = {\n"
237 );
238 for(i=0; i<nFixed && aEntry[i].eType==0; i++){
239 const char *z = aEntry[i].zPath;
240 int n = strlen(z);
 
241 printf(" { \"%s\",%*s %s,%*s 1 },\n",
242 z,
243 25-n, "",
244 aEntry[i].zFunc,
245 (int)(35-strlen(aEntry[i].zFunc)), ""
246 );
 
247 }
248 printf("};\n");
249 nType0 = i;
250 printf(
251 "static const NameMap aCommand[] = {\n"
@@ -258,22 +289,25 @@
258 n--;
259 cmdFlags = 0x02;
260 }else if( memcmp(z, "test-", 5)==0 ){
261 cmdFlags = 0x04;
262 }
 
263 printf(" { \"%.*s\",%*s %s,%*s %d },\n",
264 n, z,
265 25-n, "",
266 aEntry[i].zFunc,
267 (int)(35-strlen(aEntry[i].zFunc)), "",
268 cmdFlags
269 );
 
270 }
271 printf("};\n");
272 for(i=nType0; i<nFixed; i++){
273 char *z = aEntry[i].zHelp;
274 if( z && z[0] ){
 
275 printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
276 printf(" \"");
277 while( *z ){
278 if( *z=='\n' ){
279 printf("\\n\"\n \"");
@@ -283,22 +317,25 @@
283 putchar(*z);
284 }
285 z++;
286 }
287 printf("\";\n");
 
288 aEntry[i].zHelp[0] = 0;
289 }
290 }
291 printf(
292 "static const char * const aCmdHelp[] = {\n"
293 );
294 for(i=nType0; i<nFixed; i++){
 
295 if( aEntry[i].zHelp==0 ){
296 printf(" 0,\n");
297 }else{
298 printf(" zHelp_%s,\n", aEntry[i].zFunc);
299 }
 
300 }
301 printf("};\n");
302 }
303
304 /*
@@ -312,10 +349,11 @@
312 return;
313 }
314 nLine = 0;
315 while( fgets(zLine, sizeof(zLine), in) ){
316 nLine++;
 
317 scan_for_label("WEBPAGE:",zLine,0);
318 scan_for_label("COMMAND:",zLine,1);
319 scan_for_func(zLine);
320 }
321 fclose(in);
322
--- src/mkindex.c
+++ src/mkindex.c
@@ -61,10 +61,11 @@
61 /*
62 ** Each entry looks like this:
63 */
64 typedef struct Entry {
65 int eType;
66 char *zIf;
67 char *zFunc;
68 char *zPath;
69 char *zHelp;
70 } Entry;
71
@@ -87,10 +88,15 @@
88 ** Current help message accumulator
89 */
90 char zHelp[MX_HELP];
91 int nHelp;
92
93 /*
94 ** Most recently encountered #if
95 */
96 char zIf[200];
97
98 /*
99 ** How many entries are used
100 */
101 int nUsed;
102 int nFixed;
@@ -135,10 +141,30 @@
141 aEntry[nUsed].eType = eType;
142 aEntry[nUsed].zPath = string_dup(&zLine[i], j);
143 aEntry[nUsed].zFunc = 0;
144 nUsed++;
145 }
146
147 /*
148 ** Check to see if the current line is an #if and if it is, add it to
149 ** the zIf[] string. If the current line is an #endif or #else or #elif
150 ** then cancel the current zIf[] string.
151 */
152 void scan_for_if(const char *zLine){
153 int i;
154 int len;
155 if( zLine[0]!='#' ) return;
156 for(i=1; isspace(zLine[i]); i++){}
157 if( zLine[i]==0 ) return;
158 len = strlen(&zLine[i]);
159 if( memcmp(&zLine[i],"if",2)==0 ){
160 zIf[0] = '#';
161 memcpy(&zIf[1], &zLine[i], len+1);
162 }else if( zLine[i]=='e' ){
163 zIf[0] = 0;
164 }
165 }
166
167 /*
168 ** Scan a line for a function that implements a web page or command.
169 */
170 void scan_for_func(char *zLine){
@@ -179,10 +205,11 @@
205 z = string_dup(&zHelp[k], nHelp-k);
206 }else{
207 z = 0;
208 }
209 for(k=nFixed; k<nUsed; k++){
210 aEntry[k].zIf = zIf[0] ? string_dup(zIf, -1) : 0;
211 aEntry[k].zFunc = string_dup(&zLine[i], j);
212 aEntry[k].zHelp = z;
213 }
214 i+=j;
215 while( isspace(zLine[i]) ){ i++; }
@@ -219,11 +246,13 @@
246 int i;
247 int nType0;
248
249 qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
250 for(i=0; i<nFixed; i++){
251 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
252 printf("extern void %s(void);\n", aEntry[i].zFunc);
253 if( aEntry[i].zIf ) printf("#endif\n");
254 }
255 printf(
256 "typedef struct NameMap NameMap;\n"
257 "struct NameMap {\n"
258 " const char *zName;\n"
@@ -236,16 +265,18 @@
265 "static const NameMap aWebpage[] = {\n"
266 );
267 for(i=0; i<nFixed && aEntry[i].eType==0; i++){
268 const char *z = aEntry[i].zPath;
269 int n = strlen(z);
270 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
271 printf(" { \"%s\",%*s %s,%*s 1 },\n",
272 z,
273 25-n, "",
274 aEntry[i].zFunc,
275 (int)(35-strlen(aEntry[i].zFunc)), ""
276 );
277 if( aEntry[i].zIf ) printf("#endif\n");
278 }
279 printf("};\n");
280 nType0 = i;
281 printf(
282 "static const NameMap aCommand[] = {\n"
@@ -258,22 +289,25 @@
289 n--;
290 cmdFlags = 0x02;
291 }else if( memcmp(z, "test-", 5)==0 ){
292 cmdFlags = 0x04;
293 }
294 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
295 printf(" { \"%.*s\",%*s %s,%*s %d },\n",
296 n, z,
297 25-n, "",
298 aEntry[i].zFunc,
299 (int)(35-strlen(aEntry[i].zFunc)), "",
300 cmdFlags
301 );
302 if( aEntry[i].zIf ) printf("#endif\n");
303 }
304 printf("};\n");
305 for(i=nType0; i<nFixed; i++){
306 char *z = aEntry[i].zHelp;
307 if( z && z[0] ){
308 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
309 printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
310 printf(" \"");
311 while( *z ){
312 if( *z=='\n' ){
313 printf("\\n\"\n \"");
@@ -283,22 +317,25 @@
317 putchar(*z);
318 }
319 z++;
320 }
321 printf("\";\n");
322 if( aEntry[i].zIf ) printf("#endif\n");
323 aEntry[i].zHelp[0] = 0;
324 }
325 }
326 printf(
327 "static const char * const aCmdHelp[] = {\n"
328 );
329 for(i=nType0; i<nFixed; i++){
330 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
331 if( aEntry[i].zHelp==0 ){
332 printf(" 0,\n");
333 }else{
334 printf(" zHelp_%s,\n", aEntry[i].zFunc);
335 }
336 if( aEntry[i].zIf ) printf("#endif\n");
337 }
338 printf("};\n");
339 }
340
341 /*
@@ -312,10 +349,11 @@
349 return;
350 }
351 nLine = 0;
352 while( fgets(zLine, sizeof(zLine), in) ){
353 nLine++;
354 scan_for_if(zLine);
355 scan_for_label("WEBPAGE:",zLine,0);
356 scan_for_label("COMMAND:",zLine,1);
357 scan_for_func(zLine);
358 }
359 fclose(in);
360
--- src/winhttp.c
+++ src/winhttp.c
@@ -848,15 +848,6 @@
848848
" create delete show start stop");
849849
}
850850
return;
851851
}
852852
853
-#else /* _WIN32 -- This code is for win32 only */
854
-#include "winhttp.h"
855
-
856
-void cmd_win32_service(void){
857
- fossil_fatal("The winsrv command is platform specific "
858
- "and not available on this platform.");
859
- return;
860
-}
861
-
862853
#endif /* _WIN32 -- This code is for win32 only */
863854
--- src/winhttp.c
+++ src/winhttp.c
@@ -848,15 +848,6 @@
848 " create delete show start stop");
849 }
850 return;
851 }
852
853 #else /* _WIN32 -- This code is for win32 only */
854 #include "winhttp.h"
855
856 void cmd_win32_service(void){
857 fossil_fatal("The winsrv command is platform specific "
858 "and not available on this platform.");
859 return;
860 }
861
862 #endif /* _WIN32 -- This code is for win32 only */
863
--- src/winhttp.c
+++ src/winhttp.c
@@ -848,15 +848,6 @@
848 " create delete show start stop");
849 }
850 return;
851 }
852
 
 
 
 
 
 
 
 
 
853 #endif /* _WIN32 -- This code is for win32 only */
854

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button