mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-10-06 01:43:00 +02:00
Restore terminal if exit is called inside a TCL script at startup
If exit is called in a TCL script that is executed at startup, the libc exit() function is called directly and we don't get a chance to reset the terminal. We return to the shell with echo off, and have to run "reset". A simple example: echo exit > test.tcl magic -noconsole -dnull test.tcl There are a few ways we could solve this. We could register an exit handler using atexit(). Here I use Tcl_SetExitProc() to register a callback with the TCL interpreter.
This commit is contained in:
committed by
Anton Blanchard
parent
48b04385c3
commit
bdeb4bab50
@@ -770,6 +770,12 @@ mainInitAfterArgs()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tcl_exit_hook(ClientData clientData)
|
||||
{
|
||||
TxResetTerminal();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* mainInitFinal:
|
||||
@@ -794,6 +800,9 @@ mainInitFinal()
|
||||
char *rname;
|
||||
int result;
|
||||
|
||||
/* Reset terminal if exit is called inside a TCL script */
|
||||
Tcl_SetExitProc(tcl_exit_hook);
|
||||
|
||||
#ifdef MAGIC_WRAPPER
|
||||
|
||||
/* Read in system pre-startup file, if it exists. */
|
||||
@@ -1187,6 +1196,8 @@ mainInitFinal()
|
||||
UndoFlush();
|
||||
TxClearPoint();
|
||||
|
||||
Tcl_SetExitProc(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user