NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / sys / mac / mgetline.c
blob7fac1df96aabab1eef5737d16a365f7dcfc32977
1 /* aNetHack 0.0.1 mgetline.c $ANH-Date: 1432512797 2015/05/25 00:13:17 $ $ANH-Branch: master $:$ANH-Revision: 1.10 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* aNetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
6 #include "mactty.h"
7 #include "macwin.h"
8 #include "macpopup.h"
9 #include "func_tab.h"
11 extern int NDECL(extcmd_via_menu); /* cmd.c */
13 typedef Boolean FDECL((*key_func), (unsigned char));
15 int
16 get_line_from_key_queue(char *bufp)
18 *bufp = 0;
19 if (try_key_queue(bufp)) {
20 while (*bufp) {
21 if (*bufp == 10 || *bufp == 13) {
22 *bufp = 0;
24 bufp++;
26 return true;
28 return false;
31 static void
32 topl_getlin(const char *query, char *bufp, Boolean ext)
34 if (get_line_from_key_queue(bufp))
35 return;
37 enter_topl_mode((char *) query);
38 while (topl_key(nhgetch(), ext))
40 leave_topl_mode(bufp);
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".
49 void
50 mac_getlin(const char *query, char *bufp)
52 topl_getlin(query, bufp, false);
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
59 int
60 mac_get_ext_cmd()
62 char bufp[BUFSZ];
63 int i;
65 if (iflags.extmenu)
66 return extcmd_via_menu();
67 topl_getlin("# ", bufp, true);
68 for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++)
69 if (!strcmp(bufp, extcmdlist[i].ef_txt))
70 break;
71 if (extcmdlist[i].ef_txt == (char *) 0)
72 i = -1; /* not found */
74 return i;
77 /* macgetline.c */