History

docproc: abstract terminating lines at first space

Cleaner code. Also fixes a bug when F or P directives didn't in fact have space.

Jani Nikula committed 10 years ago

Commit 1dcdad01 parent a48dc451 file · +21 −13Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/docproc.c+21−13
@@ -430,6 +430,21 @@ static void find_all_symbols(char *filename) · 429 unmodified lines
430430 }
431431 }
432432
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+
433448 /* Return pointer to directive content, or NULL if not a directive. */
434449 static char *is_directive(char *line)
435450 {
@@ -460,27 +475,22 @@ static void parse_file(FILE *infile) · 24 unmodified lines
460475 continue;
461476 }
462477
463− s = p + 1;
464478 switch (*p++) {
465479 case 'E':
466− while (*s && !isspace(*s)) s++;
467− *s = '\0';
480+ chomp(p);
468481 externalfunctions(p);
469482 break;
470483 case 'I':
471− while (*s && !isspace(*s)) s++;
472− *s = '\0';
484+ chomp(p);
473485 internalfunctions(p);
474486 break;
475487 case 'D':
476− while (*s && !isspace(*s)) s++;
477− *s = '\0';
488+ chomp(p);
478489 symbolsonly(p);
479490 break;
480491 case 'F':
481492 /* filename */
482− while (*s && !isspace(*s)) s++;
483− *s++ = '\0';
493+ s = chomp(p);
484494 /* function names */
485495 while (isspace(*s))
486496 s++;
@@ -488,16 +498,14 @@ static void parse_file(FILE *infile) · 1 unmodified line
488498 break;
489499 case 'P':
490500 /* filename */
491− while (*s && !isspace(*s)) s++;
492− *s++ = '\0';
501+ s = chomp(p);
493502 /* DOC: section name */
494503 while (isspace(*s))
495504 s++;
496505 docsection(p, s);
497506 break;
498507 case 'C':
499− while (*s && !isspace(*s)) s++;
500− *s = '\0';
508+ chomp(p);
501509 if (findall)
502510 findall(p);
503511 break;