void CloseAllBatchSources( Environment *theEnv) { /*================================================*/ /* Free the batch buffer if it contains anything. */ /*================================================*/ if (FileCommandData(theEnv)->BatchBuffer != NULL) { if (FileCommandData(theEnv)->BatchCurrentPosition > 0) WriteString(theEnv,STDOUT,(char *) FileCommandData(theEnv)->BatchBuffer); rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); FileCommandData(theEnv)->BatchBuffer = NULL; FileCommandData(theEnv)->BatchCurrentPosition = 0; FileCommandData(theEnv)->BatchMaximumPosition = 0; } /*==========================*/ /* Delete the batch router. */ /*==========================*/ DeleteRouter(theEnv,"batch"); /*=====================================*/ /* Close each of the open batch files. */ /*=====================================*/ while (RemoveBatch(theEnv)) { /* Do Nothing */ } }
globle void CloseAllBatchSources( void *theEnv) { /*================================================*/ /* Free the batch buffer if it contains anything. */ /*================================================*/ if (FileCommandData(theEnv)->BatchBuffer != NULL) { if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,(char*)"stdout",(char *) FileCommandData(theEnv)->BatchBuffer); rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); FileCommandData(theEnv)->BatchBuffer = NULL; FileCommandData(theEnv)->BatchCurrentPosition = 0; FileCommandData(theEnv)->BatchMaximumPosition = 0; } /*==========================*/ /* Delete the batch router. */ /*==========================*/ EnvDeleteRouter(theEnv,(char*)"batch"); /*=====================================*/ /* Close each of the open batch files. */ /*=====================================*/ while (RemoveBatch(theEnv)) { /* Do Nothing */ } }
int LLGetcBatch( Environment *theEnv, const char *logicalName, bool 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(FileCommandData(theEnv)->BatchFileSource); } else { rv = ReadRouter(theEnv,FileCommandData(theEnv)->BatchLogicalSource); } if (rv == EOF) { if (FileCommandData(theEnv)->BatchCurrentPosition > 0) WriteString(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) WriteString(theEnv,STDOUT,(char *) FileCommandData(theEnv)->BatchBuffer); DeleteRouter(theEnv,"batch"); RemoveBatch(theEnv); if (returnOnEOF == true) { return (EOF); } else { return ReadRouter(theEnv,logicalName); } } /*========================================*/ /* Add the character to the batch buffer. */ /*========================================*/ if (RouterData(theEnv)->InputUngets == 0) { 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') { WriteString(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; } } /*=============================*/ /* Increment the line counter. */ /*=============================*/ if (((char) rv == '\r') || ((char) rv == '\n')) { IncrementLineCount(theEnv); } /*=====================================================*/ /* Return the character retrieved from the batch file. */ /*=====================================================*/ return(rv); }
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); }