Remove duplicate warning entry, sort.
[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         .attribute                     = true,
26         .char_subscripts               = true,
27         .format                        = true,
28         .nonnull                       = true,
29         .empty_statement               = false,
30         .fatal_errors                  = false,
31         .float_equal                   = false,
32         .implicit_function_declaration = true,
33         .implicit_int                  = true,
34         .main                          = true,
35         .missing_declarations          = false,
36         .missing_prototypes            = false,
37         .multichar                     = true,
38         .redundant_decls               = true,
39         .return_type                   = true,
40         .s_are_errors                  = false,
41         .shadow                        = false,
42         .sign_compare                  = false,
43         .strict_prototypes             = true,
44         .switch_default                = false,
45         .unknown_pragmas               = true,
46         .unused_function               = false,
47         .unused_label                  = false,
48         .unused_parameter              = false,
49         .unused_value                  = true,
50         .unused_variable               = false
51 };
52
53 void set_warning_opt(const char *const opt)
54 {
55         const char* s = opt;
56
57         bool state = true;
58
59         /* "no-" prefix */
60         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
61                 s += 3;
62                 state = false;
63         }
64
65         if (0) {}
66 #define OPTX(x)   else if (strcmp(s, x) == 0)
67 #define SET(y)    warning.y = state;
68 #define OPT(x, y) OPTX(x) SET(y)
69         OPTX("all") {
70                 /* Note: this switched on a lot of more warnings than gcc's -Wall */
71                 SET(attribute)
72                 SET(char_subscripts)
73                 SET(empty_statement)
74                 SET(format)
75                 SET(implicit_function_declaration)
76                 SET(implicit_int)
77                 SET(main)
78                 SET(nonnull)
79                 SET(redundant_decls)
80                 SET(return_type)
81                 SET(shadow)
82                 SET(sign_compare)
83                 SET(strict_prototypes)
84                 SET(unknown_pragmas)
85                 SET(unused_function)
86                 SET(unused_label)
87                 SET(unused_parameter)
88                 SET(unused_value)
89                 SET(unused_variable)
90         }
91         OPT("attribute",                     attribute)
92         OPT("char-subscripts",               char_subscripts)
93         OPT("empty-statement",               empty_statement)
94         OPT("error",                         s_are_errors)
95         OPTX("extra") {
96                 /* TODO */
97                 // TODO SET(function_end_without_return)
98                 SET(empty_statement)
99                 // TODO SET(incomplete_aggregate_init)
100                 // TODO SET(pointless_comparison)
101                 // TODO SET(sign_compare)
102                 SET(unused_parameter)
103                 SET(unused_value)
104         }
105         OPT("fatal-errors",                  fatal_errors)
106         OPT("float-equal",                   float_equal)
107         OPTX("format") {
108                 SET(format)
109                 SET(nonnull)
110         }
111         OPT("nonnull",                       nonnull)
112         OPTX("implicit") {
113                 SET(implicit_function_declaration)
114                 SET(implicit_int)
115         }
116         OPT("implicit-function-declaration", implicit_function_declaration)
117         OPT("implicit-int",                  implicit_int)
118         OPT("main",                          main)
119         OPT("missing-declarations",          missing_declarations)
120         OPT("missing-prototypes",            missing_prototypes)
121         OPT("multichar",                     multichar)
122         OPT("redundant-decls",               redundant_decls)
123         OPT("return-type",                   return_type)
124         OPT("shadow",                        shadow)
125         OPT("sign-compare",                  sign_compare)
126         OPT("strict-prototypes",             strict_prototypes)
127         OPT("switch-default",                switch_default)
128         OPT("unknown-pragmas",               unknown_pragmas)
129         OPTX("unused") {
130                 SET(unused_function)
131                 SET(unused_label)
132                 SET(unused_parameter)
133                 SET(unused_value)
134                 SET(unused_variable)
135         }
136         OPT("unused-function",               unused_function)
137         OPT("unused-label",                  unused_label)
138         OPT("unused-parameter",              unused_parameter)
139         OPT("unused-value",                  unused_value)
140         OPT("unused-variable",               unused_variable)
141 #undef OPT
142 #undef SET
143 #undef OPT_X
144         else {
145                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
146         }
147 }