MCPcopy Create free account
hub / github.com/NetHack/NetHack / mswin_yn_function

Function mswin_yn_function

outdated/sys/wince/mswproc.c:1365–1464  ·  view source on GitHub ↗

char yn_function(const char *ques, const char *choices, char default) -- Print a prompt made up of ques, choices and default. Read a single character response that is contained in choices or default. If choices is NULL, all possible inputs are accepted and returned. This overrides everything else. The ch

Source from the content-addressed store, hash-verified

1363 ports might use a popup.
1364*/
1365char
1366mswin_yn_function(const char *question, const char *choices, CHAR_P def)
1367{
1368 int result = -1;
1369 char ch;
1370 char yn_esc_map = '\033';
1371 char message[BUFSZ];
1372 char res_ch[2];
1373
1374 logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def);
1375
1376 if (choices) {
1377 char *cb, choicebuf[QBUFSZ];
1378 Strcpy(choicebuf, choices);
1379 if ((cb = strchr(choicebuf, '\033')) != 0) {
1380 /* anything beyond <esc> is hidden */
1381 *cb = '\0';
1382 }
1383 (void) strncpy(message, question, QBUFSZ - 1);
1384 message[QBUFSZ - 1] = '\0';
1385 sprintf(eos(message), " [%s]", choicebuf);
1386 if (def)
1387 sprintf(eos(message), " (%c)", def);
1388 Strcat(message, " ");
1389 /* escape maps to 'q' or 'n' or default, in that order */
1390 yn_esc_map =
1391 (strchr(choices, 'q') ? 'q' : (strchr(choices, 'n') ? 'n' : def));
1392 } else {
1393 Strcpy(message, question);
1394 }
1395
1396#if defined(WIN_CE_SMARTPHONE)
1397 {
1398 char buf[BUFSZ];
1399 ZeroMemory(buf, sizeof(buf));
1400 if (choices) {
1401 if (!strchr(choices, '\033'))
1402 buf[0] = '\033'; /* make sure ESC is always available */
1403 strncat(buf, choices, sizeof(buf) - 2);
1404 NHSPhoneSetKeypadFromString(buf);
1405 } else {
1406 /* sometimes choices are included in the message itself, e.g.
1407 * "what? [abcd]" */
1408 char *p1, *p2;
1409 p1 = strchr(question, '[');
1410 p2 = strrchr(question, ']');
1411 if (p1 && p2 && p1 < p2) {
1412 buf[0] = '\033'; /* make sure ESC is always available */
1413 strncat(buf, p1 + 1, p2 - p1 - 1);
1414 NHSPhoneSetKeypadFromString(buf);
1415 } else if (strstr(question, "direction")) {
1416 /* asking for direction here */
1417 NHSPhoneSetKeypadDirection();
1418 } else {
1419 /* anything goes */
1420 NHSPhoneSetKeypadFromString("\0330-9a-zA-Z");
1421 }
1422 }

Callers

nothing calls this directly

Calls 12

eosFunction · 0.85
strrchrFunction · 0.85
isprintFunction · 0.85
NHSPhoneSetKeypadDefaultFunction · 0.85
logDebugFunction · 0.70
mswin_putstrFunction · 0.70
mswin_nhgetchFunction · 0.70
mswin_nhbellFunction · 0.70
mswin_putstr_exFunction · 0.70
mswin_clear_nhwindowFunction · 0.70

Tested by

no test coverage detected