2 * Copyright (C) 1984-2012 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
12 * Routines dealing with getting input from the keyboard (i.e. from the user).
20 #if MSDOS_COMPILER==WIN32C
22 extern char WIN32getch();
23 static DWORD console_mode
;
31 * Open keyboard for input.
36 #if MSDOS_COMPILER==WIN32C
37 /* Need this to let child processes inherit our console handle */
38 SECURITY_ATTRIBUTES sa
;
39 memset(&sa
, 0, sizeof(SECURITY_ATTRIBUTES
));
40 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
41 sa
.bInheritHandle
= TRUE
;
42 tty
= (int) CreateFile("CONIN$", GENERIC_READ
,
44 OPEN_EXISTING
, 0L, NULL
);
45 GetConsoleMode((HANDLE
)tty
, &console_mode
);
46 /* Make sure we get Ctrl+C events. */
47 SetConsoleMode((HANDLE
)tty
, ENABLE_PROCESSED_INPUT
);
52 * Open a new handle to CON: in binary mode
53 * for unbuffered keyboard read.
57 tty
= open("CON", OPEN_READ
);
58 #if MSDOS_COMPILER==DJGPPC
60 * Setting stdin to binary causes Ctrl-C to not
61 * raise SIGINT. We must undo that side-effect.
63 (void) __djgpp_set_ctrl_c(1);
68 * If that doesn't work, use file descriptor 2,
69 * which in Unix is usually attached to the screen,
70 * but also usually lets you read from the keyboard.
73 /* The __open() system call translates "/dev/tty" to "con". */
74 tty
= __open("/dev/tty", OPEN_READ
);
76 tty
= open("/dev/tty", OPEN_READ
);
90 #if MSDOS_COMPILER==WIN32C
91 SetConsoleMode((HANDLE
)tty
, console_mode
);
92 CloseHandle((HANDLE
)tty
);
97 * Get a character from the keyboard.
107 #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC
109 * In raw read, we don't see ^C so look here for it.
112 #if MSDOS_COMPILER==WIN32C
123 result
= iread(tty
, &c
, sizeof(char));
124 if (result
== READ_INTR
)
129 * Don't call error() here,
130 * because error calls getchr!
135 #if 0 /* allow entering arbitrary hex chars for testing */
136 /* ctrl-A followed by two hex chars makes a byte */
140 if (c
== CONTROL('A'))
149 if (c
>= '0' && c
<= '9')
151 else if (c
>= 'a' && c
<= 'f')
153 else if (c
>= 'A' && c
<= 'F')
157 hex_value
= (hex_value
<< 4) | v
;
168 * Various parts of the program cannot handle
169 * an input character of '\0'.
170 * If a '\0' was actually typed, convert it to '\340' here.
174 } while (result
!= 1);