Implemented sorting of -ls by node name, implemented leaf name search patterns

This commit is contained in:
Thomas Schmitt 2007-10-21 21:32:23 +00:00
parent 71c44d8a86
commit b8988d6673
5 changed files with 87 additions and 34 deletions

View File

@ -536,7 +536,7 @@ Tell the current working directory in the ISO image.
\fB\-pwdx\fR \fB\-pwdx\fR
Tell the current working directory on local filesystem. Tell the current working directory on local filesystem.
.TP .TP
> \fB\-ls\fR pattern \fB\-ls\fR pattern
List files from the current working directory in the ISO 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 '*' '?')
.TP .TP

View File

@ -2477,7 +2477,7 @@ next_adr_part:;
} else { } else {
is_constant= 0; is_constant= 0;
if(strcmp(adr,"*")==0) { if(strcmp(adr,"*")==0 || adr[0]==0) {
is_constant= 1; is_constant= 1;
} else if(xorriso->search_mode==3 || xorriso->search_mode==4) { } else if(xorriso->search_mode==3 || xorriso->search_mode==4) {
ret= Xorriso__bourne_to_reg(adr,xorriso->reg_expr,0); ret= Xorriso__bourne_to_reg(adr,xorriso->reg_expr,0);
@ -3975,11 +3975,20 @@ int Xorriso_option_lsi(struct XorrisO *xorriso, char *pattern, int flag)
{ {
int ret; int ret;
/*
if(strcmp(pattern,"*")!=0 && pattern[0]) if(strcmp(pattern,"*")!=0 && pattern[0])
fprintf(stderr, ">>> XORRISO : TODO : filter by pattern %s\n", pattern); fprintf(stderr, ">>> XORRISO : TODO : filter by pattern %s\n", pattern);
*/
/* >>> prepare regex */ 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);
}
ret= Xorriso_ls(xorriso, flag&1); ret= Xorriso_ls(xorriso, flag&1);
return(ret); return(ret);
} }
@ -4768,14 +4777,15 @@ next_command:;
ret= Xorriso_option_j_capital(xorriso, 0); ret= Xorriso_option_j_capital(xorriso, 0);
} else if(strcmp(cmd,"-ls")==0 || strcmp(cmd,"-lsi")==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 ||
strcmp(cmd,"-ls-l")==0 || strcmp(cmd,"-ls-li")==0) {
(*idx)++; (*idx)++;
ret= Xorriso_option_lsi(xorriso, arg1, ret= Xorriso_option_lsi(xorriso, arg1, strlen(cmd)>4);
(strcmp(cmd,"-ls_l")==0 || strcmp(cmd,"-ls_li")==0));
} else if(strcmp(cmd,"-lsx")==0 || strcmp(cmd,"-ls_ls")==0) { } else if(strcmp(cmd,"-lsx")==0 || strcmp(cmd,"-ls_lx")==0
|| strcmp(cmd,"-ls-lx")==0) {
(*idx)++; (*idx)++;
ret= Xorriso_option_lsx(xorriso, arg1,strcmp(cmd,"-ls_lx")==0); ret= Xorriso_option_lsx(xorriso, arg1,strlen(cmd)>4);
} else if(strcmp(cmd,"-logfile")==0) { } else if(strcmp(cmd,"-logfile")==0) {
(*idx)+= 2; (*idx)+= 2;

View File

@ -183,6 +183,9 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag); int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
int flag);
int Sfile_str(char target[SfileadrL], char *source, int flag); int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag); double Sfile_microtime(int flag);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.21.185248" #define Xorriso_timestamP "2007.10.21.213303"

View File

