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 11*94cb6cb2Sbostic * by Mark Nudleman and the University of California, Berkeley. The 12*94cb6cb2Sbostic * 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*94cb6cb2Sbostic static char sccsid[] = "@(#)ttyin.c 5.2 (Berkeley) 07/25/88"; 22273e1e22Sbostic #endif /* not lint */ 23273e1e22Sbostic 24273e1e22Sbostic /* 25273e1e22Sbostic * Routines dealing with getting input from the keyboard (i.e. from the user). 26273e1e22Sbostic */ 27273e1e22Sbostic 28273e1e22Sbostic #include "less.h" 29273e1e22Sbostic 30273e1e22Sbostic static int tty; 31273e1e22Sbostic 32273e1e22Sbostic /* 33273e1e22Sbostic * Open keyboard for input. 34273e1e22Sbostic * (Just use file descriptor 2.) 35273e1e22Sbostic */ 36273e1e22Sbostic public void 37273e1e22Sbostic open_getchr() 38273e1e22Sbostic { 39273e1e22Sbostic tty = 2; 40273e1e22Sbostic } 41273e1e22Sbostic 42273e1e22Sbostic /* 43273e1e22Sbostic * Get a character from the keyboard. 44273e1e22Sbostic */ 45273e1e22Sbostic public int 46273e1e22Sbostic getchr() 47273e1e22Sbostic { 48273e1e22Sbostic char c; 49273e1e22Sbostic int result; 50273e1e22Sbostic 51273e1e22Sbostic do 52273e1e22Sbostic { 53273e1e22Sbostic result = iread(tty, &c, 1); 54273e1e22Sbostic if (result == READ_INTR) 55273e1e22Sbostic return (READ_INTR); 56273e1e22Sbostic if (result < 0) 57273e1e22Sbostic { 58273e1e22Sbostic /* 59273e1e22Sbostic * Don't call error() here, 60273e1e22Sbostic * because error calls getchr! 61273e1e22Sbostic */ 62273e1e22Sbostic quit(); 63273e1e22Sbostic } 64273e1e22Sbostic } while (result != 1); 65273e1e22Sbostic return (c & 0177); 66273e1e22Sbostic } 67