Sorting of nodes in a dir acording to ECMA-119, 9.3.

This commit is contained in:
Vreixo Formoso 2007-12-15 18:40:33 +01:00
parent 411524c330
commit 56cdd00638
3 changed files with 38 additions and 7 deletions

View File

@ -95,17 +95,17 @@ int main(int argc, char **argv)
ecma119->iso_level = 1;
/* create low level tree */
result = ecma119_tree_create(ecma119, (IsoNode*)iso_image_get_root(image), &tree);
result = ecma119_tree_create(ecma119, (IsoNode*)iso_image_get_root(image));
if (result < 0) {
printf ("Error creating ecma-119 tree: %d\n", result);
return 1;
}
printf("================= ECMA-119 TREE =================\n");
print_dir(tree, 0);
print_dir(ecma119->root, 0);
printf("\n\n");
ecma119_node_free(tree);
ecma119_node_free(ecma119->root);
iso_image_unref(image);
return 0;
}

View File

@ -238,18 +238,49 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
return ISO_SUCCESS;
}
int ecma119_tree_create(Ecma119Image *img, IsoNode *iso, Ecma119Node **tree)
/**
* Compare the iso name of two ECMA-119 nodes
*/
static
int cmp_node_name(const void *f1, const void *f2)
{
Ecma119Node *f = *((Ecma119Node**)f1);
Ecma119Node *g = *((Ecma119Node**)f2);
return strcmp(f->iso_name, g->iso_name);
}
/**
* Sorts a the children of each directory in the ECMA-119 tree represented
* by \p root, acording to the order specified in ECMA-119, section 9.3.
*/
static
void sort_tree(Ecma119Node *root)
{
size_t i;
qsort(root->info.dir.children, root->info.dir.nchildren,
sizeof(void*), cmp_node_name);
for (i = 0; i < root->info.dir.nchildren; i++) {
if (root->info.dir.children[i]->type == ECMA119_DIR)
sort_tree(root->info.dir.children[i]);
}
}
int ecma119_tree_create(Ecma119Image *img, IsoNode *iso)
{
int ret;
ret = create_tree(img, iso, tree, 1, 0);
Ecma119Node *root;
ret = create_tree(img, iso, &root, 1, 0);
if (ret < 0) {
return ret;
}
img->root = root;
sort_tree(root);
/*
* TODO
* - reparent if RR
* - sort files in dir
* - mangle names
*/

View File

@ -58,7 +58,7 @@ struct ecma119_node
/**
*
*/
int ecma119_tree_create(Ecma119Image *img, IsoNode *iso, Ecma119Node **tree);
int ecma119_tree_create(Ecma119Image *img, IsoNode *iso);
/**
* Free an Ecma119Node, and its children if node is a dir