int conf_string(struct menu *menu) { struct symbol *sym = menu->sym; const char *def; while (1) { printf("%*s%s ", indent - 1, "", menu->prompt->text); printf("(%s) ", sym->name); def = sym_get_string_value(sym); if (sym_get_string_value(sym)) printf("[%s] ", def); if (!conf_askvalue(sym, def)) return 0; switch (line[0]) { case '\n': break; case '?': /* print help */ if (line[1] == '\n') { printf("\n%s\n", get_help(menu)); def = NULL; break; } default: line[strlen(line)-1] = 0; def = line; } if (def && sym_set_string_value(sym, def)) return 0; } }
static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str) { struct gstr *gs = (struct gstr*)data; const char *sym_str = NULL; if (sym) sym_str = sym_get_string_value(sym); if (gs->max_width) { unsigned extra_length = strlen(str); const char *last_cr = strrchr(gs->s, '\n'); unsigned last_line_length; if (sym_str) extra_length += 4 + strlen(sym_str); if (!last_cr) last_cr = gs->s; last_line_length = strlen(gs->s) - (last_cr - gs->s); if ((last_line_length + extra_length) > gs->max_width) str_append(gs, "\\\n"); } str_append(gs, str); if (sym) str_printf(gs, " [=%s]", sym_str); }
static char *conf_expand_value(const char *in) { struct symbol *sym; const char *src; static char res_value[SYMBOL_MAXLENGTH]; char *dst, name[SYMBOL_MAXLENGTH]; res_value[0] = 0; dst = name; while ((src = strchr(in, '$'))) { strncat(res_value, in, src - in); src++; dst = name; while (isalnum((int)*src) || *src == '_') *dst++ = *src++; *dst = 0; sym = sym_lookup(name, 0); sym_calc_value(sym); strcat(res_value, sym_get_string_value(sym)); in = src; } strcat(res_value, in); return res_value; }
static void get_symbol_str(struct gstr *r, struct symbol *sym) { bool hit; struct property *prop; if (sym && sym->name) str_printf(r, "Symbol: %s [=%s]\n", sym->name, sym_get_string_value(sym)); for_all_prompts(sym, prop) get_prompt_str(r, prop); hit = false; for_all_properties(sym, prop, P_SELECT) { if (!hit) { str_append(r, " Selects: "); hit = true; } else str_printf(r, " && "); expr_gstr_print(prop->expr, r); } if (hit) str_append(r, "\n"); if (sym->rev_dep.expr) { str_append(r, _(" Selected by: ")); expr_gstr_print(sym->rev_dep.expr, r); str_append(r, "\n"); } str_append(r, "\n\n"); }
static void get_prompt_str(struct gstr *r, struct property *prop) { int i, j; struct menu *submenu[8], *menu; str_printf(r, _("Prompt: %s\n"), _(prop->text)); str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name, prop->menu->lineno); if (!expr_is_yes(prop->visible.expr)) { str_append(r, _(" Depends on: ")); expr_gstr_print(prop->visible.expr, r); str_append(r, "\n"); } menu = prop->menu->parent; for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) submenu[i++] = menu; if (i > 0) { str_printf(r, _(" Location:\n")); for (j = 4; --i >= 0; j += 2) { menu = submenu[i]; str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu))); if (menu->sym) { str_printf(r, " (%s [=%s])", menu->sym->name ? menu->sym->name : _("<choice>"), sym_get_string_value(menu->sym)); } str_append(r, "\n"); } } }
int main(int ac, char **av) { struct symbol *sym; char *mode; int res; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELVERSION", 0); sym_calc_value(sym); sprintf(menu_backtitle, _("Linux Kernel v%s Configuration"), sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); reset_dialog(); init_dialog(menu_backtitle); do { conf(&rootmenu); dialog_clear(); res = dialog_yesno(NULL, _("Do you wish to save your " "new kernel configuration?\n" "<ESC><ESC> to continue."), 6, 60); } while (res == KEY_ESC); end_dialog(); if (res == 0) { if (conf_write(NULL)) { fprintf(stderr, _("\n\n" "Error during writing of the kernel configuration.\n" "Your kernel configuration changes were NOT saved." "\n\n")); return 1; } printf(_("\n\n" "*** End of Linux kernel configuration.\n" "*** Execute 'make' to build the kernel or try 'make help'." "\n\n")); } else { fprintf(stderr, _("\n\n" "Your kernel configuration changes were NOT saved." "\n\n")); } return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELVERSION", 0); sym_calc_value(sym); sprintf(menu_backtitle, _("swupdate %s Configuration"), sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); conf(&rootmenu); do { cprint_init(); cprint("--yesno"); cprint(_("Do you wish to save your new configuration?")); cprint("5"); cprint("60"); stat = exec_conf(); } while (stat < 0); if (stat == 0) { if (conf_write(NULL)) { fprintf(stderr, _("\n\n" "Error during writing of the configuration.\n" "Your configuration changes were NOT saved." "\n\n")); return 1; } printf(_("\n\n" "*** End of configuration.\n" "*** Execute 'make' to build the project or try 'make help'." "\n\n")); } else { fprintf(stderr, _("\n\n" "Your configuration changes were NOT saved." "\n\n")); } return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELRELEASE", 0); sym_calc_value(sym); sprintf(menu_backtitle, "Linux Kernel v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); conf(&rootmenu); do { cprint_init(); cprint("--yesno"); cprint("Do you wish to save your new kernel configuration?"); cprint("5"); cprint("60"); stat = exec_conf(); } while (stat < 0); if (stat == 0) { if (conf_write(NULL)) { fprintf(stderr, "\n\n" "Error during writing of the kernel configuration.\n" "Your kernel configuration changes were NOT saved." "\n\n"); return 1; } printf("\n\n" "*** End of Linux kernel configuration.\n" "*** Execute 'make' to build the kernel or try 'make help'." "\n\n"); } else { fprintf(stderr, "\n\n" "Your kernel configuration changes were NOT saved." "\n\n"); } return 0; }
tristate expr_calc_value(struct expr * e) { tristate val1, val2; const char *str1, *str2; if (!e) return yes; switch (e->type) { case E_SYMBOL: sym_calc_value(e->left.sym); return S_TRI(e->left.sym->curr); case E_AND: val1 = expr_calc_value(e->left.expr); val2 = expr_calc_value(e->right.expr); return E_AND(val1, val2); case E_OR: val1 = expr_calc_value(e->left.expr); val2 = expr_calc_value(e->right.expr); return E_OR(val1, val2); case E_NOT: val1 = expr_calc_value(e->left.expr); return E_NOT(val1); case E_EQUAL: sym_calc_value(e->left.sym); sym_calc_value(e->right.sym); str1 = sym_get_string_value(e->left.sym); str2 = sym_get_string_value(e->right.sym); return !strcmp(str1, str2) ? yes : no; case E_UNEQUAL: sym_calc_value(e->left.sym); sym_calc_value(e->right.sym); str1 = sym_get_string_value(e->left.sym); str2 = sym_get_string_value(e->right.sym); return !strcmp(str1, str2) ? no : yes; default: printf("expr_calc_value: %d?\n", e->type); return no; } }
static void check_conf(struct menu *menu) { struct symbol *sym; struct menu *child; if (!menu_is_visible(menu)) return; sym = menu->sym; if (sym && !sym_has_value(sym)) { if (sym_is_changable(sym) || (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { if (input_mode == listnewconfig) { if (sym->name) { const char *str; if (sym->type == S_STRING) { str = sym_get_string_value(sym); str = sym_escape_string_value(str); printf("%s%s=%s\n", CONFIG_, sym->name, str); free((void *)str); } else { str = sym_get_string_value(sym); printf("%s%s=%s\n", CONFIG_, sym->name, str); } } } else { if (!conf_cnt++) printf("*\n* Restart config...\n*\n"); rootEntry = menu_get_parent_menu(menu); conf(rootEntry); } } } for (child = menu->list; child; child = child->next) check_conf(child); }
int main(int ac, char **av) { int stat; char *mode; struct symbol *sym; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("VERSION", 0); sym_calc_value(sym); snprintf(menu_backtitle, 128, "Core v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); init_dialog(); signal(SIGWINCH, winch_handler); conf(&rootmenu); end_dialog(); /* Restart dialog to act more like when lxdialog was still separate */ init_dialog(); do { stat = dialog_yesno(NULL, "Do you wish to save your new Core configuration?", 5, 60); } while (stat < 0); end_dialog(); if (stat == 0) { conf_write(NULL); printf("\n\n" "*** End of Core configuration.\n" "*** Check the top-level Makefile for additional configuration options.\n\n"); } else printf("\n\nYour Core configuration changes were NOT saved.\n\n"); return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("VERSION", 0); sym_calc_value(sym); snprintf(menu_backtitle, 128, "BusyBox v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); init_dialog(); signal(SIGWINCH, winch_handler); conf(&rootmenu); end_dialog(); /* Restart dialog to act more like when lxdialog was still separate */ init_dialog(); do { stat = dialog_yesno(NULL, "Do you wish to save your new diagnostic program configuration?", 6, 60); } while (stat < 0); end_dialog(); if (stat == 0) { conf_write(NULL); printf("\n\n" "*** End of SQ diagnostic program configuration.\n"); printf("*** Execute 'make' to build the diagnostic program or try 'make help'.\n\n"); } else printf("\n\nYour diagnostic program configuration changes were NOT saved.\n\n"); return 0; }
static void set_config_filename(const char *config_filename) { static char menu_backtitle[PATH_MAX+128]; int size; struct symbol *sym; sym = sym_lookup("VERSION", 0); sym_calc_value(sym); size = snprintf(menu_backtitle, sizeof(menu_backtitle), _("%s - uClibc v%s Configuration"), config_filename, sym_get_string_value(sym)); if (size >= sizeof(menu_backtitle)) menu_backtitle[sizeof(menu_backtitle)-1] = '\0'; set_dialog_backtitle(menu_backtitle); size = snprintf(filename, sizeof(filename), "%s", config_filename); if (size >= sizeof(filename)) filename[sizeof(filename)-1] = '\0'; }
static void conf_string(struct menu *menu) { const char *prompt = menu_get_prompt(menu); int stat; while (1) { cprint_init(); cprint("--title"); cprint("%s", prompt ? prompt : "Main Menu"); cprint("--inputbox"); switch (sym_get_type(menu->sym)) { case S_INT: cprint(inputbox_instructions_int); break; case S_HEX: cprint(inputbox_instructions_hex); break; case S_STRING: cprint(inputbox_instructions_string); break; default: /* panic? */; } cprint("10"); cprint("75"); cprint("%s", sym_get_string_value(menu->sym)); stat = exec_conf(); switch (stat) { case 0: if (sym_set_string_value(menu->sym, input_buf)) return; show_textbox(NULL, "You have made an invalid entry.", 5, 43); break; case 1: show_help(menu); break; case 255: return; } } }
static void conf_string(struct menu *menu) { const char *prompt = menu_get_prompt(menu); while (1) { int res; const char *heading; switch (sym_get_type(menu->sym)) { case S_INT: heading = _(inputbox_instructions_int); break; case S_HEX: heading = _(inputbox_instructions_hex); break; case S_STRING: heading = _(inputbox_instructions_string); break; default: heading = _("Internal mconf error!"); } dialog_clear(); res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"), heading, 10, 75, sym_get_string_value(menu->sym)); switch (res) { case 0: if (sym_set_string_value(menu->sym, dialog_input_result)) return; show_textbox(NULL, _("You have made an invalid entry."), 5, 43); break; case 1: show_help(menu); break; case KEY_ESC: return; } } }
static void conf_string(struct menu *menu) { const char *prompt = menu_get_prompt(menu); while (1) { char *heading; switch (sym_get_type(menu->sym)) { case S_INT: heading = (char *) inputbox_instructions_int; break; case S_HEX: heading = (char *) inputbox_instructions_hex; break; case S_STRING: heading = (char *) inputbox_instructions_string; break; default: heading = "Internal mconf error!"; /* panic? */; } switch (dialog_inputbox(prompt ? prompt : "Main Menu", heading, 10, 75, sym_get_string_value(menu->sym))) { case 0: if (sym_set_string_value(menu->sym, dialog_input_result)) return; show_textbox(NULL, "You have made an invalid entry.", 5, 43); break; case 1: show_help(menu); break; case 255: return; } } }
void get_symbol_str(struct gstr *r, struct symbol *sym) { bool hit; struct property *prop; if (sym && sym->name) { str_printf(r, "Symbol: %s [=%s]\n", sym->name, sym_get_string_value(sym)); str_printf(r, "Type : %s\n", sym_type_name(sym->type)); if (sym->type == S_INT || sym->type == S_HEX) { prop = sym_get_range_prop(sym); if (prop) { str_printf(r, "Range : "); expr_gstr_print(prop->expr, r); str_append(r, "\n"); } } } for_all_prompts(sym, prop) get_prompt_str(r, prop); hit = false; for_all_properties(sym, prop, P_SELECT) { if (!hit) { str_append(r, " Selects: "); hit = true; } else str_printf(r, " && "); expr_gstr_print(prop->expr, r); } if (hit) str_append(r, "\n"); if (sym->rev_dep.expr) { str_append(r, _(" Selected by: ")); expr_gstr_print(sym->rev_dep.expr, r); str_append(r, "\n"); } str_append(r, "\n\n"); }
static void build_conf(struct menu *menu) { struct symbol *sym; struct property *prop; struct menu *child; int type, tmp, doint = 2; tristate val; char ch; if (!menu_is_visible(menu)) return; sym = menu->sym; prop = menu->prompt; if (!sym) { if (prop && menu != current_menu) { const char *prompt = menu_get_prompt(menu); switch (prop->type) { case P_MENU: child_count++; cmake(); cprint_tag("m%p", menu); if (single_menu_mode) { cprint_name("%s%*c%s", menu->data ? "-->" : "++>", indent + 1, ' ', prompt); } else { cprint_name(" %*c%s --->", indent + 1, ' ', prompt); } if (single_menu_mode && menu->data) goto conf_childs; return; default: if (prompt) { child_count++; cmake(); cprint_tag(":%p", menu); cprint_name("---%*c%s", indent + 1, ' ', prompt); } } } else doint = 0; goto conf_childs; } cmake(); type = sym_get_type(sym); if (sym_is_choice(sym)) { struct symbol *def_sym = sym_get_choice_value(sym); struct menu *def_menu = NULL; child_count++; for (child = menu->list; child; child = child->next) { if (menu_is_visible(child) && child->sym == def_sym) def_menu = child; } val = sym_get_tristate_value(sym); if (sym_is_changable(sym)) { cprint_tag("t%p", menu); switch (type) { case S_BOOLEAN: cprint_name("[%c]", val == no ? ' ' : '*'); break; case S_TRISTATE: switch (val) { case yes: ch = '*'; break; case mod: ch = 'M'; break; default: ch = ' '; break; } cprint_name("<%c>", ch); break; } } else { cprint_tag("%c%p", def_menu ? 't' : ':', menu); cprint_name(" "); } cprint_name("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); if (val == yes) { if (def_menu) { cprint_name(" (%s)", menu_get_prompt(def_menu)); cprint_name(" --->"); if (def_menu->list) { indent += 2; build_conf(def_menu); indent -= 2; } } return; } } else { if (menu == current_menu) { cprint_tag(":%p", menu); cprint_name("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); goto conf_childs; } child_count++; val = sym_get_tristate_value(sym); if (sym_is_choice_value(sym) && val == yes) { cprint_tag(":%p", menu); cprint_name(" "); } else { switch (type) { case S_BOOLEAN: cprint_tag("t%p", menu); if (sym_is_changable(sym)) cprint_name("[%c]", val == no ? ' ' : '*'); else cprint_name("---"); break; case S_TRISTATE: cprint_tag("t%p", menu); switch (val) { case yes: ch = '*'; break; case mod: ch = 'M'; break; default: ch = ' '; break; } if (sym_is_changable(sym)) cprint_name("<%c>", ch); else cprint_name("---"); break; default: cprint_tag("s%p", menu); tmp = cprint_name("(%s)", sym_get_string_value(sym)); tmp = indent - tmp + 4; if (tmp < 0) tmp = 0; cprint_name("%*c%s%s", tmp, ' ', menu_get_prompt(menu), (sym_has_value(sym) || !sym_is_changable(sym)) ? "" : " (NEW)"); goto conf_childs; } } cprint_name("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), (sym_has_value(sym) || !sym_is_changable(sym)) ? "" : " (NEW)"); if (menu->prompt->type == P_MENU) { cprint_name(" --->"); return; } } conf_childs: indent += doint; for (child = menu->list; child; child = child->next) build_conf(child); indent -= doint; }
/* Write out the Linux configuration files, setting all configuration * variables to yes. */ void write_config(bool (*in_config)(struct symbol *)) { char *config_prefix = !bconf_parser ? "CONFIG_" : ""; struct symbol *sym; int i; FILE *allvars; FILE *conf; FILE *autoconf; FILE *tristate; FILE *header; allvars = fopen(".allvars", "w"); if (!allvars) { perror("fopen"); exit(1); } conf = fopen(".config", "w"); if (!conf) { perror("fopen"); exit(1); } if (mkdir("include/config/", S_IRWXU)) { if (EEXIST != errno) { perror("mkdir"); exit(1); } } autoconf = fopen("include/config/auto.conf", "w"); if (!autoconf) { perror("fopen"); exit(1); } tristate = fopen("include/config/tristate.conf", "w"); if (!tristate) { perror("fopen"); exit(1); } if (mkdir("include/generated/", S_IRWXU)) { if (EEXIST != errno) { perror("mkdir"); exit(1); } } if (!bconf_parser) header = fopen("include/generated/autoconf.h", "w"); else header = fopen("include/linux/autoconf.h", "w"); if (!header) { perror("fopen"); exit(1); } conf_set_all_new_symbols(def_yes); for_all_symbols(i, sym) { if (!sym) continue; if (!sym->name) continue; sym_calc_value(sym); } for_all_symbols(i, sym) { const char *str; if (!sym) continue; if (!sym->name) continue; if (!is_symbol(sym)) continue; if (!(*in_config)(sym)) continue; if (check_forceoff(sym)) continue; switch (sym->type) { case S_OTHER: case S_UNKNOWN: break; case S_STRING: str = sym_get_string_value(sym); str = sym_escape_string_value(str); fprintf(allvars, "%s\n", sym->name); fprintf(conf, "%s%s=%s\n", config_prefix, sym->name, str); fprintf(autoconf, "%s%s=%s\n", config_prefix, sym->name, str); free((void *)str); break; case S_BOOLEAN: case S_TRISTATE: fprintf(allvars, "%s\n", sym->name); fprintf(conf, "%s%s=y\n", config_prefix, sym->name); fprintf(autoconf, "%s%s=y\n", config_prefix, sym->name); fprintf(tristate, "%s%s=Y\n", config_prefix, sym->name); break; default: fprintf(allvars, "%s\n", sym->name); fprintf(conf, "%s%s=%s\n", config_prefix, sym->name, sym->curr.val); fprintf(autoconf, "%s%s=%s\n", config_prefix, sym->name, sym->curr.val); break; } } for_all_symbols(i, sym) { const char *str; if (!sym) continue; if (!sym->name) continue; if (!is_symbol(sym)) continue; if (!(*in_config)(sym)) continue; if (check_forceoff(sym)) continue; switch (sym->type) { case S_BOOLEAN: case S_TRISTATE: { fprintf(header, "#define %s%s 1\n", config_prefix, sym->name); break; } case S_HEX: { const char *prefix = ""; str = sym_get_string_value(sym); if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) prefix = "0x"; fprintf(header, "#define %s%s %s%s\n", config_prefix, sym->name, prefix, str); break; } case S_STRING: str = sym_get_string_value(sym); str = sym_escape_string_value(str); fprintf(header, "#define %s%s %s\n", config_prefix, sym->name, str); free((void *)str); break; case S_INT: str = sym_get_string_value(sym); fprintf(header, "#define %s%s %s\n", config_prefix, sym->name, str); break; default: break; } } if (fclose(allvars)) { perror("fclose"); exit(1); } if (fclose(conf)) { perror("fclose"); exit(1); } if (fclose(autoconf)) { perror("fclose"); exit(1); } if (fclose(tristate)) { perror("fclose"); exit(1); } if (fclose(header)) { perror("fclose"); exit(1); } }
tristate expr_calc_value(struct expr *e) { tristate val1, val2; const char *str1, *str2; enum string_value_kind k1 = k_string, k2 = k_string; union string_value lval = {}, rval = {}; int res; if (!e) return yes; switch (e->type) { case E_SYMBOL: sym_calc_value(e->left.sym); return e->left.sym->curr.tri; case E_AND: val1 = expr_calc_value(e->left.expr); val2 = expr_calc_value(e->right.expr); return EXPR_AND(val1, val2); case E_OR: val1 = expr_calc_value(e->left.expr); val2 = expr_calc_value(e->right.expr); return EXPR_OR(val1, val2); case E_NOT: val1 = expr_calc_value(e->left.expr); return EXPR_NOT(val1); case E_EQUAL: case E_GEQ: case E_GTH: case E_LEQ: case E_LTH: case E_UNEQUAL: break; default: printf("expr_calc_value: %d?\n", e->type); return no; } sym_calc_value(e->left.sym); sym_calc_value(e->right.sym); str1 = sym_get_string_value(e->left.sym); str2 = sym_get_string_value(e->right.sym); if (e->left.sym->type != S_STRING || e->right.sym->type != S_STRING) { k1 = expr_parse_string(str1, e->left.sym->type, &lval); k2 = expr_parse_string(str2, e->right.sym->type, &rval); } if (k1 == k_string || k2 == k_string) res = strcmp(str1, str2); else if (k1 == k_invalid || k2 == k_invalid) { if (e->type != E_EQUAL && e->type != E_UNEQUAL) { printf("Cannot compare \"%s\" and \"%s\"\n", str1, str2); return no; } res = strcmp(str1, str2); } else if (k1 == k_unsigned || k2 == k_unsigned) res = (lval.u > rval.u) - (lval.u < rval.u); else /* if (k1 == k_signed && k2 == k_signed) */ res = (lval.s > rval.s) - (lval.s < rval.s); switch(e->type) { case E_EQUAL: return res ? no : yes; case E_GEQ: return res >= 0 ? yes : no; case E_GTH: return res > 0 ? yes : no; case E_LEQ: return res <= 0 ? yes : no; case E_LTH: return res < 0 ? yes : no; case E_UNEQUAL: return res ? yes : no; default: printf("expr_calc_value: relation %d?\n", e->type); return no; } }
static int conf_sym(struct menu *menu) { struct symbol *sym = menu->sym; tristate oldval, newval; while (1) { printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); if (sym->name) printf("(%s) ", sym->name); putchar('['); oldval = sym_get_tristate_value(sym); switch (oldval) { case no: putchar('N'); break; case mod: putchar('M'); break; case yes: putchar('Y'); break; } if (oldval != no && sym_tristate_within_range(sym, no)) printf("/n"); if (oldval != mod && sym_tristate_within_range(sym, mod)) printf("/m"); if (oldval != yes && sym_tristate_within_range(sym, yes)) printf("/y"); if (menu_has_help(menu)) printf("/?"); printf("] "); if (!conf_askvalue(sym, sym_get_string_value(sym))) return 0; strip(line); switch (line[0]) { case 'n': case 'N': newval = no; if (!line[1] || !strcmp(&line[1], "o")) break; continue; case 'm': case 'M': newval = mod; if (!line[1]) break; continue; case 'y': case 'Y': newval = yes; if (!line[1] || !strcmp(&line[1], "es")) break; continue; case 0: newval = oldval; break; case '?': goto help; default: continue; } if (sym_set_tristate_value(sym, newval)) return 0; help: print_help(menu); } }
/* local functions */ int conf_write_confheader(const char *path){ char fname[strlen(path) + PATH_MAX + 1], b[PATH_MAX + 1], c; char *s, *p; struct symbol *sym; struct stat sb; int i, fd; unsigned int plen = strlen(path); strcpy(fname, path); strcpy(fname + plen, "/"); plen++; for_all_symbols(i, sym){ if(sym->name == 0 || sym->type == S_UNKNOWN || sym->type == S_OTHER) continue; sym_calc_value(sym); // replace '_' by '/' and append ".h" s = sym->name; p = fname + plen; while((c = *s++)){ c = tolower(c); *p++ = (c == '_') ? '/' : c; } strcpy(p, ".h"); // try to open file fd = open(fname, O_RDONLY | O_CREAT, 0644); if(fd == -1){ if(errno != ENOENT) goto err_0; // create directory components p = fname; while ((p = strchr(p, '/'))) { *p = 0; if(stat(fname, &sb) && mkdir(fname, 0755)) goto err_0; *p++ = '/'; } // retry opening header fd = open(fname, O_RDONLY | O_CREAT, 0644); if(fd == -1) goto err_0; } // read last value from file and compare against sym if(fstat(fd, &sb)) goto err_1; if(sb.st_size > PATH_MAX){ fprintf(stderr, "file \"%s\" too large for buffer\n", fname); goto err_1; } if(read(fd, b, sb.st_size) != sb.st_size) goto err_1; b[sb.st_size] = 0; if(strcmp(b, sym_get_string_value(sym)) != 0){ // update config header if last and current value to not match close(fd); fprintf(stdout, "update config header %s\n", fname); fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0644); write(fd, sym_get_string_value(sym), strlen(sym_get_string_value(sym))); } close(fd); } return 0; err_1: close(fd); err_0: return -1; }
static void build_conf(struct menu *menu) { struct symbol *sym; struct property *prop; struct menu *child; int type, tmp, doint = 2; tristate val; char ch; if (!menu_is_visible(menu)) return; sym = menu->sym; prop = menu->prompt; if (!sym) { if (prop && menu != current_menu) { const char *prompt = menu_get_prompt(menu); switch (prop->type) { case P_MENU: child_count++; prompt = _(prompt); if (single_menu_mode) { item_make("%s%*c%s", menu->data ? "-->" : "++>", indent + 1, ' ', prompt); } else item_make(" %*c%s --->", indent + 1, ' ', prompt); item_set_tag('m'); item_set_data(menu); if (single_menu_mode && menu->data) goto conf_childs; return; case P_COMMENT: if (prompt) { child_count++; item_make(" %*c*** %s ***", indent + 1, ' ', _(prompt)); item_set_tag(':'); item_set_data(menu); } break; default: if (prompt) { child_count++; item_make("---%*c%s", indent + 1, ' ', _(prompt)); item_set_tag(':'); item_set_data(menu); } } } else doint = 0; goto conf_childs; } type = sym_get_type(sym); if (sym_is_choice(sym)) { struct symbol *def_sym = sym_get_choice_value(sym); struct menu *def_menu = NULL; child_count++; for (child = menu->list; child; child = child->next) { if (menu_is_visible(child) && child->sym == def_sym) def_menu = child; } val = sym_get_tristate_value(sym); if (sym_is_changable(sym)) { switch (type) { case S_BOOLEAN: item_make("[%c]", val == no ? ' ' : '*'); break; case S_TRISTATE: switch (val) { case yes: ch = '*'; break; case mod: ch = 'M'; break; default: ch = ' '; break; } item_make("<%c>", ch); break; } item_set_tag('t'); item_set_data(menu); } else { item_make(" "); item_set_tag(def_menu ? 't' : ':'); item_set_data(menu); } item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu))); if (val == yes) { if (def_menu) { item_add_str(" (%s)", _(menu_get_prompt(def_menu))); item_add_str(" --->"); if (def_menu->list) { indent += 2; build_conf(def_menu); indent -= 2; } } return; } } else { if (menu == current_menu) { item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu))); item_set_tag(':'); item_set_data(menu); goto conf_childs; } child_count++; val = sym_get_tristate_value(sym); if (sym_is_choice_value(sym) && val == yes) { item_make(" "); item_set_tag(':'); item_set_data(menu); } else { switch (type) { case S_BOOLEAN: if (sym_is_changable(sym)) item_make("[%c]", val == no ? ' ' : '*'); else item_make("-%c-", val == no ? ' ' : '*'); item_set_tag('t'); item_set_data(menu); break; case S_TRISTATE: switch (val) { case yes: ch = '*'; break; case mod: ch = 'M'; break; default: ch = ' '; break; } if (sym_is_changable(sym)) { if (sym->rev_dep.tri == mod) item_make("{%c}", ch); else item_make("<%c>", ch); } else item_make("-%c-", ch); item_set_tag('t'); item_set_data(menu); break; default: tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ item_make("(%s)", sym_get_string_value(sym)); tmp = indent - tmp + 4; if (tmp < 0) tmp = 0; item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)), (sym_has_value(sym) || !sym_is_changable(sym)) ? "" : _(" (NEW)")); item_set_tag('s'); item_set_data(menu); goto conf_childs; } } item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)), (sym_has_value(sym) || !sym_is_changable(sym)) ? "" : _(" (NEW)")); if (menu->prompt->type == P_MENU) { item_add_str(" --->"); return; } } conf_childs: indent += doint; for (child = menu->list; child; child = child->next) build_conf(child); indent -= doint; }
void report_changes(void) { struct symbol *sym; struct menu *menu; int type, l; const char *str; fprintf(stdout, "\n#\n" "# Changes:\n" "#\n"); menu = rootmenu.list; while (menu) { sym = menu->sym; if (!sym) { if (!menu_is_visible(menu)) goto next; } else if (!(sym->flags & SYMBOL_CHOICE)) { sym_calc_value(sym); if ((sym->flags & (SYMBOL_WRITE | SYMBOL_CHANGED_REAL | SYMBOL_DEF_USER)) != (SYMBOL_WRITE | SYMBOL_CHANGED_REAL | SYMBOL_DEF_USER)) goto next; if (sym->visible == no) goto next; type = sym->type; if (type == S_TRISTATE) { sym_calc_value(modules_sym); if (modules_sym->curr.tri == no) type = S_BOOLEAN; } switch (type) { case S_BOOLEAN: case S_TRISTATE: switch (sym_get_tristate_value(sym)) { case no: fprintf(stdout, "# CONFIG_%s is not set\n", sym->name); break; case mod: fprintf(stdout, "CONFIG_%s=m\n", sym->name); break; case yes: fprintf(stdout, "CONFIG_%s=y\n", sym->name); break; } break; case S_STRING: str = sym_get_string_value(sym); fprintf(stdout, "CONFIG_%s=\"", sym->name); while (1) { l = strcspn(str, "\"\\"); if (l) { fwrite(str, l, 1, stdout); str += l; } if (!*str) break; fprintf(stdout, "\\%c", *str++); } fputs("\"\n", stdout); break; case S_HEX: str = sym_get_string_value(sym); if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { fprintf(stdout, "CONFIG_%s=%s\n", sym->name, str); break; } case S_INT: str = sym_get_string_value(sym); fprintf(stdout, "CONFIG_%s=%s\n", sym->name, str); break; } } next: if (menu->list) { menu = menu->list; continue; } if (menu->next) menu = menu->next; else while ((menu = menu->parent)) { if (menu->next) { menu = menu->next; break; } } } }
static void get_prompt_str(struct gstr *r, struct property *prop, struct jk_head *head) { int i, j; struct menu *submenu[8], *menu, *location = NULL; struct jump_key *jump; str_printf(r, _("Prompt: %s\n"), _(prop->text)); str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name, prop->menu->lineno); if (!expr_is_yes(prop->visible.expr)) { str_append(r, _(" Depends on: ")); expr_gstr_print(prop->visible.expr, r); str_append(r, "\n"); } menu = prop->menu->parent; for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); submenu[i++] = menu; if (location == NULL && accessible) location = menu; } if (head && location) { jump = malloc(sizeof(struct jump_key)); if (menu_is_visible(prop->menu)) { /* * There is not enough room to put the hint at the * beginning of the "Prompt" line. Put the hint on the * last "Location" line even when it would belong on * the former. */ jump->target = prop->menu; } else jump->target = location; if (CIRCLEQ_EMPTY(head)) jump->index = 0; else jump->index = CIRCLEQ_LAST(head)->index + 1; CIRCLEQ_INSERT_TAIL(head, jump, entries); } if (i > 0) { str_printf(r, _(" Location:\n")); for (j = 4; --i >= 0; j += 2) { menu = submenu[i]; if (head && location && menu == location) jump->offset = r->len - 1; str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu))); if (menu->sym) { str_printf(r, " (%s [=%s])", menu->sym->name ? menu->sym->name : _("<choice>"), sym_get_string_value(menu->sym)); } str_append(r, "\n"); } } }