-rw-r--r-- | scripts/kconfig/confdata.c | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 0f5fd97..9bf7af9 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1,25 +1,24 @@ /* * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> * Released under the terms of the GNU GPL v2.0. */ +#include <sys/stat.h> #include <ctype.h> -#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define LKC_DIRECT_LINK #include "lkc.h" const char conf_def_filename[] = ".config"; -char conf_filename[PATH_MAX+1]; const char conf_defname[] = "arch/$ARCH/defconfig"; const char *conf_confnames[] = { ".config", "/lib/modules/$UNAME_RELEASE/.config", "/etc/kernel-config", "/boot/config-$UNAME_RELEASE", @@ -50,79 +49,87 @@ static char *conf_expand_value(const char *in) } strcat(res_value, in); return res_value; } 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) { FILE *in = NULL; - char line[128]; + char line[1024]; char *p, *p2; int lineno = 0; struct symbol *sym; struct property *prop; struct expr *e; int i; if (name) { - in = fopen(name, "r"); - if (in) - strcpy(conf_filename, name); + in = zconf_fopen(name); } else { const char **names = conf_confnames; while ((name = *names++)) { name = conf_expand_value(name); - in = fopen(name, "r"); + in = zconf_fopen(name); if (in) { printf("#\n" "# using defaults found in %s\n" "#\n", name); break; } } } if (!in) return 1; for_all_symbols(i, sym) { - sym->flags |= SYMBOL_NEW; + sym->flags |= SYMBOL_NEW | SYMBOL_CHANGED; + sym->flags &= ~SYMBOL_VALID; switch (sym->type) { case S_INT: case S_HEX: case S_STRING: - if (S_VAL(sym->def)) { + if (S_VAL(sym->def)) free(S_VAL(sym->def)); - S_VAL(sym->def) = NULL; - } default: - ; + S_VAL(sym->def) = NULL; + S_TRI(sym->def) = no; } } - while (fgets(line, 128, in)) { + while (fgets(line, sizeof(line), in)) { lineno++; switch (line[0]) { case '#': if (memcmp(line + 2, "CONFIG_", 7)) continue; p = strchr(line + 9, ' '); if (!p) continue; *p++ = 0; if (strncmp(p, "is not set", 10)) continue; - //printf("%s -> n\n", line + 9); sym = sym_lookup(line + 9, 0); switch (sym->type) { case S_BOOLEAN: case S_TRISTATE: sym->def = symbol_no.curr; sym->flags &= ~SYMBOL_NEW; break; default: @@ -134,51 +141,63 @@ int conf_read(const char *name) continue; p = strchr(line + 7, '='); if (!p) continue; *p++ = 0; p2 = strchr(p, '\n'); if (p2) *p2 = 0; - //printf("%s -> %s\n", line + 7, p); sym = sym_find(line + 7); if (!sym) { fprintf(stderr, "%s:%d: trying to assign nonexistent symbol %s\n", name, lineno, line + 7); break; } switch (sym->type) { - case S_BOOLEAN: - sym->def = symbol_yes.curr; - sym->flags &= ~SYMBOL_NEW; - break; case S_TRISTATE: - if (p[0] == 'm') - sym->def = symbol_mod.curr; - else - sym->def = symbol_yes.curr; - sym->flags &= ~SYMBOL_NEW; + if (p[0] == 'm') { + S_TRI(sym->def) = mod; + sym->flags &= ~SYMBOL_NEW; + break; + } + case S_BOOLEAN: + if (p[0] == 'y') { + S_TRI(sym->def) = yes; + sym->flags &= ~SYMBOL_NEW; + break; + } + if (p[0] == 'n') { + S_TRI(sym->def) = no; + sym->flags &= ~SYMBOL_NEW; + break; + } break; case S_STRING: if (*p++ != '"') break; for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { if (*p2 == '"') { *p2 = 0; break; } memmove(p2, p2 + 1, strlen(p2)); } + if (!p2) { + fprintf(stderr, "%s:%d: invalid string found\n", name, lineno); + exit(1); + } case S_INT: case S_HEX: if (sym_string_valid(sym, p)) { S_VAL(sym->def) = strdup(p); sym->flags &= ~SYMBOL_NEW; - } else - fprintf(stderr, "%s:%d:symbol value '%s' invalid for %s\n", name, lineno, p, sym->name); + } else { + fprintf(stderr, "%s:%d: symbol value '%s' invalid for %s\n", name, lineno, p, sym->name); + exit(1); + } break; default: ; } if (sym_is_choice_value(sym)) { prop = sym_get_choice_prop(sym); switch (S_TRI(sym->def)) { case mod: @@ -347,14 +366,13 @@ int conf_write(const char *name) file_write_dep(NULL); } else unlink(".tmpconfig.h"); sprintf(oldname, "%s.old", name); rename(name, oldname); if (rename(".tmpconfig", name)) return 1; - strcpy(conf_filename, name); sym_change_count = 0; return 0; } |