Cleaner code. Also fixes a bug when F or P directives didn't in fact have space.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -430,6 +430,21 @@ static void find_all_symbols(char *filename) · 429 unmodified lines | ||
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | +/* | |
| 434 | + * Terminate s at first space, if any. If there was a space, return pointer to | |
| 435 | + * the character after that. Otherwise, return pointer to the terminating NUL. | |
| 436 | + */ | |
| 437 | +static char *chomp(char *s) | |
| 438 | +{ | |
| 439 | + while (*s && !isspace(*s)) | |
| 440 | + s++; | |
| 441 | + | |
| 442 | + if (*s) | |
| 443 | + *s++ = '\0'; | |
| 444 | + | |
| 445 | + return s; | |
| 446 | +} | |
| 447 | + | |
| 433 | 448 | /* Return pointer to directive content, or NULL if not a directive. */ |
| 434 | 449 | static char *is_directive(char *line) |
| 435 | 450 | { |
| @@ -460,27 +475,22 @@ static void parse_file(FILE *infile) · 24 unmodified lines | ||
| 460 | 475 | continue; |
| 461 | 476 | } |
| 462 | 477 | |
| 463 | − s = p + 1; | |
| 464 | 478 | switch (*p++) { |
| 465 | 479 | case 'E': |
| 466 | − while (*s && !isspace(*s)) s++; | |
| 467 | − *s = '\0'; | |
| 480 | + chomp(p); | |
| 468 | 481 | externalfunctions(p); |
| 469 | 482 | break; |
| 470 | 483 | case 'I': |
| 471 | − while (*s && !isspace(*s)) s++; | |
| 472 | − *s = '\0'; | |
| 484 | + chomp(p); | |
| 473 | 485 | internalfunctions(p); |
| 474 | 486 | break; |
| 475 | 487 | case 'D': |
| 476 | − while (*s && !isspace(*s)) s++; | |
| 477 | − *s = '\0'; | |
| 488 | + chomp(p); | |
| 478 | 489 | symbolsonly(p); |
| 479 | 490 | break; |
| 480 | 491 | case 'F': |
| 481 | 492 | /* filename */ |
| 482 | − while (*s && !isspace(*s)) s++; | |
| 483 | − *s++ = '\0'; | |
| 493 | + s = chomp(p); | |
| 484 | 494 | /* function names */ |
| 485 | 495 | while (isspace(*s)) |
| 486 | 496 | s++; |
| @@ -488,16 +498,14 @@ static void parse_file(FILE *infile) · 1 unmodified line | ||
| 488 | 498 | break; |
| 489 | 499 | case 'P': |
| 490 | 500 | /* filename */ |
| 491 | − while (*s && !isspace(*s)) s++; | |
| 492 | − *s++ = '\0'; | |
| 501 | + s = chomp(p); | |
| 493 | 502 | /* DOC: section name */ |
| 494 | 503 | while (isspace(*s)) |
| 495 | 504 | s++; |
| 496 | 505 | docsection(p, s); |
| 497 | 506 | break; |
| 498 | 507 | case 'C': |
| 499 | − while (*s && !isspace(*s)) s++; | |
| 500 | − *s = '\0'; | |
| 508 | + chomp(p); | |
| 501 | 509 | if (findall) |
| 502 | 510 | findall(p); |
| 503 | 511 | break; |