Browse Source

ccanlint: fix and simplify depends-accurate (with strreg)

Rusty Russell 15 years ago
parent
commit
73650a939e
1 changed files with 6 additions and 24 deletions
  1. 6 24
      tools/ccanlint/tests/depends_accurate.c

+ 6 - 24
tools/ccanlint/tests/depends_accurate.c

@@ -2,6 +2,7 @@
 #include <tools/tools.h>
 #include <tools/tools.h>
 #include <ccan/talloc/talloc.h>
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
 #include <ccan/str/str.h>
+#include <ccan/str_talloc/str_talloc.h>
 #include <ccan/foreach/foreach.h>
 #include <ccan/foreach/foreach.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
@@ -15,19 +16,6 @@
 #include <string.h>
 #include <string.h>
 #include <ctype.h>
 #include <ctype.h>
 
 
-static char *strip_spaces(const void *ctx, char *line)
-{
-	char *p = talloc_strdup(ctx, line);
-	unsigned int i, j;
-
-	for (i = 0, j = 0; p[i]; i++) {
-		if (!isspace(p[i]))
-			p[j++] = p[i];
-	}
-	p[j] = '\0';
-	return p;
-}
-
 static bool has_dep(struct manifest *m, const char *depname)
 static bool has_dep(struct manifest *m, const char *depname)
 {
 {
 	struct manifest *i;
 	struct manifest *i;
@@ -60,18 +48,12 @@ static void check_depends_accurate(struct manifest *m,
 			char **lines = get_ccan_file_lines(f);
 			char **lines = get_ccan_file_lines(f);
 
 
 			for (i = 0; lines[i]; i++) {
 			for (i = 0; lines[i]; i++) {
-				char *p;
-				if (lines[i][strspn(lines[i], " \t")] != '#')
-					continue;
-				p = strip_spaces(f, lines[i]);
-				if (!strstarts(p, "#include<ccan/")
-				    && !strstarts(p, "#include\"ccan/"))
-					continue;
-				p += strlen("#include\"ccan/");
-				if (!strchr(strchr(p, '/') + 1, '/'))
+				char *mod;
+				if (!strreg(f, lines[i],
+					    "^[ \t]*#[ \t]*include[ \t]*[<\"]"
+					    "ccan/+([^/]+)/", &mod))
 					continue;
 					continue;
-				*strchr(strchr(p, '/') + 1, '/') = '\0';
-				if (has_dep(m, p))
+				if (has_dep(m, mod))
 					continue;
 					continue;
 				score->error = "Includes a ccan module"
 				score->error = "Includes a ccan module"
 					" not listed in _info";
 					" not listed in _info";