Annotation of src/usr.bin/less/ttyin.c, Revision 1.8
1.1 etheisen 1: /*
1.6 shadchin 2: * Copyright (C) 1984-2012 Mark Nudelman
1.8 ! nicm 3: * Modified for use with illumos by Garrett D'Amore.
! 4: * Copyright 2014 Garrett D'Amore <garrett@damore.org>
1.1 etheisen 5: *
1.3 millert 6: * You may distribute under the terms of either the GNU General Public
7: * License or the Less License, as specified in the README file.
1.1 etheisen 8: *
1.6 shadchin 9: * For more information, see the README file.
1.7 nicm 10: */
1.1 etheisen 11:
12: /*
13: * Routines dealing with getting input from the keyboard (i.e. from the user).
14: */
15:
16: #include "less.h"
17:
1.7 nicm 18: int tty;
1.5 millert 19: extern volatile sig_atomic_t sigs;
1.4 shadchin 20: extern int utf_mode;
1.1 etheisen 21:
22: /*
23: * Open keyboard for input.
24: */
1.7 nicm 25: void
26: open_getchr(void)
1.1 etheisen 27: {
28: /*
29: * Try /dev/tty.
30: * If that doesn't work, use file descriptor 2,
31: * which in Unix is usually attached to the screen,
32: * but also usually lets you read from the keyboard.
33: */
1.3 millert 34: tty = open("/dev/tty", OPEN_READ);
1.1 etheisen 35: if (tty < 0)
36: tty = 2;
1.3 millert 37: }
38:
39: /*
40: * Close the keyboard.
41: */
1.7 nicm 42: void
43: close_getchr(void)
1.3 millert 44: {
1.1 etheisen 45: }
46:
47: /*
48: * Get a character from the keyboard.
49: */
1.7 nicm 50: int
51: getchr(void)
1.1 etheisen 52: {
1.7 nicm 53: unsigned char c;
1.1 etheisen 54: int result;
55:
1.7 nicm 56: do {
57: result = iread(tty, &c, sizeof (char));
1.1 etheisen 58: if (result == READ_INTR)
59: return (READ_INTR);
1.7 nicm 60: if (result < 0) {
1.1 etheisen 61: /*
62: * Don't call error() here,
63: * because error calls getchr!
64: */
65: quit(QUIT_ERROR);
66: }
67: /*
68: * Various parts of the program cannot handle
69: * an input character of '\0'.
70: * If a '\0' was actually typed, convert it to '\340' here.
71: */
72: if (c == '\0')
1.7 nicm 73: c = 0340;
1.1 etheisen 74: } while (result != 1);
75:
1.4 shadchin 76: return (c & 0xFF);
1.1 etheisen 77: }