fix warnings, disable empty statement warning by default
[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("empty-statement",               empty_statement)
22         OPT("error",                         s_are_errors)
23         OPT("fatal-errors",                  fatal_errors)
24         OPT("format",                        check_format)
25         OPTX("implicit") {
26                 SET(implicit_function_declaration)
27                 SET(implicit_int)
28         }
29         OPT("implicit-function-declaration", implicit_function_declaration)
30         OPT("implicit-int",                  implicit_int)
31         OPT("missing-declarations",          missing_declarations)
32         OPT("missing-prototypes",            missing_prototypes)
33         OPT("redundant-decls",               redundant_decls)
34         OPT("strict-prototypes",             strict_prototypes)
35         OPT("switch-default",                switch_default)
36         OPT("unknown-pragmas",               unknown_pragmas)
37 #if 0
38         OPTX("unused") {
39                 SET(unused_function)
40                 SET(unused_label)
41                 SET(unused_parameter)
42                 SET(unused_variable)
43                 SET(unused_value)
44         }
45 #endif
46         OPT("unused-value",                  unused_value)
47 #undef OPT
48 #undef SET
49 #undef OPT_X
50         else {
51                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
52         }
53 }
54
55 warning_t warning = {
56         .char_subscripts               = true,
57         .check_format                  = true,
58         .empty_statement               = false,
59         .fatal_errors                  = false,
60         .implicit_function_declaration = true,
61         .implicit_int                  = true,
62         .missing_declarations          = true,
63         .missing_prototypes            = true,
64         .redundant_decls               = true,
65         .s_are_errors                  = false,
66         .strict_prototypes             = true,
67         .switch_default                = false,
68         .unknown_pragmas               = true,
69         .unused_value                  = true
70 };