]> git.ozlabs.org Git - ccan/blobdiff - tools/doc_extract-core.c
ccanlint: fix parsing bug which believes lines starting with - are a section header.
[ccan] / tools / doc_extract-core.c
index 583328a16c6ea5797f6dfebd5789c71d206dcf5b..07d31c77c01f15e85cbc3cebda601b050b916c5f 100644 (file)
@@ -52,13 +52,20 @@ static bool is_blank(const char *line)
 
 static bool is_section(const char *line, bool one_liner)
 {
-       unsigned int len;
+       unsigned int len = 0;
 
-       if (!isupper(line[0]))
-               return false;
-       len = strspn(line, IDENT_CHARS" ");
-       if (line[len] != ':')
-               return false;
+       /* Any number of upper case words separated by spaces, ending in : */
+       for (;;) {
+               if (!isupper(line[len]))
+                       return false;
+               len += strspn(line+len, IDENT_CHARS);
+               if (line[len] == ':')
+                       break;
+
+               if (line[len] != ' ')
+                       return false;
+               len++;
+       }
 
        /* If it can be a one-liner, a space is sufficient.*/
        if (one_liner)
@@ -75,9 +82,10 @@ static unsigned int is_summary_line(const char *line)
        id_len = strspn(line, IDENT_CHARS" ");
        if (id_len == 0)
                return 0;
+       if (strspn(line, " ") == id_len)
+               return 0;
        if (!strstarts(line + id_len-1, " - "))
                return 0;
-
        return id_len - 1;
 }