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
| 1550 | ports might use a popup. |
| 1551 | */ |
| 1552 | char |
| 1553 | mswin_yn_function(const char *question, const char *choices, char def) |
| 1554 | { |
| 1555 | char ch; |
| 1556 | char yn_esc_map = '\033'; |
| 1557 | char message[BUFSZ]; |
| 1558 | char res_ch[2]; |
| 1559 | int createcaret; |
| 1560 | boolean digit_ok, allow_num = FALSE; |
| 1561 | |
| 1562 | logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); |
| 1563 | |
| 1564 | if (WIN_MESSAGE == WIN_ERR && choices == ynchars) { |
| 1565 | char *text = |
| 1566 | realloc(strdup(GetNHApp()->saved_text), |
| 1567 | strlen(question) + strlen(GetNHApp()->saved_text) + 1); |
| 1568 | DWORD box_result; |
| 1569 | strcat(text, question); |
| 1570 | box_result = |
| 1571 | NHMessageBox(NULL, NH_W2A(text, message, sizeof(message)), |
| 1572 | MB_ICONQUESTION | MB_YESNOCANCEL |
| 1573 | | ((def == 'y') ? MB_DEFBUTTON1 |
| 1574 | : (def == 'n') ? MB_DEFBUTTON2 |
| 1575 | : MB_DEFBUTTON3)); |
| 1576 | free(text); |
| 1577 | GetNHApp()->saved_text = strdup(""); |
| 1578 | return box_result == IDYES ? 'y' : box_result == IDNO ? 'n' : '\033'; |
| 1579 | } |
| 1580 | |
| 1581 | if (choices) { |
| 1582 | char *cb, choicebuf[QBUFSZ]; |
| 1583 | |
| 1584 | allow_num = (strchr(choices, '#') != 0); |
| 1585 | |
| 1586 | Strcpy(choicebuf, choices); |
| 1587 | if ((cb = strchr(choicebuf, '\033')) != 0) { |
| 1588 | /* anything beyond <esc> is hidden */ |
| 1589 | *cb = '\0'; |
| 1590 | } |
| 1591 | (void) strncpy(message, question, QBUFSZ - 1); |
| 1592 | message[QBUFSZ - 1] = '\0'; |
| 1593 | sprintf(eos(message), " [%s]", choicebuf); |
| 1594 | if (def) |
| 1595 | sprintf(eos(message), " (%c)", def); |
| 1596 | Strcat(message, " "); |
| 1597 | /* escape maps to 'q' or 'n' or default, in that order */ |
| 1598 | yn_esc_map = |
| 1599 | (strchr(choices, 'q') ? 'q' : (strchr(choices, 'n') ? 'n' : def)); |
| 1600 | } else { |
| 1601 | Strcpy(message, question); |
| 1602 | Strcat(message, " "); |
| 1603 | } |
| 1604 | |
| 1605 | createcaret = 1; |
| 1606 | SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, |
| 1607 | (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); |
| 1608 | |
| 1609 | mswin_clear_nhwindow(WIN_MESSAGE); |
nothing calls this directly
no test coverage detected