Replaced some large local variables by other means in xorriso/match.c

This commit is contained in:
Thomas Schmitt 2011-05-05 07:52:14 +00:00
parent 2e48c434b4
commit b5f674647b
2 changed files with 56 additions and 42 deletions

View File

@ -37,8 +37,12 @@
*/
int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
{
int l,ret,i,count,bonked= 0,is_constant,is_still_relative= 0;
char *cpt,*npt,adr_part[2*SfileadrL],absolute_adr[2*SfileadrL],*adr_start,*wd;
int l,ret,i,count,bonked= 0,is_constant,is_still_relative= 0, adr_size;
char *cpt,*npt,*adr_part= NULL, *absolute_adr= NULL, *adr_start,*wd;
adr_size= 2 * SfileadrL;
Xorriso_alloc_meM(adr_part, char, adr_size);
Xorriso_alloc_meM(absolute_adr, char, adr_size);
if(flag&4)
wd= xorriso->wdx;
@ -48,10 +52,10 @@ int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
if(xorriso->search_mode>=2 && xorriso->search_mode<=4) {
if(xorriso->search_mode==3 || xorriso->search_mode==4) {
l= strlen(adr)+strlen(wd)+1;
if(l*2+2>sizeof(xorriso->reg_expr) || l*2+2>sizeof(adr_part)) {
if(l*2+2>sizeof(xorriso->reg_expr) || l * 2 + 2 > adr_size) {
sprintf(xorriso->info_text,"Search pattern too long");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
{ret= 0; goto ex;}
}
}
Xorriso_destroy_re(xorriso,0);
@ -80,10 +84,10 @@ int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
count= i+1;
xorriso->re= TSOB_FELD(regex_t,count);
if(xorriso->re==NULL)
return(-1);
{ret= -1; goto ex;}
xorriso->re_constants= TSOB_FELD(char *,count);
if(xorriso->re_constants==NULL)
return(-1);
{ret= -1; goto ex;}
for(i= 0;i<count;i++)
xorriso->re_constants[i]= NULL;
xorriso->re_count= count;
@ -97,12 +101,12 @@ int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
for(i= 0;i<count;i++) {
npt= strchr(cpt,'/');
if(npt==NULL) {
if(strlen(cpt)>=sizeof(adr_part))
return(-1);
if(strlen(cpt) >= adr_size)
{ret= -1; goto ex;}
strcpy(adr_part,cpt);
} else {
if(npt-cpt>=sizeof(adr_part))
return(-1);
if(npt-cpt >= adr_size)
{ret= -1; goto ex;}
strncpy(adr_part,cpt,npt-cpt);
adr_part[npt-cpt]= 0;
}
@ -134,7 +138,7 @@ int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
if(ret==2) {
if(Sregex_string(&(xorriso->re_constants[xorriso->re_fill]),adr_part,0)
<=0)
return(-1);
{ret= -1; goto ex;}
} else {
if(regcomp(&(xorriso->re[xorriso->re_fill]),xorriso->reg_expr,0)!=0)
goto cannot_compile;
@ -149,11 +153,11 @@ next_adr_part:;
}
if(bonked) {
if(flag&2)
return(2);
{ret= 2; goto ex;}
sprintf(xorriso->info_text, "Your '..' bonked at the %s directory.",
is_still_relative ? "working" : "root");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE",0);
return(0);
{ret= 0; goto ex;}
}
Xorriso__bourne_to_reg(adr_start,xorriso->reg_expr,0); /* just for show */
@ -167,39 +171,43 @@ next_adr_part:;
is_constant= (ret==2);
} else {
if(strlen(adr)>=sizeof(xorriso->reg_expr))
return(-1);
{ret= -1; goto ex;}
strcpy(xorriso->reg_expr,adr);
}
xorriso->re_count= 0; /* tells matcher that this is not structured */
xorriso->re_constants= TSOB_FELD(char *,1);
if(xorriso->re_constants==NULL)
return(-1);
{ret= -1; goto ex;}
xorriso->re_constants[0]= NULL;
if(is_constant) {
if(strcmp(adr,"*")==0) {
if(Sregex_string(&(xorriso->re_constants[0]),"",0)<=0)
return(-1);
{ret= -1; goto ex;}
} else {
if(Sregex_string(&(xorriso->re_constants[0]),adr,0)<=0)
return(-1);
{ret= -1; goto ex;}
}
xorriso->re_fill= 1;
} else {
xorriso->re= TSOB_FELD(regex_t,1);
if(xorriso->re==NULL)
return(-1);
{ret= -1; goto ex;}
if(regcomp(&(xorriso->re[0]),xorriso->reg_expr,0)!=0) {
cannot_compile:;
sprintf(xorriso->info_text, "Cannot compile regular expression : %s",
xorriso->reg_expr);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE",0);
return(0);
{ret= 0; goto ex;}
}
}
}
}
return(1);
ret= 1;
ex:;
Xorriso_free_meM(adr_part);
Xorriso_free_meM(absolute_adr);
return(ret);
}
@ -213,7 +221,9 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
int flag)
{
int ret,i,re_start= 0,reg_nomatch= -1;
char *cpt,*npt,adr_part[SfileadrL],*mpt;
char *cpt,*npt, *adr_part= NULL, *mpt;
Xorriso_alloc_meM(adr_part, char, SfileadrL);
reg_nomatch= REG_NOMATCH;
@ -222,13 +232,13 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
if(xorriso->re_constants!=NULL)
if(xorriso->re_constants[0]!=NULL) {
if(xorriso->re_constants[0][0]==0)
return(0);
{ret= 0; goto ex;}
if(strcmp(xorriso->re_constants[0],to_match)!=0)
return(reg_nomatch);
return(0);
{ret= reg_nomatch; goto ex;}
{ret= 0; goto ex;}
}
ret= regexec(&(xorriso->re[0]),to_match,1,xorriso->match,0);
return(ret);
goto ex;
}
cpt= to_match;
@ -243,7 +253,7 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
npt= strchr(cpt,'/');
if(npt==NULL) {
if(i<xorriso->re_fill-1 && !(flag&1))
return(reg_nomatch); /* this must be the last expression part */
{ret= reg_nomatch; goto ex;} /* this must be the last expression part */
mpt= cpt;
} else {
strncpy(adr_part,cpt,npt-cpt);
@ -253,17 +263,17 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
if(xorriso->re_constants[i]!=NULL) {
if(xorriso->re_constants[i][0]!=0) /* empty constant matches anything */
if(strcmp(xorriso->re_constants[i],mpt)!=0)
return(reg_nomatch);
{ret= reg_nomatch; goto ex;}
} else {
ret= regexec(&(xorriso->re[i]),mpt,1,xorriso->match,0);
if(ret!=0)
return(ret);
goto ex;
}
if(npt==NULL) {
if(i>=xorriso->re_fill-1)
return(0); /* MATCH */
{ret= 0; goto ex;} /* MATCH */
*failed_at= i+1;
return(reg_nomatch);
{ret= reg_nomatch; goto ex;}
}
cpt= npt+1;
while(*cpt=='/')
@ -271,8 +281,11 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
}
*failed_at= xorriso->re_fill;
if(flag & 2)
return(0); /* MATCH */
return(reg_nomatch);
{ret= 0; goto ex;} /* MATCH */
ret= reg_nomatch;
ex:;
Xorriso_free_meM(adr_part);
return(ret);
}
@ -557,7 +570,6 @@ int Xorriso_check_matchcount(struct XorrisO *xorriso,
int count, int nonconst_mismatches, int num_patterns,
char **patterns, int flag)
{
char sfe[5*SfileadrL];
if((flag&1) && (count!=1 || nonconst_mismatches)){
if(count-nonconst_mismatches>0)
@ -566,8 +578,8 @@ int Xorriso_check_matchcount(struct XorrisO *xorriso,
else
sprintf(xorriso->info_text, "No pattern match with any file object");
if(num_patterns==1)
sprintf(xorriso->info_text+strlen(xorriso->info_text), ": %s",
Text_shellsafe(patterns[0], sfe, 0));
sprintf(xorriso->info_text+strlen(xorriso->info_text), ": ");
Text_shellsafe(patterns[0], xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
(flag&2 ? "FAILURE" : "SORRY"), 0);
return(0);
@ -626,7 +638,9 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
{
int ret, count= 0, abs_adr= 0, i, was_count, was_filec;
int nonconst_mismatches= 0, dive_count= 0;
char sfe[5*SfileadrL], dir_adr[SfileadrL];
char *dir_adr= NULL;
Xorriso_alloc_meM(dir_adr, char, SfileadrL);
*filec= 0;
*filev= NULL;
@ -638,7 +652,7 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
ret= Xorriso_prepare_expansion_pattern(xorriso, patterns[i], 4);
if(ret<=0)
return(ret);
goto ex;
if(ret==2)
abs_adr= 4;
@ -652,9 +666,8 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
ret= Sfile_type(dir_adr, 1|4);
if(ret!=2) {
Xorriso_msgs_submit(xorriso, 0, dir_adr, 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"Address set by -cdx is not a directory: %s",
Text_shellsafe(dir_adr, sfe, 0));
sprintf(xorriso->info_text, "Address set by -cdx is not a directory: ");
Text_shellsafe(dir_adr, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
@ -695,7 +708,7 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
ret= Xorriso_prepare_expansion_pattern(xorriso, patterns[i], 4);
if(ret<=0)
return(ret);
goto ex;
if(patterns[i][0]=='/' || abs_adr) {
strcpy(dir_adr, "/");
@ -730,6 +743,7 @@ ex:;
Sfile_destroy_argv(&count, filev, 0);
*filec= 0;
}
Xorriso_free_meM(dir_adr);
return(ret);
}

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.05.04.171628"
#define Xorriso_timestamP "2011.05.05.075233"