]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/trailing_whitespace.c
tools: fixes for 64-bit.
[ccan] / tools / ccanlint / tests / trailing_whitespace.c
1 /* Trailing whitespace test.  Almost embarrassing, but trivial. */
2 #include <tools/ccanlint/ccanlint.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5
6 /* FIXME: only print full analysis if verbose >= 2.  */
7 static char *report_on_trailing_whitespace(const char *line)
8 {
9         const char *e = strchr(line, 0);
10         while (e>line && (e[-1]==' ' || e[-1]=='\t'))
11                 e--;
12         if (*e == 0)
13                 return NULL; //there were no trailing spaces
14         if (e == line)
15                 return NULL; //the line only consists of spaces
16
17         if (strlen(line) > 20)
18                 return talloc_asprintf(line, "...'%s'",
19                                        line + strlen(line) - 20);
20         return talloc_asprintf(line, "'%s'", line);
21 }
22
23 static void *check_trailing_whitespace(struct manifest *m,
24                                        bool keep,
25                                        unsigned int *timeleft)
26 {
27         char *report;
28
29         report = report_on_lines(&m->c_files, report_on_trailing_whitespace,
30                                  NULL);
31         report = report_on_lines(&m->h_files, report_on_trailing_whitespace,
32                                  report);
33
34         return report;
35 }
36
37 static const char *describe_trailing_whitespace(struct manifest *m,
38                                                 void *check_result)
39 {
40         if (!verbose)
41                 return NULL;
42         return talloc_asprintf(check_result, 
43                                "Some source files have trailing whitespace:\n"
44                                "%s", (char *)check_result);
45 }
46
47 struct ccanlint trailing_whitespace = {
48         .key = "trailing-whitespace",
49         .name = "Module's source code has no trailing whitespace",
50         .total_score = 1,
51         .check = check_trailing_whitespace,
52         .describe = describe_trailing_whitespace,
53 };
54
55
56 REGISTER_TEST(trailing_whitespace, NULL);