kconfig: allow multiple inclusion of the same file

Allow 'source'ing the same file from multiple places (eg. from
different files, and/or under different conditions).

To avoid circular inclusion, scan the source-ancestry of the
current file, and abort if already sourced in this branch.

Regenerate the pre-parsed lex.zconf.c_shipped file.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
Yann E. MORIN 2011-02-24 19:36:42 +01:00 committed by Michal Marek
parent 466de91835
commit f094f8a1b2
2 changed files with 38 additions and 20 deletions

View File

@ -2368,6 +2368,7 @@ void zconf_initscan(const char *name)
void zconf_nextfile(const char *name) void zconf_nextfile(const char *name)
{ {
struct file *iter;
struct file *file = file_lookup(name); struct file *file = file_lookup(name);
struct buffer *buf = malloc(sizeof(*buf)); struct buffer *buf = malloc(sizeof(*buf));
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
@ -2383,16 +2384,24 @@ void zconf_nextfile(const char *name)
buf->parent = current_buf; buf->parent = current_buf;
current_buf = buf; current_buf = buf;
if (file->flags & FILE_BUSY) { for (iter = current_file->parent; iter; iter = iter->parent ) {
printf("%s:%d: do not source '%s' from itself\n", if (!strcmp(current_file->name,iter->name) ) {
zconf_curname(), zconf_lineno(), name); printf("%s:%d: recursive inclusion detected. "
exit(1); "Inclusion path:\n current file : '%s'\n",
} zconf_curname(), zconf_lineno(),
if (file->flags & FILE_SCANNED) { zconf_curname());
printf("%s:%d: file '%s' is already sourced from '%s'\n", iter = current_file->parent;
zconf_curname(), zconf_lineno(), name, while (iter && \
file->parent->name); strcmp(iter->name,current_file->name)) {
exit(1); printf(" included from: '%s:%d'\n",
iter->name, iter->lineno-1);
iter = iter->parent;
}
if (iter)
printf(" included from: '%s:%d'\n",
iter->name, iter->lineno+1);
exit(1);
}
} }
file->flags |= FILE_BUSY; file->flags |= FILE_BUSY;
file->lineno = 1; file->lineno = 1;

View File

@ -299,6 +299,7 @@ void zconf_initscan(const char *name)
void zconf_nextfile(const char *name) void zconf_nextfile(const char *name)
{ {
struct file *iter;
struct file *file = file_lookup(name); struct file *file = file_lookup(name);
struct buffer *buf = malloc(sizeof(*buf)); struct buffer *buf = malloc(sizeof(*buf));
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
@ -314,16 +315,24 @@ void zconf_nextfile(const char *name)
buf->parent = current_buf; buf->parent = current_buf;
current_buf = buf; current_buf = buf;
if (file->flags & FILE_BUSY) { for (iter = current_file->parent; iter; iter = iter->parent ) {
printf("%s:%d: do not source '%s' from itself\n", if (!strcmp(current_file->name,iter->name) ) {
zconf_curname(), zconf_lineno(), name); printf("%s:%d: recursive inclusion detected. "
exit(1); "Inclusion path:\n current file : '%s'\n",
} zconf_curname(), zconf_lineno(),
if (file->flags & FILE_SCANNED) { zconf_curname());
printf("%s:%d: file '%s' is already sourced from '%s'\n", iter = current_file->parent;
zconf_curname(), zconf_lineno(), name, while (iter && \
file->parent->name); strcmp(iter->name,current_file->name)) {
exit(1); printf(" included from: '%s:%d'\n",
iter->name, iter->lineno-1);
iter = iter->parent;
}
if (iter)
printf(" included from: '%s:%d'\n",
iter->name, iter->lineno+1);
exit(1);
}
} }
file->flags |= FILE_BUSY; file->flags |= FILE_BUSY;
file->lineno = 1; file->lineno = 1;