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