summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-11-24 16:49:36 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-11-24 16:49:36 (GMT)
commit2f36ea99d4ad1b036d377719e49eaab2dec64444 (patch)
tree63be7c282767004339c49aa0e738e6a62630c280 /tools/lib/h5tools_utils.c
parent083357dad3334473507a97e17593a9d68e42d69f (diff)
downloadhdf5-2f36ea99d4ad1b036d377719e49eaab2dec64444.zip
hdf5-2f36ea99d4ad1b036d377719e49eaab2dec64444.tar.gz
hdf5-2f36ea99d4ad1b036d377719e49eaab2dec64444.tar.bz2
[svn-r14284] Description:
Add H5Lvisit_by_name() API routine to library. Eliminated all (five!) other group traversal routines and changed them all to use the new API routine. Cleaned up output of h5ls & h5stat: - Issue error when requesting recursive traversal of a file with the "group info" flag, but no group given - Print info about root group in all(?) appropriate situations - Don't print "verbose" information about root group until the root group is in the list of objects to display (mostly because h5ls & h5stat had a different twist on traversing the groups in a file that the other utilities) Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.4.10 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c186
1 files changed, 59 insertions, 127 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index cb38e7a..512a3fb 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -30,6 +30,7 @@
#include "h5tools_utils.h"
#include "H5private.h"
+#include "h5trav.h"
/* global variables */
int nCols = 80;
@@ -44,10 +45,7 @@ static void init_table(table_t **tbl);
#ifdef H5DUMP_DEBUG
static void dump_table(char* tablename, table_t *table);
#endif /* H5DUMP_DEBUG */
-static void add_obj(table_t *table, haddr_t objno, char *objname, hbool_t recorded);
-static char * build_obj_path_name(const char *prefix, const char *name);
-static herr_t find_objs_cb(hid_t group, const char *name, const H5L_info_t *info,
- void *op_data);
+static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t recorded);
/*-------------------------------------------------------------------------
@@ -428,44 +426,15 @@ search_obj(table_t *table, haddr_t objno)
{
unsigned u;
- for (u = 0; u < table->nobjs; u++)
- if (table->objs[u].objno == objno)
- return &(table->objs[u]);
+ for(u = 0; u < table->nobjs; u++)
+ if(table->objs[u].objno == objno)
+ return &(table->objs[u]);
return NULL;
}
/*-------------------------------------------------------------------------
- * Function: build_obj_path_name
- *
- * Purpose: Allocate space & build path name from prefix & name
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Quincey Koziol
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-build_obj_path_name(const char *prefix, const char *name)
-{
- char *path;
-
- path = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
- HDstrcpy(path, prefix);
- HDstrcat(path,"/");
- HDstrcat(path,name); /* absolute name of the data set */
-
- return(path);
-} /* end build_obj_path_name() */
-
-
-/*-------------------------------------------------------------------------
* Function: find_objs_cb
*
* Purpose: Callback to find objects, committed types and store them in tables
@@ -481,90 +450,65 @@ build_obj_path_name(const char *prefix, const char *name)
*-------------------------------------------------------------------------
*/
static herr_t
-find_objs_cb(hid_t group, const char *name, const H5L_info_t UNUSED *linfo, void *op_data)
+find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen,
+ void *op_data)
{
- H5O_info_t oinfo;
find_objs_t *info = (find_objs_t*)op_data;
herr_t ret_value = 0;
- if(H5Oget_info_by_name(group, name, &oinfo, H5P_DEFAULT) < 0)
- ; /* keep going */
- else {
- switch(oinfo.type) {
- char *tmp;
- size_t tmp_len;
-
- case H5O_TYPE_GROUP:
- if(search_obj(info->group_table, oinfo.addr) == NULL) {
- char *old_prefix;
+ switch(oinfo->type) {
+ case H5O_TYPE_GROUP:
+ if(NULL == already_seen)
+ add_obj(info->group_table, oinfo->addr, name, TRUE);
+ break;
- tmp = build_obj_path_name(info->prefix, name);
- add_obj(info->group_table, oinfo.addr, tmp, TRUE);
+ case H5O_TYPE_DATASET:
+ if(NULL == already_seen) {
+ hid_t dset;
- old_prefix = info->prefix;
- tmp_len = HDstrlen(tmp);
- info->prefix = HDmalloc(tmp_len+1);
- HDstrcpy(info->prefix, tmp);
+ /* Add the dataset to the list of objects */
+ add_obj(info->dset_table, oinfo->addr, name, TRUE);
- if(H5Literate_by_name(group, name, H5_INDEX_NAME, H5_ITER_INC, NULL, find_objs_cb, (void *)info, H5P_DEFAULT) < 0)
- ret_value = FAIL;
+ /* Check for a dataset that uses a named datatype */
+ if((dset = H5Dopen2(info->fid, name, H5P_DEFAULT)) >= 0) {
+ hid_t type = H5Dget_type(dset);
- info->prefix = old_prefix;
- } /* end if */
- break;
-
- case H5O_TYPE_DATASET:
- if(search_obj(info->dset_table, oinfo.addr) == NULL) {
- hid_t dset;
-
- tmp = build_obj_path_name(info->prefix, name);
- add_obj(info->dset_table, oinfo.addr, tmp, TRUE);
-
- if((dset = H5Dopen2(group, name, H5P_DEFAULT)) >= 0) {
- hid_t type;
+ if(H5Tcommitted(type) > 0) {
+ H5O_info_t type_oinfo;
- type = H5Dget_type(dset);
-
- if(H5Tcommitted(type) > 0) {
- H5Oget_info(type, &oinfo);
- if(search_obj(info->type_table, oinfo.addr) == NULL) {
- char *type_name = HDstrdup(tmp);
-
- add_obj(info->type_table, oinfo.addr, type_name, FALSE);
- } /* end if */
- } /* end if */
-
- H5Tclose(type);
- H5Dclose(dset);
+ H5Oget_info(type, &type_oinfo);
+ if(search_obj(info->type_table, type_oinfo.addr) == NULL)
+ add_obj(info->type_table, type_oinfo.addr, name, FALSE);
} /* end if */
- else
- ret_value = FAIL;
- } /* end if */
- break;
- case H5O_TYPE_NAMED_DATATYPE:
- {
- obj_t *found_obj;
-
- tmp = build_obj_path_name(info->prefix, name);
- if((found_obj = search_obj(info->type_table, oinfo.addr)) == NULL)
- add_obj(info->type_table, oinfo.addr, tmp, TRUE);
- else {
- /* Use latest version of name */
- HDfree(found_obj->objname);
- found_obj->objname = HDstrdup(tmp);
-
- /* Mark named datatype as having valid name */
- found_obj->recorded = TRUE;
- } /* end else */
- break;
- }
-
- default:
- /* Ignore links, etc. */
- break;
+ H5Tclose(type);
+ H5Dclose(dset);
+ } /* end if */
+ else
+ ret_value = FAIL;
+ } /* end if */
+ break;
+
+ case H5O_TYPE_NAMED_DATATYPE:
+ {
+ obj_t *found_obj;
+
+ if((found_obj = search_obj(info->type_table, oinfo->addr)) == NULL)
+ add_obj(info->type_table, oinfo->addr, name, TRUE);
+ else {
+ /* Use latest version of name */
+ HDfree(found_obj->objname);
+ found_obj->objname = HDstrdup(name);
+
+ /* Mark named datatype as having valid name */
+ found_obj->recorded = TRUE;
+ } /* end else */
+ break;
}
- } /* end else */
+
+ default:
+ break;
+ } /* end switch */
return ret_value;
}
@@ -589,31 +533,19 @@ herr_t
init_objs(hid_t fid, find_objs_t *info, table_t **group_table,
table_t **dset_table, table_t **type_table)
{
- H5O_info_t oinfo;
-
/* Initialize the tables */
init_table(group_table);
init_table(dset_table);
init_table(type_table);
/* Init the find_objs_t */
- info->prefix = HDcalloc(1, 1);
+ info->fid = fid;
info->group_table = *group_table;
info->type_table = *type_table;
info->dset_table = *dset_table;
- /* add the root group as an object, it may have hard links to it */
- if(H5Oget_info(fid, &oinfo) < 0)
- return FAIL;
- else {
- /* call with an empty string, it appends '/' group separator */
- char *tmp = build_obj_path_name(info->prefix, "");
-
- add_obj(info->group_table, oinfo.addr, tmp, TRUE);
- } /* end else */
-
/* Find all shared objects */
- return(H5Literate(fid, H5_INDEX_NAME, H5_ITER_INC, NULL, find_objs_cb, (void *)info));
+ return(h5trav_visit(fid, "/", TRUE, TRUE, find_objs_cb, NULL, info));
}
@@ -632,22 +564,22 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table,
*-------------------------------------------------------------------------
*/
static void
-add_obj(table_t *table, haddr_t objno, char *objname, hbool_t record)
+add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t record)
{
unsigned u;
/* See if we need to make table larger */
- if (table->nobjs == table->size) {
+ if(table->nobjs == table->size) {
table->size *= 2;
- table->objs = HDrealloc(table->objs, table->size * sizeof(obj_t));
- }
+ table->objs = HDrealloc(table->objs, table->size * sizeof(table->objs[0]));
+ } /* end if */
/* Increment number of objects in table */
u = table->nobjs++;
/* Set information about object */
table->objs[u].objno = objno;
- table->objs[u].objname = objname;
+ table->objs[u].objname = HDstrdup(objname);
table->objs[u].recorded = record;
table->objs[u].displayed = 0;
}