From 8069e4be77f5fd438e11bb5f5c11e403ff73459f Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 30 Oct 2007 21:44:08 +0000 Subject: [PATCH] Multiple structured patterns, changed option -ls from single to multi args --- libisoburn/trunk/test/compile_xorriso.sh | 1 + libisoburn/trunk/test/xorriso.1 | 12 +- libisoburn/trunk/test/xorriso.c | 116 ++++++++------- libisoburn/trunk/test/xorriso_private.h | 2 - libisoburn/trunk/test/xorriso_timestamp.h | 2 +- libisoburn/trunk/test/xorrisoburn.c | 172 ++++++++++++++-------- libisoburn/trunk/test/xorrisoburn.h | 16 +- 7 files changed, 188 insertions(+), 133 deletions(-) diff --git a/libisoburn/trunk/test/compile_xorriso.sh b/libisoburn/trunk/test/compile_xorriso.sh index 8551c91b..7efef5d6 100755 --- a/libisoburn/trunk/test/compile_xorriso.sh +++ b/libisoburn/trunk/test/compile_xorriso.sh @@ -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 \ diff --git a/libisoburn/trunk/test/xorriso.1 b/libisoburn/trunk/test/xorriso.1 index 6d17a645..3d0982d1 100644 --- a/libisoburn/trunk/test/xorriso.1 +++ b/libisoburn/trunk/test/xorriso.1 @@ -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 diff --git a/libisoburn/trunk/test/xorriso.c b/libisoburn/trunk/test/xorriso.c index f1fee54e..f38a10a0 100644 --- a/libisoburn/trunk/test/xorriso.c +++ b/libisoburn/trunk/test/xorriso.c @@ -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; isearch_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; i4); + 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); diff --git a/libisoburn/trunk/test/xorriso_private.h b/libisoburn/trunk/test/xorriso_private.h index a693b423..fbd0220b 100644 --- a/libisoburn/trunk/test/xorriso_private.h +++ b/libisoburn/trunk/test/xorriso_private.h @@ -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 */ diff --git a/libisoburn/trunk/test/xorriso_timestamp.h b/libisoburn/trunk/test/xorriso_timestamp.h index 7c42f647..ab1aa4fd 100644 --- a/libisoburn/trunk/test/xorriso_timestamp.h +++ b/libisoburn/trunk/test/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2007.10.29.213920" +#define Xorriso_timestamP "2007.10.30.214242" diff --git a/libisoburn/trunk/test/xorrisoburn.c b/libisoburn/trunk/test/xorrisoburn.c index c880404e..f6478082 100644 --- a/libisoburn/trunk/test/xorrisoburn.c +++ b/libisoburn/trunk/test/xorrisoburn.c @@ -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; iwdi); @@ -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; iwdi); + 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; iwdi); - 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