ccanlint: more tweaks to example mangling.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 26 Sep 2011 09:53:36 +0000 (19:23 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 26 Sep 2011 09:53:36 +0000 (19:23 +0930)
Note where previous analysis said the code was outside a function, and
fix double new-line.  Also, treat end of comment as end of statement.

tools/ccanlint/tests/examples_compile.c

index 35e45ca03f26116b5584a34c5486cbc0a5d387a3..d52ee78939d4ee37c7f7ff244dd48288faad9728 100644 (file)
@@ -199,6 +199,8 @@ static bool looks_internal(char **lines, char **why)
                if (!line[0] || cisspace(line[0]) || strstarts(line, "//"))
                        continue;
 
+               assert(line[strlen(line)-1] != '\n');
+
                /* The winners. */
                if (strstarts(line, "if") && len == 2) {
                        *why = cast_const(char *, "starts with if");
@@ -237,6 +239,12 @@ static bool looks_internal(char **lines, char **why)
                        }
                }
 
+               /* Previously prepended. */
+               if (strstr(line, "didn't seem to belong inside a function")) {
+                       *why = cast_const(char *, "Comment said so");
+                       return false;
+               }
+
                /* Single identifier then operator == inside function. */
                if (last_ended && len
                    && cispunct(line[len+strspn(line+len, " ")])) {
@@ -247,6 +255,7 @@ static bool looks_internal(char **lines, char **why)
 
                last_ended = (strends(line, "}")
                              || strends(line, ";")
+                             || strends(line, "*/")
                              || streq(line, "..."));
        }
 
@@ -298,7 +307,7 @@ static char **combine(const void *ctx, char **lines, char **prev)
        prev_total = i;
 
        ret = talloc_array(ctx, char *, 1 +lines_total + prev_total + 1);
-       ret[0] = talloc_asprintf(ret, "/* The example %s, thus %s */\n",
+       ret[0] = talloc_asprintf(ret, "/* The example %s, thus %s */",
                                 why, reasoning);
        memcpy(ret+1, lines, count * sizeof(ret[0]));
        memcpy(ret+1 + count, prev, prev_total * sizeof(ret[0]));