Skip to content

Commit

Permalink
docproc: abstract terminating lines at first space
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jnikula authored and Jonathan Corbet committed May 14, 2016
1 parent a48dc45 commit 1dcdad0
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions scripts/docproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ static void find_all_symbols(char *filename)
}
}

/*
* Terminate s at first space, if any. If there was a space, return pointer to
* the character after that. Otherwise, return pointer to the terminating NUL.
*/
static char *chomp(char *s)
{
while (*s && !isspace(*s))
s++;

if (*s)
*s++ = '\0';

return s;
}

/* Return pointer to directive content, or NULL if not a directive. */
static char *is_directive(char *line)
{
Expand Down Expand Up @@ -460,44 +475,37 @@ static void parse_file(FILE *infile)
continue;
}

s = p + 1;
switch (*p++) {
case 'E':
while (*s && !isspace(*s)) s++;
*s = '\0';
chomp(p);
externalfunctions(p);
break;
case 'I':
while (*s && !isspace(*s)) s++;
*s = '\0';
chomp(p);
internalfunctions(p);
break;
case 'D':
while (*s && !isspace(*s)) s++;
*s = '\0';
chomp(p);
symbolsonly(p);
break;
case 'F':
/* filename */
while (*s && !isspace(*s)) s++;
*s++ = '\0';
s = chomp(p);
/* function names */
while (isspace(*s))
s++;
singlefunctions(p, s);
break;
case 'P':
/* filename */
while (*s && !isspace(*s)) s++;
*s++ = '\0';
s = chomp(p);
/* DOC: section name */
while (isspace(*s))
s++;
docsection(p, s);
break;
case 'C':
while (*s && !isspace(*s)) s++;
*s = '\0';
chomp(p);
if (findall)
findall(p);
break;
Expand Down

0 comments on commit 1dcdad0

Please sign in to comment.