[ccan] [patch] Check for valid summary lines
Rusty Russell
rusty at rustcorp.com.au
Mon Jan 17 14:57:53 EST 2011
On Sun, 16 Jan 2011 02:59:59 pm Brad Hards wrote:
> While looking for code that might make it easier to build a Compound Binary
> Format (aka OLE file) parser in C, I noted a little problem with display of the
> block_pool summary line on the CCAN web site.
>
> http://ccan.ozlabs.org/list.html shows
> "block_pool An efficient allocator for blocks that don't need to be"
Thanks for the fix. After discussion on IRC, I enhanced doc_extract so
we can easily traverse the docinfo and map back to the src line. The result
is like so:
Module has a single line summary in _info (info_summary_single_line): FAIL
/home/rusty/devel/cvs/ccan/ccan/block_pool/_info:6: * block_pool - An efficient allocator for blocks that don't need to be
/home/rusty/devel/cvs/ccan/ccan/block_pool/_info:7: * resized or freed.
And here's the resulting patch (on top of yours). Note that score->total
is initialized to 1, so you don't need to.
Thanks!
Rusty.
commit 12941b07e6fbd4b32687460f33d0cabfda080a3a
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Jan 17 14:22:29 2011 +1030
ccanlint: neaten info_summary_single_line with new doc_section info.
diff --git a/tools/ccanlint/tests/info_summary_single_line.c b/tools/ccanlint/tests/info_summary_single_line.c
index 12f95e6..19e9ada 100644
--- a/tools/ccanlint/tests/info_summary_single_line.c
+++ b/tools/ccanlint/tests/info_summary_single_line.c
@@ -4,50 +4,34 @@
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h>
-/* Summary line is form '<identifier> - ' (spaces for 'struct foo -') */
-/* slightly modified from doc_extract-core.c */
-static unsigned int is_summary_line(const char *line)
-{
- unsigned int id_len;
-
- 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;
-}
-
static void check_info_summary_single_line(struct manifest *m,
bool keep,
unsigned int *timeleft,
struct score *score)
{
- int i = 0;
- get_ccan_line_info(m->info_file);
- score->total = 1;
- for (i = 0; i < m->info_file->num_lines; ++i) {
- if (is_summary_line(m->info_file->lines[i])) {
- if (strspn(m->info_file->lines[i+1], " *") == strlen(m->info_file->lines[i+1])) {
- /* valid summary line */
- score->error = NULL;
- score->pass = true;
- score->score = 1;
- } else {
- /* invalid summary line - line following summary line should be empty */
- score->pass = false;
- score->score = 0;
- score->error = "invalid summary line - not on a single line:";
- score_file_error(score, m->info_file, i+1, "summary is not on a single line");
- }
- break;
+ struct list_head *infodocs = get_ccan_file_docs(m->info_file);
+ struct doc_section *d;
+
+ score->pass = true;
+ list_for_each(infodocs, d, list) {
+ const char *after;
+
+ if (!streq(d->type, "summary"))
+ continue;
+
+ /* line following summary line should be empty */
+ after = m->info_file->lines[d->srcline+1];
+ if (after && strspn(after, " *") != strlen(after)) {
+ score->pass = false;
+ score->score = 0;
+ score_file_error(score, m->info_file, d->srcline+1,
+ m->info_file->lines[d->srcline]);
+ score_file_error(score, m->info_file, d->srcline+2,
+ m->info_file->lines[d->srcline+1]);
}
}
}
-
struct ccanlint info_summary_single_line = {
.key = "info_summary_single_line",
.name = "Module has a single line summary in _info",
More information about the ccan
mailing list