Skip to content

Commit 1dcdad0

Browse files
jnikulaJonathan Corbet
authored andcommitted
docproc: abstract terminating lines at first space
Cleaner code. Also fixes a bug when F or P directives didn't in fact have space. Signed-off-by: Jani Nikula <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]>
1 parent a48dc45 commit 1dcdad0

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

scripts/docproc.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,21 @@ static void find_all_symbols(char *filename)
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,44 +475,37 @@ static void parse_file(FILE *infile)
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++;
487497
singlefunctions(p, s);
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;

0 commit comments

Comments
 (0)