Accept -Wno-all, -Wno-extra and -Wno-unused like GCC.
[cparser] / warning.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "warning.h"
4
5 warning_t warning = {
6         .char_subscripts               = true,
7         .check_format                  = true,
8         .empty_statement               = false,
9         .fatal_errors                  = false,
10         .float_equal                   = false,
11         .implicit_function_declaration = true,
12         .implicit_int                  = true,
13         .main                          = true,
14         .missing_declarations          = false,
15         .missing_prototypes            = false,
16         .redundant_decls               = true,
17         .s_are_errors                  = false,
18         .strict_prototypes             = true,
19         .switch_default                = false,
20         .unknown_pragmas               = true,
21         .unused_function               = false,
22         .unused_label                  = false,
23         .unused_parameter              = false,
24         .unused_value                  = true,
25         .unused_variable               = false
26 };
27
28 void set_warning_opt(const char *const opt)
29 {
30         const char* s = opt;
31
32         bool state = true;
33
34         /* "no-" prefix */
35         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
36                 s += 3;
37                 state = false;
38         }
39
40         if (0) {}
41 #define OPTX(x)   else if (strcmp(s, x) == 0)
42 #define SET(y)    warning.y = state;
43 #define OPT(x, y) OPTX(x) SET(y)
44         OPTX("all") {
45                 SET(char_subscripts)
46                 SET(check_format)
47                 SET(empty_statement)
48                 SET(implicit_function_declaration)
49                 SET(implicit_int)
50                 SET(main)
51                 SET(redundant_decls)
52                 SET(strict_prototypes)
53                 SET(switch_default)
54                 SET(unknown_pragmas)
55                 SET(unused_function)
56                 SET(unused_label)
57                 SET(unused_parameter)
58                 SET(unused_value)
59                 SET(unused_variable)
60         }
61         OPT("char-subscripts",               char_subscripts)
62         OPT("empty-statement",               empty_statement)
63         OPT("error",                         s_are_errors)
64         OPTX("extra") {
65                 /* TODO */
66                 // TODO SET(function_end_without_return)
67                 SET(empty_statement)
68                 // TODO SET(incomplete_aggregate_init)
69                 // TODO SET(pointless_comparison)
70                 // TODO SET(sign_compare)
71                 SET(unused_parameter)
72                 SET(unused_value)
73         }
74         OPT("fatal-errors",                  fatal_errors)
75         OPT("float-equal",                   float_equal)
76         OPT("format",                        check_format)
77         OPTX("implicit") {
78                 SET(implicit_function_declaration)
79                 SET(implicit_int)
80         }
81         OPT("implicit-function-declaration", implicit_function_declaration)
82         OPT("implicit-int",                  implicit_int)
83         OPT("main",                          main)
84         OPT("missing-declarations",          missing_declarations)
85         OPT("missing-prototypes",            missing_prototypes)
86         OPT("redundant-decls",               redundant_decls)
87         OPT("strict-prototypes",             strict_prototypes)
88         OPT("switch-default",                switch_default)
89         OPT("unknown-pragmas",               unknown_pragmas)
90         OPT("unused-function",               unused_function)
91         OPT("unused-label",                  unused_label)
92         OPT("unused-parameter",              unused_parameter)
93         OPT("unused-variable",               unused_variable)
94         OPTX("unused") {
95                 SET(unused_function)
96                 SET(unused_label)
97                 SET(unused_parameter)
98                 SET(unused_value)
99                 SET(unused_variable)
100         }
101         OPT("unused-function",               unused_function)
102         OPT("unused-label",                  unused_label)
103         OPT("unused-parameter",              unused_parameter)
104         OPT("unused-value",                  unused_value)
105         OPT("unused-variable",               unused_variable)
106 #undef OPT
107 #undef SET
108 #undef OPT_X
109         else {
110                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
111         }
112 }