aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/config/zconf.l
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/config/zconf.l')
-rw-r--r--scripts/config/zconf.l141
1 files changed, 83 insertions, 58 deletions
diff --git a/scripts/config/zconf.l b/scripts/config/zconf.l
index 71107a56e7..bce3da6653 100644
--- a/scripts/config/zconf.l
+++ b/scripts/config/zconf.l
@@ -1,5 +1,6 @@
-%option backup nostdinit noyywrap never-interactive full ecs
-%option 8bit backup nodefault perf-report perf-report
+%option nostdinit noyywrap never-interactive full ecs
+%option 8bit nodefault perf-report perf-report
+%option noinput
%x COMMAND HELP STRING PARAM
%{
/*
@@ -14,7 +15,6 @@
#include <unistd.h>
#include <glob.h>
-#define LKC_DIRECT_LINK
#include "lkc.h"
#define START_STRSIZE 16
@@ -39,15 +39,15 @@ static int last_ts, first_ts;
static void zconf_endhelp(void);
static void zconf_endfile(void);
-void new_string(void)
+static void new_string(void)
{
- text = malloc(START_STRSIZE);
+ text = xmalloc(START_STRSIZE);
text_asize = START_STRSIZE;
text_size = 0;
*text = 0;
}
-void append_string(const char *str, int size)
+static void append_string(const char *str, int size)
{
int new_size = text_size + size + 1;
if (new_size > text_asize) {
@@ -61,9 +61,9 @@ void append_string(const char *str, int size)
text[text_size] = 0;
}
-void alloc_string(const char *str, int size)
+static void alloc_string(const char *str, int size)
{
- text = malloc(size + 1);
+ text = xmalloc(size + 1);
memcpy(text, str, size);
text[size] = 0;
}
@@ -96,7 +96,7 @@ n [A-Za-z0-9_]
<COMMAND>{
{n}+ {
- struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
+ const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
BEGIN(PARAM);
current_pos.file = current_file;
current_pos.lineno = current_file->lineno;
@@ -132,7 +132,7 @@ n [A-Za-z0-9_]
\n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
--- /* ignore */
({n}|[-/.])+ {
- 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) {
zconflval.id = id;
return id->token;
@@ -218,6 +218,11 @@ n [A-Za-z0-9_]
append_string("\n", 1);
}
[^ \t\n].* {
+ while (yyleng) {
+ if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
+ break;
+ yyleng--;
+ }
append_string(yytext, yyleng);
if (!first_ts)
first_ts = last_ts;
@@ -266,7 +271,7 @@ FILE *zconf_fopen(const char *name)
FILE *f;
f = fopen(name, "r");
- if (!f && name[0] != '/') {
+ if (!f && name != NULL && name[0] != '/') {
env = getenv(SRCTREE);
if (env) {
sprintf(fullname, "%s/%s", env, name);
@@ -284,73 +289,93 @@ void zconf_initscan(const char *name)
exit(1);
}
- current_buf = malloc(sizeof(*current_buf));
+ current_buf = xmalloc(sizeof(*current_buf));
memset(current_buf, 0, sizeof(*current_buf));
current_file = file_lookup(name);
current_file->lineno = 1;
- current_file->flags = FILE_BUSY;
}
-void zconf_nextfile(const char *name)
+static void __zconf_nextfile(const char *name)
{
- size_t i;
- int retval;
- glob_t files;
- char *filename;
- struct file *file;
- struct buffer *buf;
+ struct file *iter;
+ struct file *file = file_lookup(name);
+ struct buffer *buf = xmalloc(sizeof(*buf));
+ memset(buf, 0, sizeof(*buf));
- retval = glob(name, GLOB_ERR | GLOB_MARK, NULL, &files);
- if (retval == GLOB_NOMATCH)
- return;
-
- if (retval == GLOB_NOSPACE || retval == GLOB_ABORTED) {
- printf("%s:%d: glob failed: %s \"%s\"\n", zconf_curname(), zconf_lineno(),
- retval == GLOB_NOSPACE ? "failed to allocate memory" :
- retval == GLOB_ABORTED ? "read error" : "no match",
- name);
+ current_buf->state = YY_CURRENT_BUFFER;
+ yyin = zconf_fopen(file->name);
+ if (!yyin) {
+ printf("%s:%d: can't open file \"%s\"\n",
+ zconf_curname(), zconf_lineno(), file->name);
exit(1);
}
-
- for (i = files.gl_pathc-1; i != (size_t)-1; --i) {
- filename = files.gl_pathv[i];
-
- file = file_lookup(filename);
- buf = malloc(sizeof(*buf));
- memset(buf, 0, sizeof(*buf));
- current_buf->state = YY_CURRENT_BUFFER;
- zconfin = zconf_fopen(filename);
- if (!zconfin) {
- printf("%s:%d: can't open file \"%s\"\n",
- zconf_curname(), zconf_lineno(), filename);
+ yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
+ buf->parent = current_buf;
+ current_buf = buf;
+
+ for (iter = current_file->parent; iter; iter = iter->parent ) {
+ if (!strcmp(current_file->name,iter->name) ) {
+ printf("%s:%d: recursive inclusion detected. "
+ "Inclusion path:\n current file : '%s'\n",
+ zconf_curname(), zconf_lineno(),
+ zconf_curname());
+ iter = current_file->parent;
+ while (iter && \
+ strcmp(iter->name,current_file->name)) {
+ 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);
}
- zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE));
- buf->parent = current_buf;
- current_buf = buf;
+ }
+ file->lineno = 1;
+ file->parent = current_file;
+ current_file = file;
+}
- if (file->flags & FILE_BUSY) {
- printf("recursive scan (%s)?\n", filename);
- exit(1);
- }
- if (file->flags & FILE_SCANNED) {
- printf("file %s already scanned?\n", filename);
- exit(1);
+void zconf_nextfile(const char *name)
+{
+ glob_t gl;
+ int err;
+ int i;
+
+ err = glob(name, GLOB_ERR | GLOB_MARK, NULL, &gl);
+ if (err) {
+ const char *reason = "unknown error";
+
+ switch (err) {
+ case GLOB_NOSPACE:
+ reason = "out of memory";
+ break;
+ case GLOB_ABORTED:
+ reason = "read error";
+ break;
+ case GLOB_NOMATCH:
+ reason = "No files found";
+ break;
+ default:
+ break;
}
- file->flags |= FILE_BUSY;
- file->lineno = 1;
- file->parent = current_file;
- current_file = file;
+
+ printf("%s:%d: glob failed: %s \"%s\"\n", zconf_curname(), zconf_lineno(),
+ reason, name);
+
+ exit(1);
}
+
+ for (i = 0; i < gl.gl_pathc; i++)
+ __zconf_nextfile(gl.gl_pathv[i]);
}
static void zconf_endfile(void)
{
struct buffer *parent;
- current_file->flags |= FILE_SCANNED;
- current_file->flags &= ~FILE_BUSY;
current_file = current_file->parent;
parent = current_buf->parent;
@@ -368,7 +393,7 @@ int zconf_lineno(void)
return current_pos.lineno;
}
-char *zconf_curname(void)
+const char *zconf_curname(void)
{
return current_pos.file ? current_pos.file->name : "<none>";
}