- register int c = -1;
- int old_errno = errno;
- extern EMACS_TIME *input_available_clear_time;
-
- if (waiting_for_ast)
- SYS$SETEF (input_ef);
- waiting_for_ast = 0;
- input_count++;
-#ifdef ASTDEBUG
- if (input_count == 25)
- exit (1);
- printf ("Ast # %d,", input_count);
- printf (" iosb = %x, %x, %x, %x",
- input_iosb.offset, input_iosb.status, input_iosb.termlen,
- input_iosb.term);
-#endif
- if (input_iosb.offset)
- {
- c = input_buffer;
-#ifdef ASTDEBUG
- printf (", char = 0%o", c);
-#endif
- }
-#ifdef ASTDEBUG
- printf ("\n");
- fflush (stdout);
- sleep (1);
-#endif
- if (! stop_input)
- queue_kbd_input ();
- if (c >= 0)
- {
- struct input_event e;
- EVENT_INIT (e);
-
- e.kind = ASCII_KEYSTROKE_EVENT;
- XSETINT (e.code, c);
- e.frame_or_window = selected_frame;
- kbd_buffer_store_event (&e);
- }
- if (input_available_clear_time)
- EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
- errno = old_errno;
-}
-
-/* Wait until there is something in kbd_buffer. */
-
-void
-wait_for_kbd_input ()
-{
- extern int have_process_input, process_exited;
-
- /* If already something, avoid doing system calls. */
- if (detect_input_pending ())
- {
- return;
- }
- /* Clear a flag, and tell ast routine above to set it. */
- SYS$CLREF (input_ef);
- waiting_for_ast = 1;
- /* Check for timing error: ast happened while we were doing that. */
- if (!detect_input_pending ())
- {
- /* No timing error: wait for flag to be set. */
- set_waiting_for_input (0);
- SYS$WFLOR (input_ef, input_eflist);
- clear_waiting_for_input ();
- if (!detect_input_pending ())
- /* Check for subprocess input availability */
- {
- int dsp = have_process_input || process_exited;
-
- SYS$CLREF (process_ef);
- if (have_process_input)
- process_command_input ();
- if (process_exited)
- process_exit ();
- if (dsp)
- {
- update_mode_lines++;
- prepare_menu_bars ();
- redisplay_preserve_echo_area (18);
- }
- }
- }
- waiting_for_ast = 0;
-}
-
-/* Get rid of any pending QIO, when we are about to suspend
- or when we want to throw away pending input.
- We wait for a positive sign that the AST routine has run
- and therefore there is no I/O request queued when we return.
- SYS$SETAST is used to avoid a timing error. */
-
-void
-end_kbd_input ()
-{
-#ifdef ASTDEBUG
- printf ("At end_kbd_input.\n");
- fflush (stdout);
- sleep (1);
-#endif
- if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
- {
- SYS$CANCEL (fileno (CURTTY()->input));
- return;
- }
-
- SYS$SETAST (0);
- /* Clear a flag, and tell ast routine above to set it. */
- SYS$CLREF (input_ef);
- waiting_for_ast = 1;
- stop_input = 1;
- SYS$CANCEL (fileno (CURTTY()->input));
- SYS$SETAST (1);
- SYS$WAITFR (input_ef);
- waiting_for_ast = 0;
-}
-
-/* Wait for either input available or time interval expiry. */
-
-void
-input_wait_timeout (timeval)
- int timeval; /* Time to wait, in seconds */
-{
- int time [2];
- static int zero = 0;
- static int large = -10000000;
-
- LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
-
- /* If already something, avoid doing system calls. */
- if (detect_input_pending ())
- {
- return;
- }
- /* Clear a flag, and tell ast routine above to set it. */
- SYS$CLREF (input_ef);
- waiting_for_ast = 1;
- /* Check for timing error: ast happened while we were doing that. */
- if (!detect_input_pending ())
- {
- /* No timing error: wait for flag to be set. */
- SYS$CANTIM (1, 0);
- if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */
- SYS$WFLOR (timer_ef, timer_eflist); /* Wait for timer expiry or input */
- }
- waiting_for_ast = 0;
-}
-
-/* The standard `sleep' routine works some other way
- and it stops working if you have ever quit out of it.
- This one continues to work. */
-
-sys_sleep (timeval)
- int timeval;
-{
- int time [2];
- static int zero = 0;
- static int large = -10000000;
-
- LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
-
- SYS$CANTIM (1, 0);
- if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */
- SYS$WAITFR (timer_ef); /* Wait for timer expiry only */
-}
-
-void
-init_sigio (fd)
- int fd;
-{
- request_sigio ();
-}
-
-reset_sigio (fd)
- int fd;
-{
- unrequest_sigio ();
-}
-
-void
-request_sigio ()
-{
- if (noninteractive)
- return;
- croak ("request sigio");
-}
-
-void
-unrequest_sigio ()
-{
- if (noninteractive)
- return;
- croak ("unrequest sigio");
-}
-
-#endif /* VMS */
-\f
-/* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
-#ifndef CANNOT_DUMP
-#define NEED_STARTS
-#endif
-
-#ifndef SYSTEM_MALLOC
-#ifndef NEED_STARTS
-#define NEED_STARTS
-#endif
-#endif
-
-#ifdef NEED_STARTS
-/* Some systems that cannot dump also cannot implement these. */
-
-/*
- * Return the address of the start of the text segment prior to
- * doing an unexec. After unexec the return value is undefined.
- * See crt0.c for further explanation and _start.
- *
- */
-
-#if !(defined (__NetBSD__) && defined (__ELF__))
-#ifndef HAVE_TEXT_START
-char *
-start_of_text ()
-{
-#ifdef TEXT_START
- return ((char *) TEXT_START);
-#else
- extern int _start ();
- return ((char *) _start);
-#endif /* TEXT_START */
-}
-#endif /* not HAVE_TEXT_START */
-#endif
-
-/*
- * Return the address of the start of the data segment prior to
- * doing an unexec. After unexec the return value is undefined.
- * See crt0.c for further information and definition of data_start.
- *
- * Apparently, on BSD systems this is etext at startup. On
- * USG systems (swapping) this is highly mmu dependent and
- * is also dependent on whether or not the program is running
- * with shared text. Generally there is a (possibly large)
- * gap between end of text and start of data with shared text.
- *
- * On Uniplus+ systems with shared text, data starts at a
- * fixed address. Each port (from a given oem) is generally
- * different, and the specific value of the start of data can
- * be obtained via the UniPlus+ specific "uvar" system call,
- * however the method outlined in crt0.c seems to be more portable.
- *
- * Probably what will have to happen when a USG unexec is available,
- * at least on UniPlus, is temacs will have to be made unshared so
- * that text and data are contiguous. Then once loadup is complete,
- * unexec will produce a shared executable where the data can be
- * at the normal shared text boundary and the startofdata variable
- * will be patched by unexec to the correct value.
- *
- */
-
-#ifndef start_of_data
-char *
-start_of_data ()
-{
-#ifdef DATA_START
- return ((char *) DATA_START);
-#else
-#ifdef ORDINARY_LINK
- /*
- * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
- * data_start isn't defined. We take the address of environ, which
- * is known to live at or near the start of the system crt0.c, and
- * we don't sweat the handful of bytes that might lose.
- */
- extern char **environ;
-
- return ((char *) &environ);
-#else
- extern int data_start;
- return ((char *) &data_start);
-#endif /* ORDINARY_LINK */
-#endif /* DATA_START */
-}
-#endif /* start_of_data */
-#endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
-\f
-/* init_system_name sets up the string for the Lisp function
- system-name to return. */
-
-#ifdef BSD4_1
-#include <whoami.h>
-#endif
-
-extern Lisp_Object Vsystem_name;
-
-#ifndef BSD4_1
-#ifndef VMS
-#ifdef HAVE_SOCKETS
-#include <sys/socket.h>
-#include <netdb.h>
-#endif /* HAVE_SOCKETS */
-#endif /* not VMS */
-#endif /* not BSD4_1 */
-
-#ifdef TRY_AGAIN
-#ifndef HAVE_H_ERRNO
-extern int h_errno;
-#endif
-#endif /* TRY_AGAIN */
-
-void
-init_system_name ()
-{
-#ifdef BSD4_1
- Vsystem_name = build_string (sysname);
-#else
-#ifdef VMS
- char *sp, *end;
- if ((sp = egetenv ("SYS$NODE")) == 0)
- Vsystem_name = build_string ("vax-vms");
- else if ((end = index (sp, ':')) == 0)
- Vsystem_name = build_string (sp);
- else
- Vsystem_name = make_string (sp, end - sp);
-#else