Multiple structured patterns, changed option -ls from single to multi args

This commit is contained in:
Thomas Schmitt 2007-10-30 21:44:08 +00:00
parent eb47b6c510
commit 8069e4be77
7 changed files with 188 additions and 133 deletions

View File

@ -80,6 +80,7 @@ cc -I. -DXorriso_with_maiN -DXorriso_with_regeX -DXorriso_with_readlinE \
"$burn"/read.o \
"$burn"/libdax_audioxtr.o \
"$burn"/libdax_msgs.o \
"$burn"/cleanup.o \
\
"$burn"/mmc.o \
"$burn"/sbc.o \

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "October 29, 2007"
.TH XORRISO 1 "October 30, 2007"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -541,20 +541,20 @@ Tell the current working directory in the ISO image.
\fB\-pwdx\fR
Tell the current working directory on local filesystem.
.TP
\fB\-ls\fR pattern
\fB\-ls\fR pattern [...]
List files from the current working directory in the ISO
image which match a shell pattern (i.e. wildcards '*' '?' '[...]').
image which match a shell pattern (i.e. wildcards '*' '?' '[a-z]').
Note that this resembles rather shell command ls -d than command ls.
.TP
> \fB\-lsx\fR pattern
> \fB\-lsx\fR pattern [...]
List files from the current working directory on local filesystem
which match a shell pattern.
.TP
\fB\-ls_l\fR pattern
\fB\-ls_l\fR pattern [...]
Like -ls but also list some of the file attributes.
Output format resembles shell command ls -ldn.
.TP
> \fB\-ls_lx\fR pattern
> \fB\-ls_lx\fR pattern [...]
Like -lsx but also list some of the file attributes.
.TP
> \fB\-find\fR pattern

View File

