Nested math operations in variables

this script reproduces the problem:

variable v equal atan2(atan2(1,2),2)
print $v

ERROR: Invalid syntax in variable formula

The problem is in the following code, which appears in three different places within variable.cpp:

ptr1 = strchr(contents,’,’);
if (ptr1) {
*ptr1 = ‘\0’;
ptr2 = strchr(ptr1+1,’,’);
if (ptr2) *ptr2 = ‘\0’;
} else ptr2 = NULL;

The call to strrchr while parsing the arguments of the outer atan2 incorrectly finds the first comma, which belongs to the arguments of the inner atan2.
I fixed the problem in my local copy of variable.cpp by changing the above code to the following code:

ptr1 = find_comma(contents);
if (ptr1) {
*ptr1 = ‘\0’;
ptr2 = find_comma(ptr1+1);
if (ptr2) *ptr2 = ‘\0’;
} else ptr2 = NULL;

where find_comma is defined like so:

char *Variable::find_comma(char contents)
{
int lev=0;
for (char
p=contents; *p; ++p) {
if (’(’==*p) ++lev;
else if (’)’==*p) --lev;
else if (’,’==*p && !lev) return p;
}
return NULL;
}

Dario

I'll take a look - thanks for the examples and code snippets.

Steve

yep - that fixed it - just posted a patch

Thanks,
Steve