diff options
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r-- | scripts/kconfig/confdata.c | 111 |
1 files changed, 71 insertions, 40 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f81f263b64f2..c39327e60ea4 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -412,7 +412,7 @@ static void conf_write_string(bool headerfile, const char *name, | |||
412 | while (1) { | 412 | while (1) { |
413 | l = strcspn(str, "\"\\"); | 413 | l = strcspn(str, "\"\\"); |
414 | if (l) { | 414 | if (l) { |
415 | fwrite(str, l, 1, out); | 415 | xfwrite(str, l, 1, out); |
416 | str += l; | 416 | str += l; |
417 | } | 417 | } |
418 | if (!*str) | 418 | if (!*str) |
@@ -497,7 +497,7 @@ int conf_write_defconfig(const char *filename) | |||
497 | /* | 497 | /* |
498 | * If symbol is a choice value and equals to the | 498 | * If symbol is a choice value and equals to the |
499 | * default for a choice - skip. | 499 | * default for a choice - skip. |
500 | * But only if value equal to "y". | 500 | * But only if value is bool and equal to "y" . |
501 | */ | 501 | */ |
502 | if (sym_is_choice_value(sym)) { | 502 | if (sym_is_choice_value(sym)) { |
503 | struct symbol *cs; | 503 | struct symbol *cs; |
@@ -506,9 +506,8 @@ int conf_write_defconfig(const char *filename) | |||
506 | cs = prop_get_symbol(sym_get_choice_prop(sym)); | 506 | cs = prop_get_symbol(sym_get_choice_prop(sym)); |
507 | ds = sym_choice_default(cs); | 507 | ds = sym_choice_default(cs); |
508 | if (sym == ds) { | 508 | if (sym == ds) { |
509 | if ((sym->type == S_BOOLEAN || | 509 | if ((sym->type == S_BOOLEAN) && |
510 | sym->type == S_TRISTATE) && | 510 | sym_get_tristate_value(sym) == yes) |
511 | sym_get_tristate_value(sym) == yes) | ||
512 | goto next_menu; | 511 | goto next_menu; |
513 | } | 512 | } |
514 | } | 513 | } |
@@ -919,13 +918,73 @@ void conf_set_changed_callback(void (*fn)(void)) | |||
919 | conf_changed_callback = fn; | 918 | conf_changed_callback = fn; |
920 | } | 919 | } |
921 | 920 | ||
921 | static void randomize_choice_values(struct symbol *csym) | ||
922 | { | ||
923 | struct property *prop; | ||
924 | struct symbol *sym; | ||
925 | struct expr *e; | ||
926 | int cnt, def; | ||
922 | 927 | ||
923 | void conf_set_all_new_symbols(enum conf_def_mode mode) | 928 | /* |
929 | * If choice is mod then we may have more items slected | ||
930 | * and if no then no-one. | ||
931 | * In both cases stop. | ||
932 | */ | ||
933 | if (csym->curr.tri != yes) | ||
934 | return; | ||
935 | |||
936 | prop = sym_get_choice_prop(csym); | ||
937 | |||
938 | /* count entries in choice block */ | ||
939 | cnt = 0; | ||
940 | expr_list_for_each_sym(prop->expr, e, sym) | ||
941 | cnt++; | ||
942 | |||
943 | /* | ||
944 | * find a random value and set it to yes, | ||
945 | * set the rest to no so we have only one set | ||
946 | */ | ||
947 | def = (rand() % cnt); | ||
948 | |||
949 | cnt = 0; | ||
950 | expr_list_for_each_sym(prop->expr, e, sym) { | ||
951 | if (def == cnt++) { | ||
952 | sym->def[S_DEF_USER].tri = yes; | ||
953 | csym->def[S_DEF_USER].val = sym; | ||
954 | } | ||
955 | else { | ||
956 | sym->def[S_DEF_USER].tri = no; | ||
957 | } | ||
958 | } | ||
959 | csym->flags |= SYMBOL_DEF_USER; | ||
960 | /* clear VALID to get value calculated */ | ||
961 | csym->flags &= ~(SYMBOL_VALID); | ||
962 | } | ||
963 | |||
964 | static void set_all_choice_values(struct symbol *csym) | ||
924 | { | 965 | { |
925 | struct symbol *sym, *csym; | ||
926 | struct property *prop; | 966 | struct property *prop; |
967 | struct symbol *sym; | ||
927 | struct expr *e; | 968 | struct expr *e; |
928 | int i, cnt, def; | 969 | |
970 | prop = sym_get_choice_prop(csym); | ||
971 | |||
972 | /* | ||
973 | * Set all non-assinged choice values to no | ||
974 | */ | ||
975 | expr_list_for_each_sym(prop->expr, e, sym) { | ||
976 | if (!sym_has_value(sym)) | ||
977 | sym->def[S_DEF_USER].tri = no; | ||
978 | } | ||
979 | csym->flags |= SYMBOL_DEF_USER; | ||
980 | /* clear VALID to get value calculated */ | ||
981 | csym->flags &= ~(SYMBOL_VALID); | ||
982 | } | ||
983 | |||
984 | void conf_set_all_new_symbols(enum conf_def_mode mode) | ||
985 | { | ||
986 | struct symbol *sym, *csym; | ||
987 | int i, cnt; | ||
929 | 988 | ||
930 | for_all_symbols(i, sym) { | 989 | for_all_symbols(i, sym) { |
931 | if (sym_has_value(sym)) | 990 | if (sym_has_value(sym)) |
@@ -961,8 +1020,6 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) | |||
961 | 1020 | ||
962 | sym_clear_all_valid(); | 1021 | sym_clear_all_valid(); |
963 | 1022 | ||
964 | if (mode != def_random) | ||
965 | return; | ||
966 | /* | 1023 | /* |
967 | * We have different type of choice blocks. | 1024 | * We have different type of choice blocks. |
968 | * If curr.tri equal to mod then we can select several | 1025 | * If curr.tri equal to mod then we can select several |
@@ -977,35 +1034,9 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) | |||
977 | continue; | 1034 | continue; |
978 | 1035 | ||
979 | sym_calc_value(csym); | 1036 | sym_calc_value(csym); |
980 | 1037 | if (mode == def_random) | |
981 | if (csym->curr.tri != yes) | 1038 | randomize_choice_values(csym); |
982 | continue; | 1039 | else |
983 | 1040 | set_all_choice_values(csym); | |
984 | prop = sym_get_choice_prop(csym); | ||
985 | |||
986 | /* count entries in choice block */ | ||
987 | cnt = 0; | ||
988 | expr_list_for_each_sym(prop->expr, e, sym) | ||
989 | cnt++; | ||
990 | |||
991 | /* | ||
992 | * find a random value and set it to yes, | ||
993 | * set the rest to no so we have only one set | ||
994 | */ | ||
995 | def = (rand() % cnt); | ||
996 | |||
997 | cnt = 0; | ||
998 | expr_list_for_each_sym(prop->expr, e, sym) { | ||
999 | if (def == cnt++) { | ||
1000 | sym->def[S_DEF_USER].tri = yes; | ||
1001 | csym->def[S_DEF_USER].val = sym; | ||
1002 | } | ||
1003 | else { | ||
1004 | sym->def[S_DEF_USER].tri = no; | ||
1005 | } | ||
1006 | } | ||
1007 | csym->flags |= SYMBOL_DEF_USER; | ||
1008 | /* clear VALID to get value calculated */ | ||
1009 | csym->flags &= ~(SYMBOL_VALID); | ||
1010 | } | 1041 | } |
1011 | } | 1042 | } |