1 /* NetHack 3.6 mgetline.c $NHDT-Date: 1432512797 2015/05/25 00:13:17 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
4 /* NetHack may be freely redistributed. See license for details. */
5
6 #include "hack.h"
7 #include "mactty.h"
8 #include "macwin.h"
9 #include "macpopup.h"
10 #include "func_tab.h"
11
12 extern int NDECL(extcmd_via_menu); /* cmd.c */
13
14 typedef Boolean FDECL((*key_func), (unsigned char));
15
16 int
get_line_from_key_queue(char * bufp)17 get_line_from_key_queue(char *bufp)
18 {
19 *bufp = 0;
20 if (try_key_queue(bufp)) {
21 while (*bufp) {
22 if (*bufp == 10 || *bufp == 13) {
23 *bufp = 0;
24 }
25 bufp++;
26 }
27 return true;
28 }
29 return false;
30 }
31
32 static void
topl_getlin(const char * query,char * bufp,Boolean ext)33 topl_getlin(const char *query, char *bufp, Boolean ext)
34 {
35 if (get_line_from_key_queue(bufp))
36 return;
37
38 enter_topl_mode((char *) query);
39 while (topl_key(nhgetch(), ext))
40 ;
41 leave_topl_mode(bufp);
42 }
43
44 /*
45 * Read a line closed with '\n' into the array char bufp[BUFSZ].
46 * (The '\n' is not stored. The string is closed with a '\0'.)
47 * Reading can be interrupted by an escape ('\033') - now the
48 * resulting string is "\033".
49 */
50 void
mac_getlin(const char * query,char * bufp)51 mac_getlin(const char *query, char *bufp)
52 {
53 topl_getlin(query, bufp, false);
54 }
55
56 /* Read in an extended command - doing command line completion for
57 * when enough characters have been entered to make a unique command.
58 * This is just a modified getlin() followed by a lookup. -jsb
59 */
60 int
mac_get_ext_cmd()61 mac_get_ext_cmd()
62 {
63 char bufp[BUFSZ];
64 int i;
65
66 if (iflags.extmenu)
67 return extcmd_via_menu();
68 topl_getlin("# ", bufp, true);
69 for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++)
70 if (!strcmp(bufp, extcmdlist[i].ef_txt))
71 break;
72 if (extcmdlist[i].ef_txt == (char *) 0)
73 i = -1; /* not found */
74
75 return i;
76 }
77
78 /* macgetline.c */
79