doset(#optionsfull command) menu entries for compound options */
| 9015 | |
| 9016 | /* doset(#optionsfull command) menu entries for compound options */ |
| 9017 | staticfn void |
| 9018 | doset_add_menu( |
| 9019 | winid win, /* window to add to */ |
| 9020 | const char *option, /* option name */ |
| 9021 | const char *fmtstr, /* fmtstr_doset */ |
| 9022 | int idx, /* index in allopt[] */ |
| 9023 | int indexoffset) /* value to add to index in allopt[], |
| 9024 | * or zero if option cannot be changed */ |
| 9025 | { |
| 9026 | const char *value = "unknown"; /* current value */ |
| 9027 | const char *indent; |
| 9028 | char buf[BUFSZ], buf2[BUFSZ]; |
| 9029 | anything any; |
| 9030 | int i = idx, reslt = optn_err; |
| 9031 | #ifdef PREFIXES_IN_USE |
| 9032 | int j; |
| 9033 | #endif |
| 9034 | int clr = NO_COLOR; |
| 9035 | |
| 9036 | buf2[0] = '\0'; /* per opt functs may not guarantee this, so do it */ |
| 9037 | any = cg.zeroany; |
| 9038 | if (i >= 0 && i < OPTCOUNT && allopt[i].name && allopt[i].optfn) { |
| 9039 | any.a_int = (indexoffset == 0) ? 0 : i + 1 + indexoffset; |
| 9040 | if (allopt[i].optfn) |
| 9041 | reslt = (*allopt[i].optfn)(allopt[i].idx, get_val, |
| 9042 | FALSE, buf2, empty_optstr); |
| 9043 | if (reslt == optn_ok && buf2[0]) |
| 9044 | value = (const char *) buf2; |
| 9045 | } else { |
| 9046 | /* We are trying to add an option not found in allopt[]. |
| 9047 | This is almost certainly bad, but we'll let it through anyway |
| 9048 | (with a zero value, so it can't be selected). */ |
| 9049 | any.a_int = 0; |
| 9050 | #ifdef PREFIXES_IN_USE |
| 9051 | for (j = 0; j < PREFIX_COUNT; ++j) |
| 9052 | if (!strcmp(option, fqn_prefix_names[j]) && gf.fqn_prefix[j]) |
| 9053 | Sprintf(buf2, "%s", gf.fqn_prefix[j]); |
| 9054 | #endif |
| 9055 | if (!buf2[0]) |
| 9056 | Strcpy(buf2, "unknown"); |
| 9057 | value = (const char *) buf2; |
| 9058 | } |
| 9059 | |
| 9060 | /* " " replaces "a - " -- assumes menus follow that style */ |
| 9061 | indent = !any.a_int ? " " : ""; |
| 9062 | Sprintf(buf, fmtstr, indent, option, value); |
| 9063 | add_menu(win, &nul_glyphinfo, &any, 0, 0, |
| 9064 | ATR_NONE, clr, buf, MENU_ITEMFLAGS_SKIPINVERT); |
| 9065 | } |
| 9066 | |
| 9067 | |
| 9068 | /* display keys for menu actions; used by cmd.c '?i' and pager.c '?k' */ |