Deleted Added
sdiff udiff text old ( 60786 ) new ( 89019 )
full compact
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
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.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10
11
12/*
13 * Routines dealing with getting input from the keyboard (i.e. from the user).
14 */
15
16#include "less.h"
17#if OS2
18#include "cmd.h"
19#include "pckeys.h"
20#endif
21#if MSDOS_COMPILER==WIN32C
22#include "windows.h"
23extern char WIN32getch();
24static DWORD console_mode;
25#endif
26
27static int tty;
28extern int sigs;

--- 12 unchanged lines hidden (view full) ---

41 sa.bInheritHandle = TRUE;
42 tty = (int) CreateFile("CONIN$", GENERIC_READ,
43 FILE_SHARE_READ, &sa,
44 OPEN_EXISTING, 0L, NULL);
45 GetConsoleMode((HANDLE)tty, &console_mode);
46 /* Make sure we get Ctrl+C events. */
47 SetConsoleMode((HANDLE)tty, ENABLE_PROCESSED_INPUT);
48#else
49#if MSDOS_COMPILER
50 extern int fd0;
51 /*
52 * Open a new handle to CON: in binary mode
53 * for unbuffered keyboard read.
54 */
55 fd0 = dup(0);
56 close(0);
57 tty = open("CON", OPEN_READ);

--- 6 unchanged lines hidden (view full) ---

64#endif
65#else
66 /*
67 * Try /dev/tty.
68 * If that doesn't work, use file descriptor 2,
69 * which in Unix is usually attached to the screen,
70 * but also usually lets you read from the keyboard.
71 */
72#if OS2
73 /* The __open() system call translates "/dev/tty" to "con". */
74 tty = __open("/dev/tty", OPEN_READ);
75#else
76 tty = open("/dev/tty", OPEN_READ);
77#endif
78 if (tty < 0)
79 tty = 2;
80#endif
81#endif
82}
83
84/*
85 * Close the keyboard.

--- 29 unchanged lines hidden (view full) ---

115 c = WIN32getch(tty);
116#else
117 c = getch();
118#endif
119 result = 1;
120 if (c == '\003')
121 return (READ_INTR);
122#else
123 result = iread(tty, &c, sizeof(char));
124 if (result == READ_INTR)
125 return (READ_INTR);
126 if (result < 0)
127 {
128 /*
129 * Don't call error() here,
130 * because error calls getchr!
131 */
132 quit(QUIT_ERROR);
133 }
134#endif
135 /*
136 * Various parts of the program cannot handle
137 * an input character of '\0'.
138 * If a '\0' was actually typed, convert it to '\340' here.
139 */
140 if (c == '\0')
141 c = '\340';
142 } while (result != 1);
143
144 return (c & 0377);
145}