=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/stackmachine.c,v retrieving revision 1.24 retrieving revision 1.29 diff -u -p -r1.24 -r1.29 --- OpenXM/src/kan96xx/Kan/stackmachine.c 2004/09/12 08:55:36 1.24 +++ OpenXM/src/kan96xx/Kan/stackmachine.c 2004/09/19 00:47:47 1.29 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.23 2004/09/12 01:53:11 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.28 2004/09/17 02:42:57 takayama Exp $ */ /* stackmachin.c */ #include @@ -74,6 +74,7 @@ static strToInteger(char *); static power(int s,int i); static void pstack(void); static struct object executableStringToExecutableArray(char *str); +static int isThereExecutableArrayOnStack(int n); extern int SerialCurrent; extern int QuoteMode; @@ -295,6 +296,12 @@ int putUserDictionary2(str,h0,h1,attr,dic) } return(0); } + if (OR_ATTR_FOR_ALL_WORDS & attr) { + for (i=0; i "); } if (!Calling_ctrlC_hook) { /* to avoid recursive call of ctrlC-hook. */ - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode = RestrictedMode_saved; } Calling_ctrlC_hook = 0; KSexecuteString(" (Computation is interrupted.) "); /* move to ctrlC-hook? */ @@ -862,9 +897,11 @@ void ctrlC(sig) extern int SGClock; extern int UserCtrlC; extern int OXlock; + extern int RestrictedMode, RestrictedMode_saved; signal(sig,SIG_IGN); /* see 133p */ + RestrictedMode = RestrictedMode_saved; cancelAlarm(); if (sig == SIGALRM) { fprintf(stderr,"ctrlC by SIGALRM\n"); @@ -927,7 +964,10 @@ int executeToken(token) extern int WarningMessageMode; extern int Strict; extern int InSendmsg2; + extern int RestrictedMode, RestrictedMode_saved; + int localRestrictedMode_saved; + localRestrictedMode_saved = 0; if (GotoP) { /* for goto */ if (token.kind == ID && isLiteral(token.token)) { if (strcmp(&((token.token)[1]),GotoLabel) == 0) { @@ -981,7 +1021,23 @@ int executeToken(token) if (ob.tag >= 0) { /* there is a definition in the user dictionary */ if (ob.tag == SexecutableArray) { - status = executeExecutableArray(ob,token.token); + if (RestrictedMode) { + if (UD_attr & ATTR_EXPORT) { + localRestrictedMode_saved = RestrictedMode; RestrictedMode = 0; + if (isThereExecutableArrayOnStack(5)) { + int i; + for (i=0; i<5; i++) { (void) Kpop(); } + errorStackmachine("Executable array is on the argument stack (restricted mode). They are automatically removed.\n"); + } + }else{ + tracePushName(token.token); + errorStackmachine("You cannot execute this function in restricted mode.\n"); + } + } + + status = executeExecutableArray(ob,token.token,0); + + if (localRestrictedMode_saved) RestrictedMode = localRestrictedMode_saved; if ((status & STATUS_BREAK) || (status < 0)) return status; }else { Kpush(ob); @@ -1049,6 +1105,8 @@ errorStackmachine(str) char message0[1024]; char *message; extern int ErrorMessageMode; + extern int RestrictedMode, RestrictedMode_saved; + RestrictedMode = RestrictedMode_saved; cancelAlarm(); if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { pushErrorStack(KnewErrorPacket(SerialCurrent,-1,str)); @@ -1131,6 +1189,7 @@ KSexecuteString(s) jmp_buf saved_EnvOfStackMachine; void (*sigfunc)(); int localCatchCtrlC ; + extern int RestrictedMode, RestrictedMode_saved; localCatchCtrlC = CatchCtrlC; /* If CatchCtrlC is rewrited in this program, @@ -1157,8 +1216,9 @@ KSexecuteString(s) recursive--; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } if (!Calling_ctrlC_hook) { - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode_saved; } Calling_ctrlC_hook = 0; KSexecuteString(" (Computation is interrupted.) "); /* move to ctrlC-hook?*/ @@ -1179,8 +1239,9 @@ KSexecuteString(s) recursive = 0; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } if (!Calling_ctrlC_hook) { - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode = RestrictedMode_saved; } Calling_ctrlC_hook = 0; Calling_ctrlC_hook = 0; @@ -1580,8 +1641,8 @@ char *traceShowStack(void) { if (t == NULL) { s[p] = ';'; s[p+1] = 0; break; - }else if ((strlen(t) + p -10) > TRACE_MSG_SIZE) { - /* fprintf(stderr,"p=%d, TraceNameStackp=%d, strlen(t)=%d, t=%s\n",p,TraceNameStackp,strlen(t),t); */ + }else if ((strlen(t) + p) > (TRACE_MSG_SIZE-10)) { + /* fprintf(stderr,"p=%d, TraceNameStackp=%d, strlen(t)=%d, t=%s\n",p,TraceNameStackp,strlen(t),t); */ strcpy(&(s[p])," ..."); break; } @@ -1595,7 +1656,7 @@ char *traceShowStack(void) { /* if (fname != NULL) fname is pushed to the trace stack. */ -int executeExecutableArray(struct object ob,char *fname) { +int executeExecutableArray(struct object ob,char *fname,int withGotoP) { struct tokens *tokenArray; int size,i; int status; @@ -1611,7 +1672,7 @@ int executeExecutableArray(struct object ob,char *fnam size = ob.rc.ival; for (i=0; i