From 44c480c492c4596801261d748c5e3339c30f1f7e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 15 Nov 2008 22:39:34 +1030 Subject: [PATCH] Canonicalize typenames, and remove empty sections. --- tools/doc_extract-core.c | 30 ++++++++++++++++++++++++++++-- tools/doc_extract.c | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tools/doc_extract-core.c b/tools/doc_extract-core.c index a8d9335b..f3666e59 100644 --- a/tools/doc_extract-core.c +++ b/tools/doc_extract-core.c @@ -79,15 +79,41 @@ static bool is_summary_line(const char *line) return true; } +static bool empty_section(struct doc_section *d) +{ + unsigned int i; + + for (i = 0; i < d->num_lines; i++) + if (!is_blank(d->lines[i])) + return false; + return true; +} + static struct doc_section *new_section(struct list_head *list, const char *function, const char *type) { - struct doc_section *d = talloc(list, struct doc_section); + struct doc_section *d; + char *lowertype; + unsigned int i; + + /* If previous section was empty, delete it. */ + d = list_tail(list, struct doc_section, list); + if (d && empty_section(d)) { + list_del(&d->list); + talloc_free(d); + } + + d = talloc(list, struct doc_section); d->function = function; - d->type = type; + lowertype = talloc_size(d, strlen(type) + 1); + /* Canonicalize type to lower case. */ + for (i = 0; i < strlen(type)+1; i++) + lowertype[i] = tolower(type[i]); + d->type = lowertype; d->lines = NULL; d->num_lines = 0; + list_add_tail(list, &d->list); return d; } diff --git a/tools/doc_extract.c b/tools/doc_extract.c index b8969ef2..c8ecbf8e 100644 --- a/tools/doc_extract.c +++ b/tools/doc_extract.c @@ -59,9 +59,9 @@ int main(int argc, char *argv[]) if (!streq(d->function, function)) continue; } - if (strcasecmp(type, "all") == 0) + if (streq(type, "all")) printf("%s:\n", d->type); - else if (strcasecmp(d->type, type) != 0) + else if (!streq(d->type, type)) continue; for (j = 0; j < d->num_lines; j++) -- 2.39.2