xref: /original-bsd/usr.bin/more/ttyin.c (revision 427e68f0)
1273e1e22Sbostic /*
2273e1e22Sbostic  * Copyright (c) 1988 Mark Nudleman
3273e1e22Sbostic  * Copyright (c) 1988 Regents of the University of California.
4273e1e22Sbostic  * All rights reserved.
5273e1e22Sbostic  *
6273e1e22Sbostic  * Redistribution and use in source and binary forms are permitted
7273e1e22Sbostic  * provided that the above copyright notice and this paragraph are
8273e1e22Sbostic  * duplicated in all such forms and that any documentation,
9273e1e22Sbostic  * advertising materials, and other materials related to such
10273e1e22Sbostic  * distribution and use acknowledge that the software was developed
1194cb6cb2Sbostic  * by Mark Nudleman and the University of California, Berkeley.  The
1294cb6cb2Sbostic  * name of Mark Nudleman or the
13273e1e22Sbostic  * University may not be used to endorse or promote products derived
14273e1e22Sbostic  * from this software without specific prior written permission.
15273e1e22Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16273e1e22Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17273e1e22Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18273e1e22Sbostic  */
19273e1e22Sbostic 
20273e1e22Sbostic #ifndef lint
21*427e68f0Sbostic static char sccsid[] = "@(#)ttyin.c	5.3 (Berkeley) 11/22/88";
22273e1e22Sbostic #endif /* not lint */
23273e1e22Sbostic 
24273e1e22Sbostic /*
25273e1e22Sbostic  * Routines dealing with getting input from the keyboard (i.e. from the user).
26273e1e22Sbostic  */
27273e1e22Sbostic 
28*427e68f0Sbostic #include <less.h>
29273e1e22Sbostic 
30273e1e22Sbostic static int tty;
31273e1e22Sbostic 
32273e1e22Sbostic /*
33273e1e22Sbostic  * Open keyboard for input.
34273e1e22Sbostic  * (Just use file descriptor 2.)
35273e1e22Sbostic  */
36273e1e22Sbostic open_getchr()
37273e1e22Sbostic {
38273e1e22Sbostic 	tty = 2;
39273e1e22Sbostic }
40273e1e22Sbostic 
41273e1e22Sbostic /*
42273e1e22Sbostic  * Get a character from the keyboard.
43273e1e22Sbostic  */
44273e1e22Sbostic getchr()
45273e1e22Sbostic {
46273e1e22Sbostic 	char c;
47273e1e22Sbostic 	int result;
48273e1e22Sbostic 
49273e1e22Sbostic 	do
50273e1e22Sbostic 	{
51273e1e22Sbostic 		result = iread(tty, &c, 1);
52273e1e22Sbostic 		if (result == READ_INTR)
53273e1e22Sbostic 			return (READ_INTR);
54273e1e22Sbostic 		if (result < 0)
55273e1e22Sbostic 		{
56273e1e22Sbostic 			/*
57273e1e22Sbostic 			 * Don't call error() here,
58273e1e22Sbostic 			 * because error calls getchr!
59273e1e22Sbostic 			 */
60273e1e22Sbostic 			quit();
61273e1e22Sbostic 		}
62273e1e22Sbostic 	} while (result != 1);
63273e1e22Sbostic 	return (c & 0177);
64273e1e22Sbostic }
65