Multiple structured patterns, changed option -ls from single to multi args
This commit is contained in:
@ -1237,13 +1237,11 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
|
||||
}
|
||||
|
||||
|
||||
#ifdef Xorriso_lsi_structured_patterN
|
||||
|
||||
/* @param flag bit0= long format */
|
||||
int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev,
|
||||
int flag)
|
||||
{
|
||||
int i, ret;
|
||||
int i, ret, was_error= 0;
|
||||
struct iso_tree_node *node;
|
||||
struct iso_volume *volume;
|
||||
char sfe[4*SfileadrL], path[SfileadrL], *rpt, perms[10];
|
||||
@ -1262,6 +1260,7 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev,
|
||||
|
||||
Sort_argv(filec, filev, 0);
|
||||
|
||||
/* Count valid nodes, warn of invalid ones */
|
||||
for(i= 0; i<filec; i++) {
|
||||
if(filev[i][0]!='/') {
|
||||
strcpy(path, xorriso->wdi);
|
||||
@ -1271,6 +1270,7 @@ much_too_long:;
|
||||
"Path for file listing gets much too long (%d)",
|
||||
strlen(path)+strlen(filev[i])+1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
was_error++;
|
||||
continue;
|
||||
}
|
||||
} else
|
||||
@ -1279,12 +1279,30 @@ much_too_long:;
|
||||
|
||||
node= iso_tree_volume_path_to_node(volume,path);
|
||||
if(node==NULL) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Internal error: Unexpectedly missing node %s",
|
||||
sprintf(xorriso->info_text, "Not found in ISO image: %s",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
||||
was_error++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error);
|
||||
Xorriso_info(xorriso,0);
|
||||
if(filec-was_error<=0)
|
||||
return(!was_error);
|
||||
|
||||
for(i= 0; i<filec; i++) {
|
||||
if(filev[i][0]!='/') {
|
||||
strcpy(path, xorriso->wdi);
|
||||
if(Sfile_add_to_path(path, filev[i], 0)<=0)
|
||||
continue;
|
||||
} else
|
||||
if(Sfile_str(path, filev[i], 0)<=0)
|
||||
continue;
|
||||
node= iso_tree_volume_path_to_node(volume,path);
|
||||
if(node==NULL)
|
||||
continue;
|
||||
|
||||
rpt[0]= 0;
|
||||
if(flag&1) {
|
||||
@ -1336,11 +1354,11 @@ much_too_long:;
|
||||
Text_shellsafe(filev[i], sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
return(1);
|
||||
return(!was_error);
|
||||
}
|
||||
|
||||
|
||||
#else /* Xorriso_lsi_structured_patterN */
|
||||
#ifdef Xorriso_lsi_outdated_unstructured_patterN
|
||||
|
||||
int Xorriso__node_name_cmp(const void *node1, const void *node2)
|
||||
{
|
||||
@ -1498,7 +1516,7 @@ ex:;
|
||||
return(1);
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_lsi_structured_patterN */
|
||||
#endif /* Xorriso_lsi_outdated_unstructured_patterN */
|
||||
|
||||
|
||||
int Xorriso_rename(struct XorrisO *xorriso, char *origin, char *dest, int flag)
|
||||
@ -1746,75 +1764,95 @@ out_of_memory:;
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_expand_pattern(struct XorrisO *xorriso, char *pattern,
|
||||
int Xorriso_expand_pattern(struct XorrisO *xorriso,
|
||||
int num_patterns, char **patterns,
|
||||
int *filec, char ***filev, int flag)
|
||||
{
|
||||
int ret, count= 0, abs_adr= 0;
|
||||
int ret, count= 0, abs_adr= 0, i, l, was_count, was_filec;
|
||||
off_t mem= 0;
|
||||
char mem_text[80], limit_text[80], sfe[4*SfileadrL];
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *dir;
|
||||
struct iso_tree_node_dir *dir, *root_dir;
|
||||
|
||||
*filec= 0;
|
||||
*filev= NULL;
|
||||
|
||||
xorriso->search_mode= 3;
|
||||
xorriso->structured_search= 1;
|
||||
ret= Xorriso_prepare_regex(xorriso, pattern, 1|2);
|
||||
if(ret==2) {
|
||||
ret= Xorriso_prepare_regex(xorriso, pattern, 0);
|
||||
abs_adr= 4;
|
||||
}
|
||||
if(ret<=0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot compile pattern to regular expression: %s", pattern);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
root_dir= iso_volume_get_root(volume);
|
||||
if(dir==NULL) {
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"While expanding pattern : Cannot obtain root node of ISO image");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
|
||||
if(pattern[0]=='/' || abs_adr) {
|
||||
dir= iso_volume_get_root(volume);
|
||||
if(dir==NULL) {
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"While expanding pattern %s : Cannot obtain root node of ISO image",
|
||||
Text_shellsafe(pattern, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
ret= -1; goto ex;
|
||||
for(i= 0; i<num_patterns; i++) {
|
||||
|
||||
ret= Xorriso_prepare_regex(xorriso, patterns[i], 1|2);
|
||||
if(ret==2) {
|
||||
ret= Xorriso_prepare_regex(xorriso, patterns[i], 0);
|
||||
abs_adr= 4;
|
||||
}
|
||||
abs_adr= 4;
|
||||
} else {
|
||||
dir= (struct iso_tree_node_dir *)
|
||||
iso_tree_volume_path_to_node(volume,xorriso->wdi);
|
||||
if(dir==NULL) {
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(ret<=0) {
|
||||
cannot_compile:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot compile pattern to regular expression: %s", patterns[i]);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
if(patterns[i][0]=='/' || abs_adr) {
|
||||
dir= root_dir;
|
||||
abs_adr= 4;
|
||||
} else {
|
||||
/* This is done so late ito allow the following:
|
||||
It is not an error if xorriso->wdi does not exist yet, but one may
|
||||
not use it as base for relative address searches.
|
||||
*/
|
||||
dir= (struct iso_tree_node_dir *)
|
||||
iso_tree_volume_path_to_node(volume,xorriso->wdi);
|
||||
if(dir==NULL) {
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"While expanding pattern %s : Working directory does not exist in ISO image",
|
||||
Text_shellsafe(pattern, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
if(!LIBISO_ISDIR((struct iso_tree_node *) dir)) {
|
||||
sprintf(xorriso->info_text,
|
||||
Text_shellsafe(patterns[i], sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
if(!LIBISO_ISDIR((struct iso_tree_node *) dir)) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Working directory path does not lead to a directory in ISO image");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
}
|
||||
|
||||
/* count the matches */
|
||||
was_count= count;
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, &count, NULL, 0, &mem,
|
||||
1 | abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(was_count==count && strcmp(patterns[i],"*")!=0) {
|
||||
count++;
|
||||
l= strlen(patterns[i])+1;
|
||||
mem+= sizeof(char *)+l;
|
||||
if(l % sizeof(char *))
|
||||
mem+= sizeof(char *)-(l % sizeof(char *));
|
||||
}
|
||||
}
|
||||
|
||||
/* count matches */
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, &count, NULL, 0, &mem,
|
||||
1 | abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(count<=0)
|
||||
{ret= 0; goto ex;}
|
||||
|
||||
Sfile_scale((double) mem, mem_text,5,1e4,1);
|
||||
Sfile_scale((double) mem, mem_text,5,1e4,0);
|
||||
sprintf(xorriso->info_text,
|
||||
"Temporary memory needed for pattern expansion : %s", mem_text);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
@ -1829,6 +1867,7 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso, char *pattern,
|
||||
|
||||
(*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",
|
||||
@ -1838,11 +1877,28 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso, char *pattern,
|
||||
}
|
||||
|
||||
/* now store store addresses */
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, filec, *filev, count,
|
||||
&mem, abs_adr);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
for(i= 0; i<num_patterns; i++) {
|
||||
ret= Xorriso_prepare_regex(xorriso, patterns[i], 1|2);
|
||||
if(ret==2) {
|
||||
ret= Xorriso_prepare_regex(xorriso, patterns[i], 0);
|
||||
abs_adr= 4;
|
||||
}
|
||||
if(ret<=0)
|
||||
goto cannot_compile;
|
||||
was_filec= *filec;
|
||||
ret= Xorriso_obtain_pattern_files(xorriso, "", dir, filec, *filev, count,
|
||||
&mem, 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;
|
||||
}
|
||||
(*filec)++;
|
||||
}
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(ret<=0) {
|
||||
|
Reference in New Issue
Block a user