| | @@ -61,10 +61,11 @@ |
| 61 | 61 | /* |
| 62 | 62 | ** Each entry looks like this: |
| 63 | 63 | */ |
| 64 | 64 | typedef struct Entry { |
| 65 | 65 | int eType; |
| 66 | + char *zIf; |
| 66 | 67 | char *zFunc; |
| 67 | 68 | char *zPath; |
| 68 | 69 | char *zHelp; |
| 69 | 70 | } Entry; |
| 70 | 71 | |
| | @@ -87,10 +88,15 @@ |
| 87 | 88 | ** Current help message accumulator |
| 88 | 89 | */ |
| 89 | 90 | char zHelp[MX_HELP]; |
| 90 | 91 | int nHelp; |
| 91 | 92 | |
| 93 | +/* |
| 94 | +** Most recently encountered #if |
| 95 | +*/ |
| 96 | +char zIf[200]; |
| 97 | + |
| 92 | 98 | /* |
| 93 | 99 | ** How many entries are used |
| 94 | 100 | */ |
| 95 | 101 | int nUsed; |
| 96 | 102 | int nFixed; |
| | @@ -135,10 +141,30 @@ |
| 135 | 141 | aEntry[nUsed].eType = eType; |
| 136 | 142 | aEntry[nUsed].zPath = string_dup(&zLine[i], j); |
| 137 | 143 | aEntry[nUsed].zFunc = 0; |
| 138 | 144 | nUsed++; |
| 139 | 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 | +} |
| 140 | 166 | |
| 141 | 167 | /* |
| 142 | 168 | ** Scan a line for a function that implements a web page or command. |
| 143 | 169 | */ |
| 144 | 170 | void scan_for_func(char *zLine){ |
| | @@ -179,10 +205,11 @@ |
| 179 | 205 | z = string_dup(&zHelp[k], nHelp-k); |
| 180 | 206 | }else{ |
| 181 | 207 | z = 0; |
| 182 | 208 | } |
| 183 | 209 | for(k=nFixed; k<nUsed; k++){ |
| 210 | + aEntry[k].zIf = zIf[0] ? string_dup(zIf, -1) : 0; |
| 184 | 211 | aEntry[k].zFunc = string_dup(&zLine[i], j); |
| 185 | 212 | aEntry[k].zHelp = z; |
| 186 | 213 | } |
| 187 | 214 | i+=j; |
| 188 | 215 | while( isspace(zLine[i]) ){ i++; } |
| | @@ -219,11 +246,13 @@ |
| 219 | 246 | int i; |
| 220 | 247 | int nType0; |
| 221 | 248 | |
| 222 | 249 | qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare); |
| 223 | 250 | for(i=0; i<nFixed; i++){ |
| 251 | + if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf); |
| 224 | 252 | printf("extern void %s(void);\n", aEntry[i].zFunc); |
| 253 | + if( aEntry[i].zIf ) printf("#endif\n"); |
| 225 | 254 | } |
| 226 | 255 | printf( |
| 227 | 256 | "typedef struct NameMap NameMap;\n" |
| 228 | 257 | "struct NameMap {\n" |
| 229 | 258 | " const char *zName;\n" |
| | @@ -236,16 +265,18 @@ |
| 236 | 265 | "static const NameMap aWebpage[] = {\n" |
| 237 | 266 | ); |
| 238 | 267 | for(i=0; i<nFixed && aEntry[i].eType==0; i++){ |
| 239 | 268 | const char *z = aEntry[i].zPath; |
| 240 | 269 | int n = strlen(z); |
| 270 | + if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf); |
| 241 | 271 | printf(" { \"%s\",%*s %s,%*s 1 },\n", |
| 242 | 272 | z, |
| 243 | 273 | 25-n, "", |
| 244 | 274 | aEntry[i].zFunc, |
| 245 | 275 | (int)(35-strlen(aEntry[i].zFunc)), "" |
| 246 | 276 | ); |
| 277 | + if( aEntry[i].zIf ) printf("#endif\n"); |
| 247 | 278 | } |
| 248 | 279 | printf("};\n"); |
| 249 | 280 | nType0 = i; |
| 250 | 281 | printf( |
| 251 | 282 | "static const NameMap aCommand[] = {\n" |
| | @@ -258,22 +289,25 @@ |
| 258 | 289 | n--; |
| 259 | 290 | cmdFlags = 0x02; |
| 260 | 291 | }else if( memcmp(z, "test-", 5)==0 ){ |
| 261 | 292 | cmdFlags = 0x04; |
| 262 | 293 | } |
| 294 | + if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf); |
| 263 | 295 | printf(" { \"%.*s\",%*s %s,%*s %d },\n", |
| 264 | 296 | n, z, |
| 265 | 297 | 25-n, "", |
| 266 | 298 | aEntry[i].zFunc, |
| 267 | 299 | (int)(35-strlen(aEntry[i].zFunc)), "", |
| 268 | 300 | cmdFlags |
| 269 | 301 | ); |
| 302 | + if( aEntry[i].zIf ) printf("#endif\n"); |
| 270 | 303 | } |
| 271 | 304 | printf("};\n"); |
| 272 | 305 | for(i=nType0; i<nFixed; i++){ |
| 273 | 306 | char *z = aEntry[i].zHelp; |
| 274 | 307 | if( z && z[0] ){ |
| 308 | + if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf); |
| 275 | 309 | printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc); |
| 276 | 310 | printf(" \""); |
| 277 | 311 | while( *z ){ |
| 278 | 312 | if( *z=='\n' ){ |
| 279 | 313 | printf("\\n\"\n \""); |
| | @@ -283,22 +317,25 @@ |
| 283 | 317 | putchar(*z); |
| 284 | 318 | } |
| 285 | 319 | z++; |
| 286 | 320 | } |
| 287 | 321 | printf("\";\n"); |
| 322 | + if( aEntry[i].zIf ) printf("#endif\n"); |
| 288 | 323 | aEntry[i].zHelp[0] = 0; |
| 289 | 324 | } |
| 290 | 325 | } |
| 291 | 326 | printf( |
| 292 | 327 | "static const char * const aCmdHelp[] = {\n" |
| 293 | 328 | ); |
| 294 | 329 | for(i=nType0; i<nFixed; i++){ |
| 330 | + if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf); |
| 295 | 331 | if( aEntry[i].zHelp==0 ){ |
| 296 | 332 | printf(" 0,\n"); |
| 297 | 333 | }else{ |
| 298 | 334 | printf(" zHelp_%s,\n", aEntry[i].zFunc); |
| 299 | 335 | } |
| 336 | + if( aEntry[i].zIf ) printf("#endif\n"); |
| 300 | 337 | } |
| 301 | 338 | printf("};\n"); |
| 302 | 339 | } |
| 303 | 340 | |
| 304 | 341 | /* |
| | @@ -312,10 +349,11 @@ |
| 312 | 349 | return; |
| 313 | 350 | } |
| 314 | 351 | nLine = 0; |
| 315 | 352 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 316 | 353 | nLine++; |
| 354 | + scan_for_if(zLine); |
| 317 | 355 | scan_for_label("WEBPAGE:",zLine,0); |
| 318 | 356 | scan_for_label("COMMAND:",zLine,1); |
| 319 | 357 | scan_for_func(zLine); |
| 320 | 358 | } |
| 321 | 359 | fclose(in); |
| 322 | 360 | |