diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-06-04 00:25:29 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-06-04 00:25:29 (GMT) |
commit | 6e196a7b669ed5edeb3a1329e1cb158b8df75a95 (patch) | |
tree | 712b42d6dc7399f66bd3f056d9004838710c99e8 /tools | |
parent | 79380c228cb804bb7ed9bb1ac7b3f36706719c20 (diff) | |
download | hdf5-6e196a7b669ed5edeb3a1329e1cb158b8df75a95.zip hdf5-6e196a7b669ed5edeb3a1329e1cb158b8df75a95.tar.gz hdf5-6e196a7b669ed5edeb3a1329e1cb158b8df75a95.tar.bz2 |
[svn-r15134] Description:
Brought revision 15133 back from trunk:
Fixed bug in h5ls that prevented relative group listings (like
"h5ls foo.h5/bar") from working correctly.
Tested on:
Mac OS X/32 10.5.3 (amazon)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5ls/h5ls.c | 35 | ||||
-rwxr-xr-x | tools/h5ls/testh5ls.sh | 1 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 45 | ||||
-rw-r--r-- | tools/testfiles/tgroup-3.ls | 5 |
4 files changed, 45 insertions, 41 deletions
diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 80b45d8..6f07050 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -33,8 +33,8 @@ /* Struct to pass through to visitors */ typedef struct { - hid_t fid; /* File ID */ const char *fname; /* Filename */ + hid_t gid; /* Group ID */ }iter_t; /* Command-line switches */ @@ -1687,7 +1687,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Open the object. Not all objects can be opened. If this is the case * then return right away. */ - if(obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) { + if(obj_type >= 0 && (obj = H5Oopen(iter->gid, name, H5P_DEFAULT)) < 0) { printf(" *ERROR*\n"); goto done; } /* end if */ @@ -1779,7 +1779,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) if((buf = HDmalloc(linfo->u.val_size)) == NULL) goto done; - if(H5Lget_val(iter->fid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { + if(H5Lget_val(iter->gid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { HDfree(buf); goto done; } /* end if */ @@ -1796,7 +1796,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) if((buf = HDmalloc(linfo->u.val_size)) == NULL) goto done; - if(H5Lget_val(iter->fid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { + if(H5Lget_val(iter->gid, name, buf, linfo->u.val_size, H5P_DEFAULT) < 0) { HDfree(buf); goto done; } /* end if */ @@ -2164,7 +2164,7 @@ main(int argc, const char *argv[]) /* Shorten the file name; lengthen the object name */ x = oname; - oname = strrchr(fname, '/'); + oname = HDstrrchr(fname, '/'); if(x) *x = '/'; if(!oname) @@ -2185,7 +2185,7 @@ main(int argc, const char *argv[]) /* Remember the file information for later */ iter.fname = fname; - iter.fid = file; + iter.gid = -1; /* Check for root group as object name */ if(HDstrcmp(oname, root_name)) { @@ -2209,13 +2209,28 @@ main(int argc, const char *argv[]) } /* end if */ /* Check for group iteration */ - if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) + if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) { + /* Get ID for group */ + if((iter.gid = H5Gopen2(file, oname, H5P_DEFAULT)) < 0) { + fprintf(stderr, "%s: unable to open '%s' as group\n", fname, oname); + continue; + } /* end if */ + /* Specified name is a group. List the complete contents of the group. */ h5trav_visit(file, oname, display_root_g, recursive_g, list_obj, list_lnk, &iter); - else + + /* Close group */ + H5Gclose(iter.gid); + } /* end if */ + else { + /* Use file ID for root group ID */ + iter.gid = file; + /* Specified name is a non-group object -- list that object */ list_obj(oname, &oi, NULL, &iter); - } else + } /* end else */ + } /* end if */ + else /* Specified name is not for object -- list that link */ list_lnk(oname, &li, &iter); H5Fclose(file); @@ -2223,5 +2238,5 @@ main(int argc, const char *argv[]) } /* end while */ leave(0); -} +} /* end main() */ diff --git a/tools/h5ls/testh5ls.sh b/tools/h5ls/testh5ls.sh index cef5730..6383709 100755 --- a/tools/h5ls/testh5ls.sh +++ b/tools/h5ls/testh5ls.sh @@ -113,6 +113,7 @@ TOOLTEST help-3.ls 0 -w80 -? TOOLTEST tall-1.ls 0 -w80 tall.h5 TOOLTEST tall-2.ls 0 -w80 -r -d tall.h5 TOOLTEST tgroup.ls 0 -w80 tgroup.h5 +TOOLTEST tgroup-3.ls 0 -w80 tgroup.h5/g1 # test for displaying groups # The following combination of arguments is expected to return an error message diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 14ced60..0ed6a30 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -39,6 +39,7 @@ typedef struct { typedef struct { trav_addr_t *seen; /* List of addresses seen already */ const trav_visitor_t *visitor; /* Information for visiting each link/object */ + hbool_t is_absolute; /* Whether the traversal has absolute paths */ } trav_ud_traverse_t; typedef struct { @@ -139,13 +140,19 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, void *_udata) { trav_ud_traverse_t *udata = (trav_ud_traverse_t *)_udata; /* User data */ - char *full_name; + char *new_name = NULL; + const char *full_name; const char *already_visited = NULL; /* Whether the link/object was already visited */ /* Create the full path name for the link */ - full_name = HDmalloc(HDstrlen(path) + 2); - *full_name = '/'; - HDstrcpy(full_name + 1, path); + if(udata->is_absolute) { + new_name = HDmalloc(HDstrlen(path) + 2); + *new_name = '/'; + HDstrcpy(new_name + 1, path); + full_name = new_name; + } /* end if */ + else + full_name = path; /* Perform the correct action for different types of links */ if(linfo->type == H5L_TYPE_HARD) { @@ -172,7 +179,8 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, (*udata->visitor->visit_lnk)(full_name, linfo, udata->visitor->udata); } /* end else */ - HDfree(full_name); + if(new_name) + HDfree(new_name); return(H5_ITER_CONT); } /* end traverse_cb() */ @@ -222,6 +230,7 @@ traverse(hid_t file_id, const char *grp_name, hbool_t visit_start, /* Set up user data structure */ udata.seen = &seen; udata.visitor = visitor; + udata.is_absolute = (*grp_name == '/'); /* Check for iteration of links vs. visiting all links recursively */ if(recurse) { @@ -582,32 +591,6 @@ h5trav_getindext(const char *name, const trav_table_t *table) } /*------------------------------------------------------------------------- - * Function: trav_table_search - * - * Purpose: Search in the table for OBJNO - * - * Return: index of object in table - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - *------------------------------------------------------------------------- - */ - -static size_t -trav_table_search(const trav_table_t *table, haddr_t objno) -{ - size_t i; - - for(i = 0; i < table->nobjs; i++) - if(table->objs[i].objno == objno) - return(i); - return(i); -} - - -/*------------------------------------------------------------------------- * Function: trav_table_add * * Purpose: Add OBJNO, NAME and TYPE of object to table diff --git a/tools/testfiles/tgroup-3.ls b/tools/testfiles/tgroup-3.ls new file mode 100644 index 0000000..cfb479a --- /dev/null +++ b/tools/testfiles/tgroup-3.ls @@ -0,0 +1,5 @@ +############################# + output for 'h5ls -w80 tgroup.h5/g1' +############################# +g1.1 Group +g1.2 Group |