From 48973e4ca93705aafe7348be024189e6fdf5badf Mon Sep 17 00:00:00 2001 From: "Guillermo J. Rozas" Date: Wed, 1 Sep 1993 18:45:02 +0000 Subject: [PATCH] Add select capability to NT version. --- v7/src/microcode/ntio.c | 160 ++++++++++++++++++--------------------- v7/src/microcode/ntsig.c | 19 +++-- v7/src/microcode/nttop.c | 10 ++- 3 files changed, 89 insertions(+), 100 deletions(-) diff --git a/v7/src/microcode/ntio.c b/v7/src/microcode/ntio.c index 4a0372436..28588d993 100644 --- a/v7/src/microcode/ntio.c +++ b/v7/src/microcode/ntio.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntio.c,v 1.7 1993/08/21 03:34:00 gjr Exp $ +$Id: ntio.c,v 1.8 1993/09/01 18:42:20 gjr Exp $ Copyright (c) 1992-1993 Massachusetts Institute of Technology @@ -66,8 +66,9 @@ DEFUN_VOID (NT_channel_close_all) return; } +#ifndef GUI static BOOL _stdcall -NT_ctrl_handler(DWORD dwCtrlType) +NT_ctrl_handler (DWORD dwCtrlType) { switch (dwCtrlType) { case CTRL_C_EVENT: @@ -77,64 +78,8 @@ NT_ctrl_handler(DWORD dwCtrlType) return FALSE; } } - - -extern HANDLE master_tty_window; - - -void -DEFUN_VOID (NT_initialize_channels) -{ -#ifndef GUI - STDIN_HANDLE = (GetStdHandle (STD_INPUT_HANDLE)); - STDOUT_HANDLE = (GetStdHandle (STD_OUTPUT_HANDLE)); - STDERR_HANDLE = (GetStdHandle (STD_ERROR_HANDLE)); - - if (STDIN_HANDLE == INVALID_HANDLE_VALUE || - STDOUT_HANDLE == INVALID_HANDLE_VALUE || - STDERR_HANDLE == INVALID_HANDLE_VALUE) - { - outf_fatal ("\nUnable to get standard handles %s(%d).\n", - __FILE__, __LINE__); - termination_init_error (); - } - - SetConsoleMode (STDIN_HANDLE, - ( ENABLE_LINE_INPUT - | ENABLE_ECHO_INPUT - | ENABLE_PROCESSED_INPUT)); - SetConsoleCtrlHandler (NT_ctrl_handler, TRUE); #endif /* GUI */ - master_tty_window = Screen_Create (NULL, "MIT Scheme", SW_SHOWNORMAL); - - OS_channel_table_size = (NT_SC_OPEN_MAX ()); - channel_table = - (NT_malloc (OS_channel_table_size * (sizeof (struct channel)))); - if (channel_table == 0) - { - outf_fatal ("\nUnable to allocate channel table.\n"); - termination_init_error (); - } - { - Tchannel channel; - for (channel = 0; (channel < OS_channel_table_size); channel += 1) - MARK_CHANNEL_CLOSED (channel); - } - add_reload_cleanup (NT_channel_close_all); - OS_channels_registered = 0; - return; -} - -void -DEFUN_VOID (NT_reset_channels) -{ - NT_free (channel_table); - channel_table = 0; - OS_channel_table_size = 0; - return; -} - Tchannel DEFUN_VOID (channel_allocate) { @@ -595,39 +540,78 @@ DEFUN (OS_channel_unregister, (channel), Tchannel channel) return; } -/* Hold-over from DOS. - This needs to be updated to use the NT equivalent. - */ +/* Initialization/Termination code. */ -CONST int OS_have_select_p = 0; +int OS_have_select_p = 0; -long -DEFUN (OS_channel_select_then_read, (channel, buffer, nbytes), - Tchannel channel AND - PTR buffer AND - size_t nbytes) -{ /* We can't really select amongst channels in DOS, but still need - to keep track of whether the read was interrupted. - */ - while (1) +extern HANDLE master_tty_window; +extern BOOL win32_under_win32s_p (void); +extern void EXFUN (NT_initialize_channels, (void)); +extern void EXFUN (NT_reset_channels, (void)); +extern void EXFUN (NT_restore_channels, (void)); + +void +DEFUN_VOID (NT_reset_channels) +{ + NT_free (channel_table); + channel_table = 0; + OS_channel_table_size = 0; + return; +} + +void +DEFUN_VOID (NT_restore_channels) +{ + if (master_tty_window != ((HANDLE) NULL)) + Screen_Destroy (TRUE, master_tty_window); + master_tty_window = ((HANDLE) NULL); + return; +} + +void +DEFUN_VOID (NT_initialize_channels) +{ +#ifndef GUI + STDIN_HANDLE = (GetStdHandle (STD_INPUT_HANDLE)); + STDOUT_HANDLE = (GetStdHandle (STD_OUTPUT_HANDLE)); + STDERR_HANDLE = (GetStdHandle (STD_ERROR_HANDLE)); + + if (STDIN_HANDLE == INVALID_HANDLE_VALUE || + STDOUT_HANDLE == INVALID_HANDLE_VALUE || + STDERR_HANDLE == INVALID_HANDLE_VALUE) { - long scr = (nt_channel_read (channel, buffer, nbytes)); + outf_fatal ("\nUnable to get standard handles %s(%d).\n", + __FILE__, __LINE__); + termination_init_error (); + } - if (scr < 0) - { - if (errno == ERRNO_NONBLOCK) - return -1; - else if (errno == EINTR) - return -4; - else - { - NT_prim_check_errno (syscall_read); - continue; - } - } - else if (((size_t) scr) > nbytes) - error_external_return (); - else - return (scr); + SetConsoleMode (STDIN_HANDLE, + ( ENABLE_LINE_INPUT + | ENABLE_ECHO_INPUT + | ENABLE_PROCESSED_INPUT)); + SetConsoleCtrlHandler (NT_ctrl_handler, TRUE); +#endif /* GUI */ + + master_tty_window = Screen_Create (NULL, "MIT Scheme", SW_SHOWNORMAL); + + if (win32s_under_win32s_p ()) + OS_have_select = 0; + else + OS_have_select = 1; + OS_channel_table_size = (NT_SC_OPEN_MAX ()); + channel_table = + (NT_malloc (OS_channel_table_size * (sizeof (struct channel)))); + if (channel_table == 0) + { + outf_fatal ("\nUnable to allocate channel table.\n"); + termination_init_error (); } + { + Tchannel channel; + for (channel = 0; (channel < OS_channel_table_size); channel += 1) + MARK_CHANNEL_CLOSED (channel); + } + add_reload_cleanup (NT_channel_close_all); + OS_channels_registered = 0; + return; } diff --git a/v7/src/microcode/ntsig.c b/v7/src/microcode/ntsig.c index 4ec8e4ac0..a7d6d4bcc 100644 --- a/v7/src/microcode/ntsig.c +++ b/v7/src/microcode/ntsig.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntsig.c,v 1.7 1993/08/21 03:45:54 gjr Exp $ +$Id: ntsig.c,v 1.8 1993/09/01 18:44:09 gjr Exp $ Copyright (c) 1992-1993 Massachusetts Institute of Technology @@ -280,12 +280,12 @@ DEFUN_VOID (initialize_keyboard_interrupt_table) int_handlers[4] = ((unsigned char) interrupt_handler_interactive); int_chars[5] = CONTROL_BREAK; int_handlers[5] = ((unsigned char) interrupt_handler_terminate); - update_interrupt_characters (); keyboard_interrupt_enables = (CONTROL_B_ENABLE | CONTROL_G_ENABLE | CONTROL_U_ENABLE | CONTROL_X_ENABLE | INTERACTIVE_INTERRUPT_ENABLE | TERMINATE_INTERRUPT_ENABLE); + update_interrupt_characters (); return; } @@ -349,7 +349,7 @@ DEFUN (signal_keyboard_character_interrupt, (c), int c) console_write_string ("\nTerminating scheme!"); termination_normal (0); } - goto interactive_interrupt; + tty_set_next_interrupt_char (CONTROL_G_INTERRUPT_CHAR); } return (0); } @@ -386,7 +386,7 @@ DEFUN (signal_keyboard_character_interrupt, (c), int c) } interactive_interrupt: print_interrupt_help (); - interrupt_p = 0; + interrupt_p = 1; break; default: @@ -407,10 +407,11 @@ DEFUN_VOID (OS_restartable_exit) /* Why does this raise INT_Timer as well? We could request an synchronous Windows timer that would trigger - the timer interrupt bit. + the timer interrupt bit. -- This does not seem to work! - INT_Global_1: Windows polling interrupt - INT_Timer: Scheme timer interrupt + INT_Global_GC: High-priority Windows polling interrupt. + INT_Global_1: Windows polling interrupt. + INT_Timer: Thread-switch timer interrupt. */ static void * timer_state = ((void *) NULL); @@ -422,7 +423,9 @@ DEFUN_VOID (install_timer) REGBLOCK_MEMTOP, REGBLOCK_INT_CODE, REGBLOCK_INT_MASK, - (INT_Global_1 | INT_Timer), + (INT_Global_GC + | INT_Global_1 + | INT_Timer), &timer_state)) { case WIN32_ASYNC_TIMER_OK: diff --git a/v7/src/microcode/nttop.c b/v7/src/microcode/nttop.c index b149f4d5a..f6a56e1ac 100644 --- a/v7/src/microcode/nttop.c +++ b/v7/src/microcode/nttop.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: nttop.c,v 1.7 1993/08/21 03:48:26 gjr Exp $ +$Id: nttop.c,v 1.8 1993/09/01 18:45:02 gjr Exp $ Copyright (c) 1993 Massachusetts Institute of Technology @@ -52,6 +52,7 @@ extern void EXFUN (NT_initialize_tty, (void)); extern void EXFUN (NT_reset_channels, (void)); +extern void EXFUN (NT_restore_channels, (void)); extern void EXFUN (NT_restore_signals, (void)); extern void EXFUN (NT_restore_traps, (void)); @@ -89,16 +90,16 @@ DEFUN_VOID (OS_initialize) version_t version_number; nt_get_version (&version_number); - outf_console ("MIT Scheme running under %s %d.%d 386/486\r\n", + outf_console ("MIT Scheme running under %s %d.%d 386/486\n", OS_Variant, ((int) version_number.major), ((int) version_number.minor)); /* To make our compiler vendors happy. */ outf_console - ("Copyright (c) 1993 Massachusetts Institute of Technology\r\n"); + ("Copyright (c) 1993 Massachusetts Institute of Technology\n"); } - outf_console ("\r\n"); + outf_console ("\n"); outf_flush_console (); return; } @@ -199,6 +200,7 @@ OS_restore_external_state (void) { NT_restore_traps (); NT_restore_signals (); + NT_restore_channels (); return; } -- 2.25.1