MCPcopy Index your code
hub / github.com/NetHack/NetHack / X11_yn_function_core

Function X11_yn_function_core

win/X11/winX.c:2261–2461  ·  view source on GitHub ↗

guts of the X11_yn_function(), not to be confused with core code; requires an extra argument: ynflags */

Source from the content-addressed store, hash-verified

2259/* guts of the X11_yn_function(), not to be confused with core code;
2260 requires an extra argument: ynflags */
2261char
2262X11_yn_function_core(
2263 const char *ques, /* prompt text */
2264 const char *choices, /* allowed response chars; any char if Null */
2265 char def, /* default if user hits <space> or <return> */
2266 unsigned ynflags) /* flags; currently just log-it or not */
2267{
2268 static XFontStruct *yn_font = 0;
2269 static Dimension yn_minwidth = 0;
2270 char buf[BUFSZ], buf2[BUFSZ];
2271 Arg args[4];
2272 Cardinal num_args;
2273 boolean suppress_logging = (ynflags & YN_NO_LOGMESG) != 0U,
2274 no_default_cnvrt = (ynflags & YN_NO_DEFAULT) != 0U;
2275
2276 yn_choices = choices; /* set up globals for callback to use */
2277 yn_def = def;
2278 yn_no_default = no_default_cnvrt;
2279 yn_preserve_case = !choices; /* preserve case when an arbitrary
2280 * response is allowed */
2281
2282 /*
2283 * This is sort of a kludge. There are quite a few places in the main
2284 * nethack code where a pline containing information is followed by a
2285 * call to yn_function(). There is no flush of the message window
2286 * (it is implicit in the tty window port), so the line never shows
2287 * up for us! Solution: do our own flush.
2288 */
2289 if (WIN_MESSAGE != WIN_ERR)
2290 display_message_window(&window_list[WIN_MESSAGE]);
2291
2292 if (choices) {
2293 char *cb, choicebuf[QBUFSZ];
2294
2295 Strcpy(choicebuf, choices); /* anything beyond <esc> is hidden */
2296 /* default when choices are present is to force yn answer to
2297 lowercase unless one or more choices are explicitly uppercase;
2298 check this before stripping the hidden choices */
2299 for (cb = choicebuf; *cb; ++cb)
2300 if ('A' <= *cb && *cb <= 'Z') {
2301 yn_preserve_case = TRUE;
2302 break;
2303 }
2304 if ((cb = strchr(choicebuf, '\033')) != 0)
2305 *cb = '\0';
2306 /* ques [choices] (def) */
2307 int ln = ((int) strlen(ques) /* prompt text */
2308 + 3 /* " []" */
2309 + (int) strlen(choicebuf) /* choices within "[]" */
2310 + 4 /* " (c)" */
2311 + 1 /* a trailing space */
2312 + 1); /* \0 terminator */
2313 if (ln >= BUFSZ)
2314 panic("X11_yn_function: question too long (%d)", ln);
2315 Snprintf(buf, sizeof buf, "%.*s [%s]", QBUFSZ - 1, ques, choicebuf);
2316 if (def)
2317 Sprintf(eos(buf), " (%c)", def);
2318 Strcat(buf, " ");

Callers 2

X11_yn_functionFunction · 0.85
x11_scroll_perminvFunction · 0.85

Calls 11

display_message_windowFunction · 0.85
eosFunction · 0.85
highlight_ynFunction · 0.85
positionpopupFunction · 0.85
nh_XtPopupFunction · 0.85
x_eventFunction · 0.85
nh_XtPopdownFunction · 0.85
trimspacesFunction · 0.85
visctrlFunction · 0.85
panicFunction · 0.50
plineFunction · 0.50

Tested by

no test coverage detected