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

This commit is contained in:
2007-10-21 21:32:23 +00:00
parent eff9566c2b
commit 08374c8971
5 changed files with 87 additions and 34 deletions

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 */
int Xorriso_ls(struct XorrisO *xorriso, int flag)
{
int ret, is_dir= 0;
struct iso_tree_node *node;
int ret, is_dir= 0, i, filec, failed_at;
struct iso_tree_node *node, **node_array= NULL;
struct iso_tree_node_dir *dir_node;
struct iso_volume *volume;
struct iso_tree_iter *iter;
struct iso_tree_iter *iter= NULL;
char sfe[4*SfileadrL], *npt, *rpt, perms[10];
mode_t st_mode;
@ -1236,33 +1246,61 @@ wdi_is_not_a_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);
return(0);
ret= 0; goto ex;
}
if(flag&2)
return(1);
{ret= 1; goto ex;}
dir_node= (struct iso_tree_node_dir *) node;
iter= iso_tree_node_children(dir_node);
Xorriso_process_msg_queues(xorriso,0);
/* ??? >>> is the iteration sorted by name ? */
/* if not: >>> copy to char * array */
while((node= iso_tree_iter_next(iter)) != NULL ) {
for(i= 0; (node= iso_tree_iter_next(iter)) != NULL && i<filec; ) {
npt= (char *) iso_tree_node_get_name(node);
#ifdef Xorriso_with_regeX
if(xorriso->re!=NULL) {
/* >>> test with regex */;
}
#endif /* Xorriso_with_regeX */
ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
if(ret)
continue; /* no match */
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;
if(flag&1) {
/* >>> prepend attribute info */;
if(flag&1) { /* >>> prepend attribute info */;
if(is_dir)
strcat(rpt, "d");
else if(LIBISO_ISREG(node))
@ -1289,9 +1327,9 @@ wdi_is_not_a_dir:;
/* >>> ??? How to obtain RR harlink number for other types ? */
strcat(rpt," 1 ");
sprintf(rpt+strlen(rpt), "%7lu ",
sprintf(rpt+strlen(rpt), "%-7lu ",
(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));
/* >>> obtain size */
@ -1305,11 +1343,13 @@ wdi_is_not_a_dir:;
Xorriso_result(xorriso, 0);
}
/* ??? >>> sort */
/* ??? >>> output loop */
ret= 1;
ex:;
if(iter!=NULL)
iso_tree_iter_free(iter);
Xorriso_process_msg_queues(xorriso,0);
if(node_array!=NULL)
free((char *) node_array);
return(1);
}