X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fheaders_idempotent.c;h=4e41d058d22a60fcf4edf8550aba0586c0d7bd33;hb=aabf300e324f7da5134d7ad45afba11225045c24;hp=340a0698ac6aecbcb8baf85d231ce4e4d8d978fc;hpb=051db34fb275491d4d5dfa5bf7970e8e525766d8;p=ccan diff --git a/tools/ccanlint/tests/headers_idempotent.c b/tools/ccanlint/tests/headers_idempotent.c index 340a0698..4e41d058 100644 --- a/tools/ccanlint/tests/headers_idempotent.c +++ b/tools/ccanlint/tests/headers_idempotent.c @@ -27,7 +27,7 @@ static void fix_name(char *name) unsigned int i; for (i = 0; name[i]; i++) { - if (isalnum(name[i])) + if (cisalnum(name[i])) name[i] = toupper(name[i]); else name[i] = '_'; @@ -46,10 +46,10 @@ static void handle_idem(struct manifest *m, struct score *score) /* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */ if (strstarts(e->file->name, m->basename) || 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->modname); else name = talloc_asprintf(score, "CCAN_%s_%s", - m->basename, e->file->name); + m->modname, e->file->name); fix_name(name); q = talloc_asprintf(score, @@ -58,7 +58,7 @@ static void handle_idem(struct manifest *m, struct score *score) if (!ask(q)) continue; - tmpname = maybe_temp_file(score, ".h", false, e->file->name); + tmpname = temp_file(score, ".h", e->file->name); out = fopen(tmpname, "w"); if (!out) err(1, "Opening %s", tmpname); @@ -80,7 +80,7 @@ static void handle_idem(struct manifest *m, struct score *score) } } -static bool check_idem(struct ccan_file *f, struct score *score) +static void check_idem(struct ccan_file *f, struct score *score) { struct line_info *line_info; unsigned int i, first_preproc_line; @@ -89,7 +89,7 @@ static bool check_idem(struct ccan_file *f, struct score *score) line_info = get_ccan_line_info(f); if (f->num_lines < 3) /* FIXME: We assume small headers probably uninteresting. */ - return true; + return; for (i = 0; i < f->num_lines; i++) { if (line_info[i].type == DOC_LINE @@ -99,14 +99,14 @@ static bool check_idem(struct ccan_file *f, struct score *score) score_file_error(score, f, i+1, "Expect first non-comment line to be" " #ifndef."); - return false; + return; } else if (line_info[i].type == PREPROC_LINE) break; } /* No code at all? Don't complain. */ if (i == f->num_lines) - return true; + return; first_preproc_line = i; for (i = first_preproc_line+1; i < f->num_lines; i++) { @@ -117,19 +117,19 @@ static bool check_idem(struct ccan_file *f, struct score *score) score_file_error(score, f, i+1, "Expect second non-comment line to be" " #define."); - return false; + return; } else if (line_info[i].type == PREPROC_LINE) break; } /* No code at all? Weird. */ if (i == f->num_lines) - return true; + return; /* We expect a condition on this line. */ if (!line_info[i].cond) { score_file_error(score, f, i+1, "Expected #ifndef"); - return false; + return; } line = f->lines[i]; @@ -138,26 +138,24 @@ static bool check_idem(struct ccan_file *f, struct score *score) if (line_info[i].cond->type != PP_COND_IFDEF || !line_info[i].cond->inverse) { score_file_error(score, f, i+1, "Expected #ifndef"); - return false; + return; } /* And this to be #define */ if (!get_token(&line, "#")) abort(); if (!get_token(&line, "define")) { - char *str = talloc_asprintf(score, - "expected '#define %s'", - line_info[i].cond->symbol); - score_file_error(score, f, i+1, str); - return false; + score_file_error(score, f, i+1, + "expected '#define %s'", + line_info[i].cond->symbol); + return; } sym = get_symbol_token(f, &line); if (!sym || !streq(sym, line_info[i].cond->symbol)) { - char *str = talloc_asprintf(score, - "expected '#define %s'", - line_info[i].cond->symbol); - score_file_error(score, f, i+1, str); - return false; + score_file_error(score, f, i+1, + "expected '#define %s'", + line_info[i].cond->symbol); + return; } /* Rest of code should all be covered by that conditional. */ @@ -170,25 +168,23 @@ static bool check_idem(struct ccan_file *f, struct score *score) != NOT_COMPILED) { score_file_error(score, f, i+1, "code outside" " idempotent region"); - return false; + return; } } - - return true; } static void check_idempotent(struct manifest *m, - bool keep, unsigned int *timeleft, struct score *score) { struct ccan_file *f; + /* We don't fail ccanlint for this. */ + score->pass = true; + list_for_each(&m->h_files, f, list) { - if (!check_idem(f, score)) - score->error = "Headers are not idempotent"; + check_idem(f, score); } if (!score->error) { - score->pass = true; score->score = score->total; } } @@ -198,7 +194,7 @@ struct ccanlint headers_idempotent = { .name = "Module headers are #ifndef/#define wrapped", .check = check_idempotent, .handle = handle_idem, - .needs = "" + .needs = "info_exists main_header_exists" }; REGISTER_TEST(headers_idempotent);