File: mgetline.c

package info (click to toggle)
glhack 1.2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,744 kB
  • sloc: ansic: 208,571; cpp: 13,139; yacc: 2,005; makefile: 1,152; lex: 377; sh: 121; awk: 89; sed: 11
file content (74 lines) | stat: -rw-r--r-- 1,682 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*	SCCS Id: @(#)getline.c	3.1	90/22/02 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed.  See license for details. */

#include "hack.h"
#include "mactty.h"
#include "macwin.h"
#include "macpopup.h"
#include "func_tab.h"

extern int NDECL(extcmd_via_menu);	/* cmd.c */

typedef Boolean FDECL ((* key_func), (unsigned char));

int
get_line_from_key_queue (char * bufp) {
	* bufp = 0;
	if (try_key_queue (bufp)) {
		while (* bufp) {
			if (* bufp == 10 || * bufp == 13) {
				* bufp = 0;
			}
			bufp ++;
		}
		return true;
	}
	return false;
}


static void
topl_getlin(const char *query, char *bufp, Boolean ext) {
	if (get_line_from_key_queue (bufp))
		return;

	enter_topl_mode((char *) query);
	while (topl_key(nhgetch(), ext))
		;
	leave_topl_mode(bufp);
}


/*
 * Read a line closed with '\n' into the array char bufp[BUFSZ].
 * (The '\n' is not stored. The string is closed with a '\0'.)
 * Reading can be interrupted by an escape ('\033') - now the
 * resulting string is "\033".
 */
void
mac_getlin(const char *query, char *bufp) {
	topl_getlin (query, bufp, false);
}


/* Read in an extended command - doing command line completion for
 * when enough characters have been entered to make a unique command.
 * This is just a modified getlin() followed by a lookup.   -jsb
 */
int
mac_get_ext_cmd() {
	char bufp[BUFSZ];
	int i;

	if (iflags.extmenu) return extcmd_via_menu();
	topl_getlin("# ", bufp, true);
	for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
		if (!strcmp(bufp, extcmdlist[i].ef_txt)) break;
	if (extcmdlist[i].ef_txt == (char *)0) i = -1;    /* not found */

	return i;
}


/* macgetline.c */