Commit 3cc84419 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

[PATCH] kconfig: config file parse update

- search for config files under $srctree (by Sam Ravnborg & me)
- allow to break long lines with \
parent c2b71add
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Released under the terms of the GNU GPL v2.0. * Released under the terms of the GNU GPL v2.0.
*/ */
#include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -53,7 +54,18 @@ static char *conf_expand_value(const char *in) ...@@ -53,7 +54,18 @@ static char *conf_expand_value(const char *in)
char *conf_get_default_confname(void) char *conf_get_default_confname(void)
{ {
return conf_expand_value(conf_defname); struct stat buf;
static char fullname[PATH_MAX+1];
char *env, *name;
name = conf_expand_value(conf_defname);
env = getenv(SRCTREE);
if (env) {
sprintf(fullname, "%s/%s", env, name);
if (!stat(fullname, &buf))
return fullname;
}
return name;
} }
int conf_read(const char *name) int conf_read(const char *name)
...@@ -68,12 +80,12 @@ int conf_read(const char *name) ...@@ -68,12 +80,12 @@ int conf_read(const char *name)
int i; int i;
if (name) { if (name) {
in = fopen(name, "r"); in = zconf_fopen(name);
} else { } else {
const char **names = conf_confnames; const char **names = conf_confnames;
while ((name = *names++)) { while ((name = *names++)) {
name = conf_expand_value(name); name = conf_expand_value(name);
in = fopen(name, "r"); in = zconf_fopen(name);
if (in) { if (in) {
printf("#\n" printf("#\n"
"# using defaults found in %s\n" "# using defaults found in %s\n"
......
This diff is collapsed.
...@@ -21,12 +21,14 @@ extern "C" { ...@@ -21,12 +21,14 @@ extern "C" {
#include "lkc_proto.h" #include "lkc_proto.h"
#undef P #undef P
void symbol_end(char *help); #define SRCTREE "srctree"
int zconfparse(void); int zconfparse(void);
void zconfdump(FILE *out); void zconfdump(FILE *out);
extern int zconfdebug; extern int zconfdebug;
void zconf_starthelp(void); void zconf_starthelp(void);
FILE *zconf_fopen(const char *name);
void zconf_initscan(const char *name); void zconf_initscan(const char *name);
void zconf_nextfile(const char *name); void zconf_nextfile(const char *name);
int zconf_lineno(void); int zconf_lineno(void);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Released under the terms of the GNU GPL v2.0. * Released under the terms of the GNU GPL v2.0.
*/ */
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#define LKC_DIRECT_LINK #define LKC_DIRECT_LINK
#include "lkc.h" #include "lkc.h"
#include "zconf.tab.h"
#define START_STRSIZE 16 #define START_STRSIZE 16
...@@ -141,6 +141,7 @@ n [A-Za-z0-9_] ...@@ -141,6 +141,7 @@ n [A-Za-z0-9_]
zconflval.string = text; zconflval.string = text;
return T_WORD; return T_WORD;
} }
\\\n current_file->lineno++;
. .
<<EOF>> { <<EOF>> {
BEGIN(INITIAL); BEGIN(INITIAL);
...@@ -157,12 +158,12 @@ n [A-Za-z0-9_] ...@@ -157,12 +158,12 @@ n [A-Za-z0-9_]
append_string(yytext, yyleng); append_string(yytext, yyleng);
} }
\\.?/\n { \\.?/\n {
append_string(yytext+1, yyleng); append_string(yytext + 1, yyleng - 1);
zconflval.string = text; zconflval.string = text;
return T_STRING; return T_STRING;
} }
\\.? { \\.? {
append_string(yytext+1, yyleng - 1); append_string(yytext + 1, yyleng - 1);
} }
\'|\" { \'|\" {
if (str == yytext[0]) { if (str == yytext[0]) {
...@@ -174,6 +175,7 @@ n [A-Za-z0-9_] ...@@ -174,6 +175,7 @@ n [A-Za-z0-9_]
} }
\n { \n {
printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno()); printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
current_file->lineno++;
BEGIN(INITIAL); BEGIN(INITIAL);
return T_EOL; return T_EOL;
} }
...@@ -249,9 +251,34 @@ static void zconf_endhelp(void) ...@@ -249,9 +251,34 @@ static void zconf_endhelp(void)
BEGIN(INITIAL); BEGIN(INITIAL);
} }
/*
* Try to open specified file with following names:
* ./name
* $(srctree)/name
* The latter is used when srctree is separate from objtree
* when compiling the kernel.
* Return NULL if file is not found.
*/
FILE *zconf_fopen(const char *name)
{
char *env, fullname[PATH_MAX+1];
FILE *f;
f = fopen(name, "r");
if (!f && name[0] != '/') {
env = getenv(SRCTREE);
if (env) {
sprintf(fullname, "%s/%s", env, name);
f = fopen(fullname, "r");
}
}
return f;
}
void zconf_initscan(const char *name) void zconf_initscan(const char *name)
{ {
yyin = fopen(name, "r"); yyin = zconf_fopen(name);
if (!yyin) { if (!yyin) {
printf("can't find file %s\n", name); printf("can't find file %s\n", name);
exit(1); exit(1);
...@@ -272,7 +299,7 @@ void zconf_nextfile(const char *name) ...@@ -272,7 +299,7 @@ void zconf_nextfile(const char *name)
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
current_buf->state = YY_CURRENT_BUFFER; current_buf->state = YY_CURRENT_BUFFER;
yyin = fopen(name, "r"); yyin = zconf_fopen(name);
if (!yyin) { if (!yyin) {
printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
exit(1); exit(1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment