return extended command name (without leading '#') for command (*fn)() */
| 3103 | |
| 3104 | /* return extended command name (without leading '#') for command (*fn)() */ |
| 3105 | const char * |
| 3106 | cmdname_from_func( |
| 3107 | int (*fn)(void), /* function whose command name is wanted */ |
| 3108 | char outbuf[], /* place to store the result */ |
| 3109 | boolean fullname) /* False: just enough to disambiguate */ |
| 3110 | { |
| 3111 | const struct ext_func_tab *extcmd, *cmdptr = 0; |
| 3112 | const char *res = 0; |
| 3113 | |
| 3114 | for (extcmd = extcmdlist; extcmd->ef_txt; ++extcmd) |
| 3115 | if (extcmd->ef_funct == fn) { |
| 3116 | cmdptr = extcmd; |
| 3117 | res = cmdptr->ef_txt; |
| 3118 | break; |
| 3119 | } |
| 3120 | |
| 3121 | if (!res) { |
| 3122 | /* make sure output buffer doesn't contain junk or stale data; |
| 3123 | return Null below */ |
| 3124 | outbuf[0] = '\0'; |
| 3125 | } else if (fullname) { |
| 3126 | /* easy; the entire command name */ |
| 3127 | res = strcpy(outbuf, res); |
| 3128 | } else { |
| 3129 | const struct ext_func_tab *matchcmd = extcmdlist; |
| 3130 | unsigned len = 0, maxlen = Strlen(res); |
| 3131 | |
| 3132 | /* find the shortest leading substring which is unambiguous */ |
| 3133 | do { |
| 3134 | if (++len >= maxlen) |
| 3135 | break; |
| 3136 | for (extcmd = matchcmd; extcmd->ef_txt; ++extcmd) { |
| 3137 | if (extcmd == cmdptr) |
| 3138 | continue; |
| 3139 | if ((extcmd->flags & CMD_NOT_AVAILABLE) != 0 |
| 3140 | || ((extcmd->flags & WIZMODECMD) != 0 && !wizard)) |
| 3141 | continue; |
| 3142 | if (!strncmp(res, extcmd->ef_txt, len)) { |
| 3143 | matchcmd = extcmd; |
| 3144 | break; |
| 3145 | } |
| 3146 | } |
| 3147 | } while (extcmd->ef_txt); |
| 3148 | copynchars(outbuf, res, len); |
| 3149 | /* [note: for Qt, this debugpline writes a couple dozen lines to |
| 3150 | stdout during menu setup when message window isn't ready yet] */ |
| 3151 | debugpline2("shortened %s: \"%s\"", res, outbuf); |
| 3152 | res = outbuf; |
| 3153 | } |
| 3154 | return res; |
| 3155 | } |
| 3156 | |
| 3157 | static struct { |
| 3158 | int nhkf; |
no test coverage detected