]> git.ozlabs.org Git - ccan/blobdiff - tools/doc_extract-core.c
tools: don't abort on malformed documentation lines.
[ccan] / tools / doc_extract-core.c
index 8695a7e16fa2e2437c1ca1671b2eada3134f2b76..7b9bb84ab3f93e50c06be26a1663e18be8054074 100644 (file)
@@ -15,7 +15,8 @@
 #include "doc_extract.h"
 #include "tools.h"
 
-static char **grab_doc(char **lines, unsigned int **linemap)
+static char **grab_doc(char **lines, unsigned int **linemap,
+                      const char *file)
 {
        char **ret;
        unsigned int i, num;
@@ -39,8 +40,19 @@ static char **grab_doc(char **lines, unsigned int **linemap)
                                ret[num++] = talloc_strdup(ret, lines[i]+3);
                        else if (strstarts(lines[i], " *"))
                                ret[num++] = talloc_strdup(ret, lines[i]+2);
-                       else
-                               errx(1, "Malformed line %u", i);
+                       else {
+                               /* Weird, malformed? */
+                               static bool warned;
+                               if (!warned) {
+                                       warnx("%s:%u:"
+                                             " Expected ' *' in comment.",
+                                             file, i+1);
+                                       warned++;
+                               }
+                               ret[num++] = talloc_strdup(ret, lines[i]);
+                               if (strstr(lines[i], "*/"))
+                                       printing = false;
+                       }
                        (*linemap)[num-1] = i;
                }
        }
@@ -71,7 +83,8 @@ static unsigned int is_summary_line(const char *line)
 {
        unsigned int id_len;
 
-       id_len = strspn(line, IDENT_CHARS" ");
+       /* We allow /, because it can be in (nested) module names. */
+       id_len = strspn(line, IDENT_CHARS" /");
        if (id_len == 0)
                return 0;
        if (strspn(line, " ") == id_len)
@@ -165,6 +178,7 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline)
 static void trim_lines(struct doc_section *curr)
 {
        unsigned int i, trim = -1;
+       int last_non_empty = -1;
 
        /* Get minimum whitespace prefix. */
        for (i = 0; i < curr->num_lines; i++) {
@@ -183,13 +197,20 @@ static void trim_lines(struct doc_section *curr)
                        curr->lines[i] += prefix;
                else
                        curr->lines[i] += trim;
+
+               /* All blank?  Potential to trim. */
+               if (curr->lines[i][strspn(curr->lines[i], " \t")] != '\0')
+                       last_non_empty = i;
        }
+
+       /* Remove trailing blank lines. */
+       curr->num_lines = last_non_empty + 1;
 }
 
-struct list_head *extract_doc_sections(char **rawlines)
+struct list_head *extract_doc_sections(char **rawlines, const char *file)
 {
        unsigned int *linemap;
-       char **lines = grab_doc(rawlines, &linemap);
+       char **lines = grab_doc(rawlines, &linemap, file);
        const char *function = NULL;
        struct doc_section *curr = NULL;
        unsigned int i;