📄 filecom.c
字号:
/*==============================*/ if (DribbleFP != NULL) { DribbleOff(); } /*========================*/ /* Open the dribble file. */ /*========================*/ DribbleFP = fopen(fileName,"w"); if (DribbleFP == NULL) { OpenErrorMessage("dribble-on",fileName); return(0); } /*============================*/ /* Create the dribble router. */ /*============================*/ AddRouter("dribble", 40, FindDribble, PrintDribble, GetcDribble, UngetcDribble, ExitDribble); DribbleCurrentPosition = 0; /*================================================*/ /* Call the dribble status function. This is used */ /* by some of the machine specific interfaces to */ /* do things such as changing the wording of menu */ /* items from "Turn Dribble On..." to */ /* "Turn Dribble Off..." */ /*================================================*/ if (DribbleStatusFunction != NULL) { (*DribbleStatusFunction)(CLIPS_TRUE); } /*=====================================*/ /* Return TRUE to indicate the dribble */ /* file was successfully opened. */ /*=====================================*/ return(CLIPS_TRUE); }/**********************************************//* DribbleActive: Returns TRUE if the dribble *//* router is active, otherwise FALSE> *//**********************************************/globle BOOLEAN DribbleActive() { if (DribbleFP != NULL) return(CLIPS_TRUE); return(CLIPS_FALSE); }/*******************************************//* DribbleOffCommand: CLIPS access routine *//* for the dribble-off command. *//*******************************************/globle int DribbleOffCommand() { if (ArgCountCheck("dribble-off",EXACTLY,0) == -1) return(CLIPS_FALSE); return(DribbleOff()); }/************************************//* DribbleOff: C access routine for *//* the dribble-off command. *//************************************/globle BOOLEAN DribbleOff() { int rv = 0; /*================================================*/ /* Call the dribble status function. This is used */ /* by some of the machine specific interfaces to */ /* do things such as changing the wording of menu */ /* items from "Turn Dribble On..." to */ /* "Turn Dribble Off..." */ /*================================================*/ if (DribbleStatusFunction != NULL) { (*DribbleStatusFunction)(CLIPS_FALSE); } /*=======================================*/ /* Close the dribble file and deactivate */ /* the dribble router. */ /*=======================================*/ if (DribbleFP != NULL) { if (DribbleCurrentPosition > 0) { fprintf(DribbleFP,"%s",DribbleBuffer); } DeleteRouter("dribble"); if (fclose(DribbleFP) == 0) rv = 1; } else { rv = 1; } DribbleFP = NULL; /*============================================*/ /* Free the space used by the dribble buffer. */ /*============================================*/ if (DribbleBuffer != NULL) { rm(DribbleBuffer,DribbleMaximumPosition); DribbleBuffer = NULL; } DribbleCurrentPosition = 0; DribbleMaximumPosition = 0; /*============================================*/ /* Return TRUE if the dribble file was closed */ /* without error, otherwise return FALSE. */ /*============================================*/ return(rv); }/*****************************************************//* SetDribbleStatusFunction: Sets the function which *//* is called whenever the dribble router is turned *//* on or off. *//*****************************************************/globle VOID SetDribbleStatusFunction(fnptr)#if ANSI_COMPILER int (*fnptr)(int);#else int (*fnptr)();#endif { DribbleStatusFunction = fnptr; }#endif/*************************************************//* FindBatch: Find routine for the batch router. *//*************************************************/static int FindBatch(logicalName) char *logicalName; { if (strcmp(logicalName,"stdin") == 0) { return(CLIPS_TRUE); } return(CLIPS_FALSE); }/*************************************************//* GetcBatch: Getc routine for the batch router. *//*************************************************/static int GetcBatch(logicalName) char *logicalName; { return(LLGetcBatch(logicalName,CLIPS_FALSE)); }/***************************************************//* LLGetcBatch: Lower level routine for retrieving *//* a character when a batch file is active. *//***************************************************/globle int LLGetcBatch(logicalName,returnOnEOF) char *logicalName; int returnOnEOF; { int rv = EOF, flag = 1; /*=================================================*/ /* Get a character until a valid character appears */ /* or no more batch files are left. */ /*=================================================*/ while ((rv == EOF) && (flag == 1)) { if (BatchType == FILE_BATCH) { rv = getc((FILE *) BatchSource); } else { rv = GetcCLIPS((char *) BatchSource); } if (rv == EOF) { if (BatchCurrentPosition > 0) PrintCLIPS("stdout",(char *) BatchBuffer); flag = RemoveBatch(); } } /*=========================================================*/ /* If the character retrieved is an end-of-file character, */ /* then there are no batch files with character input */ /* remaining. Remove the batch router. */ /*=========================================================*/ if (rv == EOF) { if (BatchCurrentPosition > 0) PrintCLIPS("stdout",(char *) BatchBuffer); DeleteRouter("batch"); RemoveBatch(); if (returnOnEOF == CLIPS_TRUE) { return (EOF); } else { return(GetcCLIPS(logicalName)); } } /*========================================*/ /* Add the character to the batch buffer. */ /*========================================*/ BatchBuffer = ExpandStringWithChar((char) rv,BatchBuffer,&BatchCurrentPosition, &BatchMaximumPosition,BatchMaximumPosition+BUFFER_SIZE); /*======================================*/ /* If a carriage return is encountered, */ /* then flush the batch buffer. */ /*======================================*/ if ((char) rv == '\n') { PrintCLIPS("stdout",(char *) BatchBuffer); BatchCurrentPosition = 0; if ((BatchBuffer != NULL) && (BatchMaximumPosition > BUFFER_SIZE)) { rm(BatchBuffer,BatchMaximumPosition); BatchMaximumPosition = 0; BatchBuffer = NULL; } } /*=====================================================*/ /* Return the character retrieved from the batch file. */ /*=====================================================*/ return(rv); }/*****************************************************//* UngetcBatch: Ungetc routine for the batch router. *//*****************************************************/#if IBM_TBC#pragma argsused#endifstatic int UngetcBatch(ch,logicalName) int ch; char *logicalName; {#if MAC_MPW || MAC_MCW#pragma unused(logicalName)#endif if (BatchCurrentPosition > 0) BatchCurrentPosition--; if (BatchBuffer != NULL) BatchBuffer[BatchCurrentPosition] = EOS; if (BatchType == FILE_BATCH) { return(ungetc(ch,(FILE *) BatchSource)); } return(UngetcCLIPS(ch,(char *) BatchSource)); }/*************************************************//* ExitBatch: Exit routine for the batch router. *//*************************************************/#if IBM_TBC#pragma argsused#endifstatic int ExitBatch(num) int num; {#if MAC_MPW || MAC_MCW#pragma unused(num)#endif CloseAllBatchSources(); return(1); }/**************************************//* BatchCommand: CLIPS access routine *//* for the batch command. *//**************************************/globle int BatchCommand() { char *fileName; if (ArgCountCheck("batch",EXACTLY,1) == -1) return(CLIPS_FALSE); if ((fileName = GetFileName("batch",1)) == NULL) return(CLIPS_FALSE); return(OpenBatch(fileName,CLIPS_FALSE)); } /**************************************************//* Batch: C access routine for the batch command. *//**************************************************/globle int Batch(fileName) char *fileName; { return(OpenBatch(fileName,CLIPS_FALSE)); }/***********************************************//* OpenBatch: Adds a file to the list of files *//* opened with the batch command. *//***********************************************/globle int OpenBatch(fileName,placeAtEnd) char *fileName; int placeAtEnd; { FILE *theFile; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = fopen(fileName,"r"); if (theFile == NULL) { OpenErrorMessage("batch",fileName); return(CLIPS_FALSE); } /*============================*/ /* Create the batch router if */ /* it doesn't already exist. */ /*============================*/ if (TopOfBatchList == NULL) { AddRouter("batch", 20, FindBatch, NULL, GetcBatch, UngetcBatch, ExitBatch); } /*====================================*/ /* Add the newly opened batch file to */ /* the list of batch files opened. */ /*====================================*/ AddBatch(placeAtEnd,(VOID *) theFile,FILE_BATCH,NULL); /*===================================*/ /* Return TRUE to indicate the batch */ /* file was successfully opened. */ /*===================================*/ return(CLIPS_TRUE); }/*****************************************************************//* OpenStringBatch: Opens a string source for batch processing. *//* The memory allocated for the argument stringName must be *//* deallocated by the user. The memory allocated for theString *//* will be deallocated by the batch routines when batch *//* processing for the string is completed. *//*****************************************************************/globle int OpenStringBatch(stringName,theString,placeAtEnd) char *stringName; char *theString; int placeAtEnd; { if (OpenStringSource(stringName,theString,0) == 0) { return(0); } if (TopOfBatchList == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -