第二次了

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

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

Loading…
Cancel
Save