Changed options -ls* to -lsd*, introduced new family of -ls* without d
This commit is contained in:
182
test/xorriso.c
182
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; i<filec; 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) {
|
||||
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; pass<passes; pass++)
|
||||
for(i= 0; i<filec && !(xorriso->request_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; i<nump; i++) {
|
||||
@ -6337,7 +6438,8 @@ no_memory:;
|
||||
}
|
||||
}
|
||||
if(flag&2) {
|
||||
ret= Xorriso_ls_filev(xorriso, nump, argv + (*idx), mem, flag&(1|4));
|
||||
ret= Xorriso_ls_filev(xorriso, xorriso->wdi, 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; i<nump; i++) {
|
||||
@ -6405,7 +6509,8 @@ no_memory:;
|
||||
}
|
||||
}
|
||||
if(flag&2) {
|
||||
ret= Xorriso_lsx_filev(xorriso, nump, argv + (*idx), mem, flag&(1|4));
|
||||
ret= Xorriso_lsx_filev(xorriso, xorriso->wdx,
|
||||
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;
|
||||
|
Reference in New Issue
Block a user