Check-in [1e3cae8068]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance the mkindex.c utility so that it honors #if statements in the source code.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e3cae806885d1ed0d02e1da421e37d28c7bf195
User & Date: drh 2011-11-04 18:55:21.537
References
2011-11-04
19:39
merged in trunk [1e3cae806885d] and set up the json command/page to be elided when FOSSIL_DISABLE_JSON is defined at build time. check-in: 44bba06ce6 user: json-demo tags: json-multitag-test, json
Context
2011-11-04
19:39
merged in trunk [1e3cae806885d] and set up the json command/page to be elided when FOSSIL_DISABLE_JSON is defined at build time. check-in: 44bba06ce6 user: json-demo tags: json-multitag-test, json
19:10
Merge the steveb-fixes branch into trunk. check-in: aeec10b900 user: drh tags: trunk
18:55
Enhance the mkindex.c utility so that it honors #if statements in the source code. check-in: 1e3cae8068 user: drh tags: trunk
17:59
Remove the "commands" command and replace it with --all, --aux, and --test options to the "help" command. check-in: d6a93abf2c user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/mkindex.c.
59
60
61
62
63
64
65

66
67
68
69
70
71
72
#include <string.h>

/*
** Each entry looks like this:
*/
typedef struct Entry {
  int eType;

  char *zFunc;
  char *zPath;
  char *zHelp;
} Entry;

/*
** Maximum number of entries







>







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <string.h>

/*
** Each entry looks like this:
*/
typedef struct Entry {
  int eType;
  char *zIf;
  char *zFunc;
  char *zPath;
  char *zHelp;
} Entry;

/*
** Maximum number of entries
85
86
87
88
89
90
91





92
93
94
95
96
97
98

/*
** Current help message accumulator
*/
char zHelp[MX_HELP];
int nHelp;






/*
** How many entries are used
*/
int nUsed;
int nFixed;

/*







>
>
>
>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

/*
** Current help message accumulator
*/
char zHelp[MX_HELP];
int nHelp;

/*
** Most recently encountered #if
*/
char zIf[200];

/*
** How many entries are used
*/
int nUsed;
int nFixed;

/*
133
134
135
136
137
138
139




















140
141
142
143
144
145
146
  if( zLine[i]=='/' ) i++;
  for(j=0; zLine[i+j] && !isspace(zLine[i+j]); j++){}
  aEntry[nUsed].eType = eType;
  aEntry[nUsed].zPath = string_dup(&zLine[i], j);
  aEntry[nUsed].zFunc = 0;
  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;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
  if( zLine[i]=='/' ) i++;
  for(j=0; zLine[i+j] && !isspace(zLine[i+j]); j++){}
  aEntry[nUsed].eType = eType;
  aEntry[nUsed].zPath = string_dup(&zLine[i], j);
  aEntry[nUsed].zFunc = 0;
  nUsed++;
}

/*
** Check to see if the current line is an #if and if it is, add it to
** the zIf[] string.  If the current line is an #endif or #else or #elif
** then cancel the current zIf[] string.
*/
void scan_for_if(const char *zLine){
  int i;
  int len;
  if( zLine[0]!='#' ) return;
  for(i=1; isspace(zLine[i]); i++){}
  if( zLine[i]==0 ) return;
  len = strlen(&zLine[i]);
  if( memcmp(&zLine[i],"if",2)==0 ){
    zIf[0] = '#';
    memcpy(&zIf[1], &zLine[i], len+1);
  }else if( zLine[i]=='e' ){
    zIf[0] = 0;
  }
}

/*
** 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;
177
178
179
180
181
182
183

184
185
186
187
188
189
190
  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;







>







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  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].zIf = zIf[0] ? string_dup(zIf, -1) : 0;
    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;
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

275
276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294

295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
*/
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"
    "  char cmdFlags;\n"
    "};\n"
    "#define CMDFLAG_1ST_TIER  0x01\n"
    "#define CMDFLAG_2ND_TIER  0x02\n"
    "#define CMDFLAG_TEST      0x04\n"
    "static const NameMap aWebpage[] = {\n"
  );
  for(i=0; i<nFixed && aEntry[i].eType==0; i++){
    const char *z = aEntry[i].zPath;
    int n = strlen(z);

    printf("  { \"%s\",%*s %s,%*s 1 },\n",
      z,
      25-n, "",
      aEntry[i].zFunc,
      (int)(35-strlen(aEntry[i].zFunc)), ""
    );

  }
  printf("};\n");
  nType0 = i;
  printf(
    "static const NameMap aCommand[] = {\n"
  );
  for(i=nType0; i<nFixed && aEntry[i].eType==1; i++){
    const char *z = aEntry[i].zPath;
    int n = strlen(z);
    int cmdFlags = 0x01;
    if( z[n-1]=='*' ){
      n--;
      cmdFlags = 0x02;
    }else if( memcmp(z, "test-", 5)==0 ){
      cmdFlags = 0x04;
    }

    printf("  { \"%.*s\",%*s %s,%*s %d },\n",
      n, z,
      25-n, "",
      aEntry[i].zFunc,
      (int)(35-strlen(aEntry[i].zFunc)), "",
      cmdFlags
    );

  }
  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
