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