Commit | Line | Data |
---|---|---|
bfe13c81 KB |
1 | /* |
2 | * Copyright (c) 1988 Mark Nudleman | |
3 | * Copyright (c) 1988 Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
bfe13c81 KB |
6 | * Redistribution and use in source and binary forms are permitted |
7 | * provided that the above copyright notice and this paragraph are | |
8 | * duplicated in all such forms and that any documentation, | |
9 | * advertising materials, and other materials related to such | |
10 | * distribution and use acknowledge that the software was developed | |
a942b40b KB |
11 | * by Mark Nudleman and the University of California, Berkeley. The |
12 | * name of Mark Nudleman or the | |
bfe13c81 KB |
13 | * University may not be used to endorse or promote products derived |
14 | * from this software without specific prior written permission. | |
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
18 | */ | |
19 | ||
20 | #ifndef lint | |
966c6ec0 | 21 | static char sccsid[] = "@(#)ttyin.c 5.3 (Berkeley) %G%"; |
bfe13c81 KB |
22 | #endif /* not lint */ |
23 | ||
24 | /* | |
25 | * Routines dealing with getting input from the keyboard (i.e. from the user). | |
26 | */ | |
27 | ||
966c6ec0 | 28 | #include <less.h> |
bfe13c81 KB |
29 | |
30 | static int tty; | |
31 | ||
32 | /* | |
33 | * Open keyboard for input. | |
34 | * (Just use file descriptor 2.) | |
35 | */ | |
bfe13c81 KB |
36 | open_getchr() |
37 | { | |
38 | tty = 2; | |
39 | } | |
40 | ||
41 | /* | |
42 | * Get a character from the keyboard. | |
43 | */ | |
bfe13c81 KB |
44 | getchr() |
45 | { | |
46 | char c; | |
47 | int result; | |
48 | ||
49 | do | |
50 | { | |
51 | result = iread(tty, &c, 1); | |
52 | if (result == READ_INTR) | |
53 | return (READ_INTR); | |
54 | if (result < 0) | |
55 | { | |
56 | /* | |
57 | * Don't call error() here, | |
58 | * because error calls getchr! | |
59 | */ | |
60 | quit(); | |
61 | } | |
62 | } while (result != 1); | |
63 | return (c & 0177); | |
64 | } |