@ -1209,14 +1209,24 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
} }
int Xorriso__node_name_cmp(const void *node1, const void *node2)
{
char *name1, *name2;
name1= (char *) iso_tree_node_get_name(*((struct iso_tree_node **) node1));
name2= (char *) iso_tree_node_get_name(*((struct iso_tree_node **) node2));
return(strcmp(name1,name2));
}
/* @param flag bit0= long format , bit1= only check for directory existence */ /* @param flag bit0= long format , bit1= only check for directory existence */
int Xorriso_ls(struct XorrisO *xorriso, int flag) int Xorriso_ls(struct XorrisO *xorriso, int flag)
{ {
int ret, is_dir= 0; int ret, is_dir= 0, i, filec, failed_at;
struct iso_tree_node *node; struct iso_tree_node *node, **node_array= NULL;
struct iso_tree_node_dir *dir_node; struct iso_tree_node_dir *dir_node;
struct iso_volume *volume; struct iso_volume *volume;
struct iso_tree_iter *iter; struct iso_tree_iter *iter= NULL;
char sfe[4*SfileadrL], *npt, *rpt, perms[10]; char sfe[4*SfileadrL], *npt, *rpt, perms[10];
mode_t st_mode; mode_t st_mode;
@ -1236,33 +1246,61 @@ wdi_is_not_a_dir:;
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Working directory path does not lead to a directory in ISO image"); "Working directory path does not lead to a directory in ISO image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0); ret= 0; goto ex;
} }
if(flag&2) if(flag&2)
return(1); {ret= 1; goto ex;}
dir_node= (struct iso_tree_node_dir *) node; dir_node= (struct iso_tree_node_dir *) node;
iter= iso_tree_node_children(dir_node); iter= iso_tree_node_children(dir_node);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
/* ??? >>> is the iteration sorted by name ? */ for(i= 0; (node= iso_tree_iter_next(iter)) != NULL && i<filec; ) {
/* if not: >>> copy to char * array */
while((node= iso_tree_iter_next(iter)) != NULL ) {
npt= (char *) iso_tree_node_get_name(node); npt= (char *) iso_tree_node_get_name(node);
#ifdef Xorriso_with_regeX ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
if(xorriso->re!=NULL) { if(ret)
/* >>> test with regex */; continue; /* no match */
}
#endif /* Xorriso_with_regeX */
filec++;
}
iso_tree_iter_free(iter);
iter= NULL;
Xorriso_process_msg_queues(xorriso,0);
node_array= calloc(sizeof(struct iso_tree *), filec+1);
if(node_array==NULL) {
sprintf(xorriso->info_text,
"Cannot allocate memory for %d directory entries", filec);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
ret= -1; goto ex;
}
iter= iso_tree_node_children(dir_node);
Xorriso_process_msg_queues(xorriso,0);
for(i= 0; (node= iso_tree_iter_next(iter)) != NULL && i<filec; ) {
npt= (char *) iso_tree_node_get_name(node);
ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
if(ret)
continue; /* no match */
node_array[i++]= node;
}
iso_tree_iter_free(iter);
iter= NULL;
Xorriso_process_msg_queues(xorriso,0);
filec= i;
if(filec<=0)
{ret= 1; goto ex;}
qsort(node_array, filec, sizeof(struct iso_tree *), Xorriso__node_name_cmp);
for(i= 0; i<filec; i++) {
node= node_array[i];
npt= (char *) iso_tree_node_get_name(node);
rpt[0]= 0; rpt[0]= 0;
if(flag&1) { if(flag&1) { /* >>> prepend attribute info */;
/* >>> prepend attribute info */;
if(is_dir) if(is_dir)
strcat(rpt, "d"); strcat(rpt, "d");
else if(LIBISO_ISREG(node)) else if(LIBISO_ISREG(node))
@ -1289,9 +1327,9 @@ wdi_is_not_a_dir:;
/* >>> ??? How to obtain RR harlink number for other types ? */ /* >>> ??? How to obtain RR harlink number for other types ? */
strcat(rpt," 1 "); strcat(rpt," 1 ");
sprintf(rpt+strlen(rpt), "%7lu ", sprintf(rpt+strlen(rpt), "%-7lu ",
(unsigned long) iso_tree_node_get_uid(node)); (unsigned long) iso_tree_node_get_uid(node));
sprintf(rpt+strlen(rpt), "%7lu ", sprintf(rpt+strlen(rpt), "%-7lu ",
(unsigned long) iso_tree_node_get_gid(node)); (unsigned long) iso_tree_node_get_gid(node));
/* >>> obtain size */ /* >>> obtain size */
@ -1305,11 +1343,13 @@ wdi_is_not_a_dir:;
Xorriso_result(xorriso, 0); Xorriso_result(xorriso, 0);
} }
/* ??? >>> sort */ ret= 1;
ex:;
/* ??? >>> output loop */ if(iter!=NULL)
iso_tree_iter_free(iter);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
if(node_array!=NULL)
free((char *) node_array);
return(1); return(1);
} }