@ -1397,6 +1397,7 @@ int Fileliste__escape_target(char *target, int flag)
#endif /* ! Xorriso_fileliste_externaL */
#define Xorriso_cleanup_externaL 1
#ifndef Xorriso_cleanup_externaL
/* <<< ??? ts A71006 : will this be replaced by the libburn signal handler ? */
@ -1427,9 +1428,9 @@ static int signal_list_count= 24;
/* Signals not to be caught */
static int non_signal_list[]= {
SIGKILL, SIGCHLD, SIGSTOP, SIGURG, -1
SIGKILL, SIGCHLD, SIGSTOP, SIGURG, SIGWINCH, -1
};
static int non_signal_list_count= 4;
static int non_signal_list_count= 5;
/* run time dynamic part */
@ -1484,7 +1485,8 @@ static void Cleanup_handler_generic(int signum)
}
int Cleanup_set_handlers(void *handle, Cleanup_app_handler_T handler, int flag)
static int Cleanup_set_handlers(void *handle,
Cleanup_app_handler_T handler, int flag)
/*
bit0= set to default handlers
bit1= set to ignore
@ -2060,23 +2062,15 @@ klammer_affe:;
return(3);
}
} else if(*cpt=='-' && !(flag&1)) {
Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
strcpy(xorriso->pending_option,cpt);
xorriso->request_to_abort= 1;
sprintf(xorriso->info_text,
"------------ [-* = input of option registered. Operation ends ] -------------\n");
Xorriso_info(xorriso,0);
return(2);
} else if(*cpt!=0 && !(flag&1)) {
Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
strcpy(xorriso->pending_option,cpt);
xorriso->request_to_abort= 1;
sprintf(xorriso->info_text,
"------------ [ input of searchtext registered. Operation ends ] -------------\n");
"-------------- [ Input of option registered. Operation ends ] ---------------\n");
Xorriso_info(xorriso,0);
return(2);
} else if(*cpt!=0) {
Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
sprintf(xorriso->info_text,
@ -2978,6 +2972,8 @@ int Xorriso_warn_of_wildcards(struct XorrisO *xorriso, char *path, int flag)
}
/* @param flag bit0= do not warn of wirldcards
*/
int Xorriso_end_idx(struct XorrisO *xorriso,
int argc, char **argv, int idx, int flag)
{
@ -2986,7 +2982,7 @@ int Xorriso_end_idx(struct XorrisO *xorriso,
for(i= idx; i<argc; i++) {
if(strcmp(argv[i], "--")==0)
break;
if(!warned)
if(!((flag&1) || warned))
warned= Xorriso_warn_of_wildcards(xorriso, argv[i], 0);
}
return(i);
@ -4022,48 +4018,63 @@ int Xorriso_option_j_capital(struct XorrisO *xorriso, int flag)
/* Options -ls alias -lsi and ls_l alias ls_li */
/* @param flag bit0= long format (-ls_l) */
int Xorriso_option_lsi(struct XorrisO *xorriso, char *pattern, int flag)
/* @param flag bit0= long format (-ls_l)
bit1= do not expand patterns but use literally
*/
int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret;
int ret, end_idx, filec= 0, nump, i;
char **filev= NULL, **patterns= NULL;
#define Xorriso_lsi_structured_patterN 1
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
#ifdef Xorriso_lsi_structured_patterN
char **filev= NULL, *eff_pattern;
int filec= 0;
eff_pattern= pattern;
if(pattern[0]==0)
eff_pattern= "*";
ret= Xorriso_expand_pattern(xorriso, eff_pattern, &filec, &filev, 0);
if(ret<=0)
return(0);
ret= Xorriso_ls_filev(xorriso, filec, filev, flag&1);
Sfile_destroy_argv(&filec, &filev, 0);
if(ret<=0)
return(0);
return(1);
#else /* Xorriso_lsi_structured_patterN */
xorriso->search_mode= 4;
xorriso->structured_search= 0;
ret= Xorriso_prepare_regex(xorriso, pattern, 0);
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);
nump= end_idx - *idx;
if(flag&2) {
if(nump <= 0)
return(0);
} else if(nump <= 0) {
patterns= calloc(sizeof(char *), 1);
if(patterns == NULL) {
no_memory:;
sprintf(xorriso->info_text,
"Cannot allocate enough memory for pattern expansion");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;}
}
nump= 1;
patterns[0]= "*";
} else {
patterns= calloc(sizeof(char *), nump);
if(patterns==NULL)
goto no_memory;
for(i= 0; i<nump; i++) {
if(argv[i + *idx][0]==0)
patterns[i]= "*";
else
patterns[i]= argv[i + *idx];
}
}
if(flag&2) {
ret= Xorriso_ls_filev(xorriso, nump, argv + (*idx), flag&1);
if(ret<=0)
{ret= 0; goto ex;}
} else {
ret= Xorriso_expand_pattern(xorriso, nump, patterns, &filec, &filev, 0);
if(ret<=0)
{ret= 0; goto ex;}
ret= Xorriso_ls_filev(xorriso, filec, filev, flag&1);
if(ret<=0)
{ret= 0; goto ex;}
}
ret= Xorriso_ls(xorriso, flag&1);
ret= 1;
ex:;
if(patterns!=NULL)
free((char *) patterns);
Sfile_destroy_argv(&filec, &filev, 0);
(*idx)= end_idx;
return(ret);
#endif /* ! Xorriso_lsi_structured_patterN */
}
@ -4956,8 +4967,7 @@ next_command:;
} else if(strcmp(cmd,"-ls")==0 || strcmp(cmd,"-lsi")==0 ||
strcmp(cmd,"-ls_l")==0 || strcmp(cmd,"-ls_li")==0 ||
strcmp(cmd,"-ls-l")==0 || strcmp(cmd,"-ls-li")==0) {
(*idx)++;
ret= Xorriso_option_lsi(xorriso, arg1, strlen(cmd)>4);
ret= Xorriso_option_lsi(xorriso, argc, argv, idx, strlen(cmd)>4);
} else if(strcmp(cmd,"-lsx")==0 || strcmp(cmd,"-ls_lx")==0
|| strcmp(cmd,"-ls-lx")==0) {
@ -5002,6 +5012,8 @@ next_command:;
sscanf(arg2,"%d",&num2);
if(num1<0)
num1= 0;
if(arg1[0]==0)
num1= 16;
if(num2<=0)
num2= 80;
ret= Xorriso_option_page(xorriso, num1, num2, 0);

View File

@ -202,7 +202,5 @@ char *Text_shellsafe(char *in_text, char *out_text, int flag);
int Sort_argv(int argc, char **argv, int flag);
#define Xorriso_lsi_structured_patterN 1
#endif /* Xorriso_private_includeD */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.29.213920"
#define Xorriso_timestamP "2007.10.30.214242"

View File

@ -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) {

View File

@ -14,8 +14,6 @@
#ifndef Xorrisoburn_includeD
#define Xorrisoburn_includeD yes
#define Xorriso_lsi_structured_patterN 1
struct XorrisO;
struct burn_drive;
@ -57,21 +55,10 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag);
*/
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);
#else /* Xorriso_lsi_structured_patterN */
/* @param flag bit0= long format , bit1= only check for directory existence */
int Xorriso_ls(struct XorrisO *xorriso, int flag);
#endif /* ! Xorriso_lsi_structured_patterN */
/* @param eff_path returns resulting effective path.
Must provide at least SfileadrL bytes of storage.
@param flag bit0= do not produce problem events (unless faulty path format)
@ -90,7 +77,8 @@ int Xorriso_rename(struct XorrisO *xorriso, char *origin, char *dest,int flag);
*/
int Xorriso_mkdir(struct XorrisO *xorriso, char *img_path, int flag);
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);
#endif /* Xorrisoburn_includeD */