Implement a new agile warning framework.
[cparser] / warning.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "warning.h"
4
5 void set_warning_opt(const char *const opt)
6 {
7         const char* s = opt;
8
9         bool state = true;
10         /* no- modifier */
11         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
12                 s += 3;
13                 state = false;
14         }
15
16         if (0) {}
17 #define OPTX(x)   else if (strcmp(s, x) == 0)
18 #define SET(y)    warning.y = state;
19 #define OPT(x, y) OPTX(x) SET(y)
20         OPT("char-subscripts",               char_subscripts)
21         OPT("error",                         s_are_errors)
22         OPT("fatal-errors",                  fatal_errors)
23         OPT("format",                        check_format)
24         OPTX("implicit") {
25                 SET(implicit_function_declaration)
26                 SET(implicit_int)
27         }
28         OPT("implicit-function-declaration", implicit_function_declaration)
29         OPT("implicit-int",                  implicit_int)
30         OPT("missing-declarations",          missing_declarations)
31         OPT("redundant-decls",               redundant_decls)
32         OPT("strict-prototypes",             strict_prototypes)
33 #if 0
34         OPTX("unused") {
35                 SET(unused_function)
36                 SET(unused_label)
37                 SET(unused_parameter)
38                 SET(unused_variable)
39                 SET(unused_value)
40         }
41 #endif
42 #undef OPT
43         else {
44                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
45         }
46 }
47
48 warning_t warning = {
49         .char_subscripts               = true,
50         .check_format                  = true,
51         .implicit_function_declaration = true,
52         .implicit_int                  = true,
53         .missing_declarations          = true,
54         .strict_prototypes             = true,
55         .redundant_decls               = true
56 };