From 98d7798706f6222f052c35126e0feec97c101d6a Mon Sep 17 00:00:00 2001
From: Rusty Russell <rusty@rustcorp.com.au>
Date: Mon, 26 Sep 2011 19:23:36 +0930
Subject: [PATCH] ccanlint: more tweaks to example mangling.

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 | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/ccanlint/tests/examples_compile.c b/tools/ccanlint/tests/examples_compile.c
index 35e45ca0..d52ee789 100644
--- a/tools/ccanlint/tests/examples_compile.c
+++ b/tools/ccanlint/tests/examples_compile.c
@@ -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]));
-- 
2.30.9