]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/ccanlint.h
ac169fa81156b57452708208af65fecd05402fdf
[ccan] / tools / ccanlint / ccanlint.h
1 #ifndef CCAN_LINT_H
2 #define CCAN_LINT_H
3 #include <ccan/list/list.h>
4 #include <stdbool.h>
5 #include "../doc_extract.h"
6
7 struct manifest {
8         char *basename;
9         struct ccan_file *info_file;
10
11         struct list_head c_files;
12         struct list_head h_files;
13
14         struct list_head run_tests;
15         struct list_head api_tests;
16         struct list_head compile_ok_tests;
17         struct list_head compile_fail_tests;
18         struct list_head other_test_files;
19
20         struct list_head other_files;
21 };
22
23 struct manifest *get_manifest(void);
24
25 struct ccanlint {
26         struct list_node list;
27
28         /* Unique name of test */
29         const char *name;
30
31         /* Total score that this test is worth.  0 means compulsory tests. */
32         unsigned int total_score;
33
34         /* If this returns non-NULL, it means the check failed. */
35         void *(*check)(struct manifest *m);
36
37         /* The non-NULL return from check is passed to one of these: */
38
39         /* So, what did this get out of the total_score?  (NULL means 0). */
40         unsigned int (*score)(struct manifest *m, void *check_result);
41
42         /* Verbose description of what was wrong. */
43         const char *(*describe)(struct manifest *m, void *check_result);
44
45         /* Can we do something about it? (NULL if not) */
46         void (*handle)(struct manifest *m, void *check_result);
47 };
48
49 /* Ask the user a yes/no question: the answer is NO if there's an error. */
50 bool ask(const char *question);
51
52 struct ccan_file {
53         struct list_node list;
54
55         char *name;
56
57         unsigned int num_lines;
58         char **lines;
59
60         struct list_head *doc_sections;
61 };
62
63 /* Use this rather than accessing f->lines directly: loads on demand. */
64 char **get_ccan_file_lines(struct ccan_file *f);
65
66 /* Similarly for ->doc_sections */
67 struct list_head *get_ccan_file_docs(struct ccan_file *f);
68
69 /* Call the reporting on every line in the file.  sofar contains
70  * previous results. */
71 char *report_on_lines(struct list_head *files,
72                       char *(*report)(const char *),
73                       char *sofar);
74
75 /* The critical tests which mean fail if they don't pass. */
76 extern struct ccanlint no_info;
77 extern struct ccanlint has_main_header;
78
79 /* Normal tests. */
80 extern struct ccanlint trailing_whitespace;
81
82
83 #endif /* CCAN_LINT_H */