X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=warning.c;h=67ee728493774e291099ccb28a0c74344111cbe0;hb=refs%2Fheads%2Falias;hp=f8b38076dfc20b171c11e0f140441d9c46211c2a;hpb=9634f9c53e95b6bdc7883228c5ec5147f3de4f8e;p=cparser diff --git a/warning.c b/warning.c index f8b3807..67ee728 100644 --- a/warning.c +++ b/warning.c @@ -1,26 +1,12 @@ /* * This file is part of cparser. - * Copyright (C) 2007-2009 Matthias Braun - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * Copyright (C) 2012 Matthias Braun */ #include #include #include +#include "adt/strutil.h" #include "adt/util.h" #include "warning.h" #include "help.h" @@ -36,14 +22,15 @@ static warning_switch_t warning[] = { [WARN_DECLARATION_AFTER_STATEMENT] = { WARN_STATE_NONE, "declaration-after-statement", }, [WARN_DEPRECATED_DECLARATIONS] = { WARN_STATE_ON, "deprecated-declarations", }, [WARN_DIV_BY_ZERO] = { WARN_STATE_ON, "div-by-zero", }, + [WARN_EMPTY_BODY] = { WARN_STATE_NONE, "empty-body", }, [WARN_EMPTY_STATEMENT] = { WARN_STATE_NONE, "empty-statement", }, [WARN_ERROR] = { WARN_STATE_NONE, "error" }, [WARN_FATAL_ERRORS] = { WARN_STATE_NONE, "fatal-errors" }, [WARN_FLOAT_EQUAL] = { WARN_STATE_NONE, "float-equal", }, [WARN_FORMAT] = { WARN_STATE_ON, "format" }, + [WARN_IGNORED_QUALIFIERS] = { WARN_STATE_ON, "ignored-qualifiers" }, [WARN_IMPLICIT_FUNCTION_DECLARATION] = { WARN_STATE_ON, "implicit-function-declaration" }, [WARN_IMPLICIT_INT] = { WARN_STATE_ON, "implicit-int" }, - [WARN_INIT_SELF] = { WARN_STATE_ON, "init-self", }, [WARN_LONG_LONG] = { WARN_STATE_NONE, "long-long" }, [WARN_MAIN] = { WARN_STATE_ON, "main", }, [WARN_MISSING_DECLARATIONS] = { WARN_STATE_NONE, "missing-declarations", }, @@ -63,9 +50,11 @@ static warning_switch_t warning[] = { [WARN_SHADOW] = { WARN_STATE_NONE, "shadow", }, [WARN_SHADOW_LOCAL] = { WARN_STATE_NONE, "shadow-local", }, [WARN_SIGN_COMPARE] = { WARN_STATE_NONE, "sign-compare", }, + [WARN_STRAY_SEMICOLON] = { WARN_STATE_ON, "stray-semicolon", }, [WARN_STRICT_PROTOTYPES] = { WARN_STATE_ON, "strict-prototypes" }, [WARN_SWITCH_DEFAULT] = { WARN_STATE_NONE, "switch-default", }, [WARN_SWITCH_ENUM] = { WARN_STATE_NONE, "switch-enum", }, + [WARN_SYSTEM] = { WARN_STATE_NONE, "system", }, [WARN_TRADITIONAL] = { WARN_STATE_NONE, "traditional" }, [WARN_UNINITIALIZED] = { WARN_STATE_ON, "uninitialized", }, [WARN_UNKNOWN_PRAGMAS] = { WARN_STATE_ON, "unknown-pragmas", }, @@ -89,7 +78,9 @@ void print_warning_opt_help(void) { /* TODO: write explanations */ for (warning_switch_t* i = warning; i != endof(warning); ++i) { - put_help(i->name, ""); + char buf[256]; + snprintf(buf, sizeof(buf), "-W%s", i->name); + put_help(buf, ""); } } @@ -97,8 +88,9 @@ void set_warning_opt(const char *const opt) { /* Process prefixes: -W[no-][error=] */ char const *s = opt; - bool const no = strncmp(s, "no-", 3) == 0 ? s += 3, true : false; - bool const error = strncmp(s, "error=", 6) == 0 ? s += 6, true : false; + char const *rest; + bool const no = (rest = strstart(s, "no-")) ? s = rest, true : false; + bool const error = (rest = strstart(s, "error=")) ? s = rest, true : false; warn_state_t on = WARN_STATE_NONE; warn_state_t off = WARN_STATE_NONE; @@ -115,7 +107,7 @@ void set_warning_opt(const char *const opt) } for (warning_switch_t* i = warning; i != endof(warning); ++i) { - if (strcmp(i->name, s) == 0) { + if (streq(i->name, s)) { i->state = (i->state & ~off) | on; return; } @@ -124,7 +116,7 @@ void set_warning_opt(const char *const opt) if (s[0] == '\0') { // -W is an alias for -Wextra goto extra; } -#define OPTX(x) else if (strcmp(s, x) == 0) +#define OPTX(x) else if (streq(s, x)) #define SET(y) (void)(warning[y].state = (warning[y].state & ~off) | on) OPTX("all") { /* Note: this switched on a lot more warnings than gcc's -Wall */ @@ -136,7 +128,6 @@ void set_warning_opt(const char *const opt) SET(WARN_FORMAT); SET(WARN_IMPLICIT_FUNCTION_DECLARATION); SET(WARN_IMPLICIT_INT); - SET(WARN_INIT_SELF); SET(WARN_MAIN); SET(WARN_MISSING_DECLARATIONS); SET(WARN_NONNULL); @@ -183,7 +174,7 @@ extra: } #undef SET #undef OPT_X - else if (strcmp(opt /* sic */, "error-implicit-function-declaration") == 0) { + else if (streq(opt /* sic */, "error-implicit-function-declaration")) { /* GCC legacy: This way it only can be activated. */ warning[WARN_IMPLICIT_FUNCTION_DECLARATION].state = WARN_STATE_ON | WARN_STATE_ERROR; return;