From: Chris Hanson Date: Mon, 8 Nov 1993 20:58:27 +0000 (+0000) Subject: Implement mechanism to delete temporary files when Scheme exits. X-Git-Tag: 20090517-FFI~7580 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=1fb99c6ead7c558f60e120f85430953684285604;p=mit-scheme.git Implement mechanism to delete temporary files when Scheme exits. Reimplement Edwin auto-save mechanism to use new error-catching. --- diff --git a/v7/src/microcode/term.c b/v7/src/microcode/term.c index 7ff1636ca..ae04d9eac 100644 --- a/v7/src/microcode/term.c +++ b/v7/src/microcode/term.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: term.c,v 1.9 1993/08/31 18:54:33 gjr Exp $ +$Id: term.c,v 1.10 1993/11/08 20:58:12 cph Exp $ Copyright (c) 1990-1993 Massachusetts Institute of Technology @@ -42,7 +42,7 @@ extern void EXFUN (get_band_parameters, (long * heap_size, long * const_size)); extern void EXFUN (Reset_Memory, (void)); static void EXFUN (edwin_auto_save, (void)); -static SCHEME_OBJECT edwin_auto_save_position; +static void EXFUN (delete_temp_files, (void)); #define BYTES_TO_BLOCKS(n) (((n) + 1023) / 1024) #define MIN_HEAP_DELTA 50 @@ -61,7 +61,6 @@ DEFUN_VOID (init_exit_scheme) #ifdef INIT_EXIT_SCHEME INIT_EXIT_SCHEME (); #endif - edwin_auto_save_position = SHARP_T; } static void @@ -135,6 +134,7 @@ DEFUN (termination_suffix, (code, value, abnormal_p), EXIT_HOOK (code, value, abnormal_p); #endif edwin_auto_save (); + delete_temp_files (); #if WINNT if (code != TERM_HALT) outf_flush_fatal(); /*dont salute*/ winnt_deallocate_registers(); @@ -249,21 +249,17 @@ DEFUN (termination_signal, (signal_name), CONST char * signal_name) static void DEFUN_VOID (edwin_auto_save) { - /* edwin_auto_save_position remembers what is left to be done after - this save. That way, if the save aborts due to an error and we - end up back here, we continue saving, skipping the entries - already saved as well as the entry that caused the error. */ - if (edwin_auto_save_position == SHARP_T) - { - if (Valid_Fixed_Obj_Vector ()) - edwin_auto_save_position = (Get_Fixed_Obj_Slot (FIXOBJ_EDWIN_AUTO_SAVE)); - else - edwin_auto_save_position = SHARP_F; - } - while (PAIR_P (edwin_auto_save_position)) + static SCHEME_OBJECT position; + static struct interpreter_state_s new_state; + + position = + ((Valid_Fixed_Obj_Vector ()) + ? (Get_Fixed_Obj_Slot (FIXOBJ_EDWIN_AUTO_SAVE)) + : EMPTY_LIST); + while (PAIR_P (position)) { - SCHEME_OBJECT entry = (PAIR_CAR (edwin_auto_save_position)); - edwin_auto_save_position = (PAIR_CDR (edwin_auto_save_position)); + SCHEME_OBJECT entry = (PAIR_CAR (position)); + position = (PAIR_CDR (position)); if ((PAIR_P (entry)) && (GROUP_P (PAIR_CAR (entry))) && (STRING_P (PAIR_CDR (entry))) @@ -276,18 +272,47 @@ DEFUN_VOID (edwin_auto_save) unsigned char * end = (start + (STRING_LENGTH (text))); unsigned char * gap_start = (start + (GROUP_GAP_START (group))); unsigned char * gap_end = (start + (GROUP_GAP_END (group))); - Tchannel channel; if ((start < gap_start) || (gap_end < end)) { - outf_error ("Auto-saving file \"%s\"\n", namestring); - outf_flush_error (); - channel = (OS_open_output_file (namestring)); - if (start < gap_start) - OS_channel_write (channel, start, (gap_start - start)); - if (gap_end < end) - OS_channel_write (channel, gap_end, (end - gap_end)); - OS_channel_close (channel); + bind_interpreter_state (&new_state); + if ((setjmp (interpreter_catch_env)) == 0) + { + Tchannel channel; + outf_error ("Auto-saving file \"%s\"\n", namestring); + outf_flush_error (); + channel = (OS_open_output_file (namestring)); + if (start < gap_start) + OS_channel_write (channel, start, (gap_start - start)); + if (gap_end < end) + OS_channel_write (channel, gap_end, (end - gap_end)); + OS_channel_close (channel); + } + unbind_interpreter_state (&new_state); } } } } + +static void +DEFUN_VOID (delete_temp_files) +{ + static SCHEME_OBJECT position; + static struct interpreter_state_s new_state; + + position = + ((Valid_Fixed_Obj_Vector ()) + ? (Get_Fixed_Obj_Slot (FIXOBJ_FILES_TO_DELETE)) + : EMPTY_LIST); + while (PAIR_P (position)) + { + SCHEME_OBJECT entry = (PAIR_CAR (position)); + position = (PAIR_CDR (position)); + if (STRING_P (entry)) + { + bind_interpreter_state (&new_state); + if ((setjmp (interpreter_catch_env)) == 0) + OS_file_remove ((char *) (STRING_LOC (entry, 0))); + unbind_interpreter_state (&new_state); + } + } +} diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 99bacf5e8..bb1347d0e 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: version.h,v 11.144 1993/10/14 19:20:27 gjr Exp $ +$Id: version.h,v 11.145 1993/11/08 20:58:27 cph Exp $ Copyright (c) 1988-1993 Massachusetts Institute of Technology @@ -46,5 +46,5 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 144 +#define SUBVERSION 145 #endif diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index 99bacf5e8..bb1347d0e 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: version.h,v 11.144 1993/10/14 19:20:27 gjr Exp $ +$Id: version.h,v 11.145 1993/11/08 20:58:27 cph Exp $ Copyright (c) 1988-1993 Massachusetts Institute of Technology @@ -46,5 +46,5 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 144 +#define SUBVERSION 145 #endif