diff --git a/libisoburn/trunk/test/xorriso.1 b/libisoburn/trunk/test/xorriso.1 index 284a1ffe..08d6ba39 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 "December 16, 2007" +.TH XORRISO 1 "December 18, 2007" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -907,27 +907,47 @@ Tell the current working directory in the ISO image. Tell the current working directory on local filesystem. .TP \fB\-ls\fR iso_rr_pattern [***] -List files in the ISO image which match shell patterns (i.e. with wildcards '*' -'?' '[a-z]'). +List files in the ISO image which match shell patterns +(i.e. with wildcards '*' '?' '[a-z]'). If a pattern does not begin with '/' then it is compared with addresses relative to -cd, the current working directory in the ISO image. -Note that this resembles rather shell command ls -d than command ls. +.br +Directories are listed by their content rather than as single file item. .br Pattern expansion may be disabled by command -iso_rr_pattern. .TP +\fB\-lsd\fR iso_rr_pattern [***] +Like -ls but listing directories as themselves and not by their content. +This resembles shell command ls -d. +.TP +\fB\-lsl\fR iso_rr_pattern [***] +Like -ls but also list some of the file attributes. +Output format resembles shell command ls -ln. +.TP +\fB\-lsdl\fR iso_rr_pattern [***] +Like -lsd but also list some of the file attributes. +Output format resembles shell command ls -dln. +.TP \fB\-lsx\fR disk_pattern [***] List files on local filesystem which match shell patterns. Patterns which do not begin with '/' are used relative to -cdx, the current working directory in the local filesystem. .br +Directories are listed by their content rather than as single file item. +.br Pattern expansion may be disabled by command -disk_pattern. .TP -\fB\-ls_l\fR iso_rr_pattern [***] -Like -ls but also list some of the file attributes. -Output format resembles shell command ls -ldn. +\fB\-lsdx\fR disk_pattern [***] +Like -lsx but listing directories as themselves and not by their content. +This resembles shell command ls -d. .TP -\fB\-ls_lx\fR disk_pattern [***] -Like -lsx but also list some of the file attributes. +\fB\-lslx\fR disk_pattern [***] +Like -lsx but also listing some of the file attributes. +Output format resembles shell command ls -ln. +.TP +\fB\-lsdlx\fR disk_pattern [***] +Like -lsdx but also listing some of the file attributes. +Output format resembles shell command ls -dln. .TP \fB\-du\fR iso_rr_pattern [***] Recursively list size of directories and files in the ISO image diff --git a/libisoburn/trunk/test/xorriso.c b/libisoburn/trunk/test/xorriso.c index 767d3c2f..a5e2d6bf 100644 --- a/libisoburn/trunk/test/xorriso.c +++ b/libisoburn/trunk/test/xorriso.c @@ -3928,7 +3928,7 @@ int Xorriso_obtain_pattern_files_x( { int ret, failed_at, follow_mount, follow_links; char adr[SfileadrL], name[SfileadrL], path_data[SfileadrL], *path; - struct DirseQ *dirseq; + struct DirseQ *dirseq= NULL; struct stat stbuf; dev_t dir_dev; @@ -4101,7 +4101,7 @@ int Xorriso_alloc_pattern_mem(struct XorrisO *xorriso, off_t mem, return(0); } - (*filev)= (char **) calloc(sizeof(char *), count); + (*filev)= (char **) calloc(count, sizeof(char *)); if(*filev==NULL) { Xorriso_no_pattern_memory(xorriso, mem, 0); return(-1); @@ -4316,7 +4316,7 @@ int Xorriso_opt_args(struct XorrisO *xorriso, *optv= argv+idx; if(*optc<=0 || !do_expand) return(1); - patterns= calloc(sizeof(char *), *optc); + patterns= calloc(*optc, sizeof(char *)); if(patterns==NULL) { no_memory:; sprintf(xorriso->info_text, @@ -4736,7 +4736,7 @@ much_too_long:; mem+= l; if(l % sizeof(char *)) mem+= sizeof(char *)-(l % sizeof(char *)); - if(flag&1) /* diving and counting is done further down */ + if(flag&1) /* diving and counting is done further below */ continue; ret= Xorriso_show_dux_subs(xorriso, path, show_path, &sub_size, boss_mem, own_link_stack,2); @@ -4767,7 +4767,7 @@ much_too_long:; no_sort_possible:; no_sort= 1; } else { - filev= (char **) calloc(sizeof(char *), filec+1); + filev= (char **) calloc(filec+1, sizeof(char *)); if(filev==NULL) goto no_sort_possible; else { @@ -4973,16 +4973,83 @@ int Xorriso_format_ls_l(struct XorrisO *xorriso, struct stat *stbuf, int flag) } +struct DirentrY { + char *adr; + struct DirentrY *next; +}; + + +int Xorriso_sorted_dir_x(struct XorrisO *xorriso, char *dir_path, + int *filec, char ***filev, off_t boss_mem, int flag) +{ + int count= 0, ret; + char name[SfileadrL]; + struct DirseQ *dirseq= NULL; + off_t mem; + struct DirentrY *last= NULL, *current= NULL; + + *filec= 0; + *filev= NULL; + mem= boss_mem; + ret= Dirseq_new(&dirseq, dir_path, 1); + if(ret<=0) + goto ex; + while(1) { /* loop over directory content */ + ret= Dirseq_next_adr(dirseq,name,0); + if(ret==0) + break; + if(ret<0) + goto ex; + mem+= strlen(name)+8+sizeof(struct DirentrY)+sizeof(char *); + if(mem>xorriso->temp_mem_limit) + {ret= 0; goto ex;} + + current= (struct DirentrY *) calloc(1, sizeof(struct DirentrY)); + if(current==NULL) + {ret= -1; goto ex;} + current->adr= NULL; + current->next= last; + last= current; + last->adr= strdup(name); + if(last->adr==NULL) + {ret= -1; goto ex;} + count++; + } + *filec= count; + if(count==0) + {ret= 1; goto ex;} + (*filev)= (char **) calloc(count, sizeof(char *)); + if(*filev==NULL) + {ret= -1; goto ex; } + count= 0; + for(current= last; current!=NULL; current= last) { + last= current->next; + (*filev)[count++]= current->adr; + free((char *) current); + } + Sort_argv(*filec, *filev, 0); + ret= 1; +ex:; + for(current= last; current!=NULL; current= last) { + last= current->next; + free(current->adr); + free((char *) current); + } + return(ret); +} + + /* @param flag bit0= long format bit1= do not print count of nodes bit2= du format + bit3= print directories as themselves (ls -d) */ -int Xorriso_lsx_filev(struct XorrisO *xorriso, int filec, char **filev, - off_t boss_mem, int flag) +int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd, + int filec, char **filev, off_t boss_mem, int flag) { - int i, ret, was_error= 0; + int i, ret, was_error= 0, dfilec= 0, pass, passes; char sfe[5*SfileadrL], sfe2[5*SfileadrL], path[SfileadrL]; - char *rpt, link_target[SfileadrL]; + char *rpt, link_target[SfileadrL], **dfilev= NULL; off_t size; struct stat stbuf; @@ -4992,7 +5059,7 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, int filec, char **filev, /* Count valid nodes, warn of invalid ones */ for(i= 0; iwdx, filev[i], path, 1|4); + ret= Xorriso_make_pattern_adr(xorriso, wd, filev[i], path, 1|4); if(ret<=0) { was_error++; continue; @@ -5007,15 +5074,17 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, int filec, char **filev, } } - if(!(flag&(2|4))) { + if((flag&8) && !(flag&(2|4))) { sprintf(xorriso->info_text,"Valid local files found: %d\n",filec-was_error); Xorriso_info(xorriso,1); if(filec-was_error<=0) return(!was_error); } + passes= 1+!(flag&(4|8)); + for(pass= 0; passrequest_to_abort); i++) { - ret= Xorriso_make_pattern_adr(xorriso, xorriso->wdx, filev[i], path, 1|4); + ret= Xorriso_make_pattern_adr(xorriso, wd, filev[i], path, 1|4); if(ret<=0) continue; ret= lstat(path, &stbuf); @@ -5026,8 +5095,36 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, int filec, char **filev, ret= stat(path, &stbuf); if(ret==-1) ret= lstat(path, &stbuf); + if(ret==-1) + continue; } - if(ret==-1) + if(S_ISDIR(stbuf.st_mode) && !(flag&(4|8))) { + if(pass==0) + continue; + if(filec>1) { + strcpy(xorriso->result_line, "\n"); + Xorriso_result(xorriso,0); + sprintf(xorriso->result_line, "%s:\n", Text_shellsafe(filev[i], sfe,0)); + Xorriso_result(xorriso,0); + } + ret= Xorriso_sorted_dir_x(xorriso, path, &dfilec, &dfilev, boss_mem, 0); + if(ret<=0) { + + /* >>> DirseQ loop and single item Xorriso_lsx_filev() */; + + } else { + if(flag&1) { + sprintf(xorriso->result_line, "total %d\n", dfilec); + Xorriso_result(xorriso,0); + } + Xorriso_lsx_filev(xorriso, path, + dfilec, dfilev, boss_mem, (flag&1)|2|8); + } + if(dfilec>0) + Sfile_destroy_argv(&dfilec, &dfilev, 0); + continue; + } else + if(pass>0) continue; link_target[0]= 0; rpt[0]= 0; @@ -6145,17 +6242,20 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag) " marked by [***]. \"ls\" restricts it to -ls and -du.", " -disk_pattern \"on\"|\"ls\"|\"off\"", " Enable or disable pattern expansions for local filesystem", -" commands marked by [***]. \"ls\" restricts to -lsx and -dux.", +" commands marked by [***]. \"ls\" restricts to -ls*x and -du*x.", "", " -ls pattern [***] lists files of the ISO image which match one of the", -" given shell parser patterns. (I.e. wildcards '*' '?')", -" -lsi pattern [***] same as -ls.", -" -lsx pattern [***] lists files of the local filesystem which match one", -" of the patterns.", +" given shell parser patterns. (I.e. wildcards '*' '?').", +" Directories are listed by their content.", +" -lsd pattern [***] like -ls but listing directories as single items.", +" -lsl pattern [***] like -ls but also telling some file attributes.", +" -lsdl pattern [***] like -lsd but also telling some file attributes.", "", -" -ls_l pattern [***] like -ls but also telling some file attributes.", -" -ls_li pattern [***] same as -ls_l.", -" -ls_lx pattern [***] like -lsx but also telling some file attributes.", +" -lsx pattern [***] lists files of the local filesystem which match one", +" of the patterns. Directories are listed by their content.", +" -lsdx pattern [***] like -lsx but listing directories as single items.", +" -lslx pattern [***] like -lsx but also telling some file attributes.", +" -lsdlx pattern [***] like -lsdx but also telling some file attributes.", "", " -du pattern [***] recursively lists sizes of files or directories in the", " ISO image which match one of the shell parser patterns.", @@ -6298,6 +6398,7 @@ int Xorriso_option_j_capital(struct XorrisO *xorriso, int flag) @param flag bit0= long format (-ls_l , -du) bit1= do not expand patterns but use literally bit2= du rather than ls + bit3= list directories as themselves (ls -d) */ int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv, int *idx, int flag) @@ -6314,7 +6415,7 @@ int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv, if((flag&2) && nump>0 ) { ; } else if(nump <= 0) { - patterns= calloc(sizeof(char *), 1); + patterns= calloc(1, sizeof(char *)); if(patterns == NULL) { no_memory:; sprintf(xorriso->info_text, @@ -6326,7 +6427,7 @@ no_memory:; patterns[0]= "*"; flag&= ~2; } else { - patterns= calloc(sizeof(char *), nump); + patterns= calloc(nump, sizeof(char *)); if(patterns==NULL) goto no_memory; for(i= 0; iwdi, nump, argv + (*idx), mem, + flag&(1|4|8)); } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){ /* save temporary memory by calling simpler function */ ret= Xorriso_ls(xorriso, (flag&1)|4); @@ -6346,7 +6448,8 @@ no_memory:; &mem, 0); if(ret<=0) {ret= 0; goto ex;} - ret= Xorriso_ls_filev(xorriso, filec, filev, mem, flag&(1|4)); + ret= Xorriso_ls_filev(xorriso, xorriso->wdi, filec, filev, mem, + flag&(1|4|8)); } if(ret<=0) {ret= 0; goto ex;} @@ -6361,11 +6464,12 @@ ex:; } -/* Options -lsx , -ls_lx , +/* Options -lsdx , -lsdlx , -dux , -du_sx @param flag bit0= long format (-ls_lx , -dux) bit1= do not expand patterns but use literally bit2= du rather than ls + bit3= list directories as themselves (ls -d) */ int Xorriso_option_lsx(struct XorrisO *xorriso, int argc, char **argv, int *idx, int flag) @@ -6382,7 +6486,7 @@ int Xorriso_option_lsx(struct XorrisO *xorriso, int argc, char **argv, if((flag&2) && nump>0) { ; } else if(nump <= 0) { - patterns= calloc(sizeof(char *), 1); + patterns= calloc(1, sizeof(char *)); if(patterns == NULL) { no_memory:; sprintf(xorriso->info_text, @@ -6394,7 +6498,7 @@ no_memory:; patterns[0]= "*"; flag&= ~2; } else { - patterns= calloc(sizeof(char *), nump); + patterns= calloc(nump, sizeof(char *)); if(patterns==NULL) goto no_memory; for(i= 0; iwdx, + nump, argv + (*idx), mem, flag&(1|4)); #ifdef Not_yeT } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){ @@ -6418,7 +6523,7 @@ no_memory:; &mem, 0); if(ret<=0) {ret= 0; goto ex;} - ret= Xorriso_lsx_filev(xorriso, filec, filev, mem, flag&(1|4)); + ret= Xorriso_lsx_filev(xorriso, xorriso->wdx, filec, filev, mem,flag&(1|4)); } if(ret<=0) {ret= 0; goto ex;} @@ -7418,13 +7523,18 @@ next_command:; ret= Xorriso_option_j_capital(xorriso, 0); } 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) { - ret= Xorriso_option_lsi(xorriso, argc, argv, idx, strlen(cmd)>3); + strcmp(cmd,"lsl")==0 || strcmp(cmd,"lsli")==0) { + ret= Xorriso_option_lsi(xorriso, argc, argv, idx, (cmd[2]=='l')); - } else if(strcmp(cmd,"lsx")==0 || strcmp(cmd,"ls_lx")==0 - || strcmp(cmd,"ls-lx")==0) { - ret= Xorriso_option_lsx(xorriso, argc, argv, idx, strlen(cmd)>3); + } else if(strcmp(cmd,"lsd")==0 || strcmp(cmd,"lsdi")==0 || + strcmp(cmd,"lsdl")==0 || strcmp(cmd,"lsdli")==0) { + ret= Xorriso_option_lsi(xorriso, argc, argv, idx, (cmd[3]=='l')|8); + + } else if(strcmp(cmd,"lsdx")==0 || strcmp(cmd,"lsdlx")==0) { + ret= Xorriso_option_lsx(xorriso, argc, argv, idx, (cmd[3]=='l')|8); + + } else if(strcmp(cmd,"lsx")==0 || strcmp(cmd,"lslx")==0) { + ret= Xorriso_option_lsx(xorriso, argc, argv, idx, (cmd[2]=='l')); } else if(strcmp(cmd,"logfile")==0) { (*idx)+= 2; diff --git a/libisoburn/trunk/test/xorriso_timestamp.h b/libisoburn/trunk/test/xorriso_timestamp.h index 21f42731..dc0ac884 100644 --- a/libisoburn/trunk/test/xorriso_timestamp.h +++ b/libisoburn/trunk/test/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2007.12.16.144615" +#define Xorriso_timestamP "2007.12.18.175924" diff --git a/libisoburn/trunk/test/xorrisoburn.c b/libisoburn/trunk/test/xorrisoburn.c index 03a34a10..fe41ae2b 100644 --- a/libisoburn/trunk/test/xorrisoburn.c +++ b/libisoburn/trunk/test/xorrisoburn.c @@ -1704,9 +1704,10 @@ dir_not_removed:; while((xorriso->do_reassure==1 || (xorriso->do_reassure==2 && !(flag&4))) && !xorriso->request_not_to_ask) { - Xorriso_ls_filev(xorriso, 1, &path, (off_t) 0, 1|2); /* ls -l */ - if(is_dir) - Xorriso_ls_filev(xorriso, 1, &path, (off_t) 0, 2|4); /* du -s */ + /* ls -ld */ + Xorriso_ls_filev(xorriso, xorriso->wdi, 1, &path, (off_t) 0, 1|2|8); + if(is_dir) /* du -s */ + Xorriso_ls_filev(xorriso, xorriso->wdi, 1, &path, (off_t) 0, 2|4); if(flag&8) sprintf(xorriso->info_text, "File exists. Remove ? n= keep old, y= remove, x= abort, @= stop asking\n"); @@ -1994,18 +1995,79 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf, } +int Xorriso_sorted_dir_i(struct XorrisO *xorriso, + struct iso_tree_node_dir *dir_node, + int *filec, char ***filev, off_t boss_mem, int flag) +{ + int i,j,ret; + struct iso_tree_iter *iter= NULL; + struct iso_tree_node *node; + char *name; + off_t mem; + + (*filec)= 0; + (*filev)= NULL; + + iter= iso_tree_node_children(dir_node); + if(iter==NULL) { +cannot_iter:; + 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); + {ret= -1; goto ex;} + } + mem= 0; + for(i= 0; (node= iso_tree_iter_next(iter)) != NULL; ) { + name= (char *) iso_tree_node_get_name(node); + mem+= sizeof(char *)+strlen(name)+8; + (*filec)++; + } + iso_tree_iter_free(iter); + if(*filec==0) + {ret= 1; goto ex;} + + ret= Xorriso_check_temp_mem_limit(xorriso, mem+boss_mem, 2); + if(ret<=0) + goto ex; + (*filev)= (char **) calloc(*filec, sizeof(char *)); + if(*filev==NULL) + {ret= -1; goto ex; } + iter= iso_tree_node_children(dir_node); + if(iter==NULL) + goto cannot_iter; + for(i= 0; i<*filec; i++) { + name= (char *) iso_tree_node_get_name(iso_tree_iter_next(iter)); + (*filev)[i]= strdup(name); + if((*filev)[i]==NULL) { + for(j= 0; jwdi, filev[i], path, 1|4); + ret= Xorriso_make_pattern_adr(xorriso, wd, filev[i], path, 1|4); if(ret<=0) { was_error++; continue; @@ -2034,20 +2096,51 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev, } } - if(!(flag&(2|4))) { + if((flag&8) && !(flag&(2|4))) { sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error); Xorriso_info(xorriso,1); if(filec-was_error<=0) return(!was_error); } + passes= 1+!(flag&(4|8)); + for(pass= 0; passrequest_to_abort); i++) { rpt[0]= 0; - ret= Xorriso_make_pattern_adr(xorriso, xorriso->wdi, filev[i], path, 1|4); + ret= Xorriso_make_pattern_adr(xorriso, wd, filev[i], path, 1|4); if(ret<=0) continue; ret= Xorriso_fake_stbuf(xorriso, path, &stbuf, &node, 0); if(ret<=0) + continue; + if(LIBISO_ISDIR(node) && !(flag&(4|8))) { + if(pass==0) + continue; + if(filec>1) { + strcpy(xorriso->result_line, "\n"); + Xorriso_result(xorriso,0); + sprintf(xorriso->result_line, "%s:\n", Text_shellsafe(filev[i], sfe,0)); + Xorriso_result(xorriso,0); + } + ret= Xorriso_sorted_dir_i(xorriso, + (struct iso_tree_node_dir *) node, &dfilec, &dfilev, boss_mem, 0); + if(ret<=0) { + + /* >>> libisofs iterator loop and single item Xorriso_lsx_filev() */; + + } else { + if(flag&1) { + sprintf(xorriso->result_line, "total %d\n", dfilec); + Xorriso_result(xorriso,0); + } + Xorriso_ls_filev(xorriso, path, + dfilec, dfilev, boss_mem, (flag&1)|2|8); + } + if(dfilec>0) + Sfile_destroy_argv(&dfilec, &dfilev, 0); + continue; + } else + if(pass>0) continue; link_target[0]= 0; if((flag&5)==1) { /* -ls_l */ diff --git a/libisoburn/trunk/test/xorrisoburn.h b/libisoburn/trunk/test/xorrisoburn.h index 06886f03..d5d48bd9 100644 --- a/libisoburn/trunk/test/xorrisoburn.h +++ b/libisoburn/trunk/test/xorrisoburn.h @@ -68,9 +68,13 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag); int Xorriso_rmi(struct XorrisO *xorriso, void *boss_iter, char *path, int flag); -/* @param flag bit0= long format */ -int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev, - off_t boss_mem, int flag); +/* @param flag bit0= long format + bit1= do not print count of nodes + bit2= du format + bit3= print directories as themselves (ls -d) +*/ +int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd, + int filec, char **filev, off_t boss_mem, int flag); /* This function needs less buffer memory than Xorriso_ls_filev() but cannot perform structured pattern matching.