[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.13

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.4       shadchin   19: extern int utf_mode;
1.1       etheisen   20:
                     21: /*
                     22:  * Open keyboard for input.
                     23:  */
1.7       nicm       24: void
                     25: open_getchr(void)
1.1       etheisen   26: {
                     27:        /*
                     28:         * Try /dev/tty.
                     29:         * If that doesn't work, use file descriptor 2,
                     30:         * which in Unix is usually attached to the screen,
                     31:         * but also usually lets you read from the keyboard.
                     32:         */
1.9       deraadt    33:        tty = open("/dev/tty", O_RDONLY);
1.12      deraadt    34:        if (tty == -1)
1.10      deraadt    35:                tty = STDERR_FILENO;
1.3       millert    36: }
                     37:
                     38: /*
1.1       etheisen   39:  * Get a character from the keyboard.
                     40:  */
1.7       nicm       41: int
                     42: getchr(void)
1.1       etheisen   43: {
1.7       nicm       44:        unsigned char c;
1.1       etheisen   45:        int result;
                     46:
1.7       nicm       47:        do {
                     48:                result = iread(tty, &c, sizeof (char));
1.1       etheisen   49:                if (result == READ_INTR)
                     50:                        return (READ_INTR);
1.7       nicm       51:                if (result < 0) {
1.1       etheisen   52:                        /*
                     53:                         * Don't call error() here,
                     54:                         * because error calls getchr!
                     55:                         */
                     56:                        quit(QUIT_ERROR);
                     57:                }
                     58:                /*
                     59:                 * Various parts of the program cannot handle
                     60:                 * an input character of '\0'.
                     61:                 * If a '\0' was actually typed, convert it to '\340' here.
                     62:                 */
                     63:                if (c == '\0')
1.7       nicm       64:                        c = 0340;
1.1       etheisen   65:        } while (result != 1);
                     66:
1.4       shadchin   67:        return (c & 0xFF);
1.1       etheisen   68: }