STATIC char *doStringSubstitute( const char *name, const char *oldString, const char *newString ) /************************************************************************************************ * $(macroname:oldstr=newstr) * substitute any occurence of oldstr with new str */ { VECSTR output; char const *current; char const *start; size_t old_len; output = StartVec(); WriteVec( output, "" ); assert( name != NULL && oldString != NULL && newString != NULL ); old_len = strlen( oldString ); for( start = current = name; *current != NULLCHAR; current++ ) { if( strncmp( current, oldString, old_len ) == 0 ) { CatNStrToVec( output, start, current - start ); CatStrToVec( output, newString ); start = current + old_len; current = start - 1; } } CatStrToVec( output, start ); return( FinishVec( output ) ); }
STATIC char *CatModifier( char *inString, BOOLEAN destroy ) /********************************************************** * Get the modifier * if it is modify the value inInString to the specs of the modifier * it then returns the modified string with the right format */ { STRM_T s; VECSTR output; char buffer[2]; char *ret; assert( inString != NULL ); s = PreGetCH(); if( ismsmodifier( s ) ) { buffer[0] = s; buffer[1] = NULLCHAR; output = StartVec(); WriteVec( output, "" ); CatStrToVec( output, inString ); CatStrToVec( output, buffer ); if( destroy ) { FreeSafe( inString ); } return( FinishVec( output ) ); } else { UnGetCH( s ); ret = StrDupSafe( inString ); if( destroy ) { FreeSafe( inString ); } return( ret ); } }
STATIC char *DeMacroDoubleQuote( BOOLEAN IsDoubleQuote ) /******************************************************* * This procedure takes care of double quotes in the stream * Note: each double quote must be paired with a double quote in the * input stream or this will expand until the EOL a backlash double * quote will be considered as a non-double quote. */ { char buffer[_MAX_PATH]; char *current; char *p; VECSTR OutString; int pos; STRM_T s; BOOLEAN StartDoubleQuote; s = PreGetCH(); UnGetCH( s ); if( s == EOL || s == STRM_END || s == STRM_MAGIC ) { return( StrDupSafe( "" ) ); } if( s == STRM_TMP_LEX_START ) { PreGetCH(); /* Eat STRM_TMP_LEX_START */ pos = 0; for( s = PreGetCH(); s != STRM_MAGIC && pos < _MAX_PATH; s = PreGetCH() ) { assert( s != EOL || s != STRM_END ); buffer[pos++] = s; } if( pos >= _MAX_PATH ) { PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, _MAX_PATH - 1 )); // NOTREACHED } buffer[pos] = NULLCHAR; p = StrDupSafe( buffer ); } else { p = DeMacro( MAC_WS ); } StartDoubleQuote = IsDoubleQuote; for( current = p; *current != NULLCHAR; ++current ) { if( *current == DOUBLEQUOTE ) { if( !IsDoubleQuote ) { /* Found the start of a Double Quoted String */ if( current != p ) { UnGetCH( STRM_MAGIC ); InsString( StrDupSafe( current ), TRUE ); UnGetCH( STRM_TMP_LEX_START ); *current = NULLCHAR; return( p ); } IsDoubleQuote = TRUE; } else { /* Found the end of the Double Quoted String */ if( *(current + 1) != NULLCHAR) { UnGetCH( STRM_MAGIC ); InsString( StrDupSafe( current + 1 ), TRUE ); UnGetCH( STRM_TMP_LEX_START ); *(current + 1) = NULLCHAR; } return( p ); } } } if( !StartDoubleQuote && !IsDoubleQuote ) { /* there are no double quotes in the text */ /* so return text as is */ return( p ); } pos = 0; s = PreGetCH(); while( isws( s ) ) { buffer[pos++] = s; s = PreGetCH(); } buffer[pos] = NULLCHAR; UnGetCH( s ); OutString = StartVec(); CatStrToVec( OutString, p ); FreeSafe( p ); CatStrToVec( OutString, buffer ); p = DeMacroDoubleQuote( TRUE ); CatStrToVec( OutString, p ); FreeSafe( p ); return( FinishVec( OutString ) ); }