Removed some redundancy of disk_pattern and iso_rr_pattern matching
This commit is contained in:
parent
0084c4aa10
commit
c4cf6bad98
@ -3638,17 +3638,109 @@ int Xorriso_prepare_expansion_pattern(struct XorrisO *xorriso, char *pattern,
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= count results rather than storing them
|
||||
bit1= unexpected change of number is a FATAL event
|
||||
@return <=0 error , 1 is root (end processing) ,
|
||||
2 is not root (go on processing)
|
||||
*/
|
||||
int Xorriso_check_for_root_pattern(struct XorrisO *xorriso,
|
||||
int *filec, char **filev, int count_limit, off_t *mem, int flag)
|
||||
{
|
||||
if(xorriso->re_fill!=0)
|
||||
return(2);
|
||||
/* This is the empty pattern representing root */
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
(*mem)+= 8;
|
||||
} else {
|
||||
if(*filec >= count_limit) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Number of matching files changed unexpectedly (> %d)",
|
||||
count_limit);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
|
||||
(flag&2 ? "FATAL" : "WARNING"), 0);
|
||||
return(flag&2 ? -1 : 0);
|
||||
}
|
||||
filev[*filec]= strdup("/");
|
||||
if(filev[*filec]==NULL) {
|
||||
Xorriso_no_pattern_memory(xorriso, (off_t) 2, 0);
|
||||
return(-1);
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit2= prepend wd (automatically done if wd[0]!=0)
|
||||
*/
|
||||
int Xorriso_make_pattern_adr(struct XorrisO *xorriso, char *wd, char *name,
|
||||
char adr[], int flag)
|
||||
{
|
||||
if(wd[0]!=0 || (flag&4)) {
|
||||
if(strlen(wd)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, wd);
|
||||
if(Sfile_add_to_path(adr, name, 0)<=0) {
|
||||
much_too_long:;
|
||||
Xorriso_much_too_long(xorriso, (int) (strlen(adr)+strlen(name)+1), 2);
|
||||
return(0);
|
||||
}
|
||||
} else {
|
||||
if(strlen(name)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, name);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= count result rather than storing it
|
||||
bit1= unexpected change of number is a FATAL event
|
||||
*/
|
||||
int Xorriso_register_matched_adr(struct XorrisO *xorriso,
|
||||
char *adr, int count_limit,
|
||||
int *filec, char **filev, off_t *mem, int flag)
|
||||
{
|
||||
int l;
|
||||
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
l= strlen(adr)+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
} else {
|
||||
if(*filec >= count_limit) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Number of matching files changed unexpectedly (> %d)",
|
||||
count_limit);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
|
||||
(flag&2 ? "FATAL" : "WARNING"), 0);
|
||||
return(flag&2 ? -1 : 0);
|
||||
}
|
||||
filev[*filec]= strdup(adr);
|
||||
if(filev[*filec]==NULL) {
|
||||
Xorriso_no_pattern_memory(xorriso, (off_t) (strlen(adr)+1), 0);
|
||||
return(-1);
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= count results rather than storing them
|
||||
bit1= this is a recursion
|
||||
bit2= prepend wd (automatically done if wd[0]!=0)
|
||||
@return <=0 error , 1 ok , 2 could not open directory
|
||||
*/
|
||||
int Xorriso_obtain_disk_files(
|
||||
int Xorriso_obtain_pattern_files_x(
|
||||
struct XorrisO *xorriso, char *wd, char *dir_adr,
|
||||
int *filec, char **filev, int count_limit, off_t *mem,
|
||||
int *dive_count, int flag)
|
||||
{
|
||||
int ret, failed_at, l;
|
||||
int ret, failed_at;
|
||||
char adr[SfileadrL], name[SfileadrL];
|
||||
struct DirseQ *dirseq;
|
||||
|
||||
@ -3656,21 +3748,11 @@ int Xorriso_obtain_disk_files(
|
||||
*dive_count= 0;
|
||||
else
|
||||
(*dive_count)++;
|
||||
if(xorriso->re_fill==0) { /* This is the empty pattern representing root */
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
(*mem)+= 8;
|
||||
{ret= 1; goto ex;}
|
||||
} else {
|
||||
if(*filec >= count_limit)
|
||||
goto unexpected_change;
|
||||
filev[*filec]= strdup("/");
|
||||
if(filev[*filec]==NULL)
|
||||
goto out_of_memory;
|
||||
(*filec)++;
|
||||
{ret= 1; goto ex;}
|
||||
}
|
||||
}
|
||||
|
||||
ret= Xorriso_check_for_root_pattern(xorriso, filec, filev, count_limit,
|
||||
mem, flag&1);
|
||||
if(ret!=2)
|
||||
goto ex;
|
||||
|
||||
ret= Dirseq_new(&dirseq, dir_adr, 1);
|
||||
if(ret<0) {
|
||||
@ -3690,23 +3772,10 @@ int Xorriso_obtain_disk_files(
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
if(wd[0]!=0 || (flag&4)) {
|
||||
if(strlen(wd)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, wd);
|
||||
if(Sfile_add_to_path(adr, name, 0)<=0) {
|
||||
much_too_long:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Path for pattern matching gets much too long (%d)",
|
||||
(int) (strlen(adr)+strlen(name)+1));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
} else {
|
||||
if(strlen(name)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, name);
|
||||
}
|
||||
|
||||
ret= Xorriso_make_pattern_adr(xorriso, wd, name, adr, flag&4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
ret= Xorriso_regexec(xorriso, adr, &failed_at, 1);
|
||||
if(ret>0) { /* no match */
|
||||
@ -3717,37 +3786,17 @@ much_too_long:;
|
||||
if(ret!=2)
|
||||
continue;
|
||||
/* dive deeper */
|
||||
ret= Xorriso_obtain_disk_files(xorriso, adr, adr,
|
||||
ret= Xorriso_obtain_pattern_files_x(xorriso, adr, adr,
|
||||
filec, filev, count_limit, mem, dive_count, flag|2);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
} else {
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
l= strlen(adr)+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
} else {
|
||||
if(*filec >= count_limit) {
|
||||
unexpected_change:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Number of matching files changed unexpectedly (> %d)",
|
||||
count_limit);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
filev[*filec]= strdup(adr);
|
||||
if(filev[*filec]==NULL) {
|
||||
out_of_memory:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot allocate enough memory (%d bytes) for pattern expansion",
|
||||
(int) strlen(adr)+1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
ret= Xorriso_register_matched_adr(xorriso, adr, count_limit,
|
||||
filec, filev, mem, flag&1);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret= 1;
|
||||
@ -3757,6 +3806,93 @@ ex:;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int Xorriso_eval_nonmatch(struct XorrisO *xorriso, char *pattern,
|
||||
int *nonconst_mismatches, off_t *mem, int flag)
|
||||
{
|
||||
int k,l;
|
||||
|
||||
/* Is this a constant pattern ? */
|
||||
for(k= 0; k<xorriso->re_fill; k++) {
|
||||
if(xorriso->re_constants[k]==NULL)
|
||||
break;
|
||||
if(xorriso->re_constants[k][0]==0)
|
||||
break;
|
||||
}
|
||||
if(k<xorriso->re_fill)
|
||||
(*nonconst_mismatches)++; /* it is not */
|
||||
|
||||
l= strlen(pattern)+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= a match count !=1 is a SORRY event
|
||||
*/
|
||||
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)
|
||||
sprintf(xorriso->info_text,
|
||||
"Pattern match with more than one file object");
|
||||
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));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_no_pattern_memory(struct XorrisO *xorriso, off_t mem, int flag)
|
||||
{
|
||||
char mem_text[80];
|
||||
|
||||
Sfile_scale((double) mem, mem_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot allocate enough memory (%s) for pattern expansion",
|
||||
mem_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_alloc_pattern_mem(struct XorrisO *xorriso, off_t mem,
|
||||
int count, char ***filev, int flag)
|
||||
{
|
||||
char mem_text[80], limit_text[80];
|
||||
|
||||
Sfile_scale((double) mem, mem_text,5,1e4,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"Temporary memory needed for pattern expansion : %s", mem_text);
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
if(mem > xorriso->temp_mem_limit) {
|
||||
Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"List of matching file addresses exceeds -temp_mem_limit (%s > %s)",
|
||||
mem_text, limit_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
(*filev)= (char **) calloc(sizeof(char *), count);
|
||||
if(*filev==NULL) {
|
||||
Xorriso_no_pattern_memory(xorriso, mem, 0);
|
||||
return(-1);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= a match count !=1 is a SORRY event
|
||||
bit1= with bit0 tolerate 0 matches if pattern is a constant
|
||||
@ -3765,9 +3901,9 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
|
||||
int num_patterns, char **patterns, int extra_filec,
|
||||
int *filec, char ***filev, off_t *mem, int flag)
|
||||
{
|
||||
int ret, count= 0, abs_adr= 0, i, l, was_count, was_filec, k;
|
||||
int ret, count= 0, abs_adr= 0, i, was_count, was_filec;
|
||||
int nonconst_mismatches= 0, dive_count= 0;
|
||||
char mem_text[80], limit_text[80], sfe[5*SfileadrL], dir_adr[SfileadrL];
|
||||
char sfe[5*SfileadrL], dir_adr[SfileadrL];
|
||||
|
||||
*filec= 0;
|
||||
*filev= NULL;
|
||||
@ -3800,42 +3936,23 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
|
||||
|
||||
/* count the matches */
|
||||
was_count= count;
|
||||
ret= Xorriso_obtain_disk_files(xorriso, "", dir_adr, &count, NULL, 0, mem,
|
||||
&dive_count, 1 | abs_adr);
|
||||
ret= Xorriso_obtain_pattern_files_x(xorriso, "", dir_adr, &count, NULL, 0,
|
||||
mem, &dive_count, 1 | abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(was_count==count && strcmp(patterns[i],"*")!=0 && (flag&3)!=1) {
|
||||
count++;
|
||||
|
||||
/* Is this a constant pattern ? */
|
||||
for(k= 0; k<xorriso->re_fill; k++) {
|
||||
if(xorriso->re_constants[k]==NULL)
|
||||
break;
|
||||
if(xorriso->re_constants[k][0]==0)
|
||||
break;
|
||||
}
|
||||
if(k<xorriso->re_fill)
|
||||
nonconst_mismatches++; /* it is not */
|
||||
|
||||
l= strlen(patterns[i])+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
ret= Xorriso_eval_nonmatch(xorriso, patterns[i],
|
||||
&nonconst_mismatches, mem, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
|
||||
if((flag&1) && (count!=1 || nonconst_mismatches)){
|
||||
if(count-nonconst_mismatches>0)
|
||||
sprintf(xorriso->info_text,
|
||||
"Pattern match with more than one file object");
|
||||
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));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
ret= Xorriso_check_matchcount(xorriso, count, nonconst_mismatches,
|
||||
num_patterns, patterns, flag&1);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
count+= extra_filec;
|
||||
mem+= extra_filec*sizeof(char *);
|
||||
@ -3843,30 +3960,9 @@ int Xorriso_expand_disk_pattern(struct XorrisO *xorriso,
|
||||
if(count<=0)
|
||||
{ret= 0; goto ex;}
|
||||
|
||||
Sfile_scale((double) *mem, mem_text,5,1e4,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"Temporary memory needed for pattern expansion : %s", mem_text);
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
if(*mem > xorriso->temp_mem_limit) {
|
||||
Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"List of matching file addresses exceeds -temp_mem_limit (%s > %s)",
|
||||
mem_text, limit_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
(*filev)= (char **) calloc(sizeof(char *), count);
|
||||
if(*filev==NULL) {
|
||||
no_memory:;
|
||||
Sfile_scale((double) *mem, mem_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot allocate enough memory (%s) for pattern expansion",
|
||||
mem_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
ret= Xorriso_alloc_pattern_mem(xorriso, *mem, count, filev, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
/* now store addresses */
|
||||
for(i= 0; i<num_patterns; i++) {
|
||||
@ -3882,15 +3978,17 @@ no_memory:;
|
||||
strcpy(dir_adr, xorriso->wdx);
|
||||
|
||||
was_filec= *filec;
|
||||
ret= Xorriso_obtain_disk_files(xorriso, "", dir_adr, filec, *filev, count,
|
||||
mem, &dive_count, abs_adr);
|
||||
ret= Xorriso_obtain_pattern_files_x(xorriso, "", dir_adr, filec, *filev,
|
||||
count, mem, &dive_count, abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
if(was_filec == *filec && strcmp(patterns[i],"*")!=0) {
|
||||
(*filev)[*filec]= strdup(patterns[i]);
|
||||
if((*filev)[*filec]==NULL) {
|
||||
(*mem)= strlen(patterns[i])+1;
|
||||
goto no_memory;
|
||||
Xorriso_no_pattern_memory(xorriso, *mem, 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
@ -4372,7 +4470,7 @@ no_sort_possible:;
|
||||
for(i= 0; i<filec; i++)
|
||||
filev[i]= NULL;
|
||||
fc= 0;
|
||||
for(i= 0; i<filec; i++) {
|
||||
while(1) {
|
||||
ret= Dirseq_next_adr(dirseq,name,0);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
|
@ -206,6 +206,39 @@ int Xorriso_much_too_long(struct XorrisO *xorriso, int len, int flag);
|
||||
|
||||
int Xorriso_check_temp_mem_limit(struct XorrisO *xorriso, off_t mem, int flag);
|
||||
|
||||
int Xorriso_eval_nonmatch(struct XorrisO *xorriso, char *pattern,
|
||||
int *nonconst_mismatches, off_t *mem, int flag);
|
||||
|
||||
/* @param flag bit0= a match count !=1 is a SORRY event
|
||||
*/
|
||||
int Xorriso_check_matchcount(struct XorrisO *xorriso,
|
||||
int count, int nonconst_mismatches, int num_patterns,
|
||||
char **patterns, int flag);
|
||||
|
||||
int Xorriso_no_pattern_memory(struct XorrisO *xorriso, off_t mem, int flag);
|
||||
|
||||
int Xorriso_alloc_pattern_mem(struct XorrisO *xorriso, off_t mem,
|
||||
int count, char ***filev, int flag);
|
||||
|
||||
/* @param flag bit0= count results rather than storing them
|
||||
@return <=0 error , 1 is root (end processing) ,
|
||||
2 is not root (go on processing)
|
||||
*/
|
||||
int Xorriso_check_for_root_pattern(struct XorrisO *xorriso,
|
||||
int *filec, char **filev, int count_limit, off_t *mem, int flag);
|
||||
|
||||
/* @param flag bit2= prepend wd (automatically done if wd[0]!=0)
|
||||
*/
|
||||
int Xorriso_make_pattern_adr(struct XorrisO *xorriso, char *wd, char *name,
|
||||
char adr[], int flag);
|
||||
|
||||
/* @param flag bit0= count result rather than storing it
|
||||
bit1= unexpected change of number is a FATAL event
|
||||
*/
|
||||
int Xorriso_register_matched_adr(struct XorrisO *xorriso,
|
||||
char *adr, int count_limit,
|
||||
int *filec, char **filev, off_t *mem, int flag);
|
||||
|
||||
|
||||
|
||||
int Sfile_str(char target[SfileadrL], char *source, int flag);
|
||||
|
@ -1 +1 @@
|
||||
#define Xorriso_timestamP "2007.12.04.074340"
|
||||
#define Xorriso_timestamP "2007.12.04.205919"
|
||||
|
@ -1110,6 +1110,7 @@ int Xorriso_toc(struct XorrisO *xorriso, int flag)
|
||||
struct burn_drive_info *dinfo;
|
||||
struct burn_drive *drive;
|
||||
enum burn_disc_status s;
|
||||
char mem_text[80];
|
||||
|
||||
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
||||
"on attempt to print Table Of Content", flag&2);
|
||||
@ -1244,8 +1245,9 @@ int Xorriso_toc(struct XorrisO *xorriso, int flag)
|
||||
}
|
||||
if(xorriso->request_to_abort)
|
||||
return(1);
|
||||
sprintf(respt, "Media summary: %d session%s, %d data blocks\n",
|
||||
num_sessions, (num_sessions==1 ? "" : "s"), num_data);
|
||||
Sfile_scale(((double) num_data) * 2048.0, mem_text,5,1e4,1);
|
||||
sprintf(respt, "Media summary: %d session%s, %d data blocks (%s)\n",
|
||||
num_sessions, (num_sessions==1 ? "" : "s"), num_data, mem_text);
|
||||
Xorriso_result(xorriso,0);
|
||||
|
||||
if (s == BURN_DISC_APPENDABLE && nwa!=0) {
|
||||
@ -2285,97 +2287,66 @@ int Xorriso_mkdir(struct XorrisO *xorriso, char *path, int flag)
|
||||
bit1= this is a recursion
|
||||
bit2= prepend wd (automatically done if wd[0]!=0)
|
||||
*/
|
||||
int Xorriso_obtain_pattern_files(
|
||||
int Xorriso_obtain_pattern_files_i(
|
||||
struct XorrisO *xorriso, char *wd, struct iso_tree_node_dir *dir,
|
||||
int *filec, char **filev, int count_limit, off_t *mem, int flag)
|
||||
int *filec, char **filev, int count_limit, off_t *mem,
|
||||
int *dive_count, int flag)
|
||||
{
|
||||
int ret, failed_at, l;
|
||||
int ret, failed_at;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_tree_node *node;
|
||||
char adr[SfileadrL], *name;
|
||||
|
||||
if(xorriso->re_fill==0) { /* This is the empty pattern representing root */
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
(*mem)+= 8;
|
||||
return(1);
|
||||
} else {
|
||||
if(*filec >= count_limit)
|
||||
goto unexpected_change;
|
||||
filev[*filec]= strdup("/");
|
||||
if(filev[*filec]==NULL)
|
||||
goto out_of_memory;
|
||||
(*filec)++;
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
if(!(flag&2))
|
||||
*dive_count= 0;
|
||||
else
|
||||
(*dive_count)++;
|
||||
ret= Xorriso_check_for_root_pattern(xorriso, filec, filev, count_limit,
|
||||
mem, (flag&1)|2);
|
||||
if(ret!=2)
|
||||
goto ex;
|
||||
|
||||
iter= iso_tree_node_children(dir);
|
||||
if(iter==NULL) {
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
sprintf(xorriso->info_text, "Cannot obtain ISO directory iterator");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
while((node= iso_tree_iter_next(iter)) != NULL) {
|
||||
name= (char *) iso_tree_node_get_name(node);
|
||||
if(wd[0]!=0 || (flag&4)) {
|
||||
if(strlen(wd)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, wd);
|
||||
if(Sfile_add_to_path(adr, name, 0)<=0) {
|
||||
much_too_long:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Path for pattern matching gets much too long (%d)",
|
||||
(int) (strlen(adr)+strlen(name)+1));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
} else {
|
||||
if(strlen(name)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
strcpy(adr, name);
|
||||
}
|
||||
|
||||
ret= Xorriso_regexec(xorriso, adr, &failed_at, 0);
|
||||
if(ret) { /* no match */
|
||||
if(!LIBISO_ISDIR(node))
|
||||
continue;
|
||||
/* dive deeper */
|
||||
ret= Xorriso_obtain_pattern_files(
|
||||
xorriso, adr, (struct iso_tree_node_dir *) node,
|
||||
filec, filev, count_limit, mem, flag|2);
|
||||
ret= Xorriso_make_pattern_adr(xorriso, wd, name, adr, flag&4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
ret= Xorriso_regexec(xorriso, adr, &failed_at, 1);
|
||||
if(ret) { /* no match */
|
||||
if(failed_at <= *dive_count) /* no hope for a match */
|
||||
continue;
|
||||
|
||||
if(!LIBISO_ISDIR(node)) {
|
||||
|
||||
/* >>> How to deal with softlinks ? */
|
||||
|
||||
continue;
|
||||
}
|
||||
/* dive deeper */
|
||||
ret= Xorriso_obtain_pattern_files_i(
|
||||
xorriso, adr, (struct iso_tree_node_dir *) node,
|
||||
filec, filev, count_limit, mem, dive_count, flag|2);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
} else {
|
||||
ret= Xorriso_register_matched_adr(xorriso, adr, count_limit,
|
||||
filec, filev, mem, (flag&1)|2);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(flag&2)
|
||||
(*dive_count)--;
|
||||
return(ret);
|
||||
} else {
|
||||
if(flag&1) {
|
||||
(*filec)++;
|
||||
l= strlen(adr)+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
} else {
|
||||
if(*filec >= count_limit) {
|
||||
unexpected_change:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Number of matching files changed unexpectedly (> %d)",
|
||||
count_limit);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
}
|
||||
filev[*filec]= strdup(adr);
|
||||
if(filev[*filec]==NULL) {
|
||||
out_of_memory:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot allocate enough memory (%d bytes) for pattern expansion",
|
||||
(int) strlen(adr)+1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
@ -2386,9 +2357,9 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
|
||||
int num_patterns, char **patterns, int extra_filec,
|
||||
int *filec, char ***filev, off_t *mem, int flag)
|
||||
{
|
||||
int ret, count= 0, abs_adr= 0, i, l, was_count, was_filec, k;
|
||||
int nonconst_mismatches= 0;
|
||||
char mem_text[80], limit_text[80], sfe[5*SfileadrL];
|
||||
int ret, count= 0, abs_adr= 0, i, was_count, was_filec;
|
||||
int nonconst_mismatches= 0, dive_count= 0;
|
||||
char sfe[5*SfileadrL];
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *dir= NULL, *root_dir;
|
||||
|
||||
@ -2444,74 +2415,27 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
|
||||
|
||||
/* count the matches */
|
||||
was_count= count;
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, &count, NULL, 0, mem,
|
||||
1 | abs_adr);
|
||||
ret= Xorriso_obtain_pattern_files_i(xorriso, "", dir, &count, NULL, 0,
|
||||
mem, &dive_count, 1 | abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(was_count==count && strcmp(patterns[i],"*")!=0 && (flag&3)!=1) {
|
||||
count++;
|
||||
|
||||
/* Is this a constant pattern ? */
|
||||
for(k= 0; k<xorriso->re_fill; k++) {
|
||||
if(xorriso->re_constants[k]==NULL)
|
||||
break;
|
||||
if(xorriso->re_constants[k][0]==0)
|
||||
break;
|
||||
}
|
||||
if(k<xorriso->re_fill)
|
||||
nonconst_mismatches++; /* it is not */
|
||||
|
||||
l= strlen(patterns[i])+1;
|
||||
(*mem)+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
(*mem)+= sizeof(char *)-(l % sizeof(char *));
|
||||
Xorriso_eval_nonmatch(xorriso, patterns[i], &nonconst_mismatches, mem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if((flag&1) && (count!=1 || nonconst_mismatches)){
|
||||
if(count-nonconst_mismatches>0)
|
||||
sprintf(xorriso->info_text,
|
||||
"Pattern match with more than one file object");
|
||||
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));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
ret= Xorriso_check_matchcount(xorriso, count, nonconst_mismatches,
|
||||
num_patterns, patterns, flag&1);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
count+= extra_filec;
|
||||
mem+= extra_filec*sizeof(char *);
|
||||
|
||||
if(count<=0)
|
||||
{ret= 0; goto ex;}
|
||||
|
||||
Sfile_scale((double) *mem, mem_text,5,1e4,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"Temporary memory needed for pattern expansion : %s", mem_text);
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
if(*mem > xorriso->temp_mem_limit) {
|
||||
Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"List of matching file addresses exceeds -temp_mem_limit (%s > %s)",
|
||||
mem_text, limit_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
(*filev)= (char **) calloc(sizeof(char *), count);
|
||||
if(*filev==NULL) {
|
||||
no_memory:;
|
||||
Sfile_scale((double) *mem, mem_text,5,1e4,1);
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot allocate enough memory (%s) for pattern expansion",
|
||||
mem_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
|
||||
ret= Xorriso_alloc_pattern_mem(xorriso, *mem, count, filev, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
/* now store addresses */
|
||||
for(i= 0; i<num_patterns; i++) {
|
||||
ret= Xorriso_prepare_expansion_pattern(xorriso, patterns[i], 0);
|
||||
@ -2521,15 +2445,16 @@ no_memory:;
|
||||
abs_adr= 4;
|
||||
|
||||
was_filec= *filec;
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, filec, *filev, count,
|
||||
mem, abs_adr);
|
||||
ret= Xorriso_obtain_pattern_files_i(xorriso, "", dir, filec, *filev, count,
|
||||
mem, &dive_count, abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(was_filec == *filec && strcmp(patterns[i],"*")!=0) {
|
||||
(*filev)[*filec]= strdup(patterns[i]);
|
||||
if((*filev)[*filec]==NULL) {
|
||||
(*mem)= strlen(patterns[i])+1;
|
||||
goto no_memory;
|
||||
Xorriso_no_pattern_memory(xorriso, *mem, 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user