staticvoid strip(char *str)
{ char *p = str; int l;
while ((isspace(*p)))
p++;
l = strlen(p); if (p != str)
memmove(str, p, l + 1); if (!l) return;
p = str + l - 1; while ((isspace(*p)))
*p-- = 0;
}
/* Helper function to facilitate fgets() by Jean Sacren. */ staticvoid xfgets(char *str, int size, FILE *in)
{ if (!fgets(str, size, in))
fprintf(stderr, "\nError in reading or end of file.\n");
/* * Use microseconds derived seed, compensate for systems where it may * be zero.
*/
gettimeofday(&now, NULL);
seed = (now.tv_sec + 1) * (now.tv_usec + 1);
}
/** * randomize_choice_values - randomize choice block * * @choice: menu entry for the choice
*/ staticvoid randomize_choice_values(struct menu *choice)
{ struct menu *menu; int x; int cnt = 0;
/* * First, count the number of symbols to randomize. If sym_has_value() * is true, it was specified by KCONFIG_ALLCONFIG. It needs to be * respected.
*/
menu_for_each_sub_entry(menu, choice) { struct symbol *sym = menu->sym;
if (sym && !sym_has_value(sym))
cnt++;
}
while (cnt > 0) {
x = rand() % cnt;
menu_for_each_sub_entry(menu, choice) { struct symbol *sym = menu->sym;
if (sym && !sym_has_value(sym))
x--;
if (x < 0) {
sym->def[S_DEF_USER].tri = yes;
sym->flags |= SYMBOL_DEF_USER; /* * Move the selected item to the _tail_ because * this needs to have a lower priority than the * user input from KCONFIG_ALLCONFIG.
*/
list_move_tail(&sym->choice_link,
&choice->choice_members);
staticvoid conf_set_all_new_symbols(enum conf_def_mode mode)
{ struct menu *menu; int 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 */
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);
switch (prop->type) { case P_MENU: /* * Except in oldaskconfig mode, we show only menus that * contain new symbols.
*/ if (input_mode != oldaskconfig && rootEntry != menu) {
check_conf(menu); return;
} /* fall through */ case P_COMMENT:
prompt = menu_get_prompt(menu); if (prompt)
printf("%*c\n%*c %s\n%*c\n",
indent, '*',
indent, '*', prompt,
indent, '*'); default:
;
}
}
if (!sym) goto conf_childs;
if (sym_is_choice(sym)) {
conf_choice(menu); return;
}
switch (sym->type) { case S_INT: case S_HEX: case S_STRING:
conf_string(menu); break; default:
conf_sym(menu); break;
}
conf_childs: if (sym)
indent += 2; for (child = menu->list; child; child = child->next)
conf(child); if (sym)
indent -= 2;
}
staticvoid 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) && sym_is_changeable(sym)) { switch (input_mode) { case listnewconfig: if (sym->name)
print_symbol_for_listconfig(sym); break; case helpnewconfig:
printf("-----\n");
print_help(menu);
printf("-----\n"); break; default: if (!conf_cnt++)
printf("*\n* Restart config...\n*\n");
rootEntry = menu_get_menu_or_parent_menu(menu);
conf(rootEntry); break;
}
}
for (child = menu->list; child; child = child->next)
check_conf(child);
}
staticvoid conf_usage(constchar *progname)
{
printf("Usage: %s [options] kconfig_file\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");
printf(" --oldconfig Update a configuration using a provided .config as base\n");
printf(" --syncconfig Similar to oldconfig but generates configuration in\n" " include/{generated/,config/}\n");
printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n");
printf(" --defconfig New config with default defined in \n");
printf(" --savedefconfig Save the minimal current configuration to \n");
printf(" --allnoconfig New config where all options are answered with no\n");
printf(" --allyesconfig New config where all options are answered with yes\n");
printf(" --allmodconfig New config where all options are answered with mod\n");
printf(" --alldefconfig New config with all symbols set to default\n");
printf(" --randconfig New config with random answer to all options\n");
printf(" --yes2modconfig Change answers from yes to mod if possible\n");
printf(" --mod2yesconfig Change answers from mod to yes if possible\n");
printf(" --mod2noconfig Change answers from mod to no if possible\n");
printf(" (If none of the above is given, --oldaskconfig is the default)\n");
printf("\n");
printf("Arguments:\n");
printf(" kconfig_file Top-level Kconfig file.\n");
}
int main(int ac, char **av)
{ constchar *progname = av[0]; int opt; constchar *name, *defconfig_file = NULL /* gcc uninit */; int no_conf_write = 0;
tty_stdio = isatty(0) && isatty(1);
while ((opt = getopt_long(ac, av, "hs", long_opts, NULL)) != -1) { switch (opt) { 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) {
fprintf(stderr, "%s: Kconfig file missing\n", av[0]);
conf_usage(progname); exit(1);
}
conf_parse(av[optind]); //zconfdump(stdout);
switch (input_mode) { case defconfig: if (conf_read(defconfig_file)) {
fprintf(stderr, "***\n" "*** Can't find default configuration \"%s\"!\n" "***\n",
defconfig_file); exit(1);
} break; case savedefconfig: case syncconfig: case oldaskconfig: case oldconfig: case listnewconfig: case helpnewconfig: case olddefconfig: case yes2modconfig: case mod2yesconfig: case mod2noconfig:
conf_read(NULL); break; case allnoconfig: case allyesconfig: case allmodconfig: case alldefconfig: case randconfig:
name = getenv("KCONFIG_ALLCONFIG"); if (!name) break; if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { if (conf_read_simple(name, S_DEF_USER)) {
fprintf(stderr, "*** Can't read seed configuration \"%s\"!\n",
name); exit(1);
} break;
} switch (input_mode) { case allnoconfig: name = "allno.config"; break; case allyesconfig: name = "allyes.config"; break; case allmodconfig: name = "allmod.config"; break; case alldefconfig: name = "alldef.config"; break; case randconfig: name = "allrandom.config"; break; default: break;
} if (conf_read_simple(name, S_DEF_USER) &&
conf_read_simple("all.config", S_DEF_USER)) {
fprintf(stderr, "*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n",
name); exit(1);
} break; default: break;
}
if (conf_errors()) exit(1);
if (sync_kconfig) {
name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { if (conf_get_changed()) {
fprintf(stderr, "\n*** The configuration requires explicit update.\n\n"); return 1;
}
no_conf_write = 1;
}
}
switch (input_mode) { case allnoconfig:
conf_set_all_new_symbols(def_no); break; case allyesconfig:
conf_set_all_new_symbols(def_yes); break; case allmodconfig:
conf_set_all_new_symbols(def_mod); break; case alldefconfig:
conf_set_all_new_symbols(def_default); break; case randconfig:
conf_set_all_new_symbols(def_random); break; case defconfig:
conf_set_all_new_symbols(def_default); break; case savedefconfig: break; case yes2modconfig:
conf_rewrite_tristates(yes, mod); break; case mod2yesconfig:
conf_rewrite_tristates(mod, yes); break; case mod2noconfig:
conf_rewrite_tristates(mod, no); break; case oldaskconfig:
rootEntry = &rootmenu;
conf(&rootmenu);
input_mode = oldconfig; /* fall through */ case oldconfig: case listnewconfig: case helpnewconfig: case syncconfig: /* Update until a loop caused no more changes */ do {
conf_cnt = 0;
check_conf(&rootmenu);
} while (conf_cnt); break; case olddefconfig: default: break;
}
if (sym_dep_errors()) exit(1);
if (input_mode == savedefconfig) { if (conf_write_defconfig(defconfig_file)) {
fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
defconfig_file); return 1;
}
} elseif (input_mode != listnewconfig && input_mode != helpnewconfig) { if (!no_conf_write && conf_write(NULL)) {
fprintf(stderr, "\n*** Error during writing of the configuration.\n\n"); exit(1);
}
/* * Create auto.conf if it does not exist. * This prevents GNU Make 4.1 or older from emitting * "include/config/auto.conf: No such file or directory" * in the top-level Makefile * * syncconfig always creates or updates auto.conf because it is * used during the build.
*/ if (conf_write_autoconf(sync_kconfig) && sync_kconfig) {
fprintf(stderr, "\n*** Error during sync of the configuration.\n\n"); return 1;
}
} return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.