=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/stackmachine.c,v retrieving revision 1.8 retrieving revision 1.11 diff -u -p -r1.8 -r1.11 --- OpenXM/src/kan96xx/Kan/stackmachine.c 2001/12/19 23:39:53 1.8 +++ OpenXM/src/kan96xx/Kan/stackmachine.c 2002/11/04 11:08:59 1.11 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.7 2001/05/04 01:06:25 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.10 2002/11/04 10:53:56 takayama Exp $ */ /* stackmachin.c */ #include @@ -736,7 +736,11 @@ void scanner() { getokenSM(INIT); initSystemDictionary(); +#if defined(__CYGWIN__) + if (sigsetjmp(EnvOfStackMachine,1)) { +#else if (setjmp(EnvOfStackMachine)) { +#endif /* do nothing in the case of error */ fprintf(stderr,"An error or interrupt in reading macros, files and command strings.\n"); exit(10); @@ -796,7 +800,11 @@ void scanner() { for (;;) { +#if defined(__CYGWIN__) + if (jval=sigsetjmp(EnvOfStackMachine,1)) { +#else if (jval=setjmp(EnvOfStackMachine)) { +#endif /* *** The following does not work properly. **** if (jval == 2) { if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { @@ -808,6 +816,7 @@ void scanner() { fprintf(Fstack,"\nscanner> "); } KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + KSexecuteString(" (Computation is interrupted.) "); continue ; } else { } if (DebugStack >= 1) { printOperandStack(); } @@ -829,11 +838,15 @@ void ctrlC(sig) signal(sig,SIG_IGN); /* see 133p */ + cancelAlarm(); + if (sig == SIGALRM) { + fprintf(stderr,"ctrlC by SIGALRM\n"); + } if (SGClock) { UserCtrlC = 1; fprintf(stderr,"ctrl-c is locked because of gc.\n"); - signal(SIGINT,ctrlC); + signal(sig,ctrlC); if (sig == SIGALRM) alarm((unsigned int)10); return; } if (OXlock) { @@ -846,7 +859,7 @@ void ctrlC(sig) unlockCtrlCForOx(); } fprintf(stderr,"ctrl-c is locked because of ox lock %d.\n",UserCtrlC); - signal(SIGINT,ctrlC); + signal(sig,ctrlC); if (sig == SIGALRM) alarm((unsigned int)10); return; } if (ErrorMessageMode != 1) { @@ -867,7 +880,11 @@ void ctrlC(sig) */ getokenSM(INIT); /* It might fix the bug above. 1992/11/14 */ signal(SIGINT,ctrlC); +#if defined(__CYGWIN__) + siglongjmp(EnvOfStackMachine,2); +#else longjmp(EnvOfStackMachine,2); /* returns 2 for ctrl-C */ +#endif } int executeToken(token) @@ -992,6 +1009,7 @@ errorStackmachine(str) char message0[1024]; char *message; extern int ErrorMessageMode; + cancelAlarm(); if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { pushErrorStack(KnewErrorPacket(SerialCurrent,-1,str)); } @@ -1083,7 +1101,11 @@ KSexecuteString(s) if (KSPushEnvMode) { *saved_EnvOfStackMachine = *EnvOfStackMachine; +#if defined(__CYGWIN__) + if (jval = sigsetjmp(EnvOfStackMachine,1)) { +#else if (jval = setjmp(EnvOfStackMachine)) { +#endif *EnvOfStackMachine = *saved_EnvOfStackMachine; if (jval == 2) { if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { @@ -1092,11 +1114,17 @@ KSexecuteString(s) } recursive--; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } + KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + KSexecuteString(" (Computation is interrupted.) "); return(-1); }else{ } }else{ if (recursive == 0) { +#if defined(__CYGWIN__) + if (jval=sigsetjmp(EnvOfStackMachine,1)) { +#else if (jval=setjmp(EnvOfStackMachine)) { +#endif if (jval == 2) { if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { pushErrorStack(KnewErrorPacket(SerialCurrent,-1,"User interrupt by ctrl-C.")); @@ -1104,6 +1132,8 @@ KSexecuteString(s) } recursive = 0; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } + KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + KSexecuteString(" (Computation is interrupted.) "); return(-1); }else { } } @@ -1450,4 +1480,8 @@ struct object KSdupErrors() { } return(rob); } - + +void cancelAlarm() { + alarm((unsigned int) 0); + signal(SIGALRM,SIG_DFL); +}