]> git.ozlabs.org Git - ccan/blobdiff - tools/doc_extract-core.c
config.h: HAVE_FLEXIBLE_ARRAY_MEMBER
[ccan] / tools / doc_extract-core.c
index f3666e59924926aeed86bec1478fad53e1f6eb56..2862eedc3b91a839749e34fe2f0ac516532a1eb6 100644 (file)
@@ -26,8 +26,10 @@ static char **grab_doc(char **lines, unsigned int num)
        for (i = 0; lines[i]; i++) {
                if (streq(lines[i], "/**")) {
                        printing = true;
-                       if (num != 0)
-                               talloc_append_string(ret[num-1], "\n");
+                       if (num != 0) {
+                               ret[num-1] = talloc_append_string(ret[num-1],
+                                                                 "\n");
+                       }
                } else if (streq(lines[i], " */")) 
                        printing = false;
                else if (printing) {
@@ -50,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)
@@ -65,18 +74,18 @@ static bool is_section(const char *line, bool one_liner)
        return line[len] == ':' && is_blank(line+len+1);
 }
 
-/* Summary line is form '<identifier> - ' */
-static bool is_summary_line(const char *line)
+/* Summary line is form '<identifier> - ' (spaces for 'struct foo -') */
+static unsigned int is_summary_line(const char *line)
 {
        unsigned int id_len;
 
-       id_len = strspn(line, IDENT_CHARS);
+       id_len = strspn(line, IDENT_CHARS" ");
        if (id_len == 0)
-               return false;
-       if (!strstarts(line + id_len, " - "))
-               return false;
+               return 0;
+       if (!strstarts(line + id_len-1, " - "))
+               return 0;
 
-       return true;
+       return id_len - 1;
 }
 
 static bool empty_section(struct doc_section *d)
@@ -137,11 +146,13 @@ struct list_head *extract_doc_sections(char **rawlines, unsigned int num)
        list_head_init(list);
 
        for (i = 0; lines[i]; i++) {
-               if (is_summary_line(lines[i])) {
-                       function = talloc_strndup(list, lines[i],
-                                                 strcspn(lines[i], " "));
+               unsigned funclen;
+
+               funclen = is_summary_line(lines[i]);
+               if (funclen) {
+                       function = talloc_strndup(list, lines[i], funclen);
                        curr = new_section(list, function, "summary");
-                       add_line(curr, strstr(lines[i], " - ") + 3);
+                       add_line(curr, lines[i] + funclen + 3);
                        curr = new_section(list, function, "description");
                } else if (is_section(lines[i], false)) {
                        char *type = talloc_strndup(curr, lines[i],