📄 int_toplevel.c
字号:
void CloseToplevel(void) /* merde CAREFUL WITH stdnull */{ int i,l; LEVEL level; /* If it is the last Toplevel, we have to write the history file before deleting it */ if (nToplevel == 1) { WriteHistory(toplevelCur->history,GetHistoryFile()); } DeleteHistory(toplevelCur->history); /* Delete the prompt script if any */ if (toplevelCur->promptProc != NULL) DeleteProc(toplevelCur->promptProc); /* Delete all the levels */ for (l = toplevelCur->nLevel-1; l>= 0;l--) { level = &(toplevelCur->levels[l]); DeleteHashTable(level->theVariables); CloseStream(level->out); CloseStream(level->in); CloseStream(level->err); } /* Close all the non-closed streams */ CloseStream(toplevelCur->in); CloseStream(toplevelCur->out); CloseStream(toplevelCur->err); for (i=toplevelCur->nStream-1;i>=0;i--) CloseStream(toplevelCur->theStreams[i]); /* There's one toplevel less ! */ nToplevel--; /* we restore some stuff */ if (nToplevel != 0) { toplevelCur = theToplevels[nToplevel-1]; levelCur = &(toplevelCur->levels[toplevelCur->nLevel-1]); levelFirst = &(toplevelCur->levels[0]); stdinStream = toplevelCur->in; stdoutStream = toplevelCur->out; stderrStream = toplevelCur->err; } else { toplevelCur = NULL; levelCur = levelFirst = NULL; stdinStream = stdoutStream = stderrStream = NULL; } Free(theToplevels[nToplevel]);}/* * This function is called after each command from the terminal window * is executed */ void EndOfCommandLine(void) { int l,i; LEVEL level; /* Close Postscript file if necessary */ PSClose(); for (l = toplevelCur->nLevel-1; l>= 1;l--) { level = &(toplevelCur->levels[l]); ClearHashTable(level->theVariables); level->levelVar = level; level->scriptline = NULL; level->cmdList = NULL; CloseStream(level->out); level->out = NULL; CloseStream(level->in); level->in = NULL; CloseStream(level->err); level->err = NULL; } toplevelCur->sourceFilename = NULL; if (toplevelCur->packageName) { Free(toplevelCur->packageName); toplevelCur->packageName = NULL; } toplevelCur->nLevel = 1; levelCur = &(toplevelCur->levels[0]); levelCur->levelVar = levelCur; ClearStopFlag(); levelCur->nLoops = 0; levelCur->cmdList = NULL; levelCur->scriptline = NULL; /* Close all the non-closed streams */ stdinStream = CopyStream(&_StdinStream,&toplevelCur->in); stdoutStream = CopyStream(&_StdoutStream,&toplevelCur->out); stderrStream = CopyStream(&_StderrStream,&toplevelCur->err); for (i=toplevelCur->nStream-1;i>=4;i--) CloseStream(toplevelCur->theStreams[i]); /* Clear the temporary allocation */ ClearAllTempAlloc(); /* Init of the terminal line */ InitTerminalInput(); toplevelCur->termMode = CommandTMode; _StdinStream->buffer->flagEof = NO; /* Clear the clip rect */ WSetClipRect(NULL,0,0,0,0); /* Initializes gupdates */ InitGUpdates(); /* Init the drawMessage flag */ toplevelCur->flagInDrawMessage = NO; }/****************************************************************** * * Initialization of the toplevels : we create the first toplevel * and the standard streams * ******************************************************************/void InitToplevels(void){ char filename[150]; /* We open a toplevel ! */ OpenToplevel(); if (setjmp(toplevelCur->environment) == 0) { /* We init the variables */ InitVariables(); /* We read the history file */ ReadHistory(toplevelCur->history,GetHistoryFile()); /* We set the cmdNum */ levelFirst->cmdNum = toplevelCur->history->index+1; } else return;}/*************************************************** * * Close all toplevels (and the standard streams) * ***************************************************/void CloseAllToplevels(void){ CloseStream(_StdinStream); CloseStream(_StdoutStream); CloseStream(_StderrStream); while (nToplevel != 0) CloseToplevel(); toplevelCur = NULL;}/************************** * * the toplevel flags * **************************/char IsStopFlag(void){ return (toplevelCur->flags & (CONTINUE | BREAK | RETURN));}char IsReturnFlag(void){ return (toplevelCur->flags & RETURN);}char IsBreakFlag(void){ return (toplevelCur->flags & BREAK);}char IsContinueFlag(void){ return (toplevelCur->flags & CONTINUE);}void ClearStopFlag(void){ toplevelCur->flags = 0;}void SetReturnFlag(void){ toplevelCur->flags |= RETURN;}void SetBreakFlag(void){ toplevelCur->flags |= BREAK;}void SetContinueFlag(void){ toplevelCur->flags |= CONTINUE;}/* Functions on loops */void StartLoop(void){ levelCur->nLoops++;}void EndLoop(void){ levelCur->nLoops--; if (IsContinueFlag() || IsBreakFlag()) ClearStopFlag(); if (!IsReturnFlag()) InitResult();}char IsLoop(void){ return(levelCur->nLoops != 0);}/**************************************************** * * Set the streams according to the command line * Looking for the character '200' that indicates * that the command line is redirected * ****************************************************/ void SetCurStreams(char **argv){ char *arg; STREAM stream; char *str; char flagIn,flagErr,flagOut,flagSIn,flagCloseStream; char *mode; int streamId; if (argv == NULL) { Level2ToplevelStreams(levelCur,toplevelCur); return; } /* We loop on the arguments */ while (*argv != NULL) { arg = *argv; /* If there is no redirection then error */ if (*arg != '>' && *arg != '<') Errorf("Expecting redirection string : %s",arg); flagIn=flagErr=flagOut=flagSIn=NO; /* Syntax analysis */ if (!strncmp(arg,">>!",3)) {str = arg+3;mode = "a";flagErr = YES;} else if (!strncmp(arg,">>*",3)) {str = arg+3;mode = "a";flagErr = YES;flagOut = YES;} else if (!strncmp(arg,">>",2)) {str = arg+2;mode = "a";flagOut = YES;} else if (!strncmp(arg,">!",2)) {str = arg+2;mode = "w";flagErr = YES;} else if (!strncmp(arg,">*",2)) {str = arg+2;mode = "w";flagErr = YES;flagOut = YES;} else if (!strncmp(arg,">",1)) {str = arg+1;mode = "w";flagOut = YES;} else if (!strncmp(arg,"<<",2)) {str = arg+2;mode = "r";flagSIn = YES;} else if (!strncmp(arg,"<",1)) {str = arg+1;mode = "r";flagIn = YES;} flagCloseStream = YES; /* Let's get the stream */ if (flagSIn) { stream = OpenStringStream(str); stdinStream = CopyStream(&stream,&toplevelCur->in); } else { if (flagIn && *str == '\0') Errorf("You should specify a filename or stream i.d. after '<'"); /* We are either looking for a stream i.d. or a filename */ if (ParseInt_(str,0,&streamId)) { ParseStream(str,&stream); if ((flagOut || flagErr) && stream->mode != StreamWrite) Errorf("The stream '%s' is not writable",str); if (flagIn && stream->mode != StreamRead) Errorf("The stream '%s' is not readable",str); flagCloseStream = NO; } else if (*str != '\0') { InitError(); stream = OpenFileStream(str,mode); if (stream == NULL) Errorf("Cannot open file '%s'",str); } else { stream = stdnullStream; flagCloseStream = NO; } if (flagOut) stdoutStream = CopyStream(&stream,&toplevelCur->out); if (flagErr) stderrStream = CopyStream(&stream,&toplevelCur->err); if (flagIn) stdinStream = CopyStream(&stream,&toplevelCur->in); } if (flagCloseStream) CloseStream(stream); /* Next argument */ argv++; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -