Browse Source

ccanlint: fix idempotent handler

Test for inserting idempotent header was wrong way around, and we check
all headers at once, rather than finishing after one.

Also, turn - into _ rather than removing.
Rusty Russell 15 years ago
parent
commit
f1c96e9df6
1 changed files with 13 additions and 12 deletions
  1. 13 12
      tools/ccanlint/tests/idempotent.c

+ 13 - 12
tools/ccanlint/tests/idempotent.c

@@ -24,13 +24,14 @@ static const char explain[]
 
 
 static void fix_name(char *name)
 static void fix_name(char *name)
 {
 {
-	unsigned int i, j;
+	unsigned int i;
 
 
-	for (i = j = 0; name[i]; i++) {
-		if (isalnum(name[i]) || name[i] == '_')
-			name[j++] = toupper(name[i]);
+	for (i = 0; name[i]; i++) {
+		if (isalnum(name[i]))
+			name[i] = toupper(name[i]);
+		else
+			name[i] = '_';
 	}
 	}
-	name[j] = '\0';
 }
 }
 
 
 static void handle_idem(struct manifest *m, struct score *score)
 static void handle_idem(struct manifest *m, struct score *score)
@@ -44,10 +45,10 @@ static void handle_idem(struct manifest *m, struct score *score)
 
 
 		/* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */
 		/* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */
 		if (strstarts(e->file->name, m->basename)
 		if (strstarts(e->file->name, m->basename)
-		    || strlen(e->file->name) != strlen(m->basename) + 2)
+		    || strlen(e->file->name) == strlen(m->basename) + 2)
 			name = talloc_asprintf(score, "CCAN_%s_H", m->basename);
 			name = talloc_asprintf(score, "CCAN_%s_H", m->basename);
 		else
 		else
-			name = talloc_asprintf(score, "CCAN_%s_%s_H",
+			name = talloc_asprintf(score, "CCAN_%s_%s",
 					       m->basename, e->file->name);
 					       m->basename, e->file->name);
 		fix_name(name);
 		fix_name(name);
 
 
@@ -183,13 +184,13 @@ static void check_idempotent(struct manifest *m,
 	struct ccan_file *f;
 	struct ccan_file *f;
 
 
 	list_for_each(&m->h_files, f, list) {
 	list_for_each(&m->h_files, f, list) {
-		if (!check_idem(f, score)) {
+		if (!check_idem(f, score))
 			score->error = "Headers are not idempotent";
 			score->error = "Headers are not idempotent";
-			return;
-		}
 	}
 	}
-	score->pass = true;
-	score->score = score->total;
+	if (!score->error) {
+		score->pass = true;
+		score->score = score->total;
+	}
 }
 }
 
 
 struct ccanlint idempotent = {
 struct ccanlint idempotent = {