From 89145649b0d0d51e90a85de23ca881c97d3a71a4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:24 +0900 Subject: kconfig: split randconfig setup code into set_randconfig_seed() This code is too big to be placed in the switch statement. Move the code into a new helper function. I slightly refactor the code without changing the behavior. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 54 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 957d2a0832f7..063c9e7a34c1 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -82,6 +82,36 @@ static void xfgets(char *str, int size, FILE *in) printf("%s", str); } +static void set_randconfig_seed(void) +{ + unsigned int seed; + char *env; + bool seed_set = false; + + env = getenv("KCONFIG_SEED"); + if (env && *env) { + char *endp; + + seed = strtol(env, &endp, 0); + if (*endp == '\0') + seed_set = true; + } + + if (!seed_set) { + struct timeval now; + + /* + * Use microseconds derived seed, compensate for systems where it may + * be zero. + */ + gettimeofday(&now, NULL); + seed = (now.tv_sec + 1) * (now.tv_usec + 1); + } + + printf("KCONFIG_SEED=0x%X\n", seed); + srand(seed); +} + static int conf_askvalue(struct symbol *sym, const char *def) { if (!sym_has_value(sym)) @@ -515,30 +545,8 @@ int main(int ac, char **av) defconfig_file = optarg; break; case randconfig: - { - struct timeval now; - unsigned int seed; - char *seed_env; - - /* - * Use microseconds derived seed, - * compensate for systems where it may be zero - */ - gettimeofday(&now, NULL); - seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); - - seed_env = getenv("KCONFIG_SEED"); - if( seed_env && *seed_env ) { - char *endp; - int tmp = (int)strtol(seed_env, &endp, 0); - if (*endp == '\0') { - seed = tmp; - } - } - fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed ); - srand(seed); + set_randconfig_seed(); break; - } case oldaskconfig: case oldconfig: case allnoconfig: -- cgit v1.2.3 From ed562c53104fbe097f012bec5a30196334e52d78 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:25 +0900 Subject: kconfig: refactor option parse code The current option parse code is clumsy. The 's' option is separately handled in an if-conditional due to the following code: input_mode = (enum input_mode)opt; If 's' is moved to the switch statement, the invalid value 's' would be assigned to the input_mode. Another potential problem is that we are mixing 'enum input_mode' and ASCII characters. They could overwrap if we add more input modes. To separate them out, set the flag field of long options to a pointer of input_mode_opt. For mode select options, getopt_long() returns 0, which never causes overwrap with ASCII characters that represent short options. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 91 ++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 48 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 063c9e7a34c1..dc1a67fd35a9 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -37,7 +37,7 @@ enum input_mode { mod2yesconfig, }; static enum input_mode input_mode = oldaskconfig; - +static int input_mode_opt; static int indent = 1; static int tty_stdio; static int sync_kconfig; @@ -474,21 +474,21 @@ static void check_conf(struct menu *menu) } static struct option long_opts[] = { - {"oldaskconfig", no_argument, NULL, oldaskconfig}, - {"oldconfig", no_argument, NULL, oldconfig}, - {"syncconfig", no_argument, NULL, syncconfig}, - {"defconfig", required_argument, NULL, defconfig}, - {"savedefconfig", required_argument, NULL, savedefconfig}, - {"allnoconfig", no_argument, NULL, allnoconfig}, - {"allyesconfig", no_argument, NULL, allyesconfig}, - {"allmodconfig", no_argument, NULL, allmodconfig}, - {"alldefconfig", no_argument, NULL, alldefconfig}, - {"randconfig", no_argument, NULL, randconfig}, - {"listnewconfig", no_argument, NULL, listnewconfig}, - {"helpnewconfig", no_argument, NULL, helpnewconfig}, - {"olddefconfig", no_argument, NULL, olddefconfig}, - {"yes2modconfig", no_argument, NULL, yes2modconfig}, - {"mod2yesconfig", no_argument, NULL, mod2yesconfig}, + {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, + {"oldconfig", no_argument, &input_mode_opt, oldconfig}, + {"syncconfig", no_argument, &input_mode_opt, syncconfig}, + {"defconfig", required_argument, &input_mode_opt, defconfig}, + {"savedefconfig", required_argument, &input_mode_opt, savedefconfig}, + {"allnoconfig", no_argument, &input_mode_opt, allnoconfig}, + {"allyesconfig", no_argument, &input_mode_opt, allyesconfig}, + {"allmodconfig", no_argument, &input_mode_opt, allmodconfig}, + {"alldefconfig", no_argument, &input_mode_opt, alldefconfig}, + {"randconfig", no_argument, &input_mode_opt, randconfig}, + {"listnewconfig", no_argument, &input_mode_opt, listnewconfig}, + {"helpnewconfig", no_argument, &input_mode_opt, helpnewconfig}, + {"olddefconfig", no_argument, &input_mode_opt, olddefconfig}, + {"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig}, + {"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig}, {NULL, 0, NULL, 0} }; @@ -526,43 +526,38 @@ int main(int ac, char **av) tty_stdio = isatty(0) && isatty(1); while ((opt = getopt_long(ac, av, "hs", long_opts, NULL)) != -1) { - if (opt == 's') { - conf_set_message_callback(NULL); - continue; - } - input_mode = (enum input_mode)opt; switch (opt) { - case syncconfig: - /* - * syncconfig is invoked during the build stage. - * Suppress distracting "configuration written to ..." - */ - conf_set_message_callback(NULL); - sync_kconfig = 1; - break; - case defconfig: - case savedefconfig: - defconfig_file = optarg; - break; - case randconfig: - set_randconfig_seed(); - break; - case oldaskconfig: - case oldconfig: - case allnoconfig: - case allyesconfig: - case allmodconfig: - case alldefconfig: - case listnewconfig: - case helpnewconfig: - case olddefconfig: - case yes2modconfig: - case mod2yesconfig: - break; case 'h': conf_usage(progname); exit(1); break; + case 's': + conf_set_message_callback(NULL); + break; + case 0: + input_mode = input_mode_opt; + switch (input_mode) { + case syncconfig: + /* + * syncconfig is invoked during the build stage. + * Suppress distracting + * "configuration written to ..." + */ + conf_set_message_callback(NULL); + sync_kconfig = 1; + break; + case defconfig: + case savedefconfig: + defconfig_file = optarg; + break; + case randconfig: + set_randconfig_seed(); + break; + default: + break; + } + default: + break; } } if (ac == optind) { -- cgit v1.2.3 From bafc479132160a5fa66efa1748c995e699655803 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:26 +0900 Subject: kconfig: add long options --help and --silent They are long options for -h and -s, respectively. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index dc1a67fd35a9..aac76acfd100 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -474,6 +474,8 @@ static void check_conf(struct menu *menu) } static struct option long_opts[] = { + {"help", no_argument, NULL, 'h'}, + {"silent", no_argument, NULL, 's'}, {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, {"oldconfig", no_argument, &input_mode_opt, oldconfig}, {"syncconfig", no_argument, &input_mode_opt, syncconfig}, -- cgit v1.2.3 From ee4c6f00dcee1bffcb06ffa274251c1467d3efaa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:27 +0900 Subject: kconfig: add help messages for --help (-h) and --silent (-s) Add missing options and make the help message more readable. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index aac76acfd100..9ebc1acaf1ae 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -496,9 +496,13 @@ static struct option long_opts[] = { static void conf_usage(const char *progname) { - - printf("Usage: %s [-s] [option] \n", progname); - printf("[option] is _one_ of the following:\n"); + printf("Usage: %s [options] \n", progname); + printf("\n"); + printf("Generic options:\n"); + printf(" -h, --help Print this message and exit.\n"); + printf(" -s, --silent Do not print log.\n"); + printf("\n"); + printf("Mode options:\n"); printf(" --listnewconfig List new options\n"); printf(" --helpnewconfig List new options and help text\n"); printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); -- cgit v1.2.3 From 9a3c3bc820be102f8bb1ca0e9700633d5b3aeb1f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:28 +0900 Subject: kconfig: remove assignment for Kconfig file Pass av[optind] to conf_parse() directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 9ebc1acaf1ae..42d35da86604 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -571,8 +571,7 @@ int main(int ac, char **av) conf_usage(progname); exit(1); } - name = av[optind]; - conf_parse(name); + conf_parse(av[optind]); //zconfdump(stdout); switch (input_mode) { -- cgit v1.2.3 From 15e68d09458f1b417f3129674b89ff91a1070f15 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:29 +0900 Subject: kconfig: move conf_rewrite_mod_or_yes() to conf.c This function is only used in conf.c. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 15 +++++++++++++++ scripts/kconfig/confdata.c | 15 --------------- scripts/kconfig/lkc.h | 1 - 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 42d35da86604..89c9ba83f9e7 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -112,6 +112,21 @@ static void set_randconfig_seed(void) srand(seed); } +static void conf_rewrite_mod_or_yes(enum conf_def_mode mode) +{ + struct symbol *sym; + int i; + tristate old_val = (mode == def_y2m) ? yes : mod; + tristate new_val = (mode == def_y2m) ? mod : yes; + + for_all_symbols(i, sym) { + if (sym_get_type(sym) == S_TRISTATE && + sym->def[S_DEF_USER].tri == old_val) + sym->def[S_DEF_USER].tri = new_val; + } + sym_clear_all_valid(); +} + static int conf_askvalue(struct symbol *sym, const char *def) { if (!sym_has_value(sym)) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 2568dbe16ed6..a828622cb2d0 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1322,18 +1322,3 @@ bool conf_set_all_new_symbols(enum conf_def_mode mode) return has_changed; } - -void conf_rewrite_mod_or_yes(enum conf_def_mode mode) -{ - struct symbol *sym; - int i; - tristate old_val = (mode == def_y2m) ? yes : mod; - tristate new_val = (mode == def_y2m) ? mod : yes; - - for_all_symbols(i, sym) { - if (sym_get_type(sym) == S_TRISTATE && - sym->def[S_DEF_USER].tri == old_val) - sym->def[S_DEF_USER].tri = new_val; - } - sym_clear_all_valid(); -} diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index bee2413bda63..f946ab49ef50 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -58,7 +58,6 @@ const char *conf_get_configname(void); void sym_set_change_count(int count); void sym_add_change_count(int count); bool conf_set_all_new_symbols(enum conf_def_mode mode); -void conf_rewrite_mod_or_yes(enum conf_def_mode mode); void set_all_choice_values(struct symbol *csym); /* confdata.c and expr.c */ -- cgit v1.2.3 From 98f8475c78697f6c1155f93d3a346d9027deb5aa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:30 +0900 Subject: kconfig: move conf_set_all_new_symbols() to conf.c This function is only used in conf.c. Move it there together with the randomize_choice_values() helper. Define 'enum conf_def_mode' locally in conf.c as well. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 193 +++++++++++++++++++++++++++++++++++++++++++++ scripts/kconfig/confdata.c | 176 ----------------------------------------- scripts/kconfig/lkc.h | 11 --- 3 files changed, 193 insertions(+), 187 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 89c9ba83f9e7..10958f1e41d6 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -112,6 +112,199 @@ static void set_randconfig_seed(void) srand(seed); } +static bool randomize_choice_values(struct symbol *csym) +{ + struct property *prop; + struct symbol *sym; + struct expr *e; + int cnt, def; + + /* + * If choice is mod then we may have more items selected + * and if no then no-one. + * In both cases stop. + */ + if (csym->curr.tri != yes) + return false; + + prop = sym_get_choice_prop(csym); + + /* count entries in choice block */ + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) + cnt++; + + /* + * find a random value and set it to yes, + * set the rest to no so we have only one set + */ + def = rand() % cnt; + + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) { + if (def == cnt++) { + sym->def[S_DEF_USER].tri = yes; + csym->def[S_DEF_USER].val = sym; + } else { + sym->def[S_DEF_USER].tri = no; + } + sym->flags |= SYMBOL_DEF_USER; + /* clear VALID to get value calculated */ + sym->flags &= ~SYMBOL_VALID; + } + csym->flags |= SYMBOL_DEF_USER; + /* clear VALID to get value calculated */ + csym->flags &= ~SYMBOL_VALID; + + return true; +} + +enum conf_def_mode { + def_default, + def_yes, + def_mod, + def_y2m, + def_m2y, + def_no, + def_random +}; + +static bool conf_set_all_new_symbols(enum conf_def_mode mode) +{ + struct symbol *sym, *csym; + int i, cnt; + /* + * can't go as the default in switch-case below, otherwise gcc whines + * about -Wmaybe-uninitialized + */ + int pby = 50; /* probability of bool = y */ + int pty = 33; /* probability of tristate = y */ + int ptm = 33; /* probability of tristate = m */ + bool has_changed = false; + + if (mode == def_random) { + int n, p[3]; + char *env = getenv("KCONFIG_PROBABILITY"); + + n = 0; + while (env && *env) { + char *endp; + int tmp = strtol(env, &endp, 10); + + if (tmp >= 0 && tmp <= 100) { + p[n++] = tmp; + } else { + errno = ERANGE; + perror("KCONFIG_PROBABILITY"); + exit(1); + } + env = (*endp == ':') ? endp + 1 : endp; + if (n >= 3) + break; + } + switch (n) { + case 1: + pby = p[0]; + ptm = pby / 2; + pty = pby - ptm; + break; + case 2: + pty = p[0]; + ptm = p[1]; + pby = pty + ptm; + break; + case 3: + pby = p[0]; + pty = p[1]; + ptm = p[2]; + break; + } + + if (pty + ptm > 100) { + errno = ERANGE; + perror("KCONFIG_PROBABILITY"); + exit(1); + } + } + + for_all_symbols(i, sym) { + if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) + continue; + switch (sym_get_type(sym)) { + case S_BOOLEAN: + case S_TRISTATE: + has_changed = true; + switch (mode) { + case def_yes: + sym->def[S_DEF_USER].tri = yes; + break; + case def_mod: + sym->def[S_DEF_USER].tri = mod; + break; + case def_no: + if (sym->flags & SYMBOL_ALLNOCONFIG_Y) + sym->def[S_DEF_USER].tri = yes; + else + sym->def[S_DEF_USER].tri = no; + break; + case def_random: + sym->def[S_DEF_USER].tri = no; + cnt = rand() % 100; + if (sym->type == S_TRISTATE) { + if (cnt < pty) + sym->def[S_DEF_USER].tri = yes; + else if (cnt < pty + ptm) + sym->def[S_DEF_USER].tri = mod; + } else if (cnt < pby) + sym->def[S_DEF_USER].tri = yes; + break; + default: + continue; + } + if (!(sym_is_choice(sym) && mode == def_random)) + sym->flags |= SYMBOL_DEF_USER; + break; + default: + break; + } + + } + + sym_clear_all_valid(); + + /* + * We have different type of choice blocks. + * If curr.tri equals to mod then we can select several + * choice symbols in one block. + * In this case we do nothing. + * If curr.tri equals yes then only one symbol can be + * selected in a choice block and we set it to yes, + * and the rest to no. + */ + if (mode != def_random) { + for_all_symbols(i, csym) { + if ((sym_is_choice(csym) && !sym_has_value(csym)) || + sym_is_choice_value(csym)) + csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; + } + } + + for_all_symbols(i, csym) { + if (sym_has_value(csym) || !sym_is_choice(csym)) + continue; + + sym_calc_value(csym); + if (mode == def_random) + has_changed |= randomize_choice_values(csym); + else { + set_all_choice_values(csym); + has_changed = true; + } + } + + return has_changed; +} + static void conf_rewrite_mod_or_yes(enum conf_def_mode mode) { struct symbol *sym; diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index a828622cb2d0..198f70957fbf 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1127,54 +1127,6 @@ void conf_set_changed_callback(void (*fn)(void)) conf_changed_callback = fn; } -static bool randomize_choice_values(struct symbol *csym) -{ - struct property *prop; - struct symbol *sym; - struct expr *e; - int cnt, def; - - /* - * If choice is mod then we may have more items selected - * and if no then no-one. - * In both cases stop. - */ - if (csym->curr.tri != yes) - return false; - - prop = sym_get_choice_prop(csym); - - /* count entries in choice block */ - cnt = 0; - expr_list_for_each_sym(prop->expr, e, sym) - cnt++; - - /* - * find a random value and set it to yes, - * set the rest to no so we have only one set - */ - def = (rand() % cnt); - - cnt = 0; - expr_list_for_each_sym(prop->expr, e, sym) { - if (def == cnt++) { - sym->def[S_DEF_USER].tri = yes; - csym->def[S_DEF_USER].val = sym; - } - else { - sym->def[S_DEF_USER].tri = no; - } - sym->flags |= SYMBOL_DEF_USER; - /* clear VALID to get value calculated */ - sym->flags &= ~SYMBOL_VALID; - } - csym->flags |= SYMBOL_DEF_USER; - /* clear VALID to get value calculated */ - csym->flags &= ~(SYMBOL_VALID); - - return true; -} - void set_all_choice_values(struct symbol *csym) { struct property *prop; @@ -1194,131 +1146,3 @@ void set_all_choice_values(struct symbol *csym) /* clear VALID to get value calculated */ csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES); } - -bool conf_set_all_new_symbols(enum conf_def_mode mode) -{ - struct symbol *sym, *csym; - int i, cnt, pby, pty, ptm; /* pby: probability of bool = y - * pty: probability of tristate = y - * ptm: probability of tristate = m - */ - - pby = 50; pty = ptm = 33; /* can't go as the default in switch-case - * below, otherwise gcc whines about - * -Wmaybe-uninitialized */ - if (mode == def_random) { - int n, p[3]; - char *env = getenv("KCONFIG_PROBABILITY"); - n = 0; - while( env && *env ) { - char *endp; - int tmp = strtol( env, &endp, 10 ); - if( tmp >= 0 && tmp <= 100 ) { - p[n++] = tmp; - } else { - errno = ERANGE; - perror( "KCONFIG_PROBABILITY" ); - exit( 1 ); - } - env = (*endp == ':') ? endp+1 : endp; - if( n >=3 ) { - break; - } - } - switch( n ) { - case 1: - pby = p[0]; ptm = pby/2; pty = pby-ptm; - break; - case 2: - pty = p[0]; ptm = p[1]; pby = pty + ptm; - break; - case 3: - pby = p[0]; pty = p[1]; ptm = p[2]; - break; - } - - if( pty+ptm > 100 ) { - errno = ERANGE; - perror( "KCONFIG_PROBABILITY" ); - exit( 1 ); - } - } - bool has_changed = false; - - for_all_symbols(i, sym) { - if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID)) - continue; - switch (sym_get_type(sym)) { - case S_BOOLEAN: - case S_TRISTATE: - has_changed = true; - switch (mode) { - case def_yes: - sym->def[S_DEF_USER].tri = yes; - break; - case def_mod: - sym->def[S_DEF_USER].tri = mod; - break; - case def_no: - if (sym->flags & SYMBOL_ALLNOCONFIG_Y) - sym->def[S_DEF_USER].tri = yes; - else - sym->def[S_DEF_USER].tri = no; - break; - case def_random: - sym->def[S_DEF_USER].tri = no; - cnt = rand() % 100; - if (sym->type == S_TRISTATE) { - if (cnt < pty) - sym->def[S_DEF_USER].tri = yes; - else if (cnt < (pty+ptm)) - sym->def[S_DEF_USER].tri = mod; - } else if (cnt < pby) - sym->def[S_DEF_USER].tri = yes; - break; - default: - continue; - } - if (!(sym_is_choice(sym) && mode == def_random)) - sym->flags |= SYMBOL_DEF_USER; - break; - default: - break; - } - - } - - sym_clear_all_valid(); - - /* - * We have different type of choice blocks. - * If curr.tri equals to mod then we can select several - * choice symbols in one block. - * In this case we do nothing. - * If curr.tri equals yes then only one symbol can be - * selected in a choice block and we set it to yes, - * and the rest to no. - */ - if (mode != def_random) { - for_all_symbols(i, csym) { - if ((sym_is_choice(csym) && !sym_has_value(csym)) || - sym_is_choice_value(csym)) - csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; - } - } - - for_all_symbols(i, csym) { - if (sym_has_value(csym) || !sym_is_choice(csym)) - continue; - - sym_calc_value(csym); - if (mode == def_random) - has_changed |= randomize_choice_values(csym); - else { - set_all_choice_values(csym); - has_changed = true; - } - } - - return has_changed; -} diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index f946ab49ef50..1c15e3c98bdf 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -34,16 +34,6 @@ static inline const char *CONFIG_prefix(void) #undef CONFIG_ #define CONFIG_ CONFIG_prefix() -enum conf_def_mode { - def_default, - def_yes, - def_mod, - def_y2m, - def_m2y, - def_no, - def_random -}; - extern int yylineno; void zconfdump(FILE *out); void zconf_starthelp(void); @@ -57,7 +47,6 @@ const char *zconf_curname(void); const char *conf_get_configname(void); void sym_set_change_count(int count); void sym_add_change_count(int count); -bool conf_set_all_new_symbols(enum conf_def_mode mode); void set_all_choice_values(struct symbol *csym); /* confdata.c and expr.c */ -- cgit v1.2.3 From 406616213bb776a6e6ec69192df39ab1042690f1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:31 +0900 Subject: kconfig: move JUMP_NB to mconf.c This macro is only used in mconf.c. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 -- scripts/kconfig/mconf.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 5c3443692f34..bbca80a0dc24 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -281,8 +281,6 @@ struct jump_key { int index; }; -#define JUMP_NB 9 - extern struct file *file_list; extern struct file *current_file; struct file *lookup_file(const char *name); diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 4063dbc1b927..01b6c27224e2 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -22,6 +22,8 @@ #include "lkc.h" #include "lxdialog/dialog.h" +#define JUMP_NB 9 + static const char mconf_readme[] = "Overview\n" "--------\n" -- cgit v1.2.3 From b75b0a819af9f78fc395b189cddd40f590194d20 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:32 +0900 Subject: kconfig: change defconfig_list option to environment variable "defconfig_list" is a weird option that defines a static symbol that declares the list of base config files in case the .config does not exist yet. This is quite different from other normal symbols; we just abused the "string" type and the "default" properties to list out the input files. They must be fixed values since these are searched for and loaded in the parse stage. It is an ugly hack, and should not exist in the first place. Providing this feature as an environment variable is a saner approach. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig-language.rst | 5 ---- Documentation/kbuild/kconfig.rst | 8 +++++++ init/Kconfig | 9 -------- scripts/kconfig/Makefile | 10 ++++++++ scripts/kconfig/confdata.c | 38 +++++++++++++++++++++++-------- scripts/kconfig/expr.h | 1 - scripts/kconfig/lexer.l | 1 - scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 9 -------- scripts/kconfig/parser.y | 6 ----- scripts/kconfig/symbol.c | 1 - scripts/kconfig/tests/conftest.py | 4 ++++ 12 files changed, 50 insertions(+), 43 deletions(-) (limited to 'scripts/kconfig') diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst index 226ae072da7d..3cbccfc42798 100644 --- a/Documentation/kbuild/kconfig-language.rst +++ b/Documentation/kbuild/kconfig-language.rst @@ -229,11 +229,6 @@ applicable everywhere (see syntax). which can modify the behaviour of the menu entry and its config symbol. These options are currently possible: - - "defconfig_list" - This declares a list of default entries which can be used when - looking for the default configuration (which is used when the main - .config doesn't exists yet.) - - "modules" This declares the symbol to be used as the MODULES symbol, which enables the third modular state for all config symbols. diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst index dce6801d66c9..5967c79c3baa 100644 --- a/Documentation/kbuild/kconfig.rst +++ b/Documentation/kbuild/kconfig.rst @@ -41,6 +41,14 @@ KCONFIG_CONFIG This environment variable can be used to specify a default kernel config file name to override the default name of ".config". +KCONFIG_DEFCONFIG_LIST +---------------------- + +This environment variable specifies a list of config files which can be used +as a base configuration in case the .config does not exist yet. Entries in +the list are separated with whitespaces to each other, and the first one +that exists is used. + KCONFIG_OVERWRITECONFIG ----------------------- If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not diff --git a/init/Kconfig b/init/Kconfig index 5f5c776ef192..8578c6009674 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1,13 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -config DEFCONFIG_LIST - string - depends on !UML - option defconfig_list - default "/lib/modules/$(shell,uname -r)/.config" - default "/etc/kernel-config" - default "/boot/config-$(shell,uname -r)" - default "arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)" - config CC_VERSION_TEXT string default "$(CC_VERSION_TEXT)" diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 8c19b82c6035..31c5735663c8 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -13,6 +13,16 @@ ifeq ($(quiet),silent_) silent := -s endif +export KCONFIG_DEFCONFIG_LIST := +ifneq ($(SRCARCH),um) +kernel-release := $(shell uname -r) +KCONFIG_DEFCONFIG_LIST := \ + /lib/modules/$(kernel-release)/.config \ + /etc/kernel-config \ + /boot/config-$(kernel-release) \ + arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) +endif + # We need this, in case the user has it in its environment unexport CONFIG_ diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 198f70957fbf..f3998d5ddd02 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -360,28 +360,46 @@ int conf_read_simple(const char *name, int def) if (name) { in = zconf_fopen(name); } else { - struct property *prop; + char *env; name = conf_get_configname(); in = zconf_fopen(name); if (in) goto load; sym_add_change_count(1); - if (!sym_defconfig_list) + + env = getenv("KCONFIG_DEFCONFIG_LIST"); + if (!env) return 1; - for_all_defaults(sym_defconfig_list, prop) { - if (expr_calc_value(prop->visible.expr) == no || - prop->expr->type != E_SYMBOL) - continue; - sym_calc_value(prop->expr->left.sym); - name = sym_get_string_value(prop->expr->left.sym); - in = zconf_fopen(name); + while (1) { + bool is_last; + + while (isspace(*env)) + env++; + + if (!*env) + break; + + p = env; + while (*p && !isspace(*p)) + p++; + + is_last = (*p == '\0'); + + *p = '\0'; + + in = zconf_fopen(env); if (in) { conf_message("using defaults found in %s", - name); + env); goto load; } + + if (is_last) + break; + + env = p + 1; } } if (!in) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index bbca80a0dc24..dc17152b1f14 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -287,7 +287,6 @@ struct file *lookup_file(const char *name); extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; -extern struct symbol *sym_defconfig_list; extern int cdebug; struct expr *expr_alloc_symbol(struct symbol *sym); struct expr *expr_alloc_one(enum expr_type type, struct expr *ce); diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 9c22cb554673..e918950f94a6 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -99,7 +99,6 @@ n [A-Za-z0-9_-] "def_bool" return T_DEF_BOOL; "def_tristate" return T_DEF_TRISTATE; "default" return T_DEFAULT; -"defconfig_list" return T_DEFCONFIG_LIST; "depends" return T_DEPENDS; "endchoice" return T_ENDCHOICE; "endif" return T_ENDIF; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 1c15e3c98bdf..7378e966add5 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -96,7 +96,6 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); void menu_add_option_modules(void); -void menu_add_option_defconfig_list(void); void menu_add_option_allnoconfig_y(void); void menu_finalize(struct menu *parent); void menu_set_type(int type); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index a5fbd6ccc006..5dcfc173da41 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -219,15 +219,6 @@ void menu_add_option_modules(void) modules_sym = current_entry->sym; } -void menu_add_option_defconfig_list(void) -{ - if (!sym_defconfig_list) - sym_defconfig_list = current_entry->sym; - else if (sym_defconfig_list != current_entry->sym) - zconf_error("trying to redefine defconfig symbol"); - sym_defconfig_list->flags |= SYMBOL_NO_WRITE; -} - void menu_add_option_allnoconfig_y(void) { current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 190f1117f35a..f11d8382e9e6 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -53,7 +53,6 @@ static struct menu *current_menu, *current_entry; %token T_COMMENT %token T_CONFIG %token T_DEFAULT -%token T_DEFCONFIG_LIST %token T_DEF_BOOL %token T_DEF_TRISTATE %token T_DEPENDS @@ -223,11 +222,6 @@ config_option: T_OPTION T_MODULES T_EOL menu_add_option_modules(); }; -config_option: T_OPTION T_DEFCONFIG_LIST T_EOL -{ - menu_add_option_defconfig_list(); -}; - config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL { menu_add_option_allnoconfig_y(); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index fe38e6fd2c2a..36b0fcb18117 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -35,7 +35,6 @@ static struct symbol symbol_empty = { .flags = SYMBOL_VALID, }; -struct symbol *sym_defconfig_list; struct symbol *modules_sym; static tristate modules_val; diff --git a/scripts/kconfig/tests/conftest.py b/scripts/kconfig/tests/conftest.py index 0345ef6e3273..af8774a5697c 100644 --- a/scripts/kconfig/tests/conftest.py +++ b/scripts/kconfig/tests/conftest.py @@ -53,6 +53,10 @@ class Conf: # Override 'srctree' environment to make the test as the top directory extra_env['srctree'] = self._test_dir + # Clear KCONFIG_DEFCONFIG_LIST to keep unit tests from being affected + # by the user's environment. + extra_env['KCONFIG_DEFCONFIG_LIST'] = '' + # Run Kconfig in a temporary directory. # This directory is automatically removed when done. with tempfile.TemporaryDirectory() as temp_dir: -- cgit v1.2.3 From dd4659963a4d2dde9756e31ffe5d7c639bcaa26e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:33 +0900 Subject: kconfig: move default KBUILD_DEFCONFIG back to scripts/kconfig/Makefile This is a partial revert of commit 2a86f6612164 ("kbuild: use KBUILD_DEFCONFIG as the fallback for DEFCONFIG_LIST"). Now that the reference to $(DEFCONFIG_LIST) was removed from init/Kconfig, the default KBUILD_DEFCONFIG can go back home. Signed-off-by: Masahiro Yamada --- Makefile | 3 --- scripts/kconfig/Makefile | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'scripts/kconfig') diff --git a/Makefile b/Makefile index a28bb374663d..f1093b972708 100644 --- a/Makefile +++ b/Makefile @@ -396,9 +396,6 @@ endif KCONFIG_CONFIG ?= .config export KCONFIG_CONFIG -# Default file for 'make defconfig'. This may be overridden by arch-Makefile. -export KBUILD_DEFCONFIG := defconfig - # SHELL used by kbuild CONFIG_SHELL := sh diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 31c5735663c8..7df3c0e4c52e 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -9,6 +9,10 @@ else Kconfig := Kconfig endif +ifndef KBUILD_DEFCONFIG +KBUILD_DEFCONFIG := defconfig +endif + ifeq ($(quiet),silent_) silent := -s endif -- cgit v1.2.3 From f8f0d06438e5c810d1e13b5f8c2fed501fe36e9c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:34 +0900 Subject: kconfig: do not use allnoconfig_y option allnoconfig_y is an ugly hack that sets a symbol to 'y' by allnoconfig. allnoconfig does not mean a minimal set of CONFIG options because a bunch of prompts are hidden by 'if EMBEDDED' or 'if EXPERT', but I do not like to hack Kconfig this way. Use the pre-existing feature, KCONFIG_ALLCONFIG, to provide a one liner config fragment. CONFIG_EMBEDDED=y is still forced when allnoconfig is invoked as a part of tinyconfig. No change in the .config file produced by 'make tinyconfig'. The output of 'make allnoconfig' will be changed; we will get CONFIG_EMBEDDED=n because allnoconfig literally sets all symbols to n. Signed-off-by: Masahiro Yamada --- init/Kconfig | 1 - kernel/configs/tiny-base.config | 1 + scripts/kconfig/Makefile | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 kernel/configs/tiny-base.config (limited to 'scripts/kconfig') diff --git a/init/Kconfig b/init/Kconfig index 8578c6009674..b5c65653d665 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1768,7 +1768,6 @@ config DEBUG_RSEQ config EMBEDDED bool "Embedded system" - option allnoconfig_y select EXPERT help This option should be enabled if compiling the kernel for diff --git a/kernel/configs/tiny-base.config b/kernel/configs/tiny-base.config new file mode 100644 index 000000000000..2f0e6bf6db2c --- /dev/null +++ b/kernel/configs/tiny-base.config @@ -0,0 +1 @@ +CONFIG_EMBEDDED=y diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 7df3c0e4c52e..46f2465177f0 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -102,7 +102,8 @@ configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/c PHONY += tinyconfig tinyconfig: - $(Q)$(MAKE) -f $(srctree)/Makefile allnoconfig tiny.config + $(Q)KCONFIG_ALLCONFIG=kernel/configs/tiny-base.config $(MAKE) -f $(srctree)/Makefile allnoconfig + $(Q)$(MAKE) -f $(srctree)/Makefile tiny.config # CHECK: -o cache_dir= working? PHONY += testconfig -- cgit v1.2.3 From ab838577aaaeda12242b7f1e2da3f25c9b4cec3a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:35 +0900 Subject: kconfig: remove allnoconfig_y option Now that the only user, CONFIG_EMBEDDED has stopped using this option, remove it entirely. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig-language.rst | 4 ---- scripts/kconfig/conf.c | 5 +---- scripts/kconfig/expr.h | 3 --- scripts/kconfig/lexer.l | 1 - scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 5 ----- scripts/kconfig/parser.y | 6 ------ 7 files changed, 1 insertion(+), 24 deletions(-) (limited to 'scripts/kconfig') diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst index 3cbccfc42798..4a796c601446 100644 --- a/Documentation/kbuild/kconfig-language.rst +++ b/Documentation/kbuild/kconfig-language.rst @@ -234,10 +234,6 @@ applicable everywhere (see syntax). enables the third modular state for all config symbols. At most one symbol may have the "modules" option set. - - "allnoconfig_y" - This declares the symbol as one that should have the value y when - using "allnoconfig". Used for symbols that hide other symbols. - Menu dependencies ----------------- diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 10958f1e41d6..bfa1ea8f5f98 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -242,10 +242,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) sym->def[S_DEF_USER].tri = mod; break; case def_no: - if (sym->flags & SYMBOL_ALLNOCONFIG_Y) - sym->def[S_DEF_USER].tri = yes; - else - sym->def[S_DEF_USER].tri = no; + sym->def[S_DEF_USER].tri = no; break; case def_random: sym->def[S_DEF_USER].tri = no; diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index dc17152b1f14..9c9caca5bd5f 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -156,9 +156,6 @@ struct symbol { /* choice values need to be set before calculating this symbol value */ #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 -/* Set symbol to y if allnoconfig; used for symbols that hide others */ -#define SYMBOL_ALLNOCONFIG_Y 0x200000 - #define SYMBOL_MAXLENGTH 256 #define SYMBOL_HASHSIZE 9973 diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index e918950f94a6..08c96a6ffe05 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -91,7 +91,6 @@ n [A-Za-z0-9_-] [ \t]* /* whitespaces */ \\\n /* escaped new line */ \n return T_EOL; -"allnoconfig_y" return T_ALLNOCONFIG_Y; "bool" return T_BOOL; "choice" return T_CHOICE; "comment" return T_COMMENT; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 7378e966add5..679ebad15197 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -96,7 +96,6 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); void menu_add_option_modules(void); -void menu_add_option_allnoconfig_y(void); void menu_finalize(struct menu *parent); void menu_set_type(int type); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 5dcfc173da41..d50d0de55222 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -219,11 +219,6 @@ void menu_add_option_modules(void) modules_sym = current_entry->sym; } -void menu_add_option_allnoconfig_y(void) -{ - current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y; -} - static int menu_validate_number(struct symbol *sym, struct symbol *sym2) { return sym2->type == S_INT || sym2->type == S_HEX || diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index f11d8382e9e6..2ada169c8b5d 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -45,7 +45,6 @@ static struct menu *current_menu, *current_entry; %token T_HELPTEXT %token T_WORD %token T_WORD_QUOTE -%token T_ALLNOCONFIG_Y %token T_BOOL %token T_CHOICE %token T_CLOSE_PAREN @@ -222,11 +221,6 @@ config_option: T_OPTION T_MODULES T_EOL menu_add_option_modules(); }; -config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL -{ - menu_add_option_allnoconfig_y(); -}; - /* choice entry */ choice: T_CHOICE word_opt T_EOL -- cgit v1.2.3 From 6dd85ff178cd76851e2184b13e545f5a88d1be30 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 04:48:36 +0900 Subject: kconfig: change "modules" from sub-option to first-level attribute Now "modules" is the only member of the "option" property. Remove "option", and move "modules" to the top level property. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig-language.rst | 14 ++++---------- init/Kconfig | 2 +- scripts/kconfig/lexer.l | 1 - scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 8 -------- scripts/kconfig/parser.y | 8 +++++--- scripts/kconfig/tests/choice/Kconfig | 2 +- scripts/kconfig/tests/choice_value_with_m_dep/Kconfig | 2 +- scripts/kconfig/tests/inter_choice/Kconfig | 2 +- 9 files changed, 13 insertions(+), 27 deletions(-) (limited to 'scripts/kconfig') diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst index 4a796c601446..98c24183d8c3 100644 --- a/Documentation/kbuild/kconfig-language.rst +++ b/Documentation/kbuild/kconfig-language.rst @@ -223,16 +223,10 @@ applicable everywhere (see syntax). the indentation level, this means it ends at the first line which has a smaller indentation than the first line of the help text. -- misc options: "option" [=] - - Various less common options can be defined via this option syntax, - which can modify the behaviour of the menu entry and its config - symbol. These options are currently possible: - - - "modules" - This declares the symbol to be used as the MODULES symbol, which - enables the third modular state for all config symbols. - At most one symbol may have the "modules" option set. +- module attribute: "modules" + This declares the symbol to be used as the MODULES symbol, which + enables the third modular state for all config symbols. + At most one symbol may have the "modules" option set. Menu dependencies ----------------- diff --git a/init/Kconfig b/init/Kconfig index b5c65653d665..ab9a284e6078 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2042,7 +2042,7 @@ config MODULE_SIG_FORMAT menuconfig MODULES bool "Enable loadable module support" - option modules + modules help Kernel modules are small pieces of compiled code which can be inserted in the running kernel, rather than being diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 08c96a6ffe05..312cbad2d34d 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -112,7 +112,6 @@ n [A-Za-z0-9_-] "menuconfig" return T_MENUCONFIG; "modules" return T_MODULES; "on" return T_ON; -"option" return T_OPTION; "optional" return T_OPTIONAL; "prompt" return T_PROMPT; "range" return T_RANGE; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 679ebad15197..01666f558fe9 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -95,7 +95,6 @@ void menu_add_visibility(struct expr *dep); struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); -void menu_add_option_modules(void); void menu_finalize(struct menu *parent); void menu_set_type(int type); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index d50d0de55222..8b2108b74821 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -211,14 +211,6 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep) menu_add_prop(type, expr_alloc_symbol(sym), dep); } -void menu_add_option_modules(void) -{ - if (modules_sym) - zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'", - current_entry->sym->name, modules_sym->name); - modules_sym = current_entry->sym; -} - static int menu_validate_number(struct symbol *sym, struct symbol *sym2) { return sym2->type == S_INT || sym2->type == S_HEX || diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 2ada169c8b5d..e46ce21a2fc4 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -69,7 +69,6 @@ static struct menu *current_menu, *current_entry; %token T_MODULES %token T_ON %token T_OPEN_PAREN -%token T_OPTION %token T_OPTIONAL %token T_PLUS_EQUAL %token T_PROMPT @@ -216,9 +215,12 @@ config_option: T_RANGE symbol symbol if_expr T_EOL printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); }; -config_option: T_OPTION T_MODULES T_EOL +config_option: T_MODULES T_EOL { - menu_add_option_modules(); + if (modules_sym) + zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'", + current_entry->sym->name, modules_sym->name); + modules_sym = current_entry->sym; }; /* choice entry */ diff --git a/scripts/kconfig/tests/choice/Kconfig b/scripts/kconfig/tests/choice/Kconfig index a412205b1b0c..0930eb65e932 100644 --- a/scripts/kconfig/tests/choice/Kconfig +++ b/scripts/kconfig/tests/choice/Kconfig @@ -2,7 +2,7 @@ config MODULES bool "Enable loadable module support" - option modules + modules default y choice diff --git a/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig b/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig index 7106c26bb3a8..bd970cec07d6 100644 --- a/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig +++ b/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig @@ -2,7 +2,7 @@ config MODULES def_bool y - option modules + modules config DEP tristate diff --git a/scripts/kconfig/tests/inter_choice/Kconfig b/scripts/kconfig/tests/inter_choice/Kconfig index 5698a4018dd0..26c25f68695b 100644 --- a/scripts/kconfig/tests/inter_choice/Kconfig +++ b/scripts/kconfig/tests/inter_choice/Kconfig @@ -2,7 +2,7 @@ config MODULES def_bool y - option modules + modules choice prompt "Choice" -- cgit v1.2.3 From a69b191f6297310ff140f2868b89fe2a2f355b90 Mon Sep 17 00:00:00 2001 From: Yang Li Date: Mon, 15 Mar 2021 14:55:44 +0800 Subject: kconfig: use true and false for bool variable fixed the following coccicheck: ./scripts/kconfig/confdata.c:36:9-10: WARNING: return of 0/1 in function 'is_dir' with return type bool Reported-by: Abaci Robot Signed-off-by: Yang Li Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f3998d5ddd02..c796d402665e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -33,7 +33,7 @@ static bool is_dir(const char *path) struct stat st; if (stat(path, &st)) - return 0; + return false; return S_ISDIR(st.st_mode); } -- cgit v1.2.3 From 21f8b32fbdbc1cf94e285384daf490d9c4ae5ae3 Mon Sep 17 00:00:00 2001 From: Bhaskar Chowdhury Date: Fri, 26 Mar 2021 11:31:22 +0530 Subject: kconfig: streamline_config.pl: Couple of typo fixes s/configuraton/configuration/ s/orignal/original/ Signed-off-by: Bhaskar Chowdhury Signed-off-by: Masahiro Yamada --- scripts/kconfig/streamline_config.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index 1c78ba49ca99..911c72a2dbc4 100755 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl @@ -21,7 +21,7 @@ # 1. Boot up the kernel that you want to stream line the config on. # 2. Change directory to the directory holding the source of the # kernel that you just booted. -# 3. Copy the configuraton file to this directory as .config +# 3. Copy the configuration file to this directory as .config # 4. Have all your devices that you need modules for connected and # operational (make sure that their corresponding modules are loaded) # 5. Run this script redirecting the output to some other file @@ -481,7 +481,7 @@ sub parse_config_depends # The idea is we look at all the configs that select it. If one # is already in our list of configs to enable, then there's nothing # else to do. If there isn't, we pick the first config that was -# enabled in the orignal config and use that. +# enabled in the original config and use that. sub parse_config_selects { my ($config, $p) = @_; -- cgit v1.2.3 From bffbf6e2ad6a8c9fbf78f3561404527fe69ef23d Mon Sep 17 00:00:00 2001 From: Bhaskar Chowdhury Date: Sat, 27 Mar 2021 02:48:57 +0530 Subject: kconfig: lxdialog: A spello fix and a punctuation added s/propperly/properly/ s/thats/that\'s/ Signed-off-by: Bhaskar Chowdhury Signed-off-by: Masahiro Yamada --- scripts/kconfig/lxdialog/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 1b490d4af0d3..3f78fb265136 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -363,7 +363,7 @@ void print_title(WINDOW *dialog, const char *title, int width) /* * Print a string of text in a window, automatically wrap around to the * next line if the string is too long to fit on one line. Newline - * characters '\n' are propperly processed. We start on a new line + * characters '\n' are properly processed. We start on a new line * if there is no room for at least 4 nonblanks following a double-space. */ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) @@ -541,7 +541,7 @@ int first_alpha(const char *string, const char *exempt) * lxdialog suggest which is correctly translated to two * times esc. But then we need to ignore the second esc to avoid stepping * out one menu too much. Filter away all escaped key sequences since - * keypad(FALSE) turn off ncurses support for escape sequences - and thats + * keypad(FALSE) turn off ncurses support for escape sequences - and that's * needed to make notimeout() do as expected. */ int on_key_esc(WINDOW *win) -- cgit v1.2.3 From 1f035a52918a4c97b99c5d9f0d5023fe659bccaa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 10 Apr 2021 15:52:46 +0900 Subject: kconfig: nconf: fix core dump when searching in empty menu The following code in get_mext_match(): index = (index + items_num) % items_num; ... makes the program crash when items_num is zero (that is, the menu is empty). A menu can be empty when all the options in it are hidden by unmet 'depends on'. For example, menu "This menu will be empty" config FOO bool "foo" depends on BROKEN endmenu If you visit this menu and press a '/' key and then another key, nconf crashes with: Floating point exception (core dumped) When the number of items is zero, it does not make sense to search in the menu. In this case, current_item() returns NULL, and item_index() ERR, but get_mext_match() does not check it. Let's make get_mext_match() just return if the menu is empty. While I am here, change items_num from 'int' to 'unsigned int' because it should never become negative. Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index e0f965529166..0fb48f171b66 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -268,7 +268,7 @@ static int mwin_max_cols; static MENU *curses_menu; static ITEM *curses_menu_items[MAX_MENU_ITEMS]; static struct mitem k_menu_items[MAX_MENU_ITEMS]; -static int items_num; +static unsigned int items_num; static int global_exit; /* the currently selected button */ static const char *current_instructions = menu_instructions; @@ -496,8 +496,12 @@ typedef enum {MATCH_TINKER_PATTERN_UP, MATCH_TINKER_PATTERN_DOWN, /* return the index of the matched item, or -1 if no such item exists */ static int get_mext_match(const char *match_str, match_f flag) { - int match_start = item_index(current_item(curses_menu)); - int index; + int match_start, index; + + /* Do not search if the menu is empty (i.e. items_num == 0) */ + match_start = item_index(current_item(curses_menu)); + if (match_start == ERR) + return -1; if (flag == FIND_NEXT_MATCH_DOWN) ++match_start; -- cgit v1.2.3 From 5ee546594025fc9337e4cc8b79db89f1258cf480 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 10 Apr 2021 15:57:22 +0900 Subject: kconfig: change sym_change_count to a boolean flag sym_change_count has no good reason to be 'int' type. sym_set_change_count() compares the old and new values after casting both of them to (bool). I do not see any practical diffrence between sym_set_change_count(1) and sym_add_change_count(1). Use the boolean flag, conf_changed. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 31 +++++++++++++------------------ scripts/kconfig/lkc.h | 2 -- scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/mconf.c | 2 +- scripts/kconfig/nconf.c | 2 +- scripts/kconfig/parser.y | 2 +- scripts/kconfig/symbol.c | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index c796d402665e..a8339871ef79 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -366,7 +366,7 @@ int conf_read_simple(const char *name, int def) in = zconf_fopen(name); if (in) goto load; - sym_add_change_count(1); + conf_set_changed(true); env = getenv("KCONFIG_DEFCONFIG_LIST"); if (!env) @@ -444,7 +444,7 @@ load: if (def == S_DEF_USER) { sym = sym_find(line + 2 + strlen(CONFIG_)); if (!sym) { - sym_add_change_count(1); + conf_set_changed(true); continue; } } else { @@ -487,7 +487,7 @@ load: */ conf_touch_dep(line + strlen(CONFIG_)); else - sym_add_change_count(1); + conf_set_changed(true); continue; } @@ -535,7 +535,7 @@ int conf_read(const char *name) int conf_unsaved = 0; int i; - sym_set_change_count(0); + conf_set_changed(false); if (conf_read_simple(name, S_DEF_USER)) { sym_calc_value(modules_sym); @@ -593,7 +593,8 @@ int conf_read(const char *name) } } - sym_add_change_count(conf_warnings || conf_unsaved); + if (conf_warnings || conf_unsaved) + conf_set_changed(true); return 0; } @@ -938,7 +939,7 @@ next: if (is_same(name, tmpname)) { conf_message("No change to %s", name); unlink(tmpname); - sym_set_change_count(0); + conf_set_changed(false); return 0; } @@ -950,7 +951,7 @@ next: conf_message("configuration written to %s", name); - sym_set_change_count(0); + conf_set_changed(false); return 0; } @@ -1118,26 +1119,20 @@ int conf_write_autoconf(int overwrite) return 0; } -static int sym_change_count; +static bool conf_changed; static void (*conf_changed_callback)(void); -void sym_set_change_count(int count) +void conf_set_changed(bool val) { - int _sym_change_count = sym_change_count; - sym_change_count = count; - if (conf_changed_callback && - (bool)_sym_change_count != (bool)count) + if (conf_changed_callback && conf_changed != val) conf_changed_callback(); -} -void sym_add_change_count(int count) -{ - sym_set_change_count(count + sym_change_count); + conf_changed = val; } bool conf_get_changed(void) { - return sym_change_count; + return conf_changed; } void conf_set_changed_callback(void (*fn)(void)) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 01666f558fe9..45599c52478d 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -45,8 +45,6 @@ const char *zconf_curname(void); /* confdata.c */ const char *conf_get_configname(void); -void sym_set_change_count(int count); -void sym_add_change_count(int count); void set_all_choice_values(struct symbol *csym); /* confdata.c and expr.c */ diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9e81be33c40f..a11626bdc421 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -8,6 +8,7 @@ int conf_read_simple(const char *name, int); int conf_write_defconfig(const char *name); int conf_write(const char *name); int conf_write_autoconf(int overwrite); +void conf_set_changed(bool val); bool conf_get_changed(void); void conf_set_changed_callback(void (*fn)(void)); void conf_set_message_callback(void (*fn)(const char *s)); diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 01b6c27224e2..4cfbe62938cd 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -910,7 +910,7 @@ static void conf_load(void) return; if (!conf_read(dialog_input_result)) { set_config_filename(dialog_input_result); - sym_set_change_count(1); + conf_set_changed(true); return; } show_textbox(NULL, "File does not exist!", 5, 38); diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 0fb48f171b66..0cce69ccb611 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -1408,7 +1408,7 @@ static void conf_load(void) return; if (!conf_read(dialog_input_result)) { set_config_filename(dialog_input_result); - sym_set_change_count(1); + conf_set_changed(true); return; } btn_dialog(main_window, "File does not exist!", 0); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index e46ce21a2fc4..e90889edf5b3 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -507,7 +507,7 @@ void conf_parse(const char *name) } if (yynerrs) exit(1); - sym_set_change_count(1); + conf_set_changed(true); } static bool zconf_endtoken(const char *tokenname, diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 36b0fcb18117..5844d636d38f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -472,7 +472,7 @@ void sym_clear_all_valid(void) for_all_symbols(i, sym) sym->flags &= ~SYMBOL_VALID; - sym_add_change_count(1); + conf_set_changed(true); sym_calc_value(modules_sym); } -- cgit v1.2.3 From f02aa48dde8b96eef5998b049ad11547bfc16080 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 10 Apr 2021 23:31:58 +0900 Subject: kconfig: use /boot/config-* etc. as DEFCONFIG_LIST only for native build When the .config file is missing, 'make config', 'make menuconfig', etc. uses a file listed in DEFCONFIG_LIST, if found, as base configuration. Ususally, /boot/config-$(uname -r) exists, and is used as default. However, when you are cross-compiling the kernel, it does not make sense to use /boot/config-* on the build host. It should default to arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG). UML previously did not use DEFCONFIG_LIST at all, but it should be able to use arch/um/configs/$(KBUILD_DEFCONFIG) as a base config file. Signed-off-by: Masahiro Yamada --- Makefile | 5 +++++ scripts/kconfig/Makefile | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'scripts/kconfig') diff --git a/Makefile b/Makefile index f1093b972708..697eaf6c550e 100644 --- a/Makefile +++ b/Makefile @@ -393,6 +393,11 @@ ifeq ($(ARCH),sh64) SRCARCH := sh endif +export cross_compiling := +ifneq ($(SRCARCH),$(SUBARCH)) +cross_compiling := 1 +endif + KCONFIG_CONFIG ?= .config export KCONFIG_CONFIG diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 46f2465177f0..1d1a7f83ee8d 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -18,14 +18,14 @@ silent := -s endif export KCONFIG_DEFCONFIG_LIST := -ifneq ($(SRCARCH),um) +ifndef cross_compiling kernel-release := $(shell uname -r) -KCONFIG_DEFCONFIG_LIST := \ +KCONFIG_DEFCONFIG_LIST += \ /lib/modules/$(kernel-release)/.config \ /etc/kernel-config \ - /boot/config-$(kernel-release) \ - arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) + /boot/config-$(kernel-release) endif +KCONFIG_DEFCONFIG_LIST += arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) # We need this, in case the user has it in its environment unexport CONFIG_ -- cgit v1.2.3 From 68876c38c4b30653c1779414954ce747a455253c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Apr 2021 04:45:30 +0900 Subject: kconfig: mconf,nconf: remove unneeded '\0' termination after snprintf() snprintf() always terminates the destination buffer with '\0' even if the buffer is not long enough. (In this case, the last element of the buffer becomes '\0'.) The explicit termination is unneeded. Signed-off-by: Masahiro Yamada --- scripts/kconfig/mconf.c | 11 +++-------- scripts/kconfig/nconf.c | 12 +++--------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 4cfbe62938cd..9d3cf510562f 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -299,17 +299,12 @@ static char filename[PATH_MAX+1]; static void set_config_filename(const char *config_filename) { static char menu_backtitle[PATH_MAX+128]; - int size; - size = snprintf(menu_backtitle, sizeof(menu_backtitle), - "%s - %s", config_filename, rootmenu.prompt->text); - if (size >= sizeof(menu_backtitle)) - menu_backtitle[sizeof(menu_backtitle)-1] = '\0'; + snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s", + config_filename, rootmenu.prompt->text); set_dialog_backtitle(menu_backtitle); - size = snprintf(filename, sizeof(filename), "%s", config_filename); - if (size >= sizeof(filename)) - filename[sizeof(filename)-1] = '\0'; + snprintf(filename, sizeof(filename), "%s", config_filename); } struct subtitle_part { diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 0cce69ccb611..06ebe16e4a38 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -633,16 +633,10 @@ static char filename[PATH_MAX+1]; static char menu_backtitle[PATH_MAX+128]; static const char *set_config_filename(const char *config_filename) { - int size; + snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s", + config_filename, rootmenu.prompt->text); - size = snprintf(menu_backtitle, sizeof(menu_backtitle), - "%s - %s", config_filename, rootmenu.prompt->text); - if (size >= sizeof(menu_backtitle)) - menu_backtitle[sizeof(menu_backtitle)-1] = '\0'; - - size = snprintf(filename, sizeof(filename), "%s", config_filename); - if (size >= sizeof(filename)) - filename[sizeof(filename)-1] = '\0'; + snprintf(filename, sizeof(filename), "%s", config_filename); return menu_backtitle; } -- cgit v1.2.3 From 7f5ff55bf8eb99e42c10388ccffdfbb0a0caac67 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Apr 2021 04:45:31 +0900 Subject: kconfig: nconf: fix NORMAL attributes The lower 8-bit of attributes should be 0, but this code wrongly sets it to NORMAL (=1). The correct one is A_NORMAL. Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.gui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index 77f525a8617c..a914f81092d7 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -70,7 +70,7 @@ static void normal_color_theme(void) /* automatically add color... */ #define mkattr(name, attr) do { \ attributes[name] = attr | COLOR_PAIR(name); } while (0) - mkattr(NORMAL, NORMAL); + mkattr(NORMAL, A_NORMAL); mkattr(MAIN_HEADING, A_BOLD | A_UNDERLINE); mkattr(MAIN_MENU_FORE, A_REVERSE); @@ -102,7 +102,7 @@ static void no_colors_theme(void) /* automatically add highlight, no color */ #define mkattrn(name, attr) { attributes[name] = attr; } - mkattrn(NORMAL, NORMAL); + mkattrn(NORMAL, A_NORMAL); mkattrn(MAIN_HEADING, A_BOLD | A_UNDERLINE); mkattrn(MAIN_MENU_FORE, A_STANDOUT); -- cgit v1.2.3 From 2ba50da9ec34196a895b4947dc6bb1dbf1ace670 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Apr 2021 04:45:32 +0900 Subject: kconfig: nconf: get rid of (void) casts from wattrset() calls This reverts commit 10175ba65fde ("nconfig: Silence unused return values from wattrset"). With this patch applied, recent GCC versions can cleanly build nconf without "value computed is not used" warnings. The wattrset() used to be implemented as a macro, like this: #define wattrset(win,at) \ (NCURSES_OK_ADDR(win) \ ? ((win)->_attrs = NCURSES_CAST(attr_t, at), \ OK) \ : ERR) The GCC bugzilla [1] reported a false-positive -Wunused-value warning in a similar test case. It was fixed by GCC 4.4.1. Let's revert that commit, and see if somebody will claim the issue. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39889 Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 14 +++++++------- scripts/kconfig/nconf.gui.c | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 06ebe16e4a38..bcfcf0b87a7a 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -370,18 +370,18 @@ static void print_function_line(void) int lines = getmaxy(stdscr); for (i = 0; i < function_keys_num; i++) { - (void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]); + wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]); mvwprintw(main_window, lines-3, offset, "%s", function_keys[i].key_str); - (void) wattrset(main_window, attributes[FUNCTION_TEXT]); + wattrset(main_window, attributes[FUNCTION_TEXT]); offset += strlen(function_keys[i].key_str); mvwprintw(main_window, lines-3, offset, "%s", function_keys[i].func); offset += strlen(function_keys[i].func) + skip; } - (void) wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attributes[NORMAL]); } /* help */ @@ -954,16 +954,16 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions; clear(); - (void) wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attributes[NORMAL]); print_in_middle(stdscr, 1, 0, getmaxx(stdscr), menu_backtitle, attributes[MAIN_HEADING]); - (void) wattrset(main_window, attributes[MAIN_MENU_BOX]); + wattrset(main_window, attributes[MAIN_MENU_BOX]); box(main_window, 0, 0); - (void) wattrset(main_window, attributes[MAIN_MENU_HEADING]); + wattrset(main_window, attributes[MAIN_MENU_HEADING]); mvwprintw(main_window, 0, 3, " %s ", prompt); - (void) wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attributes[NORMAL]); set_menu_items(curses_menu, curses_menu_items); diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index a914f81092d7..180d3158d380 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -167,7 +167,7 @@ void print_in_middle(WINDOW *win, length = strlen(string); temp = (width - length) / 2; x = startx + (int)temp; - (void) wattrset(win, color); + wattrset(win, color); mvwprintw(win, y, x, "%s", string); refresh(); } @@ -297,11 +297,11 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...) set_menu_fore(menu, attributes[DIALOG_MENU_FORE]); set_menu_back(menu, attributes[DIALOG_MENU_BACK]); - (void) wattrset(win, attributes[DIALOG_BOX]); + wattrset(win, attributes[DIALOG_BOX]); box(win, 0, 0); /* print message */ - (void) wattrset(msg_win, attributes[DIALOG_TEXT]); + wattrset(msg_win, attributes[DIALOG_TEXT]); fill_window(msg_win, msg); set_menu_win(menu, win); @@ -405,16 +405,16 @@ int dialog_inputbox(WINDOW *main_window, form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2); keypad(form_win, TRUE); - (void) wattrset(form_win, attributes[INPUT_FIELD]); + wattrset(form_win, attributes[INPUT_FIELD]); - (void) wattrset(win, attributes[INPUT_BOX]); + wattrset(win, attributes[INPUT_BOX]); box(win, 0, 0); - (void) wattrset(win, attributes[INPUT_HEADING]); + wattrset(win, attributes[INPUT_HEADING]); if (title) mvwprintw(win, 0, 3, "%s", title); /* print message */ - (void) wattrset(prompt_win, attributes[INPUT_TEXT]); + wattrset(prompt_win, attributes[INPUT_TEXT]); fill_window(prompt_win, prompt); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); @@ -576,7 +576,7 @@ void show_scroll_win(WINDOW *main_window, /* create the pad */ pad = newpad(total_lines+10, total_cols+10); - (void) wattrset(pad, attributes[SCROLLWIN_TEXT]); + wattrset(pad, attributes[SCROLLWIN_TEXT]); fill_window(pad, text); win_lines = min(total_lines+4, lines-2); @@ -591,9 +591,9 @@ void show_scroll_win(WINDOW *main_window, win = newwin(win_lines, win_cols, y, x); keypad(win, TRUE); /* show the help in the help window, and show the help panel */ - (void) wattrset(win, attributes[SCROLLWIN_BOX]); + wattrset(win, attributes[SCROLLWIN_BOX]); box(win, 0, 0); - (void) wattrset(win, attributes[SCROLLWIN_HEADING]); + wattrset(win, attributes[SCROLLWIN_HEADING]); mvwprintw(win, 0, 3, " %s ", title); panel = new_panel(win); -- cgit v1.2.3 From 16b0e10238b45251790ea1a2683855d4f8f3c1a3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Apr 2021 04:45:33 +0900 Subject: kconfig: nconf: remove unneeded default for menu prompt The rootmenu always has a prompt even if the 'mainmenu' statement is missing in the top Kconfig file. conf_parse() calls menu_add_prompt(P_MENU, "Main menu", NULL) in this case. So, every 'menu' has a prompt. Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index bcfcf0b87a7a..8187a2ef837d 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -1066,7 +1066,6 @@ static int do_match(int key, struct match_state *state, int *ans) static void conf(struct menu *menu) { struct menu *submenu = NULL; - const char *prompt = menu_get_prompt(menu); struct symbol *sym; int res; int current_index = 0; @@ -1084,9 +1083,8 @@ static void conf(struct menu *menu) if (!child_count) break; - show_menu(prompt ? prompt : "Main Menu", - menu_instructions, - current_index, &last_top_row); + show_menu(menu_get_prompt(menu), menu_instructions, + current_index, &last_top_row); keypad((menu_win(curses_menu)), TRUE); while (!global_exit) { if (match_state.in_search) { -- cgit v1.2.3 From 93487b17b147f22400378240d06f33badc3368da Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Apr 2021 04:45:34 +0900 Subject: kconfig: nconf: refactor attributes setup code The current attributes setup code is strange; the array attribute[] is set to values outside the range of the attribute_t enum. At least, attributes_t attributes[ATTR_MAX+1] = {0}; ... should be int attribute[ATTR_MAX+1] = {0}; Also, there is no need to hard-code the color-pair numbers in attributes_t. The current code is messy. Rewrite it. Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 22 ++-- scripts/kconfig/nconf.gui.c | 253 ++++++++++++++++++++------------------------ scripts/kconfig/nconf.h | 44 ++++---- 3 files changed, 144 insertions(+), 175 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 8187a2ef837d..e86d3511b939 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -370,18 +370,18 @@ static void print_function_line(void) int lines = getmaxy(stdscr); for (i = 0; i < function_keys_num; i++) { - wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]); + wattrset(main_window, attr_function_highlight); mvwprintw(main_window, lines-3, offset, "%s", function_keys[i].key_str); - wattrset(main_window, attributes[FUNCTION_TEXT]); + wattrset(main_window, attr_function_text); offset += strlen(function_keys[i].key_str); mvwprintw(main_window, lines-3, offset, "%s", function_keys[i].func); offset += strlen(function_keys[i].func) + skip; } - wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attr_normal); } /* help */ @@ -954,16 +954,16 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions; clear(); - wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attr_normal); print_in_middle(stdscr, 1, 0, getmaxx(stdscr), menu_backtitle, - attributes[MAIN_HEADING]); + attr_main_heading); - wattrset(main_window, attributes[MAIN_MENU_BOX]); + wattrset(main_window, attr_main_menu_box); box(main_window, 0, 0); - wattrset(main_window, attributes[MAIN_MENU_HEADING]); + wattrset(main_window, attr_main_menu_heading); mvwprintw(main_window, 0, 3, " %s ", prompt); - wattrset(main_window, attributes[NORMAL]); + wattrset(main_window, attr_normal); set_menu_items(curses_menu, curses_menu_items); @@ -1519,9 +1519,9 @@ int main(int ac, char **av) menu_opts_on(curses_menu, O_NONCYCLIC); menu_opts_on(curses_menu, O_IGNORECASE); set_menu_mark(curses_menu, " "); - set_menu_fore(curses_menu, attributes[MAIN_MENU_FORE]); - set_menu_back(curses_menu, attributes[MAIN_MENU_BACK]); - set_menu_grey(curses_menu, attributes[MAIN_MENU_GREY]); + set_menu_fore(curses_menu, attr_main_menu_fore); + set_menu_back(curses_menu, attr_main_menu_back); + set_menu_grey(curses_menu, attr_main_menu_grey); set_config_filename(conf_get_configname()); setup_windows(); diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index 180d3158d380..e747590cee17 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -7,141 +7,114 @@ #include "nconf.h" #include "lkc.h" -/* a list of all the different widgets we use */ -attributes_t attributes[ATTR_MAX+1] = {0}; - -/* available colors: - COLOR_BLACK 0 - COLOR_RED 1 - COLOR_GREEN 2 - COLOR_YELLOW 3 - COLOR_BLUE 4 - COLOR_MAGENTA 5 - COLOR_CYAN 6 - COLOR_WHITE 7 - */ -static void set_normal_colors(void) -{ - init_pair(NORMAL, -1, -1); - init_pair(MAIN_HEADING, COLOR_MAGENTA, -1); - - /* FORE is for the selected item */ - init_pair(MAIN_MENU_FORE, -1, -1); - /* BACK for all the rest */ - init_pair(MAIN_MENU_BACK, -1, -1); - init_pair(MAIN_MENU_GREY, -1, -1); - init_pair(MAIN_MENU_HEADING, COLOR_GREEN, -1); - init_pair(MAIN_MENU_BOX, COLOR_YELLOW, -1); - - init_pair(SCROLLWIN_TEXT, -1, -1); - init_pair(SCROLLWIN_HEADING, COLOR_GREEN, -1); - init_pair(SCROLLWIN_BOX, COLOR_YELLOW, -1); - - init_pair(DIALOG_TEXT, -1, -1); - init_pair(DIALOG_BOX, COLOR_YELLOW, -1); - init_pair(DIALOG_MENU_BACK, COLOR_YELLOW, -1); - init_pair(DIALOG_MENU_FORE, COLOR_RED, -1); - - init_pair(INPUT_BOX, COLOR_YELLOW, -1); - init_pair(INPUT_HEADING, COLOR_GREEN, -1); - init_pair(INPUT_TEXT, -1, -1); - init_pair(INPUT_FIELD, -1, -1); - - init_pair(FUNCTION_HIGHLIGHT, -1, -1); - init_pair(FUNCTION_TEXT, COLOR_YELLOW, -1); -} - -/* available attributes: - A_NORMAL Normal display (no highlight) - A_STANDOUT Best highlighting mode of the terminal. - A_UNDERLINE Underlining - A_REVERSE Reverse video - A_BLINK Blinking - A_DIM Half bright - A_BOLD Extra bright or bold - A_PROTECT Protected mode - A_INVIS Invisible or blank mode - A_ALTCHARSET Alternate character set - A_CHARTEXT Bit-mask to extract a character - COLOR_PAIR(n) Color-pair number n - */ -static void normal_color_theme(void) -{ - /* automatically add color... */ -#define mkattr(name, attr) do { \ -attributes[name] = attr | COLOR_PAIR(name); } while (0) - mkattr(NORMAL, A_NORMAL); - mkattr(MAIN_HEADING, A_BOLD | A_UNDERLINE); - - mkattr(MAIN_MENU_FORE, A_REVERSE); - mkattr(MAIN_MENU_BACK, A_NORMAL); - mkattr(MAIN_MENU_GREY, A_NORMAL); - mkattr(MAIN_MENU_HEADING, A_BOLD); - mkattr(MAIN_MENU_BOX, A_NORMAL); - - mkattr(SCROLLWIN_TEXT, A_NORMAL); - mkattr(SCROLLWIN_HEADING, A_BOLD); - mkattr(SCROLLWIN_BOX, A_BOLD); - - mkattr(DIALOG_TEXT, A_BOLD); - mkattr(DIALOG_BOX, A_BOLD); - mkattr(DIALOG_MENU_FORE, A_STANDOUT); - mkattr(DIALOG_MENU_BACK, A_NORMAL); - - mkattr(INPUT_BOX, A_NORMAL); - mkattr(INPUT_HEADING, A_BOLD); - mkattr(INPUT_TEXT, A_NORMAL); - mkattr(INPUT_FIELD, A_UNDERLINE); - - mkattr(FUNCTION_HIGHLIGHT, A_BOLD); - mkattr(FUNCTION_TEXT, A_REVERSE); -} - -static void no_colors_theme(void) -{ - /* automatically add highlight, no color */ -#define mkattrn(name, attr) { attributes[name] = attr; } - - mkattrn(NORMAL, A_NORMAL); - mkattrn(MAIN_HEADING, A_BOLD | A_UNDERLINE); - - mkattrn(MAIN_MENU_FORE, A_STANDOUT); - mkattrn(MAIN_MENU_BACK, A_NORMAL); - mkattrn(MAIN_MENU_GREY, A_NORMAL); - mkattrn(MAIN_MENU_HEADING, A_BOLD); - mkattrn(MAIN_MENU_BOX, A_NORMAL); - - mkattrn(SCROLLWIN_TEXT, A_NORMAL); - mkattrn(SCROLLWIN_HEADING, A_BOLD); - mkattrn(SCROLLWIN_BOX, A_BOLD); - - mkattrn(DIALOG_TEXT, A_NORMAL); - mkattrn(DIALOG_BOX, A_BOLD); - mkattrn(DIALOG_MENU_FORE, A_STANDOUT); - mkattrn(DIALOG_MENU_BACK, A_NORMAL); - - mkattrn(INPUT_BOX, A_BOLD); - mkattrn(INPUT_HEADING, A_BOLD); - mkattrn(INPUT_TEXT, A_NORMAL); - mkattrn(INPUT_FIELD, A_UNDERLINE); - - mkattrn(FUNCTION_HIGHLIGHT, A_BOLD); - mkattrn(FUNCTION_TEXT, A_REVERSE); -} +int attr_normal; +int attr_main_heading; +int attr_main_menu_box; +int attr_main_menu_fore; +int attr_main_menu_back; +int attr_main_menu_grey; +int attr_main_menu_heading; +int attr_scrollwin_text; +int attr_scrollwin_heading; +int attr_scrollwin_box; +int attr_dialog_text; +int attr_dialog_menu_fore; +int attr_dialog_menu_back; +int attr_dialog_box; +int attr_input_box; +int attr_input_heading; +int attr_input_text; +int attr_input_field; +int attr_function_text; +int attr_function_highlight; + +#define COLOR_ATTR(_at, _fg, _bg, _hl) \ + { .attr = &(_at), .has_color = true, .color_fg = _fg, .color_bg = _bg, .highlight = _hl } +#define NO_COLOR_ATTR(_at, _hl) \ + { .attr = &(_at), .has_color = false, .highlight = _hl } +#define COLOR_DEFAULT -1 + +struct nconf_attr_param { + int *attr; + bool has_color; + int color_fg; + int color_bg; + int highlight; +}; + +static const struct nconf_attr_param color_theme_params[] = { + COLOR_ATTR(attr_normal, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_main_heading, COLOR_MAGENTA, COLOR_DEFAULT, A_BOLD | A_UNDERLINE), + COLOR_ATTR(attr_main_menu_box, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_main_menu_fore, COLOR_DEFAULT, COLOR_DEFAULT, A_REVERSE), + COLOR_ATTR(attr_main_menu_back, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_main_menu_grey, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_main_menu_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_scrollwin_text, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_scrollwin_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_scrollwin_box, COLOR_YELLOW, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_dialog_text, COLOR_DEFAULT, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_dialog_menu_fore, COLOR_RED, COLOR_DEFAULT, A_STANDOUT), + COLOR_ATTR(attr_dialog_menu_back, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_dialog_box, COLOR_YELLOW, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_input_box, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_input_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD), + COLOR_ATTR(attr_input_text, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), + COLOR_ATTR(attr_input_field, COLOR_DEFAULT, COLOR_DEFAULT, A_UNDERLINE), + COLOR_ATTR(attr_function_text, COLOR_YELLOW, COLOR_DEFAULT, A_REVERSE), + COLOR_ATTR(attr_function_highlight, COLOR_DEFAULT, COLOR_DEFAULT, A_BOLD), + { /* sentinel */ } +}; + +static const struct nconf_attr_param no_color_theme_params[] = { + NO_COLOR_ATTR(attr_normal, A_NORMAL), + NO_COLOR_ATTR(attr_main_heading, A_BOLD | A_UNDERLINE), + NO_COLOR_ATTR(attr_main_menu_box, A_NORMAL), + NO_COLOR_ATTR(attr_main_menu_fore, A_STANDOUT), + NO_COLOR_ATTR(attr_main_menu_back, A_NORMAL), + NO_COLOR_ATTR(attr_main_menu_grey, A_NORMAL), + NO_COLOR_ATTR(attr_main_menu_heading, A_BOLD), + NO_COLOR_ATTR(attr_scrollwin_text, A_NORMAL), + NO_COLOR_ATTR(attr_scrollwin_heading, A_BOLD), + NO_COLOR_ATTR(attr_scrollwin_box, A_BOLD), + NO_COLOR_ATTR(attr_dialog_text, A_NORMAL), + NO_COLOR_ATTR(attr_dialog_menu_fore, A_STANDOUT), + NO_COLOR_ATTR(attr_dialog_menu_back, A_NORMAL), + NO_COLOR_ATTR(attr_dialog_box, A_BOLD), + NO_COLOR_ATTR(attr_input_box, A_BOLD), + NO_COLOR_ATTR(attr_input_heading, A_BOLD), + NO_COLOR_ATTR(attr_input_text, A_NORMAL), + NO_COLOR_ATTR(attr_input_field, A_UNDERLINE), + NO_COLOR_ATTR(attr_function_text, A_REVERSE), + NO_COLOR_ATTR(attr_function_highlight, A_BOLD), + { /* sentinel */ } +}; void set_colors(void) { - start_color(); - use_default_colors(); - set_normal_colors(); + const struct nconf_attr_param *p; + int pair = 0; + if (has_colors()) { - normal_color_theme(); + start_color(); + use_default_colors(); + p = color_theme_params; } else { - /* give defaults */ - no_colors_theme(); + p = no_color_theme_params; } -} + for (; p->attr; p++) { + int attr = p->highlight; + + if (p->has_color) { + pair++; + init_pair(pair, p->color_fg, p->color_bg); + attr |= COLOR_PAIR(pair); + } + + *p->attr = attr; + } +} /* this changes the windows attributes !!! */ void print_in_middle(WINDOW *win, @@ -294,14 +267,14 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...) msg_win = derwin(win, win_rows-2, msg_width, 1, 1+(total_width+2-msg_width)/2); - set_menu_fore(menu, attributes[DIALOG_MENU_FORE]); - set_menu_back(menu, attributes[DIALOG_MENU_BACK]); + set_menu_fore(menu, attr_dialog_menu_fore); + set_menu_back(menu, attr_dialog_menu_back); - wattrset(win, attributes[DIALOG_BOX]); + wattrset(win, attr_dialog_box); box(win, 0, 0); /* print message */ - wattrset(msg_win, attributes[DIALOG_TEXT]); + wattrset(msg_win, attr_dialog_text); fill_window(msg_win, msg); set_menu_win(menu, win); @@ -405,16 +378,16 @@ int dialog_inputbox(WINDOW *main_window, form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2); keypad(form_win, TRUE); - wattrset(form_win, attributes[INPUT_FIELD]); + wattrset(form_win, attr_input_field); - wattrset(win, attributes[INPUT_BOX]); + wattrset(win, attr_input_box); box(win, 0, 0); - wattrset(win, attributes[INPUT_HEADING]); + wattrset(win, attr_input_heading); if (title) mvwprintw(win, 0, 3, "%s", title); /* print message */ - wattrset(prompt_win, attributes[INPUT_TEXT]); + wattrset(prompt_win, attr_input_text); fill_window(prompt_win, prompt); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); @@ -576,7 +549,7 @@ void show_scroll_win(WINDOW *main_window, /* create the pad */ pad = newpad(total_lines+10, total_cols+10); - wattrset(pad, attributes[SCROLLWIN_TEXT]); + wattrset(pad, attr_scrollwin_text); fill_window(pad, text); win_lines = min(total_lines+4, lines-2); @@ -591,9 +564,9 @@ void show_scroll_win(WINDOW *main_window, win = newwin(win_lines, win_cols, y, x); keypad(win, TRUE); /* show the help in the help window, and show the help panel */ - wattrset(win, attributes[SCROLLWIN_BOX]); + wattrset(win, attr_scrollwin_box); box(win, 0, 0); - wattrset(win, attributes[SCROLLWIN_HEADING]); + wattrset(win, attr_scrollwin_heading); mvwprintw(win, 0, 3, " %s ", title); panel = new_panel(win); @@ -607,7 +580,7 @@ void show_scroll_win(WINDOW *main_window, 0, text_cols, "", - attributes[DIALOG_MENU_FORE]); + attr_dialog_menu_fore); wrefresh(win); res = wgetch(win); diff --git a/scripts/kconfig/nconf.h b/scripts/kconfig/nconf.h index fa5245eb93a7..90a1ae331878 100644 --- a/scripts/kconfig/nconf.h +++ b/scripts/kconfig/nconf.h @@ -32,30 +32,26 @@ typeof(b) _b = b;\ _a < _b ? _a : _b; }) -typedef enum { - NORMAL = 1, - MAIN_HEADING, - MAIN_MENU_BOX, - MAIN_MENU_FORE, - MAIN_MENU_BACK, - MAIN_MENU_GREY, - MAIN_MENU_HEADING, - SCROLLWIN_TEXT, - SCROLLWIN_HEADING, - SCROLLWIN_BOX, - DIALOG_TEXT, - DIALOG_MENU_FORE, - DIALOG_MENU_BACK, - DIALOG_BOX, - INPUT_BOX, - INPUT_HEADING, - INPUT_TEXT, - INPUT_FIELD, - FUNCTION_TEXT, - FUNCTION_HIGHLIGHT, - ATTR_MAX -} attributes_t; -extern attributes_t attributes[]; +extern int attr_normal; +extern int attr_main_heading; +extern int attr_main_menu_box; +extern int attr_main_menu_fore; +extern int attr_main_menu_back; +extern int attr_main_menu_grey; +extern int attr_main_menu_heading; +extern int attr_scrollwin_text; +extern int attr_scrollwin_heading; +extern int attr_scrollwin_box; +extern int attr_dialog_text; +extern int attr_dialog_menu_fore; +extern int attr_dialog_menu_back; +extern int attr_dialog_box; +extern int attr_input_box; +extern int attr_input_heading; +extern int attr_input_text; +extern int attr_input_field; +extern int attr_function_text; +extern int attr_function_highlight; typedef enum { F_HELP = 1, -- cgit v1.2.3 From ecdb733f8fa843f632f4306939a5c3704be4a2dd Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 12 Apr 2021 10:12:25 +0900 Subject: kconfig: nconf: change set_config_filename() to void function No one uses the return value of this function. Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index e86d3511b939..d8a6ab5fb521 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -631,13 +631,12 @@ static int item_is_tag(char tag) static char filename[PATH_MAX+1]; static char menu_backtitle[PATH_MAX+128]; -static const char *set_config_filename(const char *config_filename) +static void set_config_filename(const char *config_filename) { snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s", config_filename, rootmenu.prompt->text); snprintf(filename, sizeof(filename), "%s", config_filename); - return menu_backtitle; } /* return = 0 means we are successful. -- cgit v1.2.3 From 0a94768cfda6a77c42e5373d264c96c77ef1a2e5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 12 Apr 2021 10:12:26 +0900 Subject: kconfig: nconf: remove meaningless wattrset() call from show_menu() This attribute is not used because it will be overridden some lines below: wattrset(main_window, attr_main_menu_box); Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index d8a6ab5fb521..5209a18eeacb 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -953,7 +953,6 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions; clear(); - wattrset(main_window, attr_normal); print_in_middle(stdscr, 1, 0, getmaxx(stdscr), menu_backtitle, attr_main_heading); -- cgit v1.2.3 From 08718745d8610c2ed9870568b8d9c01b7f103efb Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 12 Apr 2021 10:12:27 +0900 Subject: kconfig: nconf: refactor in print_in_middle() This helper is the same as the sample code in the NCURSES HOWTO [1], but it is over-engineering to be used for nconf. I do not see any good reason to use the 'float' type just for the division by 2. All the call-sites pass a non-NULL pointer to the first argument, so 'if (win == NULL) win = stdscr;' is dead code. 'if (startx != 0) x = startx;' is dead code because 'x' will be overridden some lines below, by 'x = startx + (int)temp;'. All the call-sites pass a non-zero value to the second argument, so 'if (starty != 0)' is always true. getyx(win, y, x) is also dead-code because both 'y' and 'x' are overridden. All the call-sites pass 0 to the third parameter, so 'startx' can be removed. All the call-sites pass a non-zero value to the fourth parameter, so 'if (width == 0) width = 80;' is dead code. The window will be refreshed later, so there is no need to call refresh() in this function. Change the type of the last parameter from 'chtype' to 'int' to be aligned with the prototype, 'int wattrset(WINDOW *win, int attrs);' I also slightly cleaned up the indentation style. [1]: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/color.html Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 2 +- scripts/kconfig/nconf.gui.c | 31 ++++--------------------------- scripts/kconfig/nconf.h | 7 +------ 3 files changed, 6 insertions(+), 34 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 5209a18eeacb..b11b75f83f7e 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -953,7 +953,7 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions; clear(); - print_in_middle(stdscr, 1, 0, getmaxx(stdscr), + print_in_middle(stdscr, 1, getmaxx(stdscr), menu_backtitle, attr_main_heading); diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index e747590cee17..9aedf40f1dc0 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -117,32 +117,10 @@ void set_colors(void) } /* this changes the windows attributes !!! */ -void print_in_middle(WINDOW *win, - int starty, - int startx, - int width, - const char *string, - chtype color) -{ int length, x, y; - float temp; - - - if (win == NULL) - win = stdscr; - getyx(win, y, x); - if (startx != 0) - x = startx; - if (starty != 0) - y = starty; - if (width == 0) - width = 80; - - length = strlen(string); - temp = (width - length) / 2; - x = startx + (int)temp; - wattrset(win, color); - mvwprintw(win, y, x, "%s", string); - refresh(); +void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs) +{ + wattrset(win, attrs); + mvwprintw(win, y, (width - strlen(str)) / 2, "%s", str); } int get_line_no(const char *text) @@ -577,7 +555,6 @@ void show_scroll_win(WINDOW *main_window, text_cols, 0); print_in_middle(win, text_lines+2, - 0, text_cols, "", attr_dialog_menu_fore); diff --git a/scripts/kconfig/nconf.h b/scripts/kconfig/nconf.h index 90a1ae331878..6f925bc74eb3 100644 --- a/scripts/kconfig/nconf.h +++ b/scripts/kconfig/nconf.h @@ -68,12 +68,7 @@ typedef enum { void set_colors(void); /* this changes the windows attributes !!! */ -void print_in_middle(WINDOW *win, - int starty, - int startx, - int width, - const char *string, - chtype color); +void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs); int get_line_length(const char *line); int get_line_no(const char *text); const char *get_line(const char *text, int line_no); -- cgit v1.2.3 From a77a05dc9cf24a8c88b9d9c70e8984f936d075f3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 14 Apr 2021 00:08:17 +0900 Subject: kconfig: split menu.c out of parser.y Compile menu.c as an independent compilation unit. Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 4 ++-- scripts/kconfig/internal.h | 9 +++++++++ scripts/kconfig/menu.c | 1 + scripts/kconfig/parser.y | 5 ++--- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 scripts/kconfig/internal.h (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 1d1a7f83ee8d..5a215880b268 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -143,8 +143,8 @@ help: # =========================================================================== # object files used by all kconfig flavours -common-objs := confdata.o expr.o lexer.lex.o parser.tab.o preprocess.o \ - symbol.o util.o +common-objs := confdata.o expr.o lexer.lex.o menu.o parser.tab.o \ + preprocess.o symbol.o util.o $(obj)/lexer.lex.o: $(obj)/parser.tab.h HOSTCFLAGS_lexer.lex.o := -I $(srctree)/$(src) diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h new file mode 100644 index 000000000000..2f7298c21b64 --- /dev/null +++ b/scripts/kconfig/internal.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef INTERNAL_H +#define INTERNAL_H + +struct menu; + +extern struct menu *current_menu, *current_entry; + +#endif /* INTERNAL_H */ diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 8b2108b74821..606ba8a63c24 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -9,6 +9,7 @@ #include #include "lkc.h" +#include "internal.h" static const char nohelp_text[] = "There is no help available for this option."; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index e90889edf5b3..2af7ce4e1531 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -12,6 +12,7 @@ #include #include "lkc.h" +#include "internal.h" #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) @@ -28,7 +29,7 @@ static bool zconf_endtoken(const char *tokenname, struct symbol *symbol_hash[SYMBOL_HASHSIZE]; -static struct menu *current_menu, *current_entry; +struct menu *current_menu, *current_entry; %} @@ -713,5 +714,3 @@ void zconfdump(FILE *out) } } } - -#include "menu.c" -- cgit v1.2.3 From 8c94b430b9f6213dec84e309bb480a71778c4213 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan Date: Thu, 15 Apr 2021 09:28:03 +0200 Subject: kconfig: nconf: stop endless search loops If the user selects the very first entry in a page and performs a search-up operation, or selects the very last entry in a page and performs a search-down operation that will not succeed (e.g., via [/]asdfzzz[Up Arrow]), nconf will never terminate searching the page. The reason is that in this case, the starting point will be set to -1 or n, which is then translated into (n - 1) (i.e., the last entry of the page) or 0 (i.e., the first entry of the page) and finally the search begins. This continues to work fine until the index reaches 0 or (n - 1), at which point it will be decremented to -1 or incremented to n, but not checked against the starting point right away. Instead, it's wrapped around to the bottom or top again, after which the starting point check occurs... and naturally fails. My original implementation added another check for -1 before wrapping the running index variable around, but Masahiro Yamada pointed out that the actual issue is that the comparison point (starting point) exceeds bounds (i.e., the [0,n-1] interval) in the first place and that, instead, the starting point should be fixed. This has the welcome side-effect of also fixing the case where the starting point was n while searching down, which also lead to an infinite loop. OTOH, this code is now essentially all his work. Amazingly, nobody seems to have been hit by this for 11 years - or at the very least nobody bothered to debug and fix this. Signed-off-by: Mihai Moldovan Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index b11b75f83f7e..7b371bd7fb36 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -508,8 +508,8 @@ static int get_mext_match(const char *match_str, match_f flag) else if (flag == FIND_NEXT_MATCH_UP) --match_start; + match_start = (match_start + items_num) % items_num; index = match_start; - index = (index + items_num) % items_num; while (true) { char *str = k_menu_items[index].str; if (strcasestr(str, match_str) != NULL) -- cgit v1.2.3 From 989e5d4b576f010de4bacb9fdad0cb879c75e9d7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 17 Apr 2021 23:50:36 +0900 Subject: kconfig: remove unused PACKAGE definition Commit 3b9fa0931dd8 ("[PATCH] Kconfig i18n support") added this code, and then commit ("kconfig: drop localization support") removed the i18n support entirely. Remove the left-over. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 45599c52478d..fa8c010aa683 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -20,10 +20,6 @@ extern "C" { #define SRCTREE "srctree" -#ifndef PACKAGE -#define PACKAGE "linux" -#endif - #ifndef CONFIG_ #define CONFIG_ "CONFIG_" #endif -- cgit v1.2.3 From ed63ef7796979835d7cfb4dc2d108b6eeeb2b7c2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 17 Apr 2021 23:50:37 +0900 Subject: kconfig: gconf: remove unused code Remove the unused inclusion, and commented out lines. Signed-off-by: Masahiro Yamada --- scripts/kconfig/gconf.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c index 5527482c3077..7698eea6fb6e 100644 --- a/scripts/kconfig/gconf.c +++ b/scripts/kconfig/gconf.c @@ -3,10 +3,6 @@ * Copyright (C) 2002-2003 Romain Lievin */ -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include "lkc.h" #include "images.h" @@ -1452,9 +1448,6 @@ int main(int ac, char *av[]) gtk_init(&ac, &av); glade_init(); - //add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); - //add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps"); - /* Determine GUI path */ env = getenv(SRCTREE); if (env) -- cgit v1.2.3 From 5fb35ec10bb0665080c8de8a360fb4dba9a0f73f Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sat, 17 Apr 2021 22:51:22 -0700 Subject: kconfig: highlight gconfig 'comment' lines with '***' Mark Kconfig "comment" lines with "*** ***" so that it is clear that these lines are comments and not some kconfig item that cannot be modified. This is helpful in some menus to be able to provide a menu "sub-heading" for groups of similar config items. This also makes the comments be presented in a way that is similar to menuconfig and nconfig. Signed-off-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- scripts/kconfig/gconf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c index 7698eea6fb6e..17adabfd6e6b 100644 --- a/scripts/kconfig/gconf.c +++ b/scripts/kconfig/gconf.c @@ -1044,8 +1044,13 @@ static gchar **fill_row(struct menu *menu) g_free(row[i]); bzero(row, sizeof(row)); + ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; + row[COL_OPTION] = - g_strdup_printf("%s %s", menu_get_prompt(menu), + g_strdup_printf("%s %s %s %s", + ptype == P_COMMENT ? "***" : "", + menu_get_prompt(menu), + ptype == P_COMMENT ? "***" : "", sym && !sym_has_value(sym) ? "(NEW)" : ""); if (opt_mode == OPT_ALL && !menu_is_visible(menu)) @@ -1056,7 +1061,6 @@ static gchar **fill_row(struct menu *menu) else row[COL_COLOR] = g_strdup("Black"); - ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; switch (ptype) { case P_MENU: row[COL_PIXBUF] = (gchar *) xpm_menu; -- cgit v1.2.3 From 92f8a9217a1215cc3d71e82d5d1cde0793cf0501 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sat, 17 Apr 2021 22:51:23 -0700 Subject: kconfig: highlight xconfig 'comment' lines with '***' Mark Kconfig "comment" lines with "*** ***" so that it is clear that these lines are comments and not some kconfig item that cannot be modified. This is helpful in some menus to be able to provide a menu "sub-heading" for groups of similar config items. This also makes the comments be presented in a way that is similar to menuconfig and nconfig. Signed-off-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- scripts/kconfig/qconf.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index d000869b787c..78087b2d9ac6 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -122,6 +122,7 @@ void ConfigItem::updateMenu(void) goto set_prompt; case P_COMMENT: setIcon(promptColIdx, QIcon()); + prompt = "*** " + prompt + " ***"; goto set_prompt; default: ; -- cgit v1.2.3 From 8ac27f2c6eac1f140531411e404fb3ba23339ba5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 24 Apr 2021 22:55:24 +0900 Subject: kconfig: refactor .gitignore Add '/' prefix to clarify that the generated files exist right under scripts/kconfig/, but not in any sub-directory. Replace '*conf-cfg' with '[gmnq]conf-cfg' to make it explicit, and still short enough. Use '[gmnq]conf' to combine gconf, mconf, nconf, and qconf. Signed-off-by: Masahiro Yamada --- scripts/kconfig/.gitignore | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore index c3d537cd0275..500e7424b3ef 100644 --- a/scripts/kconfig/.gitignore +++ b/scripts/kconfig/.gitignore @@ -1,12 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +/conf +/[gmnq]conf +/[gmnq]conf-cfg /qconf-moc.cc -*conf-cfg - -# -# configuration programs -# -conf -mconf -nconf -qconf -gconf -- cgit v1.2.3