OSDN Git Service

import nethack-3.6.0
[jnethack/source.git] / sys / mac / mgetline.c
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 /* 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
16 get_line_from_key_queue(char *bufp)
17 {
18     *bufp = 0;
19     if (try_key_queue(bufp)) {
20         while (*bufp) {
21             if (*bufp == 10 || *bufp == 13) {
22                 *bufp = 0;
23             }
24             bufp++;
25         }
26         return true;
27     }
28     return false;
29 }
30
31 static void
32 topl_getlin(const char *query, char *bufp, Boolean ext)
33 {
34     if (get_line_from_key_queue(bufp))
35         return;
36
37     enter_topl_mode((char *) query);
38     while (topl_key(nhgetch(), ext))
39         ;
40     leave_topl_mode(bufp);
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
50 mac_getlin(const char *query, char *bufp)
51 {
52     topl_getlin(query, bufp, false);
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
60 mac_get_ext_cmd()
61 {
62     char bufp[BUFSZ];
63     int i;
64
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 */
73
74     return i;
75 }
76
77 /* macgetline.c */