Removed some redundancy of disk_pattern and iso_rr_pattern matching
This commit is contained in:
@ -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);
|
||||
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(!LIBISO_ISDIR(node))
|
||||
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(
|
||||
xorriso, adr, (struct iso_tree_node_dir *) node,
|
||||
filec, filev, count_limit, mem, flag|2);
|
||||
if(ret<=0)
|
||||
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)++;
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
return(1);
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(flag&2)
|
||||
(*dive_count)--;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
@ -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)++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user