kconfig: warn of unhandled characters in Kconfig commands
authorAndreas Ruprecht <andreas.ruprecht@fau.de>
Sun, 12 Jul 2015 07:41:50 +0000 (09:41 +0200)
committerChristian Lamparter <chunkeey@googlemail.com>
Wed, 27 Apr 2016 14:17:14 +0000 (16:17 +0200)
In Kconfig, definitions of options take the following form:
"<COMMAND> <PARAM> <PARAM> ...". COMMANDs and PARAMs are treated
slightly different by the underlying parser.

While commit 2e0d737fc76f ("kconfig: don't silently ignore unhandled
characters") introduced a warning for unsupported characters around
PARAMs, it does not cover situations where a COMMAND has additional
characters before it.

This change makes Kconfig emit a warning if superfluous characters
are found before COMMANDs. As the 'help' statement sometimes is
written as '---help---', the '-' character would now also be regarded
as unhandled and generate a warning. To avoid that, '-' is added to
the list of allowed characters, and the token '---help---' is included
in the zconf.gperf file.

Reported-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Andreas Ruprecht <andreas.ruprecht@fau.de>
Reviewed-by: Ulf Magnusson <ulfalizer@gmail.com>
Tested-by: Ulf Magnusson <ulfalizer@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
config/zconf.gperf
config/zconf.l

index f639adb0fb943daaee3d0c069277e990070d4d23..9ce6b53d903f8cdd99fcfe2a59c52dd981b7626a 100644 (file)
@@ -22,6 +22,7 @@ comment,      T_COMMENT,      TF_COMMAND
 config,                T_CONFIG,       TF_COMMAND
 menuconfig,    T_MENUCONFIG,   TF_COMMAND
 help,          T_HELP,         TF_COMMAND
+---help---,    T_HELP,         TF_COMMAND
 if,            T_IF,           TF_COMMAND|TF_PARAM
 endif,         T_ENDIF,        TF_COMMAND
 depends,       T_DEPENDS,      TF_COMMAND
index 020c099a3a6568190a5584db7245e8f53a1f3760..9720530ed688d1593b2fe1ef72ce7d6b054a6a0d 100644 (file)
@@ -66,9 +66,16 @@ static void alloc_string(const char *str, int size)
        memcpy(text, str, size);
        text[size] = 0;
 }
+
+static void warn_ignored_character(char chr)
+{
+       fprintf(stderr,
+               "%s:%d:warning: ignoring unsupported character '%c'\n",
+               zconf_curname(), zconf_lineno(), chr);
+}
 %}
 
-n      [A-Za-z0-9_]
+n      [A-Za-z0-9_-]
 
 %%
        int str = 0;
@@ -106,7 +113,7 @@ n   [A-Za-z0-9_]
                zconflval.string = text;
                return T_WORD;
        }
-       .
+       .       warn_ignored_character(*yytext);
        \n      {
                BEGIN(INITIAL);
                current_file->lineno++;
@@ -132,8 +139,7 @@ n   [A-Za-z0-9_]
                BEGIN(STRING);
        }
        \n      BEGIN(INITIAL); current_file->lineno++; return T_EOL;
-       ---     /* ignore */
-       ({n}|[-/.])+    {
+       ({n}|[/.])+     {
                const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
                if (id && id->flags & TF_PARAM) {
                        zconflval.id = id;
@@ -146,11 +152,7 @@ n  [A-Za-z0-9_]
        #.*     /* comment */
        \\\n    current_file->lineno++;
        [[:blank:]]+
-       .       {
-               fprintf(stderr,
-                       "%s:%d:warning: ignoring unsupported character '%c'\n",
-                       zconf_curname(), zconf_lineno(), *yytext);
-       }
+       .       warn_ignored_character(*yytext);
        <<EOF>> {
                BEGIN(INITIAL);
        }