\f
#ifndef VMS
-/* This remembers the last number of characters read, so we could
- avoid zeroing out the whole struct input_event buf and instead zero
- out only its used slots. */
-static int prev_read = KBD_BUFFER_SIZE;
+/* We make the read_avail_input buffer static to avoid zeroing out the
+ whole struct input_event buf on every call. */
+static struct input_event read_avail_input_buf[KBD_BUFFER_SIZE];
+
+/* I don't know whether it is necessary, but make read_avail_input
+ re-entrant. */
+static int in_read_avail_input = 0;
/* Read any terminal input already buffered up by the system
into the kbd_buffer, but do not wait.
read_avail_input (expected)
int expected;
{
- struct input_event buf[KBD_BUFFER_SIZE];
+ struct input_event *buf = read_avail_input_buf;
register int i;
int nread;
- for (i = 0; i < prev_read; i++)
- EVENT_INIT (buf[i]);
+ /* Trivial hack to make read_avail_input re-entrant. */
+ if (in_read_avail_input)
+ return 0;
+ in_read_avail_input = 1;
if (read_socket_hook)
/* No need for FIONREAD or fcntl; just say don't wait. */
/* Determine how many characters we should *try* to read. */
#ifdef WINDOWSNT
- return (prev_read = 0);
+ return (in_read_avail_input = 0);
#else /* not WINDOWSNT */
#ifdef MSDOS
n_to_read = dos_keysns ();
if (n_to_read == 0)
- return (prev_read = 0);
+ return (in_read_avail_input = 0);
#else /* not MSDOS */
#ifdef FIONREAD
/* Find out how much input is available. */
n_to_read = 0;
}
if (n_to_read == 0)
- return (prev_read = 0);
+ return (in_read_avail_input = 0);
if (n_to_read > sizeof cbuf)
n_to_read = sizeof cbuf;
#else /* no FIONREAD */
break;
}
- return (prev_read = nread);
+ /* Clear used events */
+ for (i = 0; i < nread; i++)
+ EVENT_INIT (buf[i]);
+
+ in_read_avail_input = 0;
+ return nread;
}
#endif /* not VMS */
\f
do_mouse_tracking = Qnil;
#endif
input_pending = 0;
+#ifndef VMS
+ {
+ int i;
+ for (i = 0; i < KBD_BUFFER_SIZE; i++)
+ EVENT_INIT (read_avail_input_buf[i]);
+ }
+#endif
+
/* This means that command_loop_1 won't try to select anything the first
time through. */