summaryrefslogtreecommitdiff
path: root/config/zconf.l
diff options
context:
space:
mode:
Diffstat (limited to 'config/zconf.l')
-rw-r--r--config/zconf.l172
1 files changed, 72 insertions, 100 deletions
diff --git a/config/zconf.l b/config/zconf.l
index 3a4947a88..21ff69c9a 100644
--- a/config/zconf.l
+++ b/config/zconf.l
@@ -1,5 +1,6 @@
%option backup nostdinit noyywrap never-interactive full ecs
%option 8bit backup nodefault perf-report perf-report
+%option noinput
%x COMMAND HELP STRING PARAM
%{
/*
@@ -12,15 +13,18 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <glob.h>
#define LKC_DIRECT_LINK
#include "lkc.h"
#define START_STRSIZE 16
-char *text;
-static char *text_ptr;
+static struct {
+ struct file *file;
+ int lineno;
+} current_pos;
+
+static char *text;
static int text_size, text_asize;
struct buffer {
@@ -33,29 +37,28 @@ struct buffer *current_buf;
static int last_ts, first_ts;
static void zconf_endhelp(void);
-static struct buffer *zconf_endfile(void);
+static void zconf_endfile(void);
void new_string(void)
{
text = malloc(START_STRSIZE);
text_asize = START_STRSIZE;
- text_ptr = text;
text_size = 0;
- *text_ptr = 0;
+ *text = 0;
}
void append_string(const char *str, int size)
{
int new_size = text_size + size + 1;
if (new_size > text_asize) {
+ new_size += START_STRSIZE - 1;
+ new_size &= -START_STRSIZE;
text = realloc(text, new_size);
text_asize = new_size;
- text_ptr = text + text_size;
}
- memcpy(text_ptr, str, size);
- text_ptr += size;
+ memcpy(text + text_size, str, size);
text_size += size;
- *text_ptr = 0;
+ text[text_size] = 0;
}
void alloc_string(const char *str, int size)
@@ -73,10 +76,13 @@ n [A-Za-z0-9_]
int str = 0;
int ts, i;
-[ \t]*#.*\n current_file->lineno++;
+[ \t]*#.*\n |
+[ \t]*\n {
+ current_file->lineno++;
+ return T_EOL;
+}
[ \t]*#.*
-[ \t]*\n current_file->lineno++; return T_EOL;
[ \t]+ {
BEGIN(COMMAND);
@@ -89,42 +95,25 @@ n [A-Za-z0-9_]
<COMMAND>{
- "mainmenu" BEGIN(PARAM); return T_MAINMENU;
- "menu" BEGIN(PARAM); return T_MENU;
- "endmenu" BEGIN(PARAM); return T_ENDMENU;
- "source" BEGIN(PARAM); return T_SOURCE;
- "choice" BEGIN(PARAM); return T_CHOICE;
- "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
- "comment" BEGIN(PARAM); return T_COMMENT;
- "config" BEGIN(PARAM); return T_CONFIG;
- "menuconfig" BEGIN(PARAM); return T_MENUCONFIG;
- "help" BEGIN(PARAM); return T_HELP;
- "if" BEGIN(PARAM); return T_IF;
- "endif" BEGIN(PARAM); return T_ENDIF;
- "depends" BEGIN(PARAM); return T_DEPENDS;
- "requires" BEGIN(PARAM); return T_REQUIRES;
- "optional" BEGIN(PARAM); return T_OPTIONAL;
- "default" BEGIN(PARAM); return T_DEFAULT;
- "prompt" BEGIN(PARAM); return T_PROMPT;
- "tristate" BEGIN(PARAM); return T_TRISTATE;
- "def_tristate" BEGIN(PARAM); return T_DEF_TRISTATE;
- "bool" BEGIN(PARAM); return T_BOOLEAN;
- "boolean" BEGIN(PARAM); return T_BOOLEAN;
- "def_bool" BEGIN(PARAM); return T_DEF_BOOLEAN;
- "def_boolean" BEGIN(PARAM); return T_DEF_BOOLEAN;
- "int" BEGIN(PARAM); return T_INT;
- "hex" BEGIN(PARAM); return T_HEX;
- "string" BEGIN(PARAM); return T_STRING;
- "select" BEGIN(PARAM); return T_SELECT;
- "enable" BEGIN(PARAM); return T_SELECT;
- "range" BEGIN(PARAM); return T_RANGE;
{n}+ {
+ struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
+ BEGIN(PARAM);
+ current_pos.file = current_file;
+ current_pos.lineno = current_file->lineno;
+ if (id && id->flags & TF_COMMAND) {
+ zconflval.id = id;
+ return id->token;
+ }
alloc_string(yytext, yyleng);
zconflval.string = text;
return T_WORD;
}
.
- \n current_file->lineno++; BEGIN(INITIAL);
+ \n {
+ BEGIN(INITIAL);
+ current_file->lineno++;
+ return T_EOL;
+ }
}
<PARAM>{
@@ -135,8 +124,6 @@ n [A-Za-z0-9_]
"!" return T_NOT;
"=" return T_EQUAL;
"!=" return T_UNEQUAL;
- "if" return T_IF;
- "on" return T_ON;
\"|\' {
str = yytext[0];
new_string();
@@ -145,6 +132,11 @@ 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);
+ if (id && id->flags & TF_PARAM) {
+ zconflval.id = id;
+ return id->token;
+ }
alloc_string(yytext, yyleng);
zconflval.string = text;
return T_WORD;
@@ -226,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;
@@ -237,9 +234,9 @@ n [A-Za-z0-9_]
}
<<EOF>> {
- if (current_buf) {
+ if (current_file) {
zconf_endfile();
- return T_EOF;
+ return T_EOL;
}
fclose(yyin);
yyterminate();
@@ -274,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);
@@ -302,55 +299,38 @@ void zconf_initscan(const char *name)
void zconf_nextfile(const char *name)
{
- size_t i;
- int retval;
- glob_t files;
- char *filename;
- struct file *file;
- struct buffer *buf;
-
- retval = glob(name, GLOB_ERR | GLOB_MARK, NULL, &files);
- if (retval == GLOB_NOSPACE || retval == GLOB_ABORTED || retval == GLOB_NOMATCH) {
- 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);
+ struct file *file = file_lookup(name);
+ struct buffer *buf = malloc(sizeof(*buf));
+ memset(buf, 0, sizeof(*buf));
+
+ current_buf->state = YY_CURRENT_BUFFER;
+ yyin = zconf_fopen(name);
+ if (!yyin) {
+ printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
exit(1);
}
+ yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
+ buf->parent = current_buf;
+ current_buf = buf;
- 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);
- exit(1);
- }
- zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE));
- buf->parent = current_buf;
- current_buf = buf;
-
- 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);
- }
- file->flags |= FILE_BUSY;
- file->lineno = 1;
- file->parent = current_file;
- current_file = file;
+ if (file->flags & FILE_BUSY) {
+ printf("%s:%d: do not source '%s' from itself\n",
+ zconf_curname(), zconf_lineno(), name);
+ exit(1);
}
+ if (file->flags & FILE_SCANNED) {
+ printf("%s:%d: file '%s' is already sourced from '%s'\n",
+ zconf_curname(), zconf_lineno(), name,
+ file->parent->name);
+ exit(1);
+ }
+ file->flags |= FILE_BUSY;
+ file->lineno = 1;
+ file->parent = current_file;
+ current_file = file;
}
-static struct buffer *zconf_endfile(void)
+static void zconf_endfile(void)
{
struct buffer *parent;
@@ -366,22 +346,14 @@ static struct buffer *zconf_endfile(void)
}
free(current_buf);
current_buf = parent;
-
- return parent;
}
int zconf_lineno(void)
{
- if (current_buf)
- return current_file->lineno - 1;
- else
- return 0;
+ return current_pos.lineno;
}
char *zconf_curname(void)
{
- if (current_buf)
- return current_file->name;
- else
- return "<none>";
+ return current_pos.file ? current_pos.file->name : "<none>";
}