globle char *ExpandStringWithChar( void *theEnv, int inchar, char *str, int *pos, unsigned *max, unsigned newSize) { if ((*pos + 1) >= (int) *max) { str = (char *) genrealloc(theEnv,str,*max,newSize); *max = newSize; } if (inchar != '\b') { str[*pos] = (char) inchar; (*pos)++; str[*pos] = '\0'; } else { if (*pos > 0) (*pos)--; str[*pos] = '\0'; } return(str); }
globle char *ExpandStringWithChar( int inchar, char *str, int *pos, int *max, int newSize) { if (*pos >= (*max - 1)) { str = (char *) genrealloc(str,(unsigned) *max,(unsigned) newSize); *max = newSize; } if (inchar != '\b') { str[*pos] = (char) inchar; (*pos)++; str[*pos] = '\0'; } else { if (*pos > 0) (*pos)--; str[*pos] = '\0'; } return(str); }
globle void SavePPBuffer( void *theEnv, EXEC_STATUS, char *str) { size_t increment; /*==========================================*/ /* If the pretty print buffer isn't needed, */ /* then don't bother writing to it. */ /*==========================================*/ if ((PrettyPrintData(theEnv,execStatus)->PPBufferStatus == OFF) || (! PrettyPrintData(theEnv,execStatus)->PPBufferEnabled)) { return; } /*===============================*/ /* Determine the increment size. */ /*===============================*/ increment = 512; if (PrettyPrintData(theEnv,execStatus)->PPBufferPos > increment) { increment = PrettyPrintData(theEnv,execStatus)->PPBufferPos * 3; } /*================================================*/ /* If the pretty print buffer isn't big enough to */ /* contain the string, then increase its size. */ /*================================================*/ if (strlen(str) + PrettyPrintData(theEnv,execStatus)->PPBufferPos + 1 >= PrettyPrintData(theEnv,execStatus)->PPBufferMax) { PrettyPrintData(theEnv,execStatus)->PrettyPrintBuffer = (char *) genrealloc(theEnv,execStatus,PrettyPrintData(theEnv,execStatus)->PrettyPrintBuffer, PrettyPrintData(theEnv,execStatus)->PPBufferMax, PrettyPrintData(theEnv,execStatus)->PPBufferMax + increment); PrettyPrintData(theEnv,execStatus)->PPBufferMax += increment; } /*==================================================*/ /* Remember the previous tokens saved to the pretty */ /* print buffer in case it is necessary to back up. */ /*==================================================*/ PrettyPrintData(theEnv,execStatus)->PPBackupTwice = PrettyPrintData(theEnv,execStatus)->PPBackupOnce; PrettyPrintData(theEnv,execStatus)->PPBackupOnce = PrettyPrintData(theEnv,execStatus)->PPBufferPos; /*=============================================*/ /* Save the string to the pretty print buffer. */ /*=============================================*/ PrettyPrintData(theEnv,execStatus)->PrettyPrintBuffer = AppendToString(theEnv,execStatus,str,PrettyPrintData(theEnv,execStatus)->PrettyPrintBuffer,&PrettyPrintData(theEnv,execStatus)->PPBufferPos,&PrettyPrintData(theEnv,execStatus)->PPBufferMax); }
globle char *AppendNToString( void *theEnv, char *appendStr, char *oldStr, unsigned length, int *oldPos, unsigned *oldMax) { unsigned lengthWithEOS; /*====================================*/ /* Determine the number of characters */ /* to be appended from the string. */ /*====================================*/ if (appendStr[length-1] != '\0') lengthWithEOS = length + 1; else lengthWithEOS = length; /*=========================================*/ /* Expand the old string so it can contain */ /* the new string (if necessary). */ /*=========================================*/ if (lengthWithEOS + *oldPos > *oldMax) { oldStr = (char *) genrealloc(theEnv,oldStr,(unsigned) *oldMax,(unsigned) *oldPos + lengthWithEOS); *oldMax = (unsigned) *oldPos + lengthWithEOS; } /*==============================================================*/ /* Return NULL if the old string was not successfully expanded. */ /*==============================================================*/ if (oldStr == NULL) { return(NULL); } /*==================================*/ /* Append N characters from the new */ /* string to the expanded string. */ /*==================================*/ strncpy(&oldStr[*oldPos],appendStr,(STD_SIZE) length); *oldPos += (int) (lengthWithEOS - 1); oldStr[*oldPos] = '\0'; /*============================================================*/ /* Return the expanded string containing the appended string. */ /*============================================================*/ return(oldStr); }
void SetNCommandString( void *theEnv, const char *str, unsigned length) { FlushCommandString(theEnv); CommandLineData(theEnv)->CommandString = (char *) genrealloc(theEnv,CommandLineData(theEnv)->CommandString,(unsigned) CommandLineData(theEnv)->MaximumCharacters, (unsigned) CommandLineData(theEnv)->MaximumCharacters + length + 1); genstrncpy(CommandLineData(theEnv)->CommandString,str,length); CommandLineData(theEnv)->CommandString[CommandLineData(theEnv)->MaximumCharacters + length] = 0; CommandLineData(theEnv)->MaximumCharacters += (length + 1); RouterData(theEnv)->CommandBufferInputCount += (int) length; }
void SetCommandString( void *theEnv, const char *str) { size_t length; FlushCommandString(theEnv); length = strlen(str); CommandLineData(theEnv)->CommandString = (char *) genrealloc(theEnv,CommandLineData(theEnv)->CommandString,(unsigned) CommandLineData(theEnv)->MaximumCharacters, (unsigned) CommandLineData(theEnv)->MaximumCharacters + length + 1); genstrcpy(CommandLineData(theEnv)->CommandString,str); CommandLineData(theEnv)->MaximumCharacters += (length + 1); RouterData(theEnv)->CommandBufferInputCount += (int) length; }
globle char *AppendToString( void *theEnv, char *appendStr, char *oldStr, int *oldPos, unsigned *oldMax) { size_t length; /*=========================================*/ /* Expand the old string so it can contain */ /* the new string (if necessary). */ /*=========================================*/ length = strlen(appendStr); if (length + *oldPos + 1 > *oldMax) { oldStr = (char *) genrealloc(theEnv,oldStr,(unsigned) *oldMax,(unsigned) length + *oldPos + 1); *oldMax = length + *oldPos + 1; } /*==============================================================*/ /* Return NULL if the old string was not successfully expanded. */ /*==============================================================*/ if (oldStr == NULL) { return(NULL); } /*===============================================*/ /* Append the new string to the expanded string. */ /*===============================================*/ strcpy(&oldStr[*oldPos],appendStr); *oldPos += (int) length; /*============================================================*/ /* Return the expanded string containing the appended string. */ /*============================================================*/ return(oldStr); }
globle void SavePPBuffer( char *str) { long int longSize; int normalSize; int increment; /*==========================================*/ /* If the pretty print buffer isn't needed, */ /* then don't bother writing to it. */ /*==========================================*/ if (PPBufferStatus == OFF) return; /*===============================*/ /* Determine the increment size. */ /*===============================*/ increment = 512; if (PPBufferPos > increment) { increment = PPBufferPos * 3; if (increment < 0) { increment = 512; } } /*==================================================*/ /* The pretty print buffer is limited in size to */ /* the maximum size of a signed int. Any characters */ /* beyond that number are discarded. */ /*==================================================*/ normalSize = strlen(str); longSize = (long) normalSize; longSize += (long) PPBufferPos + ((long) increment) + 1L; normalSize += PPBufferPos + increment + 1; if (normalSize != longSize) return; /*================================================*/ /* If the pretty print buffer isn't big enough to */ /* contain the string, then increase its size. */ /*================================================*/ if (((int) strlen(str)) + PPBufferPos + 1 >= PPBufferMax) { PrettyPrintBuffer = (char *) genrealloc(PrettyPrintBuffer,(unsigned) PPBufferMax, (unsigned) PPBufferMax + increment); PPBufferMax += increment; } /*==================================================*/ /* Remember the previous tokens saved to the pretty */ /* print buffer in case it is necessary to back up. */ /*==================================================*/ PPBackupTwice = PPBackupOnce; PPBackupOnce = PPBufferPos; /*=============================================*/ /* Save the string to the pretty print buffer. */ /*=============================================*/ PrettyPrintBuffer = AppendToString(str,PrettyPrintBuffer,&PPBufferPos,&PPBufferMax); }