📄 filecom.c
字号:
{ AddRouter("batch", 20, FindBatch, NULL, GetcBatch, UngetcBatch, ExitBatch); } AddBatch(placeAtEnd,(VOID *) stringName,STRING_BATCH,theString); return(1); }/*******************************************************//* AddBatch: Creates the batch file data structure and *//* adds it to the list of opened batch files. *//*******************************************************/static VOID AddBatch(placeAtEnd,theSource,type,theString) int placeAtEnd; VOID *theSource; int type; char *theString; { struct batchEntry *bptr; /*=========================*/ /* Create the batch entry. */ /*=========================*/ bptr = get_struct(batchEntry); bptr->batchType = type; bptr->inputSource = theSource; bptr->theString = theString; bptr->next = NULL; /*============================*/ /* Add the entry to the list. */ /*============================*/ if (TopOfBatchList == NULL) { TopOfBatchList = bptr; BottomOfBatchList = bptr; BatchType = type; BatchSource = theSource; BatchCurrentPosition = 0; } else if (placeAtEnd == CLIPS_FALSE) { bptr->next = TopOfBatchList; TopOfBatchList = bptr; BatchType = type; BatchSource = theSource; BatchCurrentPosition = 0; } else { BottomOfBatchList->next = bptr; BottomOfBatchList = bptr; } }/******************************************************************//* RemoveBatch: Removes the top entry on the list of batch files. *//******************************************************************/globle int RemoveBatch() { struct batchEntry *bptr; int rv; if (TopOfBatchList == NULL) return(CLIPS_FALSE); /*==================================================*/ /* Close the source from which batch input is read. */ /*==================================================*/ if (TopOfBatchList->batchType == FILE_BATCH) { fclose((FILE *) TopOfBatchList->inputSource); } else { CloseStringSource((char *) TopOfBatchList->inputSource); rm(TopOfBatchList->theString,(int) strlen(TopOfBatchList->theString) + 1); } /*=================================*/ /* Remove the entry from the list. */ /*=================================*/ bptr = TopOfBatchList; TopOfBatchList = TopOfBatchList->next; rtn_struct(batchEntry,bptr); /*========================================================*/ /* If there are no batch files remaining to be processed, */ /* then free the space used by the batch buffer. */ /*========================================================*/ if (TopOfBatchList == NULL) { BottomOfBatchList = NULL; BatchSource = NULL; if (BatchBuffer != NULL) { rm(BatchBuffer,BatchMaximumPosition); BatchBuffer = NULL; } BatchCurrentPosition = 0; BatchMaximumPosition = 0; rv = 0; } /*===========================================*/ /* Otherwise move on to the next batch file. */ /*===========================================*/ else { BatchType = TopOfBatchList->batchType; BatchSource = TopOfBatchList->inputSource; BatchCurrentPosition = 0; rv = 1; } /*====================================================*/ /* Return TRUE if a batch file if there are remaining */ /* batch files to be processed, otherwise FALSE. */ /*====================================================*/ return(rv); }/****************************************//* BatchActive: Returns TRUE if a batch *//* file is open, otherwise FALSE. *//****************************************/globle BOOLEAN BatchActive() { if (TopOfBatchList != NULL) return(CLIPS_TRUE); return(CLIPS_FALSE); }/******************************************************//* CloseAllBatchSources: Closes all open batch files. *//******************************************************/globle VOID CloseAllBatchSources() { /*================================================*/ /* Free the batch buffer if it contains anything. */ /*================================================*/ if (BatchBuffer != NULL) { if (BatchCurrentPosition > 0) PrintCLIPS("stdout",(char *) BatchBuffer); rm(BatchBuffer,BatchMaximumPosition); BatchBuffer = NULL; BatchCurrentPosition = 0; BatchMaximumPosition = 0; } /*==========================*/ /* Delete the batch router. */ /*==========================*/ DeleteRouter("batch"); /*=====================================*/ /* Close each of the open batch files. */ /*=====================================*/ while (RemoveBatch()) { /* Do Nothing */ } } /******************************************//* BatchStarCommand: CLIPS access routine *//* for the batch* command. *//******************************************/globle int BatchStarCommand() { char *fileName; if (ArgCountCheck("batch*",EXACTLY,1) == -1) return(CLIPS_FALSE); if ((fileName = GetFileName("batch*",1)) == NULL) return(CLIPS_FALSE); return(BatchStar(fileName)); }#if ! RUN_TIME /*******************************************************//* BatchStar: C access routine for the batch* command. *//*******************************************************/globle int BatchStar(fileName) char *fileName; { int inchar; FILE *theFile; char *theString = NULL; int position = 0; int maxChars = 0; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = fopen(fileName,"r"); if (theFile == NULL) { OpenErrorMessage("batch",fileName); return(CLIPS_FALSE); } /*========================*/ /* Reset the error state. */ /*========================*/ SetHaltExecution(CLIPS_FALSE); SetEvaluationError(CLIPS_FALSE); /*=============================================*/ /* Evaluate commands from the file one by one. */ /*=============================================*/ while ((inchar = getc(theFile)) != EOF) { theString = ExpandStringWithChar(inchar,theString,&position, &maxChars,maxChars+80); if (CompleteCommand(theString) != 0) { FlushPPBuffer(); SetPPBufferStatus(OFF); RouteCommand(theString,CLIPS_FALSE); FlushPPBuffer(); SetHaltExecution(CLIPS_FALSE); SetEvaluationError(CLIPS_FALSE); FlushBindList(); genfree(theString,(unsigned) maxChars); theString = NULL; maxChars = 0; position = 0; } } /*=======================*/ /* Close the batch file. */ /*=======================*/ fclose(theFile); return(CLIPS_TRUE); } #else/*******************************************************//* BatchStar: This is the non-functional stub provided *//* for use with a run-time version of CLIPS. *//*******************************************************/globle int BatchStar(fileName) char *fileName; {#if (MAC_MPW || MAC_MCW) && RUN_TIME#pragma unused(fileName)#endif PrintErrorID("FILECOM",1,CLIPS_FALSE); PrintCLIPS(WERROR,"Function batch* does not work in run time modules.\n"); return(CLIPS_FALSE); } #endif /***********************************************************//* LoadCommand: CLIPS access routine for the load command. *//***********************************************************/globle int LoadCommand() {#if (! BLOAD_ONLY) && (! RUN_TIME) char *theFileName; int rv; if (ArgCountCheck("load",EXACTLY,1) == -1) return(CLIPS_FALSE); if ((theFileName = GetFileName("load",1)) == NULL) return(CLIPS_FALSE); SetPrintWhileLoading(CLIPS_TRUE); if ((rv = Load(theFileName)) == CLIPS_FALSE) { SetPrintWhileLoading(CLIPS_FALSE); OpenErrorMessage("load",theFileName); return(CLIPS_FALSE); } SetPrintWhileLoading(CLIPS_FALSE); if (rv == -1) return(CLIPS_FALSE); return(CLIPS_TRUE);#else PrintCLIPS(WDIALOG,"Load is not available in this environment\n"); return(CLIPS_FALSE);#endif }/****************************************************************//* LoadStarCommand: CLIPS access routine for the load* command. *//****************************************************************/globle int LoadStarCommand() {#if (! BLOAD_ONLY) && (! RUN_TIME) char *theFileName; int rv; if (ArgCountCheck("load*",EXACTLY,1) == -1) return(CLIPS_FALSE); if ((theFileName = GetFileName("load*",1)) == NULL) return(CLIPS_FALSE); if ((rv = Load(theFileName)) == CLIPS_FALSE) { OpenErrorMessage("load*",theFileName); return(CLIPS_FALSE); } if (rv == -1) return(CLIPS_FALSE); return(CLIPS_TRUE);#else PrintCLIPS(WDIALOG,"Load* is not available in this environment\n"); return(CLIPS_FALSE);#endif } #if DEBUGGING_FUNCTIONS/***********************************************************//* SaveCommand: CLIPS access routine for the save command. *//***********************************************************/globle int SaveCommand() {#if (! BLOAD_ONLY) && (! RUN_TIME) char *theFileName; if (ArgCountCheck("save",EXACTLY,1) == -1) return(CLIPS_FALSE); if ((theFileName = GetFileName("save",1)) == NULL) return(CLIPS_FALSE); if (Save(theFileName) == CLIPS_FALSE) { OpenErrorMessage("save",theFileName); return(CLIPS_FALSE); } return(CLIPS_TRUE);#else PrintCLIPS(WDIALOG,"Save is not available in this environment\n"); return(CLIPS_FALSE);#endif }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -