Implement -Wunknown-pragmas.
[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("missing-prototypes",            missing_prototypes)
32         OPT("redundant-decls",               redundant_decls)
33         OPT("strict-prototypes",             strict_prototypes)
34         OPT("switch-default",                switch_default)
35         OPT("unknown-pragmas",               unknown_pragmas)
36 #if 0
37         OPTX("unused") {
38                 SET(unused_function)
39                 SET(unused_label)
40                 SET(unused_parameter)
41                 SET(unused_variable)
42                 SET(unused_value)
43         }
44 #endif
45         OPT("unused-value",                  unused_value)
46 #undef OPT
47 #undef SET
48 #undef OPT_X
49         else {
50                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
51         }
52 }
53
54 warning_t warning = {
55         .char_subscripts               = true,
56         .check_format                  = true,
57         .fatal_errors                  = false,
58         .implicit_function_declaration = true,
59         .implicit_int                  = true,
60         .missing_declarations          = true,
61         .missing_prototypes            = true,
62         .redundant_decls               = true,
63         .s_are_errors                  = false,
64         .strict_prototypes             = true,
65         .switch_default                = false,
66         .unknown_pragmas               = true,
67         .unused_value                  = true
68 };