📄 filecom.c
字号:
/* DribbleOnCommand: H/L access routine *//* for the dribble-on command. *//******************************************/globle int DribbleOnCommand( void *theEnv) { char *fileName; if (EnvArgCountCheck(theEnv,"dribble-on",EXACTLY,1) == -1) return(FALSE); if ((fileName = GetFileName(theEnv,"dribble-on",1)) == NULL) return(FALSE); return (EnvDribbleOn(theEnv,fileName)); }/**********************************//* EnvDribbleOn: C access routine *//* for the dribble-on command. *//**********************************/globle intBool EnvDribbleOn( void *theEnv, char *fileName) { /*==============================*/ /* If a dribble file is already */ /* open, then close it. */ /*==============================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { EnvDribbleOff(theEnv); } /*========================*/ /* Open the dribble file. */ /*========================*/ FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,"w"); if (FileCommandData(theEnv)->DribbleFP == NULL) { OpenErrorMessage(theEnv,"dribble-on",fileName); return(0); } /*============================*/ /* Create the dribble router. */ /*============================*/ EnvAddRouter(theEnv,"dribble", 40, FindDribble, PrintDribble, GetcDribble, UngetcDribble, ExitDribble); FileCommandData(theEnv)->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 (FileCommandData(theEnv)->DribbleStatusFunction != NULL) { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,TRUE); } /*=====================================*/ /* Return TRUE to indicate the dribble */ /* file was successfully opened. */ /*=====================================*/ return(TRUE); }/*************************************************//* EnvDribbleActive: Returns TRUE if the dribble *//* router is active, otherwise FALSE> *//*************************************************/globle intBool EnvDribbleActive( void *theEnv) { if (FileCommandData(theEnv)->DribbleFP != NULL) return(TRUE); return(FALSE); }/*******************************************//* DribbleOffCommand: H/L access routine *//* for the dribble-off command. *//*******************************************/globle int DribbleOffCommand( void *theEnv) { if (EnvArgCountCheck(theEnv,"dribble-off",EXACTLY,0) == -1) return(FALSE); return(EnvDribbleOff(theEnv)); }/***********************************//* EnvDribbleOff: C access routine *//* for the dribble-off command. *//***********************************/globle intBool EnvDribbleOff( void *theEnv) { 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 (FileCommandData(theEnv)->DribbleStatusFunction != NULL) { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,FALSE); } /*=======================================*/ /* Close the dribble file and deactivate */ /* the dribble router. */ /*=======================================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); } EnvDeleteRouter(theEnv,"dribble"); if (GenClose(theEnv,FileCommandData(theEnv)->DribbleFP) == 0) rv = 1; } else { rv = 1; } FileCommandData(theEnv)->DribbleFP = NULL; /*============================================*/ /* Free the space used by the dribble buffer. */ /*============================================*/ if (FileCommandData(theEnv)->DribbleBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->DribbleBuffer,FileCommandData(theEnv)->DribbleMaximumPosition); FileCommandData(theEnv)->DribbleBuffer = NULL; } FileCommandData(theEnv)->DribbleCurrentPosition = 0; FileCommandData(theEnv)->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( void *theEnv, int (*fnptr)(void *,int)) { FileCommandData(theEnv)->DribbleStatusFunction = fnptr; }#endif/*************************************************//* FindBatch: Find routine for the batch router. *//*************************************************/#if IBM_TBC#pragma argsused#endifstatic int FindBatch( void *theEnv, char *logicalName) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv)#endif if (strcmp(logicalName,"stdin") == 0) { return(TRUE); } return(FALSE); }/*************************************************//* GetcBatch: Getc routine for the batch router. *//*************************************************/static int GetcBatch( void *theEnv, char *logicalName) { return(LLGetcBatch(theEnv,logicalName,FALSE)); }/***************************************************//* LLGetcBatch: Lower level routine for retrieving *//* a character when a batch file is active. *//***************************************************/globle int LLGetcBatch( void *theEnv, 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 (FileCommandData(theEnv)->BatchType == FILE_BATCH) { rv = getc((FILE *) FileCommandData(theEnv)->BatchSource); } else { rv = EnvGetcRouter(theEnv,(char *) FileCommandData(theEnv)->BatchSource); } if (rv == EOF) { if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer); flag = RemoveBatch(theEnv); } } /*=========================================================*/ /* 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 (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer); EnvDeleteRouter(theEnv,"batch"); RemoveBatch(theEnv); if (returnOnEOF == TRUE) { return (EOF); } else { return(EnvGetcRouter(theEnv,logicalName)); } } /*========================================*/ /* Add the character to the batch buffer. */ /*========================================*/ FileCommandData(theEnv)->BatchBuffer = ExpandStringWithChar(theEnv,(char) rv,FileCommandData(theEnv)->BatchBuffer,&FileCommandData(theEnv)->BatchCurrentPosition, &FileCommandData(theEnv)->BatchMaximumPosition,FileCommandData(theEnv)->BatchMaximumPosition+BUFFER_SIZE); /*======================================*/ /* If a carriage return is encountered, */ /* then flush the batch buffer. */ /*======================================*/ if ((char) rv == '\n') { EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer); FileCommandData(theEnv)->BatchCurrentPosition = 0; if ((FileCommandData(theEnv)->BatchBuffer != NULL) && (FileCommandData(theEnv)->BatchMaximumPosition > BUFFER_SIZE)) { rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); FileCommandData(theEnv)->BatchMaximumPosition = 0; FileCommandData(theEnv)->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( void *theEnv, int ch, char *logicalName) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(logicalName)#endif if (FileCommandData(theEnv)->BatchCurrentPosition > 0) FileCommandData(theEnv)->BatchCurrentPosition--; if (FileCommandData(theEnv)->BatchBuffer != NULL) FileCommandData(theEnv)->BatchBuffer[FileCommandData(theEnv)->BatchCurrentPosition] = EOS; if (FileCommandData(theEnv)->BatchType == FILE_BATCH) { return(ungetc(ch,(FILE *) FileCommandData(theEnv)->BatchSource)); } return(EnvUngetcRouter(theEnv,ch,(char *) FileCommandData(theEnv)->BatchSource)); }/*************************************************//* ExitBatch: Exit routine for the batch router. *//*************************************************/#if IBM_TBC#pragma argsused#endifstatic int ExitBatch( void *theEnv, int num) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(num)#endif CloseAllBatchSources(theEnv); return(1); }/**************************************//* BatchCommand: H/L access routine *//* for the batch command. *//**************************************/globle int BatchCommand( void *theEnv) { char *fileName; if (EnvArgCountCheck(theEnv,"batch",EXACTLY,1) == -1) return(FALSE); if ((fileName = GetFileName(theEnv,"batch",1)) == NULL) return(FALSE); return(OpenBatch(theEnv,fileName,FALSE)); }/**************************************************//* Batch: C access routine for the batch command. *//**************************************************/globle int Batch( void *theEnv, char *fileName) { return(OpenBatch(theEnv,fileName,FALSE)); }/***********************************************//* OpenBatch: Adds a file to the list of files *//* opened with the batch command. *//***********************************************/globle int OpenBatch( void *theEnv, char *fileName, int placeAtEnd) { FILE *theFile; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return(FALSE); } /*============================*/ /* Create the batch router if */ /* it doesn't already exist. */ /*============================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { EnvAddRouter(theEnv,"batch", 20, FindBatch, NULL, GetcBatch, UngetcBatch, ExitBatch); } /*====================================*/ /* Add the newly opened batch file to */ /* the list of batch files opened. */ /*====================================*/ AddBatch(theEnv,placeAtEnd,(void *) theFile,FILE_BATCH,NULL); /*===================================*/ /* Return TRUE to indicate the batch */ /* file was successfully opened. */ /*===================================*/ return(TRUE); }/*****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -