expr_p()
By SalimMeghani
- 231 reads
// Convert a formula to its raw native numeric form (including brackets).
double expr_p(int *error, char *form, int qol, int rw)
{
char *source=NULL, *form9=NULL,
*dest=NULL;
int start=0,
pvalue=0, end=0,
bracket=0,
length=0;
double answer=0;
source=(char *) calloc((unsigned long) 32767, sizeof(char));
dest=(char *) calloc((unsigned long) 32767, sizeof(char));
form9=(char *) calloc((unsigned long) 32767, sizeof(char));
strcpy(source, form);
strcpy(form9, form);
clr_str(genetic);
while ((fcat)&&(*error==0))
{
fcat=0;
parser(error, form9,dest,qol,rw,0);
strcpy(form9,dest);
strcat(form9,"#");
free(dest);
dest=(char *) calloc((unsigned long) 32767, sizeof(char));
}
//strcpy(genetic,form9);
fcat=1;
while ((fcat)&&(*error==0))
{
fcat=0;
parser(error, source,dest,qol,rw,1);
strcpy(source,dest);
strcat(source,"#");
free(dest);
dest=(char *) calloc((unsigned long) 32767, sizeof(char));
}
fcat=1;
//
if (gene == 1) strcpy(genetic, form9); else strcpy(genetic, source); // else part is usually form copied to genetic..
if ((!*error) && (preced==1))
{
newyk=(char *) calloc((unsigned long) 32767, sizeof(char));
length=strlen(source)-1;
source[length]='\0';
clr_str(newyk);
strcpy(newyk,"%");
strcat(newyk,source);
if ((!isdigit(source[length-1])) && (!(source[length-1]==')'))) *error=1;
else strcat(newyk,"%\0");
if ((source[length-1]=='+') || (source[length-1]=='-')) *error=1;
length=0;
if (!*error) ans=eval_parser(newyk, error);
free(newyk);
clear_vars();
}
else
ans=0;
free(source);
free(dest);
free(form9);
if (*error==0)
{
*rtype='F';
return (ans);
}
else
return (0);
}
- Log in to post comments