Commit 904cfe94 authored by Rusty Russell's avatar Rusty Russell

tools: fix bug in doc-extract, handle spaces in summary line

      
      /**
       * struct foo - some description
      
So, <identifier> here can have a space in it.
parent d40331c7
...@@ -26,8 +26,10 @@ static char **grab_doc(char **lines, unsigned int num) ...@@ -26,8 +26,10 @@ static char **grab_doc(char **lines, unsigned int num)
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
if (streq(lines[i], "/**")) { if (streq(lines[i], "/**")) {
printing = true; printing = true;
if (num != 0) if (num != 0) {
talloc_append_string(ret[num-1], "\n"); ret[num-1] = talloc_append_string(ret[num-1],
"\n");
}
} else if (streq(lines[i], " */")) } else if (streq(lines[i], " */"))
printing = false; printing = false;
else if (printing) { else if (printing) {
...@@ -65,18 +67,18 @@ static bool is_section(const char *line, bool one_liner) ...@@ -65,18 +67,18 @@ static bool is_section(const char *line, bool one_liner)
return line[len] == ':' && is_blank(line+len+1); return line[len] == ':' && is_blank(line+len+1);
} }
/* Summary line is form '<identifier> - ' */ /* Summary line is form '<identifier> - ' (spaces for 'struct foo -') */
static bool is_summary_line(const char *line) static unsigned int is_summary_line(const char *line)
{ {
unsigned int id_len; unsigned int id_len;
id_len = strspn(line, IDENT_CHARS); id_len = strspn(line, IDENT_CHARS" ");
if (id_len == 0) if (id_len == 0)
return false; return 0;
if (!strstarts(line + id_len, " - ")) if (!strstarts(line + id_len-1, " - "))
return false; return 0;
return true; return id_len - 1;
} }
static bool empty_section(struct doc_section *d) static bool empty_section(struct doc_section *d)
...@@ -137,11 +139,13 @@ struct list_head *extract_doc_sections(char **rawlines, unsigned int num) ...@@ -137,11 +139,13 @@ struct list_head *extract_doc_sections(char **rawlines, unsigned int num)
list_head_init(list); list_head_init(list);
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
if (is_summary_line(lines[i])) { unsigned funclen;
function = talloc_strndup(list, lines[i],
strcspn(lines[i], " ")); funclen = is_summary_line(lines[i]);
if (funclen) {
function = talloc_strndup(list, lines[i], funclen);
curr = new_section(list, function, "summary"); 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"); curr = new_section(list, function, "description");
} else if (is_section(lines[i], false)) { } else if (is_section(lines[i], false)) {
char *type = talloc_strndup(curr, lines[i], char *type = talloc_strndup(curr, lines[i],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment