From ecbbf2f50e26b32ca8fc0b311f4c2e76d1aa6483 Mon Sep 17 00:00:00 2001 From: Arnaud Lacombe Date: Sun, 19 Sep 2010 22:45:00 -0400 Subject: [PATCH] --- yaml --- r: 261628 b: refs/heads/master c: 8494453ad50599b0c9d099a230e423a89222ad08 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/scripts/kconfig/confdata.c | 315 ++++++++++-------------------- trunk/scripts/kconfig/expr.c | 12 +- trunk/scripts/kconfig/lkc.h | 5 - trunk/scripts/kconfig/lkc_proto.h | 1 - trunk/scripts/kconfig/menu.c | 2 +- trunk/scripts/kconfig/symbol.c | 46 +---- 7 files changed, 107 insertions(+), 276 deletions(-) diff --git a/[refs] b/[refs] index 6e3d923c4eb6..ee55e72ef79c 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: e54e692ba613c2170c66ce36a3791c009680af08 +refs/heads/master: 8494453ad50599b0c9d099a230e423a89222ad08 diff --git a/trunk/scripts/kconfig/confdata.c b/trunk/scripts/kconfig/confdata.c index be6952c7fb29..c257bb0bf90a 100644 --- a/trunk/scripts/kconfig/confdata.c +++ b/trunk/scripts/kconfig/confdata.c @@ -422,228 +422,64 @@ int conf_read(const char *name) return 0; } -/* - * Kconfig configuration printer - * - * This printer is used when generating the resulting configuration after - * kconfig invocation and `defconfig' files. Unset symbol might be omitted by - * passing a non-NULL argument to the printer. - * - */ -static void -kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: - if (*value == 'n') { - bool skip_unset = (arg != NULL); - - if (!skip_unset) - fprintf(fp, "# %s%s is not set\n", - CONFIG_, sym->name); - return; - } - break; - default: - break; - } - - fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); -} - -static void -kconfig_print_comment(FILE *fp, const char *value, void *arg) +/* Write a S_STRING */ +static void conf_write_string(bool headerfile, const char *name, + const char *str, FILE *out) { - const char *p = value; - size_t l; - - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, "#"); + int l; + if (headerfile) + fprintf(out, "#define %s%s \"", CONFIG_, name); + else + fprintf(out, "%s%s=\"", CONFIG_, name); + + while (1) { + l = strcspn(str, "\"\\"); if (l) { - fprintf(fp, " "); - fwrite(p, l, 1, fp); - p += l; + xfwrite(str, l, 1, out); + str += l; } - fprintf(fp, "\n"); - if (*p++ == '\0') + if (!*str) break; + fprintf(out, "\\%c", *str++); } + fputs("\"\n", out); } -static struct conf_printer kconfig_printer_cb = -{ - .print_symbol = kconfig_print_symbol, - .print_comment = kconfig_print_comment, -}; - -/* - * Header printer - * - * This printer is used when generating the `include/generated/autoconf.h' file. - */ -static void -header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) +static void conf_write_symbol(struct symbol *sym, FILE *out, bool write_no) { - const char *suffix = ""; + const char *str; switch (sym->type) { case S_BOOLEAN: case S_TRISTATE: - switch (*value) { - case 'n': - return; - case 'm': - suffix = "_MODULE"; - /* FALLTHROUGH */ - default: - value = "1"; + switch (sym_get_tristate_value(sym)) { + case no: + if (write_no) + fprintf(out, "# %s%s is not set\n", + CONFIG_, sym->name); + break; + case mod: + fprintf(out, "%s%s=m\n", CONFIG_, sym->name); + break; + case yes: + fprintf(out, "%s%s=y\n", CONFIG_, sym->name); + break; } break; - default: + case S_STRING: + conf_write_string(false, sym->name, sym_get_string_value(sym), out); break; - } - - fprintf(fp, "#define %s%s%s %s\n", - CONFIG_, sym->name, suffix, value); -} - -static void -header_print_comment(FILE *fp, const char *value, void *arg) -{ - const char *p = value; - size_t l; - - fprintf(fp, "/*\n"); - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, " *"); - if (l) { - fprintf(fp, " "); - fwrite(p, l, 1, fp); - p += l; - } - fprintf(fp, "\n"); - if (*p++ == '\0') - break; - } - fprintf(fp, " */\n"); -} - -static struct conf_printer header_printer_cb = -{ - .print_symbol = header_print_symbol, - .print_comment = header_print_comment, -}; - -/* - * Function-style header printer - * - * This printer is used to generate the config_is_xxx() function-style macros - * in `include/generated/autoconf.h' - */ -static void -header_function_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - int val = 0; - char c; - char *tmp, *d; - - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: + case S_HEX: + case S_INT: + str = sym_get_string_value(sym); + fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str); break; - default: - return; - } - if (*value == 'm') - val = 2; - else if (*value == 'y') - val = 1; - - d = strdup(CONFIG_); - tmp = d; - while ((c = *d)) { - *d = tolower(c); - d++; - } - - fprintf(fp, "#define %sis_", tmp); - free(tmp); - - d = strdup(sym->name); - tmp = d; - while ((c = *d)) { - *d = tolower(c); - d++; - } - fprintf(fp, "%s%s() %d\n", tmp, (val > 1) ? "_module" : "", - val ? 1 : 0); - free(tmp); -} - -static struct conf_printer header_function_printer_cb = -{ - .print_symbol = header_function_print_symbol, -}; - - -/* - * Tristate printer - * - * This printer is used when generating the `include/config/tristate.conf' file. - */ -static void -tristate_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - if (sym->type == S_TRISTATE && *value != 'n') - fprintf(fp, "%s%s=%c\n", CONFIG_, sym->name, (char)toupper(*value)); -} - -static struct conf_printer tristate_printer_cb = -{ - .print_symbol = tristate_print_symbol, - .print_comment = kconfig_print_comment, -}; - -static void conf_write_symbol(FILE *fp, struct symbol *sym, - struct conf_printer *printer, void *printer_arg) -{ - const char *str; - - switch (sym->type) { case S_OTHER: case S_UNKNOWN: break; - case S_STRING: - str = sym_get_string_value(sym); - str = sym_escape_string_value(str); - printer->print_symbol(fp, sym, str, printer_arg); - free((void *)str); - break; - default: - str = sym_get_string_value(sym); - printer->print_symbol(fp, sym, str, printer_arg); } } -static void -conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg) -{ - char buf[256]; - - snprintf(buf, sizeof(buf), - "\n" - "Automatically generated file; DO NOT EDIT.\n" - "%s\n", - rootmenu.prompt->text); - - printer->print_comment(fp, buf, printer_arg); -} - /* * Write out a minimal config. * All values that has default values are skipped as this is redundant. @@ -700,7 +536,7 @@ int conf_write_defconfig(const char *filename) goto next_menu; } } - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + conf_write_symbol(sym, out, true); } next_menu: if (menu->list != NULL) { @@ -765,7 +601,11 @@ int conf_write(const char *name) if (!out) return 1; - conf_write_heading(out, &kconfig_printer_cb, NULL); + fprintf(out, _("#\n" + "# Automatically generated make config: don't edit\n" + "# %s\n" + "#\n"), + rootmenu.prompt->text); if (!conf_get_changed()) sym_clear_all_valid(); @@ -786,8 +626,8 @@ int conf_write(const char *name) if (!(sym->flags & SYMBOL_WRITE)) goto next; sym->flags &= ~SYMBOL_WRITE; - - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + /* Write config symbol to file */ + conf_write_symbol(sym, out, true); } next: @@ -936,6 +776,7 @@ static int conf_split_config(void) int conf_write_autoconf(void) { struct symbol *sym; + const char *str; const char *name; FILE *out, *tristate, *out_h; int i; @@ -964,24 +805,68 @@ int conf_write_autoconf(void) return 1; } - conf_write_heading(out, &kconfig_printer_cb, NULL); - - conf_write_heading(tristate, &tristate_printer_cb, NULL); - - conf_write_heading(out_h, &header_printer_cb, NULL); + fprintf(out, "#\n" + "# Automatically generated make config: don't edit\n" + "# %s\n" + "#\n", + rootmenu.prompt->text); + fprintf(tristate, "#\n" + "# Automatically generated - do not edit\n" + "\n"); + fprintf(out_h, "/*\n" + " * Automatically generated C config: don't edit\n" + " * %s\n" + " */\n", + rootmenu.prompt->text); for_all_symbols(i, sym) { sym_calc_value(sym); if (!(sym->flags & SYMBOL_WRITE) || !sym->name) continue; - /* write symbol to auto.conf, tristate and header files */ - conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); + /* write symbol to config file */ + conf_write_symbol(sym, out, false); - conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); - - conf_write_symbol(out_h, sym, &header_printer_cb, NULL); - conf_write_symbol(out_h, sym, &header_function_printer_cb, NULL); + /* update autoconf and tristate files */ + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + switch (sym_get_tristate_value(sym)) { + case no: + break; + case mod: + fprintf(tristate, "%s%s=M\n", + CONFIG_, sym->name); + fprintf(out_h, "#define %s%s_MODULE 1\n", + CONFIG_, sym->name); + break; + case yes: + if (sym->type == S_TRISTATE) + fprintf(tristate,"%s%s=Y\n", + CONFIG_, sym->name); + fprintf(out_h, "#define %s%s 1\n", + CONFIG_, sym->name); + break; + } + break; + case S_STRING: + conf_write_string(true, sym->name, sym_get_string_value(sym), out_h); + break; + case S_HEX: + str = sym_get_string_value(sym); + if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { + fprintf(out_h, "#define %s%s 0x%s\n", + CONFIG_, sym->name, str); + break; + } + case S_INT: + str = sym_get_string_value(sym); + fprintf(out_h, "#define %s%s %s\n", + CONFIG_, sym->name, str); + break; + default: + break; + } } fclose(out); fclose(tristate); diff --git a/trunk/scripts/kconfig/expr.c b/trunk/scripts/kconfig/expr.c index 792c62ed9d63..290ce41f8ba4 100644 --- a/trunk/scripts/kconfig/expr.c +++ b/trunk/scripts/kconfig/expr.c @@ -13,8 +13,7 @@ struct expr *expr_alloc_symbol(struct symbol *sym) { - struct expr *e = malloc(sizeof(*e)); - memset(e, 0, sizeof(*e)); + struct expr *e = calloc(1, sizeof(*e)); e->type = E_SYMBOL; e->left.sym = sym; return e; @@ -22,8 +21,7 @@ struct expr *expr_alloc_symbol(struct symbol *sym) struct expr *expr_alloc_one(enum expr_type type, struct expr *ce) { - struct expr *e = malloc(sizeof(*e)); - memset(e, 0, sizeof(*e)); + struct expr *e = calloc(1, sizeof(*e)); e->type = type; e->left.expr = ce; return e; @@ -31,8 +29,7 @@ struct expr *expr_alloc_one(enum expr_type type, struct expr *ce) struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2) { - struct expr *e = malloc(sizeof(*e)); - memset(e, 0, sizeof(*e)); + struct expr *e = calloc(1, sizeof(*e)); e->type = type; e->left.expr = e1; e->right.expr = e2; @@ -41,8 +38,7 @@ struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2) { - struct expr *e = malloc(sizeof(*e)); - memset(e, 0, sizeof(*e)); + struct expr *e = calloc(1, sizeof(*e)); e->type = type; e->left.sym = s1; e->right.sym = s2; diff --git a/trunk/scripts/kconfig/lkc.h b/trunk/scripts/kconfig/lkc.h index 306c5a59efc2..625ec69ebeee 100644 --- a/trunk/scripts/kconfig/lkc.h +++ b/trunk/scripts/kconfig/lkc.h @@ -87,11 +87,6 @@ void sym_set_change_count(int count); void sym_add_change_count(int count); void conf_set_all_new_symbols(enum conf_def_mode mode); -struct conf_printer { - void (*print_symbol)(FILE *, struct symbol *, const char *, void *); - void (*print_comment)(FILE *, const char *, void *); -}; - /* confdata.c and expr.c */ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) { diff --git a/trunk/scripts/kconfig/lkc_proto.h b/trunk/scripts/kconfig/lkc_proto.h index 47fe9c340f9a..17342fef38b9 100644 --- a/trunk/scripts/kconfig/lkc_proto.h +++ b/trunk/scripts/kconfig/lkc_proto.h @@ -31,7 +31,6 @@ P(symbol_hash,struct symbol *,[SYMBOL_HASHSIZE]); P(sym_lookup,struct symbol *,(const char *name, int flags)); P(sym_find,struct symbol *,(const char *name)); P(sym_expand_string_value,const char *,(const char *in)); -P(sym_escape_string_value, const char *,(const char *in)); P(sym_re_search,struct symbol **,(const char *pattern)); P(sym_type_name,const char *,(enum symbol_type type)); P(sym_calc_value,void,(struct symbol *sym)); diff --git a/trunk/scripts/kconfig/menu.c b/trunk/scripts/kconfig/menu.c index d66008639a43..aab5a1fee5a8 100644 --- a/trunk/scripts/kconfig/menu.c +++ b/trunk/scripts/kconfig/menu.c @@ -351,7 +351,7 @@ void menu_finalize(struct menu *parent) last_menu->next = NULL; } - sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep); + sym->dir_dep.expr = parent->dep; } for (menu = parent->list; menu; menu = menu->next) { if (sym && sym_is_choice(sym) && diff --git a/trunk/scripts/kconfig/symbol.c b/trunk/scripts/kconfig/symbol.c index 071f00c3046e..cf8edf4fc429 100644 --- a/trunk/scripts/kconfig/symbol.c +++ b/trunk/scripts/kconfig/symbol.c @@ -750,8 +750,7 @@ const char *sym_get_string_value(struct symbol *sym) case no: return "n"; case mod: - sym_calc_value(modules_sym); - return (modules_sym->curr.tri == no) ? "n" : "m"; + return "m"; case yes: return "y"; } @@ -893,49 +892,6 @@ const char *sym_expand_string_value(const char *in) return res; } -const char *sym_escape_string_value(const char *in) -{ - const char *p; - size_t reslen; - char *res; - size_t l; - - reslen = strlen(in) + strlen("\"\"") + 1; - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - p += l; - - if (p[0] == '\0') - break; - - reslen++; - p++; - } - - res = malloc(reslen); - res[0] = '\0'; - - strcat(res, "\""); - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - strncat(res, p, l); - p += l; - - if (p[0] == '\0') - break; - - strcat(res, "\\"); - strncat(res, p++, 1); - } - - strcat(res, "\""); - return res; -} - struct symbol **sym_re_search(const char *pattern) { struct symbol *sym, **sym_arr = NULL;