improved error output for function cases
[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("float-equal",                   float_equal)
25         OPT("format",                        check_format)
26         OPTX("implicit") {
27                 SET(implicit_function_declaration)
28                 SET(implicit_int)
29         }
30         OPT("implicit-function-declaration", implicit_function_declaration)
31         OPT("implicit-int",                  implicit_int)
32         OPT("main",                          main)
33         OPT("missing-declarations",          missing_declarations)
34         OPT("missing-prototypes",            missing_prototypes)
35         OPT("redundant-decls",               redundant_decls)
36         OPT("strict-prototypes",             strict_prototypes)
37         OPT("switch-default",                switch_default)
38         OPT("unknown-pragmas",               unknown_pragmas)
39         OPT("unused-label",                  unused_label)
40         OPT("unused-parameter",              unused_parameter)
41         OPT("unused-variable",               unused_variable)
42 #if 0
43         OPTX("unused") {
44                 SET(unused_function)
45                 SET(unused_label)
46                 SET(unused_parameter)
47                 SET(unused_variable)
48                 SET(unused_value)
49         }
50 #endif
51         OPT("unused-value",                  unused_value)
52 #undef OPT
53 #undef SET
54 #undef OPT_X
55         else {
56                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
57         }
58 }
59
60 warning_t warning = {
61         .char_subscripts               = true,
62         .check_format                  = true,
63         .empty_statement               = false,
64         .fatal_errors                  = false,
65         .float_equal                   = false,
66         .implicit_function_declaration = true,
67         .implicit_int                  = true,
68         .main                          = true,
69         .missing_declarations          = false,
70         .missing_prototypes            = false,
71         .redundant_decls               = true,
72         .s_are_errors                  = false,
73         .strict_prototypes             = true,
74         .switch_default                = false,
75         .unknown_pragmas               = true,
76         .unused_label                  = false,
77         .unused_parameter              = false,
78         .unused_variable               = false,
79         .unused_value                  = true
80 };