i finally had some time off from work and went through and fixed this code, in case anyone was waiting for the fix i commented around the addition to the code that fixes it, the following code is flawlessly working version.
char *parse_setvar( char *cmnd, CHAR_DATA *mob, CHAR_DATA *actor, OBJ_DATA *obj, void *vo, CHAR_DATA *rndm )
{
static char results[MSL*2];
int x;
CHAR_DATA *chkchar = NULL;
OBJ_DATA *chkobj = NULL;
ROOM_INDEX_DATA *chkroom = NULL;
bool function = FALSE;
char parse[MIL];
sprintf( parse, "%s", cmnd );
results[0] = '\0';
if ( !str_infix( "(", parse ) )
{
int left = 0, z, right = 0;
char func[MIL];
bool infunc = FALSE, skipToRightParen = FALSE;
cmnd[0] = '\0';
for ( x=0; parse[x] != '\0'; x++ )
{
if ( parse[x] == '(' )
left++;
}
func[0] = '\0';
infunc = FALSE;
for ( z = 0; parse[z] != '\0'; z++ )
{
if ( infunc )
{
if ( parse[z] == ')' )
{
right++;
if ( right == left )
{
sprintf( func, "%s", parse_setvar( func, mob, actor, obj, vo, rndm ) );
break;
}
else
add_letter( func, parse[z] );
continue;
}
else
{
add_letter( func, parse[z] );
continue;
}
}
if ( parse[z] == '(' )
{
infunc = TRUE;
}
}
right = 0;
for ( z = 0; parse[z] != '\0'; z++ )
{
if ( parse[z] == ')' )
right++;
if ( skipToRightParen )
{
if ( right < left )
continue;
skipToRightParen = FALSE;
}
if ( parse[z] == '(' )
{
int a;
add_letter( cmnd, parse[z] );
for ( a = 0; func[a] != '\0'; a++ )
{
add_letter( cmnd, func[a] );
}
skipToRightParen = TRUE;
}
else
{
add_letter( cmnd, parse[z] );
}
}
}
// Fixed with one simple correction
results[0] = '\0';
// End Fix
for ( x=0; cmnd[x] != '\0'; x++)
{
chkchar = NULL;
chkobj = NULL;
chkroom = NULL;
function = FALSE;
if (cmnd[x] == '\0')
return results;
if (cmnd[x] != '$')
add_letter( results, cmnd[x]);
else
{
... section not to do with string manipulation
}
if (chkchar || chkobj || chkroom || function) // Ok, so one of them is valid, lets find out what the info we're looking at is.
{
x+=2; // skip over the identifier and go straight into whats next...
if (cmnd[x] != '.' || cmnd[x] == '\0') // not a period, so this isnt a pointer, just a variable.
{
add_letter( results, cmnd[x-2]); // Put this piece back
add_letter( results, cmnd[x-1]); // Put this piece back
add_letter( results, cmnd[x]); // Put this piece back
if ( cmnd[x] == '\0')
return results;
continue; // and keep going.
}
else // Ok, they used the right syntax, lets fight out what our 'word' is.
{
char word[MIL];;
word[0] = '\0';
x++;
while ( !isspace(cmnd[x]) && cmnd[x] != '\0' )
{
add_letter( word, cmnd[x]);
x++;
}
// If we get here, we assume we now have the word.
if (chkchar != NULL) // Begin looking for possible character matches.
{
if (!str_prefix( "getvar", word))
{
VAR_DATA *var;
char arg[MIL];
bool found = FALSE;
arg[0] = '\0';
int y;
if ( word[6] != '(' )
{
progbug( format( "Function GETVAR missing opening parenthesis(%c)", word[6] ), mob );
return results;
}
for ( y = 7; y <= strlen(word); y++ )
{
if ( word[y] == ')' )
break;
if ( word[y] == '\0' )
{
progbug( "Illegal use of GETVAR function (End of String Reached Before Finding a Closing Parenthesis)", mob );
return results;
}
add_letter( arg, word[y] );
}
for ( var = chkchar->first_var; var; var = var->next )
{
if ( !str_cmp( var->name, arg ) )
{
strcat( results, format( "%s", var->value ) );
found = TRUE;
}
}
if ( !found )
{
progbug( format( "Getvar: Var not found on char(%s)", arg ), mob );
strcat( results, "NullVar" );
}
}
}
if (cmnd[x] == '\0')
return results;
else
add_letter( results, cmnd[x]);
}
}
}
return results;
}
|