提交 c2264564 编写于 作者: A Andreas Ruprecht 提交者: Michal Marek

kconfig: warn of unhandled characters in Kconfig commands

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 2e0d737f ("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: NValentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: NAndreas Ruprecht <andreas.ruprecht@fau.de>
Reviewed-by: NUlf Magnusson <ulfalizer@gmail.com>
Tested-by: NUlf Magnusson <ulfalizer@gmail.com>
Signed-off-by: NMichal Marek <mmarek@suse.com>
上级 35ffd08d
...@@ -22,6 +22,7 @@ comment, T_COMMENT, TF_COMMAND ...@@ -22,6 +22,7 @@ comment, T_COMMENT, TF_COMMAND
config, T_CONFIG, TF_COMMAND config, T_CONFIG, TF_COMMAND
menuconfig, T_MENUCONFIG, TF_COMMAND menuconfig, T_MENUCONFIG, TF_COMMAND
help, T_HELP, TF_COMMAND help, T_HELP, TF_COMMAND
---help---, T_HELP, TF_COMMAND
if, T_IF, TF_COMMAND|TF_PARAM if, T_IF, TF_COMMAND|TF_PARAM
endif, T_ENDIF, TF_COMMAND endif, T_ENDIF, TF_COMMAND
depends, T_DEPENDS, TF_COMMAND depends, T_DEPENDS, TF_COMMAND
......
...@@ -66,9 +66,16 @@ static void alloc_string(const char *str, int size) ...@@ -66,9 +66,16 @@ static void alloc_string(const char *str, int size)
memcpy(text, str, size); memcpy(text, str, size);
text[size] = 0; 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; int str = 0;
...@@ -106,7 +113,7 @@ n [A-Za-z0-9_] ...@@ -106,7 +113,7 @@ n [A-Za-z0-9_]
zconflval.string = text; zconflval.string = text;
return T_WORD; return T_WORD;
} }
. . warn_ignored_character(*yytext);
\n { \n {
BEGIN(INITIAL); BEGIN(INITIAL);
current_file->lineno++; current_file->lineno++;
...@@ -132,8 +139,7 @@ n [A-Za-z0-9_] ...@@ -132,8 +139,7 @@ n [A-Za-z0-9_]
BEGIN(STRING); BEGIN(STRING);
} }
\n BEGIN(INITIAL); current_file->lineno++; return T_EOL; \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
--- /* ignore */ ({n}|[/.])+ {
({n}|[-/.])+ {
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
if (id && id->flags & TF_PARAM) { if (id && id->flags & TF_PARAM) {
zconflval.id = id; zconflval.id = id;
...@@ -146,11 +152,7 @@ n [A-Za-z0-9_] ...@@ -146,11 +152,7 @@ n [A-Za-z0-9_]
#.* /* comment */ #.* /* comment */
\\\n current_file->lineno++; \\\n current_file->lineno++;
[[:blank:]]+ [[:blank:]]+
. { . warn_ignored_character(*yytext);
fprintf(stderr,
"%s:%d:warning: ignoring unsupported character '%c'\n",
zconf_curname(), zconf_lineno(), *yytext);
}
<<EOF>> { <<EOF>> {
BEGIN(INITIAL); BEGIN(INITIAL);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册