#include #include #include #include #include #include "functions.h" #include "common.h" #include "db.h" int is_float(char *c) { int i; syslog(LOG_DEBUG, "Starting is_float:%s", c ); for(i=0;i<=strlen(c);i++) { if((c[i]=='(')||(c[i]==')')||(c[i]=='{')||(c[i]=='<')||(c[i]=='>')||(c[i]=='=')) { return FAIL; } } return SUCCEED; } void delete_spaces(char *c) { int i,j; syslog( LOG_DEBUG, "Before deleting spaces:%s", c ); j=0; for(i=0;i') != FAIL ) { syslog(LOG_DEBUG, "> is found" ); l=find_char(exp,'>'); strcpy(first, exp); first[l]=0; j=0; for(i=l+1;i value2 ) { *result=1; } else { *result=0; } return SUCCEED; } else if( find_char(exp,'<') != FAIL ) { syslog(LOG_DEBUG, "< is found" ); l=find_char(exp,'<'); strcpy(first, exp); first[l]=0; j=0; for(i=l+1;i=0;i--) { if( exp[i] == '(' ) { l=i; break; } } if( r == -1 ) { syslog(LOG_WARNING, "Cannot find left bracket [(]. Expression:%s", exp ); return FAIL; } for(i=l+1;i=l+3) && (i<=r) ) continue; exp[j]=exp[i]; if(i==l) exp[j]='%'; if(i==l+1) exp[j]='f'; j++; } exp[j]=0; syslog( LOG_DEBUG, "Expression3:%s", exp ); sprintf(res,exp,value); strcpy(exp,res); // delete_spaces(exp); syslog( LOG_DEBUG, "Expression4:%s", exp ); } syslog( LOG_DEBUG, "Result expression:%s", exp ); return SUCCEED; } /* * Translate "{15}>10" to "6.456>10" */ int substitute_functions(char *exp) { float value; char functionid[1024]; char res[1024]; int i,l,r; syslog(LOG_DEBUG, "BEGIN substitute_functions" ); while( find_char(exp,'{') != FAIL ) { l=find_char(exp,'{'); r=find_char(exp,'}'); if( r == FAIL ) { syslog( LOG_WARNING, "Cannot find right bracket. Expression:%s", exp ); return FAIL; } if( r < l ) { syslog( LOG_WARNING, "Right bracket is before left one. Expression:%s", exp ); return FAIL; } for(i=l+1;i