]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/license_comment.c
ccanlint: remove argument to -k/--keep
[ccan] / tools / ccanlint / tests / license_comment.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <ccan/foreach/foreach.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <limits.h>
8 #include <errno.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <err.h>
12 #include <ccan/talloc/talloc.h>
13 #include <ccan/str/str.h>
14 #include <ccan/str_talloc/str_talloc.h>
15
16 static void check_license_comment(struct manifest *m,
17                                   unsigned int *timeleft, struct score *score)
18 {
19         struct list_head *list;
20
21         /* No requirements on public domain. */
22         if (m->license == LICENSE_PUBLIC_DOMAIN
23             || m->license == LICENSE_UNKNOWN) {
24                 score->pass = true;
25                 score->score = score->total;
26                 return;
27         }
28
29         foreach_ptr(list, &m->c_files, &m->h_files) {
30                 struct ccan_file *f;
31
32                 list_for_each(list, f, list) {
33                         unsigned int i;
34                         char **lines = get_ccan_file_lines(f);
35                         struct line_info *info = get_ccan_line_info(f);
36                         bool found_license = false, found_flavor = false;
37
38                         for (i = 0; lines[i]; i++) {
39                                 if (info[i].type == CODE_LINE)
40                                         break;
41                                 if (strstr(lines[i], "LICENSE"))
42                                         found_license = true;
43                                 if (strstr(lines[i],
44                                            licenses[m->license].shortname))
45                                         found_flavor = true;
46                         }
47                         if ((!found_license || !found_flavor)
48                             && !find_boilerplate(f, m->license)) {
49                                 score_file_error(score, f, lines[i] ? i : 0,
50                                                  "No reference to license"
51                                                  " found");
52                         }
53                 }
54         }
55
56         if (list_empty(&score->per_file_errors)) {
57                 score->pass = true;
58                 score->score = score->total;
59         }
60 }
61
62 struct ccanlint license_comment = {
63         .key = "license_comment",
64         .name = "Source and header files refer to LICENSE",
65         .check = check_license_comment,
66         .needs = "license_exists"
67 };
68 REGISTER_TEST(license_comment);