1 /* SCCS Id: @(#)getline.c 3.1 90/22/02 */
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 #include "func_tab.h"
10
11 extern int NDECL(extcmd_via_menu); /* cmd.c */
12
13 typedef Boolean FDECL ((* key_func), (unsigned char));
14
15 int
get_line_from_key_queue(char * bufp)16 get_line_from_key_queue (char * bufp) {
17 * bufp = 0;
18 if (try_key_queue (bufp)) {
19 while (* bufp) {
20 if (* bufp == 10 || * bufp == 13) {
21 * bufp = 0;
22 }
23 bufp ++;
24 }
25 return true;
26 }
27 return false;
28 }
29
30
31 static void
topl_getlin(const char * query,char * bufp,Boolean ext)32 topl_getlin(const char *query, char *bufp, Boolean ext) {
33 if (get_line_from_key_queue (bufp))
34 return;
35
36 enter_topl_mode((char *) query);
37 while (topl_key(nhgetch(), ext))
38 ;
39 leave_topl_mode(bufp);
40 }
41
42
43 /*
44 * Read a line closed with '\n' into the array char bufp[BUFSZ].
45 * (The '\n' is not stored. The string is closed with a '\0'.)
46 * Reading can be interrupted by an escape ('\033') - now the
47 * resulting string is "\033".
48 */
49 void
mac_getlin(const char * query,char * bufp)50 mac_getlin(const char *query, char *bufp) {
51 topl_getlin (query, bufp, false);
52 }
53
54
55 /* Read in an extended command - doing command line completion for
56 * when enough characters have been entered to make a unique command.
57 * This is just a modified getlin() followed by a lookup. -jsb
58 */
59 int
mac_get_ext_cmd()60 mac_get_ext_cmd() {
61 char bufp[BUFSZ];
62 int i;
63
64 if (iflags.extmenu) return extcmd_via_menu();
65 topl_getlin("# ", bufp, true);
66 for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
67 if (!strcmp(bufp, extcmdlist[i].ef_txt)) break;
68 if (extcmdlist[i].ef_txt == (char *)0) i = -1; /* not found */
69
70 return i;
71 }
72
73
74 /* macgetline.c */
75