sprintf(tbuf,"WARNING: line %d, '%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
lineno,*cp);
global_lineno,*cp);
else
sprintf(tbuf,"WARNING: line %d, '%c%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
lineno,*cp,*(cp+1));
global_lineno,*cp,*(cp+1));
strcat(error_report,tbuf);
warn_count++;
global_warn_count++;
warn_found++;
}
}
@ -80,8 +118,80 @@ int check_expr(char *buffer, char *error_report)
returnwarn_found;
}
intcheck_eval(char*buffer,char*error_report)
{
char*cp,*ep,*xp,*s;
charevalbuf[80000];
externchar*ast_expr(char*);
intoplen=0;
intwarn_found=0;
error_report[0]=0;
ep=evalbuf;
for(cp=buffer;*cp;cp++){
if(*cp=='$'&&*(cp+1)=='{'){
intbrack_lev=1;
char*xp=cp+2;
while(*xp){
if(*xp=='{')
brack_lev++;
elseif(*xp=='}')
brack_lev--;
if(brack_lev==0)
break;
xp++;
}
if(*xp=='}'){
charvarname[200];
char*val;
strncpy(varname,cp+2,xp-cp-2);
varname[xp-cp-2]=0;
cp=xp;
val=find_var(varname);
if(val){
char*z=val;
while(*z)
*ep++=*z++;
}
else{
*ep++='5';/* why not */
*ep++='5';
*ep++='5';
}
}
else{
printf("Unterminated variable reference at line %d\n",global_lineno);
*ep++=*cp;
}
}
elseif(*cp=='\\'){
/* braindead simple elim of backslash */
cp++;
*ep++=*cp;
}
else
*ep++=*cp;
}
*ep++=0;
/* now, run the test */
s=ast_expr(evalbuf);
if(s){
sprintf(error_report,"line %d, evaluation of $[ %s ] result: %s\n",global_lineno,evalbuf,s);
return1;
}
else{
sprintf(error_report,"line %d, evaluation of $[ %s ] result: ****SYNTAX ERROR****\n",global_lineno,evalbuf);
return1;
}
}
voidparse_file(char*fname)
voidparse_file(constchar*fname)
{
FILE*f=fopen(fname,"r");
FILE*l=fopen("expr2_log","w");
@ -89,90 +199,83 @@ void parse_file(char *fname)
charlast_char=0;
charbuffer[30000];/* I sure hope no expr gets this big! */
if(!f)
{
if(!f){
fprintf(stderr,"Couldn't open %s for reading... need an extensions.conf file to parse!\n");
exit(20);
}
if(!l)
{
if(!l){
fprintf(stderr,"Couldn't open 'expr2_log' file for writing... please fix and re-run!\n");
exit(21);
}
lineno =1;
global_lineno =1;
while((c1=fgetc(f))!=EOF)
{
if(c1=='\n')
lineno++;
elseif(c1=='[')
{
if(last_char=='$')
{
while((c1=fgetc(f))!=EOF){
if(c1=='\n')
global_lineno++;
elseif(c1=='['){
if(last_char=='$'){
/* bingo, an expr */
intbracklev=1;
intbufcount=0;
intretval;
charerror_report[30000];
while((c1=fgetc(f))!=EOF)
{
if(c1=='[')
while((c1=fgetc(f))!=EOF){
if(c1=='[')
bracklev++;
elseif(c1==']')
elseif(c1==']')
bracklev--;
if(c1=='\n')
{
fprintf(l,"ERROR-- A newline in an expression? Weird! ...at line %d\n",lineno);
if(c1=='\n'){
fprintf(l,"ERROR-- A newline in an expression? Weird! ...at line %d\n",global_lineno);
fclose(f);
fclose(l);
printf("--- ERROR --- A newline in the middle of an expression at line %d!\n", lineno);
printf("--- ERROR --- A newline in the middle of an expression at line %d!\n",global_lineno);
}
if(bracklev==0)
if(bracklev==0)
break;
buffer[bufcount++]=c1;
}
if(c1==EOF)
{
fprintf(l,"ERROR-- End of File Reached in the middle of an Expr at line %d\n",lineno);
if(c1==EOF){
fprintf(l,"ERROR-- End of File Reached in the middle of an Expr at line %d\n",global_lineno);
fclose(f);
fclose(l);
printf("--- ERROR --- EOF reached in middle of an expression at line %d!\n", lineno);
printf("--- ERROR --- EOF reached in middle of an expression at line %d!\n",global_lineno);
exit(22);
}
buffer[bufcount]=0;
/* update stats */
expr_tot_size +=bufcount;
expr_count++;
if(bufcount> expr_max_size)
expr_max_size =bufcount;
global_expr_tot_size +=bufcount;
global_expr_count++;
if(bufcount>global_expr_max_size)
global_expr_max_size =bufcount;
retval=check_expr(buffer,error_report);/* check_expr should bump the warning counter */
if(retval!=0)
{
if(retval!=0){
/* print error report */
printf("Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n",
lineno,buffer);
global_lineno,buffer);
fprintf(l,"%s",error_report);
}
else
{
printf("OK -- $[%s] at line %d\n",buffer,lineno);
OK_count++;
else{
printf("OK -- $[%s] at line %d\n",buffer,global_lineno);