[BACK]Return to ttyin.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Annotation of src/usr.bin/less/ttyin.c, Revision 1.7

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