Spell the option -Wpointer-arith, not -Wpointer_arith.
[cparser] / warning.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <stdio.h>
21 #include <string.h>
22 #include "warning.h"
23
24 warning_t warning = {
25         .aggregate_return              = false,
26         .attribute                     = true,
27         .cast_qual                     = false,
28         .char_subscripts               = true,
29         .comment                       = false,
30         .conversion                    = false,
31         .declaration_after_statement   = false,
32         .deprecated_declarations       = true,
33         .div_by_zero                   = true,
34         .empty_statement               = false,
35         .fatal_errors                  = false,
36         .float_equal                   = false,
37         .format                        = true,
38         .implicit_function_declaration = true,
39         .implicit_int                  = true,
40         .init_self                     = true,
41         .long_long                     = false,
42         .main                          = true,
43         .missing_declarations          = false,
44         .missing_noreturn              = false,
45         .missing_prototypes            = false,
46         .multichar                     = true,
47         .nested_externs                = false,
48         .nonnull                       = true,
49         .old_style_definition          = false,
50         .packed                        = false,
51         .padded                        = false,
52         .pointer_arith                 = true,
53         .redundant_decls               = true,
54         .return_type                   = true,
55         .s_are_errors                  = false,
56         .shadow                        = false,
57         .sign_compare                  = false,
58         .strict_prototypes             = true,
59         .switch_default                = false,
60         .switch_enum                   = false,
61         .traditional                   = false,
62         .unknown_pragmas               = true,
63         .unreachable_code              = false,
64         .unused_function               = false,
65         .unused_label                  = false,
66         .unused_parameter              = false,
67         .unused_value                  = true,
68         .unused_variable               = false,
69         .write_strings                 = false
70 };
71
72 void set_warning_opt(const char *const opt)
73 {
74         const char* s = opt;
75
76         bool state = true;
77
78         /* "no-" prefix */
79         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
80                 s += 3;
81                 state = false;
82         }
83
84         if (0) {}
85 #define OPTX(x)   else if (strcmp(s, x) == 0)
86 #define SET(y)    (void)(warning.y = state)
87 #define OPT(x, y) OPTX(x) SET(y)
88         OPTX("all") {
89                 /* Note: this switched on a lot of more warnings than gcc's -Wall */
90                 SET(attribute);
91                 SET(char_subscripts);
92                 SET(comment);
93                 SET(empty_statement);
94                 SET(format);
95                 SET(implicit_function_declaration);
96                 SET(implicit_int);
97                 SET(init_self);
98                 SET(main);
99                 SET(nonnull);
100                 SET(pointer_arith);
101                 SET(redundant_decls);
102                 SET(return_type);
103                 SET(shadow);
104                 SET(sign_compare);
105                 SET(strict_prototypes);
106                 SET(switch_enum);
107                 SET(unknown_pragmas);
108                 SET(unreachable_code);
109                 SET(unused_function);
110                 SET(unused_label);
111                 SET(unused_parameter);
112                 SET(unused_value);
113                 SET(unused_variable);
114         }
115         OPT("aggregate-return",              aggregate_return);
116         OPT("attribute",                     attribute);
117         OPT("cast-qual",                     cast_qual);
118         OPT("char-subscripts",               char_subscripts);
119         OPT("comment",                       comment);
120         OPT("conversion",                    conversion);
121         OPT("declaration-after-statement",   declaration_after_statement);
122         OPT("deprecated-declarations",       deprecated_declarations);
123         OPT("div-by-zero",                   div_by_zero);
124         OPT("empty-statement",               empty_statement);
125         OPT("error",                         s_are_errors);
126         OPTX("extra") {
127                 /* TODO */
128                 // TODO SET(function_end_without_return);
129                 SET(empty_statement);
130                 // TODO SET(incomplete_aggregate_init);
131                 // TODO SET(missing_field_initializers);
132                 // TODO SET(pointless_comparison);
133                 SET(unused_parameter);
134                 SET(unused_value);
135         }
136         OPT("fatal-errors",                  fatal_errors);
137         OPT("float-equal",                   float_equal);
138         OPTX("format") {
139                 SET(format);
140                 SET(nonnull);
141         }
142         OPTX("implicit") {
143                 SET(implicit_function_declaration);
144                 SET(implicit_int);
145         }
146         OPT("implicit-function-declaration", implicit_function_declaration);
147         OPT("implicit-int",                  implicit_int);
148         OPT("init-self",                     init_self);
149         OPT("long-long",                     long_long);
150         OPT("main",                          main);
151         OPT("missing-declarations",          missing_declarations);
152         OPT("missing-noreturn",              missing_noreturn);
153         OPT("missing-prototypes",            missing_prototypes);
154         OPT("multichar",                     multichar);
155         OPT("nested-externs",                nested_externs);
156         OPT("nonnull",                       nonnull);
157         OPT("old-style-definition",          old_style_definition);
158         OPT("packed",                        packed);
159         OPT("padded",                        padded);
160         OPT("pointer-arith",                 pointer_arith);
161         OPT("redundant-decls",               redundant_decls);
162         OPT("return-type",                   return_type);
163         OPT("shadow",                        shadow);
164         OPT("sign-compare",                  sign_compare);
165         OPT("strict-prototypes",             strict_prototypes);
166         OPT("switch-default",                switch_default);
167         OPT("switch-enum",                   switch_enum);
168         OPT("traditional",                   traditional);
169         OPT("unknown-pragmas",               unknown_pragmas);
170         OPT("unreachable-code",              unreachable_code);
171         OPTX("unused") {
172                 SET(unused_function);
173                 SET(unused_label);
174                 SET(unused_parameter);
175                 SET(unused_value);
176                 SET(unused_variable);
177         }
178         OPT("unused-function",               unused_function);
179         OPT("unused-label",                  unused_label);
180         OPT("unused-parameter",              unused_parameter);
181         OPT("unused-value",                  unused_value);
182         OPT("unused-variable",               unused_variable);
183         OPT("write-strings",                 write_strings);
184 #undef OPT
185 #undef SET
186 #undef OPT_X
187         else {
188                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
189         }
190 }