summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-12-03 18:25:41 +1030
committerRusty Russell <rusty@rustcorp.com.au>2012-12-03 18:25:41 +1030
commit6a4d45337811b56d947e52f031b9ca0c955fcb6c (patch)
treeca928ceae01263e803f7b990d501ce25a52fa35e
parent2b7f1fca3e33d017dd86b2de12547f9720fb5c3d (diff)
tools: don't abort on malformed documentation lines.
ccanlint would abort with 'Malformed line 53' if there was a bad header. That's very poor, and deeply unhelpful. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--tools/ccanlint/file_analysis.c2
-rw-r--r--tools/doc_extract-core.c22
-rw-r--r--tools/doc_extract.c2
-rw-r--r--tools/doc_extract.h2
4 files changed, 20 insertions, 8 deletions
diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c
index 575425df..852ecbfc 100644
--- a/tools/ccanlint/file_analysis.c
+++ b/tools/ccanlint/file_analysis.c
@@ -27,7 +27,7 @@ struct list_head *get_ccan_file_docs(struct ccan_file *f)
{
if (!f->doc_sections) {
get_ccan_file_lines(f);
- f->doc_sections = extract_doc_sections(f->lines);
+ f->doc_sections = extract_doc_sections(f->lines, f->name);
}
return f->doc_sections;
}
diff --git a/tools/doc_extract-core.c b/tools/doc_extract-core.c
index 7788fd07..7b9bb84a 100644
--- a/tools/doc_extract-core.c
+++ b/tools/doc_extract-core.c
@@ -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;
}
}
@@ -195,10 +207,10 @@ static void trim_lines(struct doc_section *curr)
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;
diff --git a/tools/doc_extract.c b/tools/doc_extract.c
index f792b57b..aa0c5a04 100644
--- a/tools/doc_extract.c
+++ b/tools/doc_extract.c
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
err(1, "Reading file %s", argv[i]);
lines = strsplit(file, file, "\n");
- list = extract_doc_sections(lines);
+ list = extract_doc_sections(lines, argv[i]);
if (list_empty(list))
errx(1, "No documentation in file %s", argv[i]);
talloc_free(file);
diff --git a/tools/doc_extract.h b/tools/doc_extract.h
index 1f4650a1..d5bc693a 100644
--- a/tools/doc_extract.h
+++ b/tools/doc_extract.h
@@ -13,5 +13,5 @@ struct doc_section {
char **lines;
};
-struct list_head *extract_doc_sections(char **rawlines);
+struct list_head *extract_doc_sections(char **rawlines, const char *file);
#endif /* _DOC_EXTRACT_CORE_H */