该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
int MathCompute(char *string,char *Value,int *IsFloat)
{
char String[1000];
if(string[0]=='('&&string[strlen(string)-1]==')')
{
strcpy(String,&string[1]);
String[strlen(String)-1]=0;
}
else
strcpy(String,string);
char Left[500],Right[500],Symbol;
char Symbols1[5]="+-";
char Symbols2[5]="*/%";
char Symbols3[5]="-*"; int Index=GetFirstSymbolPointerThisLevel(String,Symbols1,2);
if(Index
return Index;
if(Index==-1||Index==0)
{
Index=GetFirstSymbolPointerThisLevel(String,Symbols2,3);
if(Index
return Index;
if(Index==-1||Index==0)
{
Index=GetFirstSymbolPointerThisLevel(String,Symbols3,2);
if(Index
return Index;
if(Index==-1)
{
//Vars *n=0;
Vars *n=GetVarsNODEByName(VarsHead,String);
if(n==0)
{
char *p=strchr(String,'.');
if(p)
{
*IsFloat=TRUE;
int sret=sscanf(String,"%f",Value);
if(sret==0)
return -8;
}
else if(String[0]=='0'&&String[1]=='x')
{
*IsFloat=FALSE;
int sret=sscanf(&String[2],"%x",Value);
if(sret==0)
return -8;
}
else if(String[0]=='\''&&String[2]=='\'')
{
*IsFloat=FALSE;
int sret=sscanf(&String[1],"%c",Value);
if(sret==0)
return -8;
Value[1]=0;
Value[2]=0;
Value[3]=0;
}
else
{
*IsFloat=FALSE;
int sret=sscanf(String,"%d",Value);
if(sret==0)
return -8;
}
return TRUE;
}
if(n->VarType==FLOAT)
{
*IsFloat=TRUE;
memcpy(Value,(char *)&n->Var,4);
}
else
{
*IsFloat=FALSE;
*(long *)Value=n->Var;
}
return TRUE;
}
Symbol=String[Index];
strcpy(Right,&String[1]);
char rRight[10];
int Ret;
Ret=MathCompute(Right,rRight,IsFloat);
if(Ret!=TRUE)
return Ret;
long RightValue=*(long *)rRight;
if(Symbol=='*')
{
if(*IsFloat)
return -6;//*运算不允许FLOAT
*(unsigned long *)Value=*(unsigned long *)RightValue;
}
else if(Symbol=='-')
{
if(*IsFloat)
*(float *)Value=-(*(float *)rRight);
else
*(long *)Value=-RightValue;
}
return TRUE; }
Symbol=String[Index];
String[Index]=0;
strcpy(Left,String);
strcpy(Right,&String[Index+1]); char rLeft[10],rRight[10];
int lIsFloat,rIsFloat;
int Ret;
Ret=MathCompute(Left,rLeft,&lIsFloat);
if(Ret!=TRUE)
return Ret;
Ret=MathCompute(Right,rRight,&rIsFloat);
if(Ret!=TRUE)
return Ret; if(lIsFloat||rIsFloat)
*IsFloat=TRUE;
else
*IsFloat=FALSE; if(Symbol=='*')
{
if(*IsFloat)