diff options
Diffstat (limited to 'tools/lib/h5tools_ref.c')
-rw-r--r-- | tools/lib/h5tools_ref.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/tools/lib/h5tools_ref.c b/tools/lib/h5tools_ref.c index d6e5f01..a634bc7 100644 --- a/tools/lib/h5tools_ref.c +++ b/tools/lib/h5tools_ref.c @@ -6,7 +6,7 @@ * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -18,7 +18,6 @@ #include "h5tools_utils.h" #include "h5trav.h" - /* * Table to look up a path name for an object * reference. @@ -34,12 +33,12 @@ */ typedef struct { - haddr_t objno; /* Object ID (i.e. address) */ - char *path; /* Object path */ + haddr_t objno; /* Object ID (i.e. address) */ + char * path; /* Object path */ } ref_path_node_t; -static H5SL_t *ref_path_table = NULL; /* the "table" (implemented with a skip list) */ -static hid_t thefile = (-1); +static H5SL_t *ref_path_table = NULL; /* the "table" (implemented with a skip list) */ +static hid_t thefile = (-1); static int ref_path_table_put(const char *, haddr_t objno); @@ -57,14 +56,14 @@ static int ref_path_table_put(const char *, haddr_t objno); *------------------------------------------------------------------------- */ static herr_t -free_ref_path_info(void *item, void H5_ATTR_UNUSED *key, void H5_ATTR_UNUSED *operator_data/*in,out*/) +free_ref_path_info(void *item, void H5_ATTR_UNUSED *key, void H5_ATTR_UNUSED *operator_data /*in,out*/) { ref_path_node_t *node = (ref_path_node_t *)item; HDfree(node->path); HDfree(node); - return(0); + return (0); } /*------------------------------------------------------------------------- @@ -80,11 +79,11 @@ free_ref_path_info(void *item, void H5_ATTR_UNUSED *key, void H5_ATTR_UNUSED *op *------------------------------------------------------------------------- */ static herr_t -init_ref_path_cb(const char *obj_name, const H5O_info_t *oinfo, - const char *already_seen, void H5_ATTR_UNUSED *_udata) +init_ref_path_cb(const char *obj_name, const H5O_info_t *oinfo, const char *already_seen, + void H5_ATTR_UNUSED *_udata) { /* Check if the object is already in the path table */ - if(NULL == already_seen) { + if (NULL == already_seen) { /* Insert the object into the path table */ ref_path_table_put(obj_name, oinfo->addr); } /* end if */ @@ -107,18 +106,18 @@ static int init_ref_path_table(void) { /* Sanity check */ - if(thefile > 0) { + if (thefile > 0) { /* Create skip list to store reference path information */ - if((ref_path_table = H5SL_create(H5SL_TYPE_HADDR, NULL))==NULL) + if ((ref_path_table = H5SL_create(H5SL_TYPE_HADDR, NULL)) == NULL) return (-1); /* Iterate over objects in this file */ - if(h5trav_visit(thefile, "/", TRUE, TRUE, init_ref_path_cb, NULL, NULL) < 0) { + if (h5trav_visit(thefile, "/", TRUE, TRUE, init_ref_path_cb, NULL, NULL) < 0) { error_msg("unable to construct reference path table\n"); h5tools_setstatus(EXIT_FAILURE); } /* end if */ - return(0); + return (0); } else return (-1); @@ -141,10 +140,10 @@ int term_ref_path_table(void) { /* Destroy reference path table, freeing all memory */ - if(ref_path_table) + if (ref_path_table) H5SL_destroy(ref_path_table, free_ref_path_info, NULL); - return(0); + return (0); } /*------------------------------------------------------------------------- @@ -165,30 +164,30 @@ term_ref_path_table(void) haddr_t ref_path_table_lookup(const char *thepath) { - H5O_info_t oi; + H5O_info_t oi; - if((thepath == NULL) || (HDstrlen(thepath) == 0)) + if ((thepath == NULL) || (HDstrlen(thepath) == 0)) return HADDR_UNDEF; /* Allow lookups on the root group, even though it doesn't have any link info */ - if(HDstrcmp(thepath, "/")) { - H5L_info_t li; + if (HDstrcmp(thepath, "/")) { + H5L_info_t li; /* Check for external link first, so we don't return the OID of an object in another file */ - if(H5Lget_info(thefile, thepath, &li, H5P_DEFAULT) < 0) + if (H5Lget_info(thefile, thepath, &li, H5P_DEFAULT) < 0) return HADDR_UNDEF; /* UD links can't be followed, so they always "dangle" like soft links. */ - if(li.type >= H5L_TYPE_UD_MIN) + if (li.type >= H5L_TYPE_UD_MIN) return HADDR_UNDEF; } /* end if */ /* Get the object info now */ /* (returns failure for dangling soft links) */ - if(H5Oget_info_by_name(thefile, thepath, &oi, H5P_DEFAULT) < 0) + if (H5Oget_info_by_name(thefile, thepath, &oi, H5P_DEFAULT) < 0) return HADDR_UNDEF; /* Return OID */ - return(oi.addr); + return (oi.addr); } /*------------------------------------------------------------------------- @@ -215,14 +214,14 @@ ref_path_table_put(const char *path, haddr_t objno) { ref_path_node_t *new_node; - if(ref_path_table && path) { - if((new_node = (ref_path_node_t *)HDmalloc(sizeof(ref_path_node_t))) == NULL) - return(-1); + if (ref_path_table && path) { + if ((new_node = (ref_path_node_t *)HDmalloc(sizeof(ref_path_node_t))) == NULL) + return (-1); new_node->objno = objno; - new_node->path = HDstrdup(path); + new_node->path = HDstrdup(path); - return(H5SL_insert(ref_path_table, new_node, &(new_node->objno))); + return (H5SL_insert(ref_path_table, new_node, &(new_node->objno))); } else return (-1); @@ -233,7 +232,9 @@ ref_path_table_put(const char *path, haddr_t objno) */ int xid = 1; -int get_next_xid(void) { +int +get_next_xid(void) +{ return xid++; } @@ -245,7 +246,8 @@ int get_next_xid(void) { */ haddr_t fake_xid = HADDR_MAX; haddr_t -get_fake_xid (void) { +get_fake_xid(void) +{ return (fake_xid--); } @@ -266,13 +268,13 @@ ref_path_table_gen_fake(const char *path) fake_objno = get_fake_xid(); /* Create ref path table, if it hasn't already been created */ - if(ref_path_table == NULL) + if (ref_path_table == NULL) init_ref_path_table(); /* Insert "fake" object into table */ ref_path_table_put(path, fake_objno); - return(fake_objno); + return (fake_objno); } /*------------------------------------------------------------------------- @@ -294,16 +296,16 @@ lookup_ref_path(haddr_t ref) ref_path_node_t *node; /* Be safer for h5ls */ - if(thefile < 0) - return(NULL); + if (thefile < 0) + return (NULL); /* Create ref path table, if it hasn't already been created */ - if(ref_path_table == NULL) + if (ref_path_table == NULL) init_ref_path_table(); node = (ref_path_node_t *)H5SL_search(ref_path_table, &ref); - return(node ? node->path : NULL); + return (node ? node->path : NULL); } /*------------------------------------------------------------------------- @@ -328,4 +330,3 @@ fill_ref_path_table(hid_t fid) return 0; } - |