xref: /original-bsd/usr.bin/more/ttyin.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1988 Mark Nudleman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char sccsid[] = "@(#)ttyin.c	8.1 (Berkeley) 06/06/93";
11 #endif /* not lint */
12 
13 /*
14  * Routines dealing with getting input from the keyboard (i.e. from the user).
15  */
16 
17 #include <less.h>
18 
19 static int tty;
20 
21 /*
22  * Open keyboard for input.
23  * (Just use file descriptor 2.)
24  */
25 open_getchr()
26 {
27 	tty = 2;
28 }
29 
30 /*
31  * Get a character from the keyboard.
32  */
33 getchr()
34 {
35 	char c;
36 	int result;
37 
38 	do
39 	{
40 		result = iread(tty, &c, 1);
41 		if (result == READ_INTR)
42 			return (READ_INTR);
43 		if (result < 0)
44 		{
45 			/*
46 			 * Don't call error() here,
47 			 * because error calls getchr!
48 			 */
49 			quit();
50 		}
51 	} while (result != 1);
52 	return (c & 0177);
53 }
54