135209Sbostic /* 235209Sbostic * Copyright (c) 1988 Mark Nudleman 3*62131Sbostic * Copyright (c) 1988, 1993 4*62131Sbostic * The Regents of the University of California. All rights reserved. 535209Sbostic * 642742Sbostic * %sccs.include.redist.c% 735209Sbostic */ 835209Sbostic 935209Sbostic #ifndef lint 10*62131Sbostic static char sccsid[] = "@(#)ttyin.c 8.1 (Berkeley) 06/06/93"; 1135209Sbostic #endif /* not lint */ 1235209Sbostic 1335209Sbostic /* 1435209Sbostic * Routines dealing with getting input from the keyboard (i.e. from the user). 1535209Sbostic */ 1635209Sbostic 1736253Sbostic #include <less.h> 1835209Sbostic 1935209Sbostic static int tty; 2035209Sbostic 2135209Sbostic /* 2235209Sbostic * Open keyboard for input. 2335209Sbostic * (Just use file descriptor 2.) 2435209Sbostic */ open_getchr()2535209Sbosticopen_getchr() 2635209Sbostic { 2735209Sbostic tty = 2; 2835209Sbostic } 2935209Sbostic 3035209Sbostic /* 3135209Sbostic * Get a character from the keyboard. 3235209Sbostic */ getchr()3335209Sbosticgetchr() 3435209Sbostic { 3535209Sbostic char c; 3635209Sbostic int result; 3735209Sbostic 3835209Sbostic do 3935209Sbostic { 4035209Sbostic result = iread(tty, &c, 1); 4135209Sbostic if (result == READ_INTR) 4235209Sbostic return (READ_INTR); 4335209Sbostic if (result < 0) 4435209Sbostic { 4535209Sbostic /* 4635209Sbostic * Don't call error() here, 4735209Sbostic * because error calls getchr! 4835209Sbostic */ 4935209Sbostic quit(); 5035209Sbostic } 5135209Sbostic } while (result != 1); 5235209Sbostic return (c & 0177); 5335209Sbostic } 54