*/
void process_file(void){
  FILE *in = fopen(zFile, "r");
  char zLine[2000];
  if( in==0 ){
    fprintf(stderr,"%s: cannot open\n", zFile);
    return;
  }
  nLine = 0;
  while( fgets(zLine, sizeof(zLine), in) ){
    nLine++;

    scan_for_label("WEBPAGE:",zLine,0);
    scan_for_label("COMMAND:",zLine,1);
    scan_for_func(zLine);
  }
  fclose(in);
  nUsed = nFixed; 
}







>

>
















>






>
















>







>





>













>







>





>

















>







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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
*/
void build_table(void){
  int i;
  int nType0;

  qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
  for(i=0; i<nFixed; i++){
    if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
    printf("extern void %s(void);\n", aEntry[i].zFunc);
    if( aEntry[i].zIf ) printf("#endif\n");
  }
  printf(
    "typedef struct NameMap NameMap;\n"
    "struct NameMap {\n"
    "  const char *zName;\n"
    "  void (*xFunc)(void);\n"
    "  char cmdFlags;\n"
    "};\n"
    "#define CMDFLAG_1ST_TIER  0x01\n"
    "#define CMDFLAG_2ND_TIER  0x02\n"
    "#define CMDFLAG_TEST      0x04\n"
    "static const NameMap aWebpage[] = {\n"
  );
  for(i=0; i<nFixed && aEntry[i].eType==0; i++){
    const char *z = aEntry[i].zPath;
    int n = strlen(z);
    if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
    printf("  { \"%s\",%*s %s,%*s 1 },\n",
      z,
      25-n, "",
      aEntry[i].zFunc,
      (int)(35-strlen(aEntry[i].zFunc)), ""
    );
    if( aEntry[i].zIf ) printf("#endif\n");
  }
  printf("};\n");
  nType0 = i;
  printf(
    "static const NameMap aCommand[] = {\n"
  );
  for(i=nType0; i<nFixed && aEntry[i].eType==1; i++){
    const char *z = aEntry[i].zPath;
    int n = strlen(z);
    int cmdFlags = 0x01;
    if( z[n-1]=='*' ){
      n--;
      cmdFlags = 0x02;
    }else if( memcmp(z, "test-", 5)==0 ){
      cmdFlags = 0x04;
    }
    if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
    printf("  { \"%.*s\",%*s %s,%*s %d },\n",
      n, z,
      25-n, "",
      aEntry[i].zFunc,
      (int)(35-strlen(aEntry[i].zFunc)), "",
      cmdFlags
    );
    if( aEntry[i].zIf ) printf("#endif\n");
  }
  printf("};\n");
  for(i=nType0; i<nFixed; i++){
    char *z = aEntry[i].zHelp;
    if( z && z[0] ){
      if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
      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");
      if( aEntry[i].zIf ) printf("#endif\n");
      aEntry[i].zHelp[0] = 0;
    }
  }
  printf(
    "static const char * const aCmdHelp[] = {\n"
  );
  for(i=nType0; i<nFixed; i++){
    if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
    if( aEntry[i].zHelp==0 ){
      printf("  0,\n");
    }else{
      printf("  zHelp_%s,\n", aEntry[i].zFunc);
    }
    if( aEntry[i].zIf ) printf("#endif\n");
  }
  printf("};\n");
}

/*
** Process a single file of input
*/
void process_file(void){
  FILE *in = fopen(zFile, "r");
  char zLine[2000];
  if( in==0 ){
    fprintf(stderr,"%s: cannot open\n", zFile);
    return;
  }
  nLine = 0;
  while( fgets(zLine, sizeof(zLine), in) ){
    nLine++;
    scan_for_if(zLine);
    scan_for_label("WEBPAGE:",zLine,0);
    scan_for_label("COMMAND:",zLine,1);
    scan_for_func(zLine);
  }
  fclose(in);
  nUsed = nFixed; 
}
Changes to src/winhttp.c.
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
  {
    fossil_fatal("METHOD should be one of:"
                 " create delete show start stop");
  }
  return;
}

#else /* _WIN32  -- This code is for win32 only */
#include "winhttp.h"

void cmd_win32_service(void){
  fossil_fatal("The winsrv command is platform specific "
               "and not available on this platform."); 
  return;
}

#endif /* _WIN32  -- This code is for win32 only */







<
<
<
<
<
<
<
<
<

846
847
848
849
850
851
852









853
  {
    fossil_fatal("METHOD should be one of:"
                 " create delete show start stop");
  }
  return;
}










#endif /* _WIN32  -- This code is for win32 only */