From 08d9e44c5fb7b3ca68922e054671a6021edfd1a5 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 5 Nov 1990 11:55:48 +0000 Subject: [PATCH] * Eliminate obsolete TTY I/O primitives. These have not been used for several months now. * If stdin or stdout is a terminal, save its state when entering Scheme, and restore it when leaving, as is done with the control terminal. Ignore any attempts to change the state if Scheme is not in the foreground. This code helps prevent buggy Scheme programs from screwing up the user's terminal. * On machines with TERMIOS and BSD_JOB_CONTROL, such as HP-UX, alter VSUSPC and t_suspc together. Altering one and not the other can cause the change to be lost. --- v7/src/microcode/osterm.h | 4 +- v7/src/microcode/ostty.h | 33 +------ v7/src/microcode/prosterm.c | 23 +---- v7/src/microcode/prostty.c | 171 +---------------------------------- v7/src/microcode/sysprim.c | 5 +- v7/src/microcode/uxctty.c | 175 +++++++++++++++++++++++++----------- v7/src/microcode/uxterm.c | 141 ++++------------------------- v7/src/microcode/uxterm.h | 3 +- v7/src/microcode/uxtop.c | 5 +- v7/src/microcode/uxtty.c | 110 ++--------------------- v7/src/microcode/version.h | 4 +- v8/src/microcode/version.h | 4 +- 12 files changed, 158 insertions(+), 520 deletions(-) diff --git a/v7/src/microcode/osterm.h b/v7/src/microcode/osterm.h index 5a75a0be3..a9bb60daf 100644 --- a/v7/src/microcode/osterm.h +++ b/v7/src/microcode/osterm.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osterm.h,v 1.3 1990/11/01 04:33:05 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osterm.h,v 1.4 1990/11/05 11:55:01 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -37,8 +37,6 @@ MIT in each case. */ #include "os.h" -extern int EXFUN (OS_terminal_read_char, (Tchannel channel)); -extern int EXFUN (OS_terminal_char_ready_p, (Tchannel channel, clock_t delay)); extern unsigned int EXFUN (OS_terminal_get_ispeed, (Tchannel channel)); extern unsigned int EXFUN (OS_terminal_get_ospeed, (Tchannel channel)); extern unsigned int EXFUN (arg_baud_index, (unsigned int argument)); diff --git a/v7/src/microcode/ostty.h b/v7/src/microcode/ostty.h index 93f8e80e8..33db9b756 100644 --- a/v7/src/microcode/ostty.h +++ b/v7/src/microcode/ostty.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/ostty.h,v 1.1 1990/06/20 19:36:54 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/ostty.h,v 1.2 1990/11/05 11:55:06 cph Rel $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -37,43 +37,12 @@ MIT in each case. */ #include "os.h" -/* New interface uses standard terminal and channel I/O. */ extern Tchannel EXFUN (OS_tty_input_channel, (void)); extern Tchannel EXFUN (OS_tty_output_channel, (void)); extern unsigned int EXFUN (OS_tty_x_size, (void)); extern unsigned int EXFUN (OS_tty_y_size, (void)); extern CONST char * EXFUN (OS_tty_command_beep, (void)); extern CONST char * EXFUN (OS_tty_command_clear, (void)); - -/* These are for the convenience of the microcode. */ -extern void EXFUN (OS_tty_write_char, (unsigned char c)); -extern void EXFUN (OS_tty_write_string, (CONST char * string)); -extern void EXFUN (OS_tty_beep, (void)); - -/* Old interface requires special entry points and buffered output. */ -extern int EXFUN (OS_tty_char_ready_p, (clock_t delay)); -extern unsigned char EXFUN (OS_tty_read_char, (void)); -extern unsigned char EXFUN (OS_tty_read_char_immediate, (void)); - -/* `OS_tty_clean_interrupts' is used to clear the input buffer when a - character interrupt is received. On most systems this is not - currently used, but the Emacs interface needs some assistance. - Normally this is used in conjunction with some kind of - distinguished marker in the input stream that indicates where each - interrupt occurred. - - The `mode' argument allows the following values: - - `tty_clean_most_recent' indicates that the input buffer should be - flushed up to and including the most recent interrupt marker. - - `tty_clean_multiple_copies' indicates that all interrupts which - match `interrupt_char' should be removed from the input buffer. - Any other interrupts should be left alone. */ - -enum tty_clean_mode { tty_clean_most_recent, tty_clean_multiple_copies }; extern cc_t EXFUN (OS_tty_next_interrupt_char, (void)); -extern int EXFUN - (OS_tty_clean_interrupts, (enum tty_clean_mode mode, cc_t interrupt_char)); #endif /* SCM_OSTTY_H */ diff --git a/v7/src/microcode/prosterm.c b/v7/src/microcode/prosterm.c index e645f2c32..1bc4488c4 100644 --- a/v7/src/microcode/prosterm.c +++ b/v7/src/microcode/prosterm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prosterm.c,v 1.4 1990/11/01 06:16:39 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prosterm.c,v 1.5 1990/11/05 11:55:10 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -49,27 +49,6 @@ DEFUN (arg_terminal, (argument_number), int argument_number) return (channel); } -DEFINE_PRIMITIVE ("TERMINAL-READ-CHAR", Prim_terminal_read_char, 1, 1, - "Read and return a single character from TERMINAL.") -{ - PRIMITIVE_HEADER (1); - { - int c = (OS_terminal_read_char (arg_terminal (1))); - PRIMITIVE_RETURN ((c < 0) ? SHARP_F : (ASCII_TO_CHAR (c))); - } -} - -DEFINE_PRIMITIVE ("TERMINAL-CHAR-READY?", Prim_terminal_char_ready_p, 2, 2, - "Return #T if a character from TERMINAL.\n\ -Second arg DELAY says how long to wait for one to arrive, in milliseconds.") -{ - PRIMITIVE_HEADER (2); - PRIMITIVE_RETURN - (BOOLEAN_TO_OBJECT - (OS_terminal_char_ready_p ((arg_terminal (1)), - (arg_nonnegative_integer (2))))); -} - DEFINE_PRIMITIVE ("TERMINAL-GET-ISPEED", Prim_terminal_get_ispeed, 1, 1, 0) { PRIMITIVE_HEADER (1); diff --git a/v7/src/microcode/prostty.c b/v7/src/microcode/prostty.c index 577bd7b02..b7212e5d3 100644 --- a/v7/src/microcode/prostty.c +++ b/v7/src/microcode/prostty.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prostty.c,v 1.1 1990/06/20 19:38:38 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prostty.c,v 1.2 1990/11/05 11:55:15 cph Rel $ Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology @@ -42,37 +42,6 @@ MIT in each case. */ #include "osfile.h" #include "osio.h" -static int transcript_file_open; -static Tchannel transcript_channel; - -void -DEFUN_VOID (OS_initialize_transcript_file) -{ - transcript_file_open = 0; - return; -} - -DEFINE_PRIMITIVE ("TRANSCRIPT-ON", Prim_transcript_on, 1, 1, 0) -{ - PRIMITIVE_HEADER (1); - if (transcript_file_open) - error_external_return (); - transcript_channel = (OS_open_output_file (STRING_ARG (1))); - transcript_file_open = 1; - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("TRANSCRIPT-OFF", Prim_transcript_off, 0, 0, 0) -{ - PRIMITIVE_HEADER (0); - if (transcript_file_open) - { - OS_channel_close (transcript_channel); - transcript_file_open = 0; - } - PRIMITIVE_RETURN (UNSPECIFIC); -} - DEFINE_PRIMITIVE ("TTY-INPUT-CHANNEL", Prim_tty_input_channel, 0, 0, "Return the standard input channel.") { @@ -114,118 +83,7 @@ DEFINE_PRIMITIVE ("TTY-COMMAND-CLEAR", Prim_tty_command_clear, 0, 0, PRIMITIVE_HEADER (0); PRIMITIVE_RETURN (char_pointer_to_string (OS_tty_command_clear ())); } - -DEFINE_PRIMITIVE ("TTY-READ-CHAR-READY?", Prim_tty_read_char_ready_p, 1, 1, - "This is an obsolete primitive.\n\ -Return #T iff a character is ready to be read from the console.\n\ -Argument DELAY says how many milliseconds to wait for a character.\n\ -If a character is typed, #T is returned immediately,\n\ - otherwise #F is returned after DELAY has expired.") -{ - PRIMITIVE_HEADER (1); - PRIMITIVE_RETURN - (BOOLEAN_TO_OBJECT (OS_tty_char_ready_p (arg_nonnegative_integer (1)))); -} -DEFINE_PRIMITIVE ("TTY-READ-CHAR", Prim_tty_read_char, 0, 0, - "This is an obsolete primitive.\n\ -Read a character from the console.\n\ -The operating system's input editor is used to provide the character.") -{ - PRIMITIVE_HEADER (0); - { - char c = (OS_tty_read_char ()); - if (transcript_file_open) - { - if ((OS_channel_write (transcript_channel, (&c), 1)) != 1) - error_external_return (); - } - PRIMITIVE_RETURN (ASCII_TO_CHAR (c)); - } -} - -DEFINE_PRIMITIVE ("TTY-READ-CHAR-IMMEDIATE", Prim_tty_read_char_immediate, 0, 0, - "This is an obsolete primitive.\n\ -Read a character from the console, without input editing.\n\ -First, any pending input is discarded,\n\ - then the next character typed is returned immediately.") -{ - PRIMITIVE_HEADER (0); - { - char c = (OS_tty_read_char_immediate ()); - if (transcript_file_open) - { - if ((OS_channel_write (transcript_channel, (&c), 1)) != 1) - error_external_return (); - } - PRIMITIVE_RETURN (ASCII_TO_CHAR (c)); - } -} - -DEFINE_PRIMITIVE ("TTY-WRITE-CHAR", Prim_tty_write_char, 1, 1, - "This is an obsolete primitive.\n\ -Write a character to the console.") -{ - PRIMITIVE_HEADER (1); - { - char c = (arg_ascii_char (1)); - OS_tty_write_char (c); - if (transcript_file_open) - { - if ((OS_channel_write (transcript_channel, (&c), 1)) != 1) - error_external_return (); - } - } - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("TTY-WRITE-STRING", Prim_tty_write_string, 1, 1, - "This is an obsolete primitive.\n\ -Write a string to the console.") -{ - PRIMITIVE_HEADER (1); - CHECK_ARG (1, STRING_P); - { - fast SCHEME_OBJECT argument = (ARG_REF (1)); - fast CONST PTR string = (STRING_LOC (argument, 0)); - OS_tty_write_string (string); - if (transcript_file_open) - { - long length = (STRING_LENGTH (argument)); - if ((OS_channel_write (transcript_channel, string, length)) != length) - error_external_return (); - } - } - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("TTY-FLUSH-OUTPUT", Prim_tty_flush_output, 0, 0, - "This is an obsolete primitive.\n\ -Write the contents of the console output buffer to the console.\n\ -Return after all of the contents has been written.") -{ - PRIMITIVE_HEADER (0); - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("TTY-BEEP", Prim_tty_beep, 0, 0, - "This is an obsolete primitive.\n\ -Ring the console bell.") -{ - PRIMITIVE_HEADER (0); - OS_tty_beep (); - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("TTY-CLEAR", Prim_tty_clear, 0, 0, - "This is an obsolete primitive.\n\ -Clear the console screen.") -{ - PRIMITIVE_HEADER (0); - OS_tty_write_string (OS_tty_command_clear ()); - PRIMITIVE_RETURN (UNSPECIFIC); -} - DEFINE_PRIMITIVE ("TTY-NEXT-INTERRUPT-CHAR", Prim_tty_next_interrupt_char, 0, 0, "Return the next interrupt character in the console input buffer.\n\ The character is returned as an unsigned integer.") @@ -233,20 +91,6 @@ The character is returned as an unsigned integer.") PRIMITIVE_HEADER (0); PRIMITIVE_RETURN (long_to_integer (OS_tty_next_interrupt_char ())); } - -DEFINE_PRIMITIVE ("TTY-CLEAN-INTERRUPTS", Prim_tty_clean_interrupts, 2, 2, - "Clear the input buffer for a character interrupt.\n\ -First arg MODE says how:\n\ - 0 ==> discard input up to the most recent interrupt marker\n\ - that matches second arg CHAR.\n\ - 1 ==> remove all interrupt markers that match second arg CHAR.\n\ -CHAR should be the result of a call to `tty-next-interrupt-char'.") -{ - PRIMITIVE_HEADER (2); - OS_tty_clean_interrupts ((arg_index_integer (1, 2)), - ((enum tty_clean_mode) (arg_ascii_integer (2)))); - PRIMITIVE_RETURN (UNSPECIFIC); -} DEFINE_PRIMITIVE ("TTY-GET-INTERRUPT-ENABLES", Prim_tty_get_interrupt_enables, 0, 0, "Return the current keyboard interrupt enables.") @@ -307,16 +151,3 @@ STRING must be in the correct form for this operating system.") } PRIMITIVE_RETURN (UNSPECIFIC); } - -DEFINE_PRIMITIVE ("SET-TTY-INTERRUPT-ENABLES!", Prim_set_tty_interrupt_enables, 1, 1, - "This primitive is obsolete.") -{ - PRIMITIVE_HEADER (1); - { - Tinterrupt_enables old; - Tinterrupt_enables new = (arg_integer (1)); - OS_ctty_get_interrupt_enables (&old); - OS_ctty_set_interrupt_enables (&new); - PRIMITIVE_RETURN (long_to_integer (old)); - } -} diff --git a/v7/src/microcode/sysprim.c b/v7/src/microcode/sysprim.c index 8039324f6..ed52919af 100644 --- a/v7/src/microcode/sysprim.c +++ b/v7/src/microcode/sysprim.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/sysprim.c,v 9.34 1990/06/20 17:42:19 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/sysprim.c,v 9.35 1990/11/05 11:55:19 cph Rel $ Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology @@ -72,7 +72,8 @@ DEFINE_PRIMITIVE ("SET-RUN-LIGHT!", Prim_set_run_light, 1, 1, 0) { PRIMITIVE_HEADER (1); #ifdef RUN_LIGHT_IS_BEEP - OS_tty_beep (); + fputs ((OS_tty_command_beep ()), stdout); + fflush (stdout); PRIMITIVE_RETURN (SHARP_T); #else PRIMITIVE_RETURN (SHARP_F); diff --git a/v7/src/microcode/uxctty.c b/v7/src/microcode/uxctty.c index eba651bea..2b37f82c6 100644 --- a/v7/src/microcode/uxctty.c +++ b/v7/src/microcode/uxctty.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxctty.c,v 1.2 1990/11/01 04:33:33 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxctty.c,v 1.3 1990/11/05 11:55:24 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -42,87 +42,160 @@ MIT in each case. */ terminal's settings. */ static int ctty_fildes; -/* If `ctty_fildes' is nonnegative, this flag says whether Scheme was - in the foreground when it was last entered. Provided that no other - process forces Scheme out of the foreground, it will remain in the - foreground until it exits or is stopped. +/* This flag says whether Scheme was in the foreground when it was + last entered. Provided that no other process forces Scheme out of + the foreground, it will remain in the foreground until it exits or + is stopped. - If `ctty_foreground' is zero, Scheme should not alter the control - terminal's settings. */ -static int ctty_foreground; + If `scheme_in_foreground' is zero, Scheme should not alter the + control terminal's settings, nor should it alter the settings of + stdin, stdout, or stderr if they are terminals. */ +int scheme_in_foreground; /* This flag, set during initialization, says whether we are permitted to change the settings of the control terminal. */ static int permit_ctty_control; -/* Original states of the control terminal when Scheme was last - continued or stopped, respectively. If the corresponding - `_recorded' flag is zero, then no information is saved. */ -static int outside_ctty_state_recorded; -static Ttty_state outside_ctty_state; -static int inside_ctty_state_recorded; -static Ttty_state inside_ctty_state; +/* Original states of the control terminal, stdin, and stdout when + Scheme was last continued or stopped, respectively. If the + corresponding `_recorded' flag is zero, then no information is + saved. */ + +struct terminal_state_recording +{ + int fd; + int recorded_p; + Ttty_state state; +}; + +static struct terminal_state_recording outside_ctty_state; +static struct terminal_state_recording outside_stdin_state; +static struct terminal_state_recording outside_stdout_state; +static struct terminal_state_recording inside_ctty_state; +static struct terminal_state_recording inside_stdin_state; +static struct terminal_state_recording inside_stdout_state; static void EXFUN (ctty_update_interrupt_chars, (void)); +static void +DEFUN (save_external_state, (s), struct terminal_state_recording * s) +{ + (s -> recorded_p) = + (scheme_in_foreground + && (isatty (s -> fd)) + && ((UX_terminal_get_state ((s -> fd), (& (s -> state)))) >= 0)); +} + +static void +DEFUN (restore_external_state, (s), struct terminal_state_recording * s) +{ + if (s -> recorded_p) + { + UX_terminal_set_state ((s -> fd), (& (s -> state))); + (s -> recorded_p) = 0; + } +} + +void +DEFUN (save_internal_state, (s, es), + struct terminal_state_recording * s AND + struct terminal_state_recording * es) +{ + /* Don't do anything unless we have a recording of the external + state. Otherwise, we should preserve the previous recording of + the internal state, if any. */ + if (es -> recorded_p) + (s -> recorded_p) = + ((UX_terminal_get_state ((s -> fd), (& (s -> state)))) >= 0); +} + +static void +DEFUN (restore_internal_state, (s, es), + struct terminal_state_recording * s AND + struct terminal_state_recording * es) +{ + /* When we recorded the internal state, we had a recording of the + external state. But since we've stopped Scheme and restarted it, + we may no longer have a current recording of the external state. + If we don't, then we can't restore the internal state. + + The usual reason that we don't have a recording is that Scheme is + in the background. In that case it would be nice to preserve the + previous internal state until we go back to the foreground. But + doing that transparently would also require tracking all + attempted state changes in the recording, which is a pain. So if + we can't restore the internal state, we just thrown it away. */ + if (s -> recorded_p) + { + if (es -> recorded_p) + UX_terminal_set_state ((s -> fd), (& (s -> state))); + (s -> recorded_p) = 0; + } +} + void DEFUN_VOID (UX_ctty_save_external_state) { if (permit_ctty_control && (ctty_fildes >= 0)) { pid_t pgrp_id = (UX_tcgetpgrp (ctty_fildes)); - ctty_foreground = + scheme_in_foreground = ((pgrp_id < 0) /* If no job control, assume we're in foreground. */ ? (errno == ENOSYS) : ((UX_getpgrp ()) == pgrp_id)); } else - ctty_foreground = 0; - outside_ctty_state_recorded = - (ctty_foreground && - ((UX_terminal_get_state (ctty_fildes, (&outside_ctty_state))) >= 0)); + scheme_in_foreground = 0; + save_external_state (&outside_ctty_state); + save_external_state (&outside_stdin_state); + save_external_state (&outside_stdout_state); } void DEFUN_VOID (UX_ctty_restore_internal_state) { - if (inside_ctty_state_recorded) - { - if (outside_ctty_state_recorded) - { - UX_terminal_set_state (ctty_fildes, (&inside_ctty_state)); - ctty_update_interrupt_chars (); - } - inside_ctty_state_recorded = 0; - } + save_internal_state ((&inside_ctty_state), (&outside_ctty_state)); + save_internal_state ((&inside_stdin_state), (&outside_stdin_state)); + save_internal_state ((&inside_stdout_state), (&outside_stdout_state)); } void DEFUN_VOID (UX_ctty_save_internal_state) { - inside_ctty_state_recorded = - (outside_ctty_state_recorded - ? ((UX_terminal_get_state (ctty_fildes, (&inside_ctty_state))) >= 0) - /* If outside state not recorded, we haven't changed anything, so - there's no need to save the inside state. */ - : 0); + int do_update = + ((inside_ctty_state . recorded_p) + && (outside_ctty_state . recorded_p)); + restore_internal_state ((&inside_ctty_state), (&outside_ctty_state)); + restore_internal_state ((&inside_stdin_state), (&outside_stdin_state)); + restore_internal_state ((&inside_stdout_state), (&outside_stdout_state)); + if (do_update) + ctty_update_interrupt_chars (); } void DEFUN_VOID (UX_ctty_restore_external_state) { - if (outside_ctty_state_recorded) - { - UX_terminal_set_state (ctty_fildes, (&outside_ctty_state)); - outside_ctty_state_recorded = 0; - } + restore_external_state (&outside_ctty_state); + restore_external_state (&outside_stdin_state); + restore_external_state (&outside_stdout_state); } int DEFUN_VOID (OS_ctty_interrupt_control) { - return (outside_ctty_state_recorded); + return (outside_ctty_state . recorded_p); +} + +int +DEFUN (UX_terminal_control_ok, (fd), int fd) +{ + return + ((fd == STDIN_FILENO) + ? (outside_stdin_state . recorded_p) + : (fd == STDOUT_FILENO) + ? (outside_stdout_state . recorded_p) + : 1); } /* Keyboard Interrupt Characters */ @@ -241,28 +314,21 @@ DEFUN (ctty_set_interrupt_chars, (ic), Tinterrupt_chars * ic) ((s . tio . c_cc) [VQUIT]) = (ic -> quit); ((s . tio . c_cc) [VINTR]) = (ic -> intrpt); ((s . tio . c_cc) [VSUSP]) = (ic -> tstp); -#ifdef HAVE_BSD_JOB_CONTROL - (s . ltc . t_dsuspc) = (ic -> dtstp); -#endif #else /* not HAVE_TERMIOS */ #ifdef HAVE_TERMIO ((s . tio . c_cc) [VQUIT]) = (ic -> quit); ((s . tio . c_cc) [VINTR]) = (ic -> intrpt); -#ifdef HAVE_BSD_JOB_CONTROL - (s . ltc . t_suspc) = (ic -> tstp); - (s . ltc . t_dsuspc) = (ic -> dtstp); -#endif #else /* not HAVE_TERMIO */ #ifdef HAVE_BSD_TTY_DRIVER (s . tc . t_quitc) = (ic -> quit); (s . tc . t_intrc) = (ic -> intrpt); +#endif /* HAVE_BSD_TTY_DRIVER */ +#endif /* HAVE_TERMIO */ +#endif /* HAVE_TERMIOS */ #ifdef HAVE_BSD_JOB_CONTROL (s . ltc . t_suspc) = (ic -> tstp); (s . ltc . t_dsuspc) = (ic -> dtstp); #endif -#endif /* HAVE_BSD_TTY_DRIVER */ -#endif /* HAVE_TERMIO */ -#endif /* HAVE_TERMIOS */ UX_terminal_set_state (ctty_fildes, (&s)); } } @@ -270,7 +336,7 @@ DEFUN (ctty_set_interrupt_chars, (ic), Tinterrupt_chars * ic) static void DEFUN_VOID (ctty_update_interrupt_chars) { - if (outside_ctty_state_recorded) + if (outside_ctty_state . recorded_p) { cc_t disabled_char = (UX_PC_VDISABLE (ctty_fildes)); /* Must split declaration and assignment because some compilers @@ -325,11 +391,14 @@ DEFUN (UX_initialize_ctty, (interactive), int interactive) } permit_ctty_control = interactive; UX_ctty_save_external_state (); + (inside_ctty_state . recorded_p) = 0; + (inside_stdin_state . recorded_p) = 0; + (inside_stdout_state . recorded_p) = 0; (current_interrupt_chars . quit) = DEFAULT_SIGQUIT_CHAR; (current_interrupt_chars . intrpt) = DEFAULT_SIGINT_CHAR; (current_interrupt_chars . tstp) = DEFAULT_SIGTSTP_CHAR; (current_interrupt_chars . dtstp) = (UX_PC_VDISABLE (ctty_fildes)); current_interrupt_enables = KEYBOARD_ALL_INTERRUPTS; - if (outside_ctty_state_recorded) + if (outside_ctty_state . recorded_p) ctty_set_interrupt_chars (¤t_interrupt_chars); } diff --git a/v7/src/microcode/uxterm.c b/v7/src/microcode/uxterm.c index 04d9eaa6c..6462dc8c0 100644 --- a/v7/src/microcode/uxterm.c +++ b/v7/src/microcode/uxterm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.c,v 1.5 1990/11/01 04:33:40 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.c,v 1.6 1990/11/05 11:55:29 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -101,22 +101,22 @@ DEFUN (terminal_open, (channel), Tchannel channel) get_terminal_state (channel, (& (TERMINAL_ORIGINAL_STATE (channel)))); } -int -DEFUN (OS_terminal_read_char, (channel), Tchannel channel) +void +DEFUN (get_terminal_state, (channel, s), Tchannel channel AND Ttty_state * s) { - { - int c = (TERMINAL_BUFFER (channel)); - if (c >= 0) - { - (TERMINAL_BUFFER (channel)) = (-1); - return (c); - } - } - { - unsigned char c; - long nread = (OS_channel_read (channel, (&c), 1)); - return ((nread == 1) ? c : (-1)); - } + STD_VOID_SYSTEM_CALL + ("terminal_get_state", + (UX_terminal_get_state ((CHANNEL_DESCRIPTOR (channel)), s))); +} + +void +DEFUN (set_terminal_state, (channel, s), Tchannel channel AND Ttty_state * s) +{ + extern int EXFUN (UX_terminal_control_ok, (int fd)); + if (UX_terminal_control_ok (CHANNEL_DESCRIPTOR (channel))) + STD_VOID_SYSTEM_CALL + ("terminal_set_state", + (UX_terminal_set_state ((CHANNEL_DESCRIPTOR (channel)), s))); } unsigned int @@ -269,115 +269,6 @@ DEFUN (terminal_state_buffered, (s, channel), #endif /* HAVE_TERMIOS or HAVE_TERMIO */ } -void -DEFUN (get_terminal_state, (channel, s), Tchannel channel AND Ttty_state * s) -{ - STD_VOID_SYSTEM_CALL - ("tty_get_state", - (UX_terminal_get_state ((CHANNEL_DESCRIPTOR (channel)), s))); -} - -void -DEFUN (set_terminal_state, (channel, s), Tchannel channel AND Ttty_state * s) -{ - STD_VOID_SYSTEM_CALL - ("tty_set_state", - (UX_terminal_set_state ((CHANNEL_DESCRIPTOR (channel)), s))); -} - -struct terminal_state_record -{ - Tchannel channel; - Ttty_state state; -}; - -static void -DEFUN (restore_terminal_state, (ap), PTR ap) -{ - set_terminal_state ((((struct terminal_state_record *) ap) -> channel), - (& (((struct terminal_state_record *) ap) -> state))); -} - -Ttty_state * -DEFUN (preserve_terminal_state, (channel), Tchannel channel) -{ - struct terminal_state_record * record = - (dstack_alloc (sizeof (struct terminal_state_record))); - (record -> channel) = channel; - get_terminal_state (channel, (& (record -> state))); - transaction_record_action (tat_always, restore_terminal_state, record); - return (& (record -> state)); -} - -#ifdef HAVE_FIONREAD -/* This covers HAVE_BSD_TTY_DRIVER and some others. */ - -int -DEFUN (OS_terminal_char_ready_p, (channel, delay), - Tchannel channel AND clock_t delay) -{ - clock_t limit; - if (delay > 0) - limit = ((OS_real_time_clock ()) + delay); - while (1) - { - long n; - int scr; - INTERRUPTABLE_EXTENT - (scr, (UX_ioctl ((CHANNEL_DESCRIPTOR (channel)), FIONREAD, (&n)))); - if (scr < 0) - UX_prim_check_errno ("ioctl_FIONREAD"); - else if (n > 0) - return (1); - else if ((delay <= 0) || ((OS_real_time_clock ()) >= limit)) - return (0); - } -} - -#else /* not HAVE_FIONREAD */ -#if defined(HAVE_TERMIO) || defined(HAVE_TERMIOS) - -int -DEFUN (OS_terminal_char_ready_p, (channel, delay), - Tchannel channel AND clock_t delay) -{ - clock_t limit; - if (delay > 0) - limit = ((OS_real_time_clock ()) + delay); - transaction_begin (); - { - /* Must split declaration and assignment because some compilers - do not permit aggregate initializers. */ - Ttty_state s; - s = (* (preserve_terminal_state (channel))); - terminal_state_nonbuffered ((&s), 1); - set_terminal_state (channel, (&s)); - } - while (1) - { - unsigned char c; - int nread; - INTERRUPTABLE_EXTENT - (nread, (UX_read ((CHANNEL_DESCRIPTOR (channel)), (&c), 1))); - if (nread < 0) - UX_prim_check_errno ("read"); - else if (nread == 1) - { - (TERMINAL_BUFFER (channel)) = c; - transaction_commit (); - return (1); - } - if ((delay <= 0) || ((OS_real_time_clock ()) >= limit)) - { - transaction_commit (); - return (0); - } - } -} - -#endif /* HAVE_TERMIO or HAVE_TERMIOS */ -#endif /* HAVE_FIONREAD */ - unsigned int DEFUN (OS_terminal_get_ispeed, (channel), Tchannel channel) { diff --git a/v7/src/microcode/uxterm.h b/v7/src/microcode/uxterm.h index fa8783e4b..fea0d8ca0 100644 --- a/v7/src/microcode/uxterm.h +++ b/v7/src/microcode/uxterm.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.h,v 1.1 1990/06/20 19:37:42 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.h,v 1.2 1990/11/05 11:55:34 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -44,6 +44,5 @@ extern void EXFUN (terminal_state_nonbuffered, (Ttty_state * s, int polling)); extern void EXFUN (terminal_state_raw, (Ttty_state * s)); extern void EXFUN (get_terminal_state, (Tchannel channel, Ttty_state * s)); extern void EXFUN (set_terminal_state, (Tchannel channel, Ttty_state * s)); -extern Ttty_state * EXFUN (preserve_terminal_state, (Tchannel channel)); #endif /* SCM_UXTERM_H */ diff --git a/v7/src/microcode/uxtop.c b/v7/src/microcode/uxtop.c index 22bb3cf48..f2a2d7c0d 100644 --- a/v7/src/microcode/uxtop.c +++ b/v7/src/microcode/uxtop.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtop.c,v 1.4 1990/08/16 23:36:36 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtop.c,v 1.5 1990/11/05 11:55:38 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -54,8 +54,6 @@ extern void EXFUN (UX_reset_processes, (void)); extern void EXFUN (UX_reset_terminals, (void)); extern void EXFUN (execute_reload_cleanups, (void)); -extern void EXFUN (OS_initialize_transcript_file, (void)); - extern void EXFUN (UX_ctty_save_external_state, (void)); extern void EXFUN (UX_ctty_save_internal_state, (void)); extern void EXFUN (UX_ctty_restore_internal_state, (void)); @@ -109,7 +107,6 @@ DEFUN_VOID (OS_initialize) UX_initialize_signals (); UX_initialize_trap_recovery (); UX_initialize_directory_reader (); - OS_initialize_transcript_file (); OS_Name = SYSTEM_NAME; OS_Variant = SYSTEM_VARIANT; fprintf (stdout, "MIT Scheme running under %s\n", OS_Variant); diff --git a/v7/src/microcode/uxtty.c b/v7/src/microcode/uxtty.c index 8e763507a..81e640e55 100644 --- a/v7/src/microcode/uxtty.c +++ b/v7/src/microcode/uxtty.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtty.c,v 1.2 1990/06/21 20:01:58 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtty.c,v 1.3 1990/11/05 11:55:43 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -38,9 +38,14 @@ MIT in each case. */ #include "uxio.h" #include "uxterm.h" -/* Standard Input */ +/* Standard Input and Output */ static Tchannel input_channel; +static Tchannel output_channel; +static int tty_x_size; +static int tty_y_size; +static CONST char * tty_command_beep; +static CONST char * tty_command_clear; Tchannel DEFUN_VOID (OS_tty_input_channel) @@ -48,84 +53,6 @@ DEFUN_VOID (OS_tty_input_channel) return (input_channel); } -/* New input interface doesn't require the following, because they - can be provided by standard terminal and channel operations. */ - -static unsigned char -DEFUN (tty_read_char, (immediate), int immediate) -{ - if ((OS_channel_type (input_channel)) == channel_type_terminal) - { - transaction_begin (); - preserve_terminal_state (input_channel); - if (immediate) - OS_terminal_nonbuffered (input_channel); - else - OS_terminal_buffered (input_channel); - { - int c = (OS_terminal_read_char (input_channel)); - if (c == (-1)) - termination_eof (); - transaction_commit (); - return ((unsigned char) c); - } - } - else - { - unsigned char c; - if ((OS_channel_read (input_channel, (&c), 1)) != 1) - termination_eof (); - if ((OS_channel_type (input_channel)) == channel_type_file) - OS_tty_write_char (c); - return (c); - } -} - -unsigned char -DEFUN_VOID (OS_tty_read_char) -{ - return (tty_read_char (0)); -} - -unsigned char -DEFUN_VOID (OS_tty_read_char_immediate) -{ - return (tty_read_char (1)); -} - -int -DEFUN (OS_tty_char_ready_p, (delay), clock_t delay) -{ - if ((OS_channel_type (input_channel)) == channel_type_terminal) - return (OS_terminal_char_ready_p (input_channel, delay)); - if (delay > 0) - { - clock_t limit = ((OS_real_time_clock ()) + delay); - while ((OS_real_time_clock ()) < limit) - ; - } - return (0); -} - -int -DEFUN (OS_tty_clean_interrupts, (mode, interrupt_char), - enum tty_clean_mode mode AND - cc_t interrupt_char) -{ - if (parent_process_is_emacs && (mode == tty_clean_most_recent)) - while ((OS_tty_read_char_immediate ()) != '\0') - ; - return (1); -} - -/* Standard Output */ - -static Tchannel output_channel; -static int tty_x_size; -static int tty_y_size; -static CONST char * tty_command_beep; -static CONST char * tty_command_clear; - Tchannel DEFUN_VOID (OS_tty_output_channel) { @@ -169,29 +96,6 @@ DEFUN_VOID (OS_tty_command_clear) { return (tty_command_clear); } - -/* Old output interface requires output buffering at the microcode - level. The new runtime system will provide the buffering so that - the microcode doesn't have to. */ - -void -DEFUN (OS_tty_write_char, (c), unsigned char c) -{ - if ((OS_channel_write (output_channel, (&c), 1)) != 1) - error_external_return (); -} - -void -DEFUN (OS_tty_write_string, (s), CONST char * s) -{ - OS_channel_write_string (output_channel, s); -} - -void -DEFUN_VOID (OS_tty_beep) -{ - OS_channel_write_string (output_channel, tty_command_beep); -} #ifndef TERMCAP_BUFFER_SIZE #define TERMCAP_BUFFER_SIZE 2048 diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index be72ca239..442a7b93f 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.50 1990/11/01 04:33:46 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.51 1990/11/05 11:55:48 cph Exp $ Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology @@ -46,7 +46,7 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 50 +#define SUBVERSION 51 #endif #ifndef UCODE_TABLES_FILENAME diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index c6bc474eb..de15b3478 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.50 1990/11/01 04:33:46 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.51 1990/11/05 11:55:48 cph Exp $ Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology @@ -46,7 +46,7 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 50 +#define SUBVERSION 51 #endif #ifndef UCODE_TABLES_FILENAME -- 2.25.1