Ask a question and get a response */
| 994 | |
| 995 | /* Ask a question and get a response */ |
| 996 | char |
| 997 | amii_yn_function(const char *query, const char *resp, char def) |
| 998 | { |
| 999 | |
| 1000 | /* |
| 1001 | * Generic yes/no function. 'def' is the default (returned by space or |
| 1002 | * return; 'esc' returns 'q', or 'n', or the default, depending on |
| 1003 | * what's in the string. The 'query' string is printed before the user |
| 1004 | * is asked about the string. |
| 1005 | * If resp is NULL, any single character is accepted and returned. |
| 1006 | * If not-NULL, only characters in it are allowed (exceptions: the |
| 1007 | * quitchars are always allowed, and if it contains '#' then digits |
| 1008 | * are allowed); if it includes an <esc>, anything beyond that won't |
| 1009 | * be shown in the prompt to the user but will be acceptable as input. |
| 1010 | */ |
| 1011 | char q; |
| 1012 | char rtmp[40]; |
| 1013 | boolean digit_ok, allow_num; |
| 1014 | char prompt[BUFSZ]; |
| 1015 | struct amii_WinDesc *cw; |
| 1016 | |
| 1017 | if (cw = amii_wins[WIN_MESSAGE]) |
| 1018 | cw->disprows = 0; |
| 1019 | if (resp) { |
| 1020 | char *rb, respbuf[QBUFSZ]; |
| 1021 | |
| 1022 | allow_num = (strchr(resp, '#') != 0); |
| 1023 | Strcpy(respbuf, resp); |
| 1024 | /* any acceptable responses that follow <esc> aren't displayed */ |
| 1025 | if ((rb = strchr(respbuf, '\033')) != 0) |
| 1026 | *rb = '\0'; |
| 1027 | (void) strncpy(prompt, query, QBUFSZ - 1); |
| 1028 | prompt[QBUFSZ - 1] = '\0'; |
| 1029 | Sprintf(eos(prompt), " [%s]", respbuf); |
| 1030 | if (def) |
| 1031 | Sprintf(eos(prompt), " (%c)", def); |
| 1032 | Strcat(prompt, " "); |
| 1033 | pline("%s", prompt); |
| 1034 | } else { |
| 1035 | amii_putstr(WIN_MESSAGE, 0, query); |
| 1036 | cursor_on(WIN_MESSAGE); |
| 1037 | q = WindowGetchar(); |
| 1038 | cursor_off(WIN_MESSAGE); |
| 1039 | *rtmp = q; |
| 1040 | rtmp[1] = '\0'; |
| 1041 | amii_addtopl(rtmp); |
| 1042 | goto clean_up; |
| 1043 | } |
| 1044 | |
| 1045 | do { /* loop until we get valid input */ |
| 1046 | cursor_on(WIN_MESSAGE); |
| 1047 | q = lowc(WindowGetchar()); |
| 1048 | cursor_off(WIN_MESSAGE); |
| 1049 | #if 0 |
| 1050 | /* fix for PL2 */ |
| 1051 | if (q == '\020') { /* ctrl-P */ |
| 1052 | if(!doprev) |
| 1053 | (void) tty_doprev_message(); /* need two initially */ |
nothing calls this directly
no test coverage detected