1273e1e22Sbostic /* 2273e1e22Sbostic * Copyright (c) 1988 Mark Nudleman 3*76f06662Sbostic * Copyright (c) 1988, 1993 4*76f06662Sbostic * The Regents of the University of California. All rights reserved. 5273e1e22Sbostic * 69918a12eSbostic * %sccs.include.redist.c% 7273e1e22Sbostic */ 8273e1e22Sbostic 9273e1e22Sbostic #ifndef lint 10*76f06662Sbostic static char sccsid[] = "@(#)ttyin.c 8.1 (Berkeley) 06/06/93"; 11273e1e22Sbostic #endif /* not lint */ 12273e1e22Sbostic 13273e1e22Sbostic /* 14273e1e22Sbostic * Routines dealing with getting input from the keyboard (i.e. from the user). 15273e1e22Sbostic */ 16273e1e22Sbostic 17427e68f0Sbostic #include <less.h> 18273e1e22Sbostic 19273e1e22Sbostic static int tty; 20273e1e22Sbostic 21273e1e22Sbostic /* 22273e1e22Sbostic * Open keyboard for input. 23273e1e22Sbostic * (Just use file descriptor 2.) 24273e1e22Sbostic */ open_getchr()25273e1e22Sbosticopen_getchr() 26273e1e22Sbostic { 27273e1e22Sbostic tty = 2; 28273e1e22Sbostic } 29273e1e22Sbostic 30273e1e22Sbostic /* 31273e1e22Sbostic * Get a character from the keyboard. 32273e1e22Sbostic */ getchr()33273e1e22Sbosticgetchr() 34273e1e22Sbostic { 35273e1e22Sbostic char c; 36273e1e22Sbostic int result; 37273e1e22Sbostic 38273e1e22Sbostic do 39273e1e22Sbostic { 40273e1e22Sbostic result = iread(tty, &c, 1); 41273e1e22Sbostic if (result == READ_INTR) 42273e1e22Sbostic return (READ_INTR); 43273e1e22Sbostic if (result < 0) 44273e1e22Sbostic { 45273e1e22Sbostic /* 46273e1e22Sbostic * Don't call error() here, 47273e1e22Sbostic * because error calls getchr! 48273e1e22Sbostic */ 49273e1e22Sbostic quit(); 50273e1e22Sbostic } 51273e1e22Sbostic } while (result != 1); 52273e1e22Sbostic return (c & 0177); 53273e1e22Sbostic } 54