Fix for a problem I believe is about quotes in patternsin dbInitSubs().
Added some debug code.
This commit is contained in:
@@ -259,13 +259,22 @@ int dbLoadRecords(char* pfilename, char* pattern, char* container)
|
||||
|
||||
if(is_not_inited)
|
||||
{
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"initing parser\n");
|
||||
#endif
|
||||
yyin=fp;
|
||||
is_not_inited=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"restarting parser\n");
|
||||
#endif
|
||||
yyrestart(fp);
|
||||
}
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"before parser startup\n");
|
||||
#endif
|
||||
yyparse();
|
||||
|
||||
#ifndef vxWorks
|
||||
|
||||
@@ -105,11 +105,11 @@ subst: PATTERN pattern subs
|
||||
|
||||
pattern: O_BRACE vars C_BRACE
|
||||
{
|
||||
/*
|
||||
#ifdef ERROR_STUFF
|
||||
int i;
|
||||
for(i=0;i<var_count;i++) fprintf(stderr,"variable=(%s)\n",vars[i]);
|
||||
fprintf(stderr,"var_count=%d\n",var_count);
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
;
|
||||
|
||||
@@ -130,7 +130,9 @@ subs: subs sub
|
||||
sub: WORD O_BRACE vals C_BRACE
|
||||
{
|
||||
sub_collect[strlen(sub_collect)-1]='\0';
|
||||
/* fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect);
|
||||
#endif
|
||||
#ifndef SUB_TOOL
|
||||
if(db_file_name)
|
||||
dbLoadRecords(db_file_name,sub_collect,$1);
|
||||
@@ -147,7 +149,9 @@ sub: WORD O_BRACE vals C_BRACE
|
||||
| O_BRACE vals C_BRACE
|
||||
{
|
||||
sub_collect[strlen(sub_collect)-1]='\0';
|
||||
/* fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect);
|
||||
#endif
|
||||
#ifndef SUB_TOOL
|
||||
if(db_file_name)
|
||||
dbLoadRecords(db_file_name,sub_collect,NULL);
|
||||
@@ -199,7 +203,9 @@ var_subs: var_subs var_sub
|
||||
var_sub: WORD O_BRACE sub_pats C_BRACE
|
||||
{
|
||||
sub_collect[strlen(sub_collect)-1]='\0';
|
||||
/* fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect);
|
||||
#endif
|
||||
#ifndef SUB_TOOL
|
||||
if(db_file_name)
|
||||
dbLoadRecords(db_file_name,sub_collect,$1);
|
||||
@@ -216,7 +222,9 @@ var_sub: WORD O_BRACE sub_pats C_BRACE
|
||||
| O_BRACE sub_pats C_BRACE
|
||||
{
|
||||
sub_collect[strlen(sub_collect)-1]='\0';
|
||||
/* fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect);
|
||||
#endif
|
||||
#ifndef SUB_TOOL
|
||||
if(db_file_name)
|
||||
dbLoadRecords(db_file_name,sub_collect,NULL);
|
||||
@@ -292,7 +300,10 @@ int dbLoadTemplate(char* sub_file)
|
||||
yyin=fp;
|
||||
is_not_inited=0;
|
||||
}
|
||||
else yyrestart(fp);
|
||||
else
|
||||
{
|
||||
yyrestart(fp);
|
||||
}
|
||||
|
||||
yyparse();
|
||||
|
||||
@@ -328,8 +339,18 @@ int sub_it()
|
||||
{
|
||||
FILE* fp;
|
||||
char var_buff[500];
|
||||
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"In sub_it()\n");
|
||||
#endif
|
||||
|
||||
if( *sub_collect )
|
||||
{
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr," dbInitSubst() calling\n");
|
||||
#endif
|
||||
dbInitSubst(sub_collect);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"No valid substitutions found in table\n");
|
||||
@@ -345,10 +366,16 @@ int sub_it()
|
||||
/* do the work here */
|
||||
while( fgets(var_buff,200,fp)!=(char*)NULL )
|
||||
{
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr," calling dbDoSubst()\n");
|
||||
#endif
|
||||
dbDoSubst(var_buff,500,NULL);
|
||||
fputs(var_buff,stdout);
|
||||
}
|
||||
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr," calling dbFreeSubst()\n");
|
||||
#endif
|
||||
dbFreeSubst();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
|
||||
@@ -191,13 +191,19 @@ long dbInitSubst(char* parm_pattern)
|
||||
/* find vars and subs */
|
||||
switch(*pp)
|
||||
{
|
||||
case '\\': pp++; break;
|
||||
case '\\': pp++; break; /* skip the next character */
|
||||
case '=': subst_total++; break;
|
||||
case '\"': for(++pp;*pp!='\"';pp++) if(*pp=='\\') pp++; pp++; break;
|
||||
case '\"':
|
||||
for(++pp;*pp && *pp!='\"';pp++);
|
||||
if(*pp=='\\') pp++;
|
||||
pp++;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
/* fprintf(stderr,"total = %d\n",subst_total); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"total = %d\n",subst_total);
|
||||
#endif
|
||||
|
||||
/* allocate the substitution table */
|
||||
subst = (struct var_sub*)malloc( sizeof(struct var_sub)*subst_total );
|
||||
@@ -235,12 +241,12 @@ long dbInitSubst(char* parm_pattern)
|
||||
}
|
||||
|
||||
/* debug code */
|
||||
/*
|
||||
#ifdef ERROR_STUFF
|
||||
for(pi=0;pi<subst_total;pi++)
|
||||
{
|
||||
printf("table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
|
||||
fprintf(stderr,"table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* resolve the multiple substitutions now */
|
||||
for(pi=0;pi<subst_total;pi++)
|
||||
@@ -253,12 +259,12 @@ long dbInitSubst(char* parm_pattern)
|
||||
}
|
||||
|
||||
/* more debug code */
|
||||
/*
|
||||
#ifdef ERROR_STUFF
|
||||
for(pi=0;pi<subst_total;pi++)
|
||||
{
|
||||
printf("table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
|
||||
fprintf(stderr,"table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -276,7 +282,9 @@ static char* get_var(char** to, char* from)
|
||||
pp = strpbrk(from," \t=");
|
||||
*pp = '\0';
|
||||
pp++;
|
||||
/* fprintf(stderr,"get_var: (%s)\n",from); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"get_var: (%s)\n",from);
|
||||
#endif
|
||||
*to=from;
|
||||
return pp;
|
||||
}
|
||||
@@ -297,7 +305,9 @@ static char* get_sub(char* to, char* from)
|
||||
else *cp++ = *pp;
|
||||
}
|
||||
*cp='\0';
|
||||
/* fprintf(stderr,"get_sub: quote (%s)\n",to); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"get_sub: quote (%s)\n",to);
|
||||
#endif
|
||||
pp++;
|
||||
}
|
||||
else
|
||||
@@ -307,7 +317,9 @@ static char* get_sub(char* to, char* from)
|
||||
{
|
||||
*hold = '\0';
|
||||
hold++;
|
||||
/* fprintf(stderr,"get_sub: regular (%s)\n",pp); */
|
||||
#ifdef ERROR_STUFF
|
||||
fprintf(stderr,"get_sub: regular (%s)\n",pp);
|
||||
#endif
|
||||
}
|
||||
|
||||
strcpy(to,pp);
|
||||
|
||||
Reference in New Issue
Block a user