globle char *StringPrintForm( void *theEnv, char *str) { int i = 0, pos = 0; unsigned max = 0; char *theString = NULL; void *thePtr; theString = ExpandStringWithChar(theEnv,'"',theString,&pos,&max,max+80); while (str[i] != EOS) { if ((str[i] == '"') || (str[i] == '\\')) { theString = ExpandStringWithChar(theEnv,'\\',theString,&pos,&max,max+80); theString = ExpandStringWithChar(theEnv,str[i],theString,&pos,&max,max+80); } else { theString = ExpandStringWithChar(theEnv,str[i],theString,&pos,&max,max+80); } i++; } theString = ExpandStringWithChar(theEnv,'"',theString,&pos,&max,max+80); thePtr = EnvAddSymbol(theEnv,theString); rm(theEnv,theString,max); return(ValueToString(thePtr)); }
bool ExpandCommandString( void *theEnv, int inchar) { size_t k; k = RouterData(theEnv)->CommandBufferInputCount; CommandLineData(theEnv)->CommandString = ExpandStringWithChar(theEnv,inchar,CommandLineData(theEnv)->CommandString,&RouterData(theEnv)->CommandBufferInputCount, &CommandLineData(theEnv)->MaximumCharacters,CommandLineData(theEnv)->MaximumCharacters+80); return((RouterData(theEnv)->CommandBufferInputCount != k) ? true : false); }
globle int ExpandCommandString( void *theEnv, int inchar) { register int k; k = RouterData(theEnv)->CommandBufferInputCount; CommandLineData(theEnv)->CommandString = ExpandStringWithChar(theEnv,inchar,CommandLineData(theEnv)->CommandString,&RouterData(theEnv)->CommandBufferInputCount, &CommandLineData(theEnv)->MaximumCharacters,CommandLineData(theEnv)->MaximumCharacters+80); return((RouterData(theEnv)->CommandBufferInputCount != k) ? TRUE : FALSE); }
static void PutcDribbleBuffer( void *theEnv, int rv) { /*===================================================*/ /* Receiving an end-of-file character will cause the */ /* contents of the dribble buffer to be flushed. */ /*===================================================*/ if (rv == EOF) { if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); FileCommandData(theEnv)->DribbleCurrentPosition = 0; FileCommandData(theEnv)->DribbleBuffer[0] = EOS; } } /*===========================================================*/ /* If we aren't receiving command input, then the character */ /* just received doesn't need to be placed in the dribble */ /* buffer--It can be written directly to the file. This will */ /* occur for example when the command prompt is being */ /* printed (the CommandBufferInputCount variable will be -1 */ /* because command input has not been receivied yet). Before */ /* writing the character to the file, the dribble buffer is */ /* flushed. */ /*===========================================================*/ else if (RouterData(theEnv)->CommandBufferInputCount < 0) { if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); FileCommandData(theEnv)->DribbleCurrentPosition = 0; FileCommandData(theEnv)->DribbleBuffer[0] = EOS; } fputc(rv,FileCommandData(theEnv)->DribbleFP); } /*=====================================================*/ /* Otherwise, add the character to the dribble buffer. */ /*=====================================================*/ else { FileCommandData(theEnv)->DribbleBuffer = ExpandStringWithChar(theEnv,rv,FileCommandData(theEnv)->DribbleBuffer, &FileCommandData(theEnv)->DribbleCurrentPosition, &FileCommandData(theEnv)->DribbleMaximumPosition, FileCommandData(theEnv)->DribbleMaximumPosition+BUFFER_SIZE); } }
bool BatchStar( Environment *theEnv, const char *fileName) { int inchar; bool done = false; FILE *theFile; char *theString = NULL; size_t position = 0; size_t maxChars = 0; #if (! RUN_TIME) && (! BLOAD_ONLY) char *oldParsingFileName; long oldLineCountValue; #endif /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return false; } /*======================================*/ /* Setup for capturing errors/warnings. */ /*======================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) oldParsingFileName = CopyString(theEnv,GetParsingFileName(theEnv)); SetParsingFileName(theEnv,fileName); CreateErrorCaptureRouter(theEnv); oldLineCountValue = SetLineCount(theEnv,1); #endif /*=====================================*/ /* If embedded, clear the error flags. */ /*=====================================*/ if (EvaluationData(theEnv)->CurrentExpression == NULL) { ResetErrorFlags(theEnv); } /*=============================================*/ /* Evaluate commands from the file one by one. */ /*=============================================*/ while (! done) { inchar = getc(theFile); if (inchar == EOF) { inchar = '\n'; done = true; } theString = ExpandStringWithChar(theEnv,inchar,theString,&position, &maxChars,maxChars+80); if (CompleteCommand(theString) != 0) { FlushPPBuffer(theEnv); SetPPBufferStatus(theEnv,false); RouteCommand(theEnv,theString,false); FlushPPBuffer(theEnv); SetHaltExecution(theEnv,false); SetEvaluationError(theEnv,false); FlushBindList(theEnv,NULL); genfree(theEnv,theString,maxChars); theString = NULL; maxChars = 0; position = 0; #if (! RUN_TIME) && (! BLOAD_ONLY) FlushParsingMessages(theEnv); #endif } if ((inchar == '\r') || (inchar == '\n')) { IncrementLineCount(theEnv); } } if (theString != NULL) { genfree(theEnv,theString,maxChars); } /*=======================*/ /* Close the batch file. */ /*=======================*/ GenClose(theEnv,theFile); /*========================================*/ /* Cleanup for capturing errors/warnings. */ /*========================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) FlushParsingMessages(theEnv); DeleteErrorCaptureRouter(theEnv); SetLineCount(theEnv,oldLineCountValue); SetParsingFileName(theEnv,oldParsingFileName); DeleteString(theEnv,oldParsingFileName); #endif return true; }
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 EnvBatchStar( void *theEnv, char *fileName) { int inchar; FILE *theFile; char *theString = NULL; size_t position = 0; size_t maxChars = 0; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return(FALSE); } /*========================*/ /* Reset the error state. */ /*========================*/ SetHaltExecution(theEnv,FALSE); SetEvaluationError(theEnv,FALSE); /*=============================================*/ /* Evaluate commands from the file one by one. */ /*=============================================*/ while ((inchar = getc(theFile)) != EOF) { theString = ExpandStringWithChar(theEnv,inchar,theString,&position, &maxChars,maxChars+80); if (CompleteCommand(theString) != 0) { FlushPPBuffer(theEnv); SetPPBufferStatus(theEnv,OFF); RouteCommand(theEnv,theString,FALSE); FlushPPBuffer(theEnv); SetHaltExecution(theEnv,FALSE); SetEvaluationError(theEnv,FALSE); FlushBindList(theEnv); genfree(theEnv,theString,(unsigned) maxChars); theString = NULL; maxChars = 0; position = 0; } } if (theString != NULL) { genfree(theEnv,theString,(unsigned) maxChars); } /*=======================*/ /* Close the batch file. */ /*=======================*/ GenClose(theEnv,theFile); return(TRUE); }
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); }