Skip to content
Snippets Groups Projects
Commit 4ecee598 authored by Davide Cardillo's avatar Davide Cardillo
Browse files

[KCONFIG SYNTAX] Add osource keyword

Motivation: we want to load external configuration file based on the
state of some environment's variable (for example) and this file may not
exist.
For the nature of source keyword, the sourcing of a configuration file
is performed, neglecting the fact that the entry is inside a
contictional structure and that the condition is not verified (and the
configuration file doesn't exist). With this context the conf tool
exits with error.

Solution: introduce a newer keyword, similar to source one but where the
conf tool doesn't return an error, but instead a warning, if the
configuration file doesn't exist. This newer keyword is osource

Syntax:

	"osource" <prompt>
parent 6630a8a8
Branches master
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ static struct kconf_id kconf_id_array[] = {
{ "menu", T_MENU, TF_COMMAND },
{ "endmenu", T_ENDMENU, TF_COMMAND },
{ "source", T_SOURCE, TF_COMMAND },
{ "osource", T_OSOURCE, TF_COMMAND },
{ "choice", T_CHOICE, TF_COMMAND },
{ "endchoice", T_ENDCHOICE, TF_COMMAND },
{ "comment", T_COMMENT, TF_COMMAND },
......
......@@ -58,7 +58,7 @@ void zconfdump(FILE *out);
void zconf_starthelp(void);
FILE *zconf_fopen(const char *name);
void zconf_initscan(const char *name);
void zconf_nextfile(const char *name);
void zconf_nextfile(const char *name, bool is_optional);
int zconf_lineno(void);
const char *zconf_curname(void);
......
......@@ -385,7 +385,7 @@ void zconf_initscan(const char *name)
yylineno = 1;
}
void zconf_nextfile(const char *name)
void zconf_nextfile(const char *name, bool is_optional)
{
struct file *iter;
struct file *file = file_lookup(name);
......@@ -395,9 +395,15 @@ void zconf_nextfile(const char *name)
current_buf->state = YY_CURRENT_BUFFER;
yyin = zconf_fopen(file->name);
if (!yyin) {
fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
zconf_curname(), zconf_lineno(), file->name);
exit(1);
if (is_optional == false) {
fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
zconf_curname(), zconf_lineno(), file->name);
exit(1);
} else {
fprintf(stdout, "%s:%d: can't open file \"%s\"\n",
zconf_curname(), zconf_lineno(), file->name);
return;
}
}
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
buf->parent = current_buf;
......
......@@ -48,6 +48,7 @@ static struct menu *current_menu, *current_entry;
%token <id>T_MENU
%token <id>T_ENDMENU
%token <id>T_SOURCE
%token <id>T_OSOURCE
%token <id>T_CHOICE
%token <id>T_ENDCHOICE
%token <id>T_COMMENT
......@@ -147,6 +148,7 @@ common_stmt:
| config_stmt
| menuconfig_stmt
| source_stmt
| osource_stmt
| assignment_stmt
;
......@@ -398,7 +400,14 @@ menu_block:
source_stmt: T_SOURCE prompt T_EOL
{
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
zconf_nextfile($2);
zconf_nextfile($2, false);
free($2);
};
osource_stmt: T_OSOURCE prompt T_EOL
{
printd(DEBUG_PARSE, "%s:%d:osource %s\n", zconf_curname(), zconf_lineno(), $2);
zconf_nextfile($2, true);
free($2);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment