第二次了

Scripts解析
sbj 2 months ago
parent 7a3266e2be
commit e55d4304a0

@ -182,105 +182,127 @@ static int conf_string(struct menu *menu)
}
// 配置符号的值yes、no、mod的函数
static int conf_sym(struct menu *menu)
{
struct symbol *sym = menu->sym;
tristate oldval, newval;
struct symbol *sym = menu->sym; // 获取菜单项的符号
tristate oldval, newval; // 旧值和新值变量tristate表示三种状态yes、no、mod
while (1) {
// 打印菜单提示信息,包括符号名称(如果存在)
printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); // 打印缩进和提示文本
if (sym->name) // 如果符号有名称,打印符号名称
printf("(%s) ", sym->name);
putchar('['); // 打印开头的方括号
oldval = sym_get_tristate_value(sym); // 获取符号的当前值
// 根据当前的状态值oldval打印相应的字符
switch (oldval) {
case no:
putchar('N'); // 输出 'N' 表示当前为 no
break;
case mod:
putchar('M'); // 输出 'M' 表示当前为 mod
break;
case yes:
putchar('Y'); // 输出 'Y' 表示当前为 yes
break;
}
// 根据当前的状态值显示可选的值no、mod、yes如果符号的值在范围内
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("] "); // 打印结束的方括号
// 询问用户输入新值,如果没有输入有效值,返回 0
if (!conf_askvalue(sym, sym_get_string_value(sym)))
return 0;
strip(line); // 去除用户输入的字符串两端空格
// 根据用户输入的值进行处理
switch (line[0]) {
case 'n':
case 'N': // 如果输入是 'n' 或 'N',设置新值为 no
newval = no;
if (!line[1] || !strcmp(&line[1], "o"))
break;
continue; // 如果有其他字符,继续下一次循环
case 'm':
case 'M': // 如果输入是 'm' 或 'M',设置新值为 mod
newval = mod;
if (!line[1])
break;
continue; // 如果有其他字符,继续下一次循环
case 'y':
case 'Y': // 如果输入是 'y' 或 'Y',设置新值为 yes
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; // 如果设置失败,返回 0
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);
}
print_help(menu); // 打印帮助信息
}
}
// 配置选择菜单项的函数
static int conf_choice(struct menu *menu)
{
struct symbol *sym, *def_sym;
struct menu *child;
bool is_new;
sym = menu->sym;
is_new = !sym_has_value(sym);
if (sym_is_changable(sym)) {
conf_sym(menu);
sym_calc_value(sym);
switch (sym_get_tristate_value(sym)) {
case no:
return 1;
case mod:
return 0;
case yes:
break;
}
} else {
switch (sym_get_tristate_value(sym)) {
case no:
return 1;
case mod:
printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
return 0;
case yes:
break;
}
}
struct symbol *sym, *def_sym;
struct menu *child;
bool is_new;
sym = menu->sym; // 获取当前菜单项的符号
is_new = !sym_has_value(sym); // 检查符号是否有值(是否为新符号)
// 如果符号可修改,进行符号的配置
if (sym_is_changable(sym)) {
conf_sym(menu); // 调用 conf_sym 函数配置符号
sym_calc_value(sym); // 计算符号的值
// 根据符号的值执行不同的操作
switch (sym_get_tristate_value(sym)) {
case no: // 如果值是 no返回 1
return 1;
case mod: // 如果值是 mod返回 0
return 0;
case yes: // 如果值是 yes继续执行
break;
}
} else { // 如果符号不可修改
switch (sym_get_tristate_value(sym)) {
case no: // 如果值是 no返回 1
return 1;
case mod: // 如果值是 mod打印菜单提示并返回 0
printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
return 0;
case yes: // 如果值是 yes继续执行
break;
}
}
}
while (1) {
int cnt, def;

Loading…
Cancel
Save