1 /*	SCCS Id: @(#)mactopl.c	3.1	91/07/23 */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed.  See license for details. */
4 
5 #include "hack.h"
6 #include "mactty.h"
7 #include "macwin.h"
8 #include "macpopup.h"
9 
10 char
queued_resp(char * resp)11 queued_resp(char *resp) {
12 	char buf[30];
13 	if (try_key_queue(buf)) {
14 		if (!resp || strchr(resp, buf[0]))
15 			return buf[0];
16 		if (digit(buf[0]) && strchr(resp, '#')) {
17 			yn_number = atoi(buf);
18 			return '#';
19 		}
20 	}
21 	return '\0';
22 }
23 
24 
25 char
topl_yn_function(const char * query,const char * resp,char def)26 topl_yn_function(const char *query, const char *resp, char def) {
27 	char buf[30];
28 	char c = queued_resp((char *) resp);
29 	if (!c) {
30 		enter_topl_mode((char *) query);
31 		topl_set_resp((char *) resp, def);
32 
33 		do {
34 			c = readchar();
35 			if (c && resp && !strchr(resp, c)) {
36 				nhbell();
37 				c = '\0';
38 			}
39 		} while (!c);
40 
41 		topl_set_resp("", '\0');
42 		leave_topl_mode(buf);
43 		if (c == '#')
44 			yn_number = atoi(buf);
45 	}
46 	return c;
47 }
48 
49 
50 char
mac_yn_function(query,resp,def)51 mac_yn_function(query, resp, def)
52 const char *query,*resp;
53 char def;
54 /*
55  *   Generic yes/no function. 'def' is the default (returned by space or
56  *   return; 'esc' returns 'q', or 'n', or the default, depending on
57  *   what's in the string. The 'query' string is printed before the user
58  *   is asked about the string.
59  *   If resp is NULL, any single character is accepted and returned.
60  */
61 {
62 		return topl_yn_function(query, resp, def);
63 }
64 
65 /* mactopl.c */
66