diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-01-23 20:46:34 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-01-23 20:46:34 (GMT) |
commit | 56e3f667d6e3e265ac044f3faf1b17137556e0f7 (patch) | |
tree | 70f04688f0596ca5be22dd4e9260f601ee77bbd8 /tools/lib | |
parent | b09695738a95d8f1fb823894d1880f28dc16669c (diff) | |
download | hdf5-56e3f667d6e3e265ac044f3faf1b17137556e0f7.zip hdf5-56e3f667d6e3e265ac044f3faf1b17137556e0f7.tar.gz hdf5-56e3f667d6e3e265ac044f3faf1b17137556e0f7.tar.bz2 |
[svn-r11886] Purpose:
Code cleanup
Description:
Check in some of the code cleanups from working on the external link
support. (This doesn't include any of the external link features)
Platforms tested:
FreeBSD 4.11 (sleipnir)
Mac OSX.4 (amazon)
Linux 2.4
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff.c | 87 | ||||
-rw-r--r-- | tools/lib/h5diff_array.c | 44 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 29 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 159 | ||||
-rw-r--r-- | tools/lib/h5tools_ref.c | 27 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 12 | ||||
-rw-r--r-- | tools/lib/h5tools_str.h | 8 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 2 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 83 | ||||
-rw-r--r-- | tools/lib/h5trav.h | 7 |
10 files changed, 136 insertions, 322 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 7a25d4f..b61cc60 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -161,35 +161,31 @@ static void print_incoming_data(void) * * Date: October 22, 2003 * - * Modifications: Jan 2005 Leon Arber, larber@uiuc.edu - * Added support for parallel diffing - * *------------------------------------------------------------------------- */ -hsize_t -h5diff (const char *fname1, - const char *fname2, - const char *objname1, const char *objname2, diff_opt_t * options) +hsize_t h5diff(const char *fname1, + const char *fname2, + const char *objname1, + const char *objname2, + diff_opt_t *options) { int nobjects1, nobjects2; trav_info_t *info1 = NULL; trav_info_t *info2 = NULL; hid_t file1_id=(-1), file2_id=(-1); - char filenames[2][1024]; - hsize_t nfound = 0; - int not_cmp = 0; + char filenames[2][1024]; + hsize_t nfound = 0; memset(filenames, 0, 1024*2); - - if (options->m_quiet && (options->m_verbose || options->m_report)) - { - printf - ("Error: -q (quiet mode) cannot be added to verbose or report modes\n"); - options->err_stat = 1; - return 0; - } + if (options->m_quiet && + (options->m_verbose || options->m_report)) + { + printf("Error: -q (quiet mode) cannot be added to verbose or report modes\n"); + options->err_stat=1; + return 0; + } /*------------------------------------------------------------------------- * open the files first; if they are not valid, no point in continuing @@ -256,8 +252,6 @@ h5diff (const char *fname1, goto out; } - - /*------------------------------------------------------------------------- * get the list of objects in the files *------------------------------------------------------------------------- @@ -269,10 +263,8 @@ h5diff (const char *fname1, { printf ("Error: Not enough memory for object list\n"); options->err_stat = 1; - if (info1) - h5trav_freeinfo (info1, nobjects1); - if (info2) - h5trav_freeinfo (info2, nobjects1); + if (info1) h5trav_freeinfo (info1, nobjects1); + if (info2) h5trav_freeinfo (info2, nobjects1); #ifdef H5_HAVE_PARALLEL if(g_Parallel) { @@ -875,10 +867,10 @@ diff_compare (hid_t file1_id, * * Purpose: switch between types and choose the diff function * TYPE is either - * H5G_LINK Object is a symbolic link * H5G_GROUP Object is a group * H5G_DATASET Object is a dataset * H5G_TYPE Object is a named data type + * H5G_LINK Object is a symbolic link * * Return: Number of differences found * @@ -901,8 +893,6 @@ diff (hid_t file1_id, int ret; H5G_stat_t sb1; H5G_stat_t sb2; - char *buf1 = NULL; - char *buf2 = NULL; hsize_t nfound = 0; switch (type) @@ -1042,18 +1032,22 @@ diff (hid_t file1_id, *------------------------------------------------------------------------- */ case H5G_LINK: - if (H5Gget_objinfo (file1_id, path1, FALSE, &sb1) < 0) - goto out; - if (H5Gget_objinfo (file1_id, path1, FALSE, &sb2) < 0) - goto out; + { + char *buf1 = NULL; + char *buf2 = NULL; - buf1 = malloc (sb1.u.slink.linklen); - buf2 = malloc (sb2.u.slink.linklen); + if (H5Gget_objinfo (file1_id, path1, FALSE, &sb1) < 0) + goto out; + if (H5Gget_objinfo (file1_id, path1, FALSE, &sb2) < 0) + goto out; + + buf1 = HDmalloc (sb1.u.slink.linklen); + buf2 = HDmalloc (sb2.u.slink.linklen); if (H5Gget_linkval (file1_id, path1, sb1.u.slink.linklen, buf1) < 0) - goto out; + goto out; if (H5Gget_linkval (file2_id, path2, sb1.u.slink.linklen, buf2) < 0) - goto out; + goto out; ret = HDstrcmp (buf1, buf2); @@ -1061,23 +1055,13 @@ diff (hid_t file1_id, nfound = (ret != 0) ? 1 : 0; if (print_objname (options, nfound)) - parallel_print("Link: <%s> and <%s>\n", path1, path2); - - if (buf1) - { - free (buf1); - buf1 = NULL; - } - - if (buf2) - { - free (buf2); - buf2 = NULL; - } + parallel_print("Soft Link: <%s> and <%s>\n", path1, path2); + HDfree (buf1); + HDfree (buf2); + } break; - default: nfound = 0; if (options->m_verbose) @@ -1105,11 +1089,6 @@ out: } H5E_END_TRY; - if (buf1) - free (buf1); - if (buf2) - free (buf2); - return nfound; } diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index dd4784d..f9f0da7 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -336,7 +336,7 @@ hsize_t diff_datum(void *_mem1, } else { - s = mem1; + s = (char *)mem1; size = H5Tget_size(m_type); } @@ -382,6 +382,7 @@ hsize_t diff_datum(void *_mem1, } break; + /*------------------------------------------------------------------------- * H5T_OPAQUE *------------------------------------------------------------------------- @@ -831,7 +832,6 @@ hsize_t diff_datum(void *_mem1, print_pos(ph,1,i,acc,pos,rank,obj1,obj2); parallel_print(SPACES); parallel_print(IPFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short), abs(1-temp2_short/temp1_short)); - } nfound++; } @@ -841,7 +841,6 @@ hsize_t diff_datum(void *_mem1, if ( print_data(options) ) { print_pos(ph,0,i,acc,pos,rank,obj1,obj2); - parallel_print(SPACES); parallel_print(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); } @@ -1124,7 +1123,7 @@ hsize_t diff_datum(void *_mem1, parallel_print(SPACES); parallel_print(LPIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long), labs(1-temp2_long/temp1_long)); } - nfound++; + nfound++; } } /* -d and -p */ @@ -1752,13 +1751,13 @@ void close_obj(H5G_obj_t obj_type, hid_t obj_id) */ static int diff_region(hid_t region1_id, hid_t region2_id) { - hssize_t nblocks1, npoints1; - hssize_t nblocks2, npoints2; + hssize_t nblocks1, npoints1; + hssize_t nblocks2, npoints2; hsize_t alloc_size; hsize_t *ptdata1; hsize_t *ptdata2; - int ndims1 = H5Sget_simple_extent_ndims(region1_id); - int ndims2 = H5Sget_simple_extent_ndims(region2_id); + int ndims1 = H5Sget_simple_extent_ndims(region1_id); + int ndims2 = H5Sget_simple_extent_ndims(region2_id); int ret=0; #if defined (H5DIFF_DEBUG) @@ -2190,7 +2189,7 @@ hsize_t diff_schar(unsigned char *mem1, nfound++; } mem1+=sizeof(char); - mem2+=sizeof(char); + mem2+=sizeof(char); if (options->n && nfound>=options->count) return nfound; } @@ -2217,7 +2216,7 @@ hsize_t diff_schar(unsigned char *mem1, nfound++; } mem1+=sizeof(char); - mem2+=sizeof(char); + mem2+=sizeof(char); if (options->n && nfound>=options->count) return nfound; } @@ -2245,7 +2244,7 @@ hsize_t diff_schar(unsigned char *mem1, nfound++; } mem1+=sizeof(char); - mem2+=sizeof(char); + mem2+=sizeof(char); if (options->n && nfound>=options->count) return nfound; } @@ -2330,7 +2329,7 @@ hsize_t diff_uchar(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned char); - mem2+=sizeof(unsigned char); + mem2+=sizeof(unsigned char); if (options->n && nfound>=options->count) return nfound; } @@ -2358,7 +2357,7 @@ hsize_t diff_uchar(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned char); - mem2+=sizeof(unsigned char); + mem2+=sizeof(unsigned char); if (options->n && nfound>=options->count) return nfound; } @@ -2472,7 +2471,7 @@ hsize_t diff_short(unsigned char *mem1, nfound++; } mem1+=sizeof(short); - mem2+=sizeof(short); + mem2+=sizeof(short); if (options->n && nfound>=options->count) return nfound; } @@ -2500,7 +2499,7 @@ hsize_t diff_short(unsigned char *mem1, nfound++; } mem1+=sizeof(short); - mem2+=sizeof(short); + mem2+=sizeof(short); if (options->n && nfound>=options->count) return nfound; } @@ -2530,7 +2529,7 @@ hsize_t diff_short(unsigned char *mem1, nfound++; } mem1+=sizeof(short); - mem2+=sizeof(short); + mem2+=sizeof(short); if (options->n && nfound>=options->count) return nfound; } @@ -2614,7 +2613,7 @@ hsize_t diff_ushort(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned short); - mem2+=sizeof(unsigned short); + mem2+=sizeof(unsigned short); if (options->n && nfound>=options->count) return nfound; } @@ -2642,7 +2641,7 @@ hsize_t diff_ushort(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned short); - mem2+=sizeof(unsigned short); + mem2+=sizeof(unsigned short); if (options->n && nfound>=options->count) return nfound; } @@ -2672,7 +2671,7 @@ hsize_t diff_ushort(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned short); - mem2+=sizeof(unsigned short); + mem2+=sizeof(unsigned short); if (options->n && nfound>=options->count) return nfound; } @@ -2889,7 +2888,7 @@ hsize_t diff_uint(unsigned char *mem1, memcpy(&temp1_uint, mem1, sizeof(unsigned int)); memcpy(&temp2_uint, mem2, sizeof(unsigned int)); - if (abs(temp1_uint-temp2_uint) > options->delta) + if (abs((int)(temp1_uint-temp2_uint)) > options->delta) { if ( print_data(options) ) { @@ -3063,9 +3062,6 @@ hsize_t diff_long(unsigned char *mem1, { if ( print_data(options) ) { - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); - if (labs(temp1_long-temp2_long) > (long)options->delta) { if ( print_data(options) ) @@ -3218,7 +3214,7 @@ hsize_t diff_ulong(unsigned char *mem1, nfound++; } mem1+=sizeof(unsigned long); - mem2+=sizeof(unsigned long); + mem2+=sizeof(unsigned long); if (options->n && nfound>=options->count) return nfound; } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 9556fe7..01f0fca 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -44,7 +44,6 @@ #define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z)) /* global variables */ -int indent; int compound_data; FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */ @@ -425,7 +424,7 @@ h5tools_ncols(const char *s) *------------------------------------------------------------------------- */ static void -h5tools_simple_prefix(FILE *stream, const h5dump_t *info, +h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hsize_t elmtno, int secnum) { h5tools_str_t prefix; @@ -538,7 +537,7 @@ h5tools_simple_prefix(FILE *stream, const h5dump_t *info, *------------------------------------------------------------------------- */ void -h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, +h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, h5tools_context_t *ctx/*in,out*/, unsigned flags, hsize_t nelmts, hid_t type, void *_mem) { @@ -670,11 +669,8 @@ h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, multiline++; /* pass to the prefix in h5tools_simple_prefix the total position - instead of the current stripmine position i; this is necessary - to print the array indices */ - - /* pass to the prefix in h5tools_simple_prefix the total position - this is necessary to print the array indices */ + instead of the current stripmine position i; this is necessary + to print the array indices */ curr_pos = ctx->sm_pos + i; h5tools_simple_prefix(stream, info, ctx, curr_pos, secnum); @@ -709,7 +705,7 @@ h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, *------------------------------------------------------------------------- */ static herr_t -h5tools_dump_simple_subset(FILE *stream, const h5dump_t *info, hid_t dset, +h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset, hid_t p_type, struct subset_t *sset, int indentlevel) { @@ -876,7 +872,7 @@ done: *------------------------------------------------------------------------- */ static int -h5tools_dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, +h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, hid_t p_type, int indentlevel) { hid_t f_space; /*file data space */ @@ -1071,7 +1067,7 @@ h5tools_dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, *------------------------------------------------------------------------- */ static int -h5tools_dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, +h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, hid_t type, hid_t space, void *mem, int indentlevel) { int i; /*counters */ @@ -1160,7 +1156,7 @@ h5tools_dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, *------------------------------------------------------------------------- */ int -h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, +h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, hid_t _p_type, struct subset_t *sset, int indentlevel) { hid_t f_space; @@ -1168,7 +1164,7 @@ h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, hid_t f_type; H5S_class_t space_type; int status = FAIL; - h5dump_t info_dflt; + h5tool_format_t info_dflt; /* Use default values */ if (!stream) @@ -1238,10 +1234,10 @@ done: *------------------------------------------------------------------------- */ int -h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, +h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, hid_t type, hid_t space, void *mem, int indentlevel) { - h5dump_t info_dflt; + h5tool_format_t info_dflt; /* Use default values */ if (!stream) @@ -1260,8 +1256,6 @@ h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, indentlevel); } - - /*------------------------------------------------------------------------- * Function: init_acc_pos * @@ -1290,4 +1284,3 @@ void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) ctx->pos[i]=0; } - diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index c5ca4fa..4bbc2d6 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -26,13 +26,13 @@ #define ESCAPE_HTML 1 #define OPT(X,S) ((X) ? (X) : (S)) #define OPTIONAL_LINE_BREAK "\001" /* Special strings embedded in the output */ -#define START_OF_DATA 0x0001 -#define END_OF_DATA 0x0002 +#define START_OF_DATA 0x0001 +#define END_OF_DATA 0x0002 /* * Information about how to format output. */ -typedef struct h5dump_t { +typedef struct h5tool_format_t { /* * Fields associated with formatting numeric data. If a datatype matches * multiple formats based on its size, then the first applicable format @@ -321,82 +321,7 @@ typedef struct h5dump_t { /*escape non printable characters */ int do_escape; -} h5dump_t; - -typedef struct dump_header{ - const char *name; - const char *filebegin; - const char *fileend; - const char *bootblockbegin; - const char *bootblockend; - const char *groupbegin; - const char *groupend; - const char *datasetbegin; - const char *datasetend; - const char *attributebegin; - const char *attributeend; - const char *datatypebegin; - const char *datatypeend; - const char *dataspacebegin; - const char *dataspaceend; - const char *databegin; - const char *dataend; - const char *softlinkbegin; - const char *softlinkend; - const char *subsettingbegin; - const char *subsettingend; - const char *startbegin; - const char *startend; - const char *stridebegin; - const char *strideend; - const char *countbegin; - const char *countend; - const char *blockbegin; - const char *blockend; - - const char *fileblockbegin; - const char *fileblockend; - const char *bootblockblockbegin; - const char *bootblockblockend; - const char *groupblockbegin; - const char *groupblockend; - const char *datasetblockbegin; - const char *datasetblockend; - const char *attributeblockbegin; - const char *attributeblockend; - const char *datatypeblockbegin; - const char *datatypeblockend; - const char *dataspaceblockbegin; - const char *dataspaceblockend; - const char *datablockbegin; - const char *datablockend; - const char *softlinkblockbegin; - const char *softlinkblockend; - const char *strblockbegin; - const char *strblockend; - const char *enumblockbegin; - const char *enumblockend; - const char *structblockbegin; - const char *structblockend; - const char *vlenblockbegin; - const char *vlenblockend; - const char *subsettingblockbegin; - const char *subsettingblockend; - const char *startblockbegin; - const char *startblockend; - const char *strideblockbegin; - const char *strideblockend; - const char *countblockbegin; - const char *countblockend; - const char *blockblockbegin; - const char *blockblockend; - - const char *dataspacedescriptionbegin; - const char *dataspacedescriptionend; - const char *dataspacedimbegin; - const char *dataspacedimend; - -} dump_header; +} h5tool_format_t; typedef struct h5tools_context_t { size_t cur_column; /*current column for output */ @@ -419,8 +344,6 @@ typedef struct h5tools_context_t { hsize_t sm_pos; /* current stripmine element position */ } h5tools_context_t; - - /* a structure to hold the subsetting particulars for a dataset */ struct subset_t { hsize_t *start; @@ -429,74 +352,12 @@ struct subset_t { hsize_t *block; }; -/*if we get a new program that needs to use the library add its name here*/ -typedef enum { - UNKNOWN = 0, - H5LS, - H5DUMP -} ProgType; - -/* taken from h5dump.h */ -#define ATTRIBUTE_DATA 0 -#define DATASET_DATA 1 -#define ENUM_DATA 2 - -#define COL 3 - -extern int indent; /*how far in to indent the line */ extern FILE *rawdatastream; /*output stream for raw data */ -/* taken from h5dump.h*/ -#define ATTRIBUTE "ATTRIBUTE" -#define BLOCK "BLOCK" -#define SUPER_BLOCK "SUPER_BLOCK" -#define COMPRESSION "COMPRESSION" -#define CONCATENATOR "//" -#define COMPLEX "COMPLEX" -#define COUNT "COUNT" -#define CSET "CSET" -#define CTYPE "CTYPE" -#define DATA "DATA" +/* Strings for output */ +#define GROUP "GROUP" #define DATASET "DATASET" -#define DATASPACE "DATASPACE" #define DATATYPE "DATATYPE" -#define EXTERNAL "EXTERNAL" -#define FILENO "FILENO" -#define GROUPNAME "GROUP" -#define HARDLINK "HARDLINK" -#define NLINK "NLINK" -#define OBJID "OBJECTID" -#define OBJNO "OBJNO" -#define S_SCALAR "SCALAR" -#define S_SIMPLE "SIMPLE" -#define S_NULL "NULL" -#define SOFTLINK "SOFTLINK" -#define STORAGELAYOUT "STORAGELAYOUT" -#define START "START" -#define STRIDE "STRIDE" -#define STRSIZE "STRSIZE" -#define STRPAD "STRPAD" -#define SUBSET "SUBSET" -#define FILTERS "FILTERS" -#define DEFLATE "COMPRESSION DEFLATE" -#define DEFLATE_LEVEL "LEVEL" -#define SHUFFLE "PREPROCESSING SHUFFLE" -#define FLETCHER32 "CHECKSUM FLETCHER32" -#define SZIP "COMPRESSION SZIP" -#define NBIT "COMPRESSION NBIT" -#define SCALEOFFSET "COMPRESSION SCALEOFFSET" -#define SCALEOFFSET_MINBIT "MIN BITS" -#define STORAGE_LAYOUT "STORAGE_LAYOUT" -#define CONTIGUOUS "CONTIGUOUS" -#define COMPACT "COMPACT" -#define CHUNKED "CHUNKED" -#define EXTERNAL_FILE "EXTERNAL_FILE" -#define FILLVALUE "FILLVALUE" -#define FILE_CONTENTS "FILE_CONTENTS" - - -#define BEGIN "{" -#define END "}" /* Definitions of useful routines */ extern void h5tools_init(void); @@ -504,13 +365,13 @@ extern void h5tools_close(void); extern hid_t h5tools_fopen(const char *fname, const char *driver, char *drivername, size_t drivername_len, int argc, const char *argv[]); -extern int h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, +extern int h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, hid_t p_typ, struct subset_t *sset, int indentlevel); -extern int h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, +extern int h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, hid_t type, hid_t space, void *mem, int indentlevel); extern hid_t h5tools_get_native_type(hid_t type); -extern void h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, +extern void h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, h5tools_context_t *ctx/*in,out*/, unsigned flags, hsize_t nelmts, hid_t type, void *_mem); @@ -520,5 +381,5 @@ extern int h5tools_can_encode(H5Z_filter_t filtn); void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims); - #endif /* H5TOOLS_H__ */ + diff --git a/tools/lib/h5tools_ref.c b/tools/lib/h5tools_ref.c index c93d2e5..89bdaf1 100644 --- a/tools/lib/h5tools_ref.c +++ b/tools/lib/h5tools_ref.c @@ -156,17 +156,26 @@ haddr_t ref_path_table_lookup(const char *thepath) { H5G_stat_t sb; - haddr_t ret_value; - /* Get object ID for object at path */ - if(H5Gget_objinfo(thefile, thepath, TRUE, &sb)<0) - /* fatal error ? */ + /* Check for external link first, so we don't return the OID of an object in another file */ + if(H5Gget_objinfo(thefile, thepath, FALSE, &sb)<0) return HADDR_UNDEF; - - /* Return OID or HADDR_UNDEF */ - ret_value = ref_path_table_find(sb.u.obj.objno) ? sb.u.obj.objno : HADDR_UNDEF; - - return(ret_value); + if(sb.type == H5G_LINK) { + /* Get object ID for object at path */ + /* (If the object is not a soft link, we've already retrieved the + * correct information and don't have to perform this call. -QAK + */ + if(H5Gget_objinfo(thefile, thepath, TRUE, &sb)<0) + /* fatal error ? */ + return HADDR_UNDEF; + } /* end if */ + + + /* All existing objects in the file had better be in the table */ + HDassert(ref_path_table_find(sb.u.obj.objno)); + + /* Return OID */ + return(sb.u.obj.objno); } /*------------------------------------------------------------------------- diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 1c1c1b2..73ca045 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -24,7 +24,7 @@ #include <string.h> #include "H5private.h" -#include "h5tools.h" /*for h5dump_t structure */ +#include "h5tools.h" /*for h5tool_format_t structure */ #include "h5tools_ref.h" #include "h5tools_str.h" /*function prototypes */ @@ -304,7 +304,7 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) *------------------------------------------------------------------------- */ char * -h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5dump_t *info, +h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5tool_format_t *info, hsize_t elmtno, int ndims, hsize_t min_idx[], hsize_t max_idx[], h5tools_context_t *ctx) { @@ -364,7 +364,7 @@ h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5dump_t *info, *------------------------------------------------------------------------- */ int -h5tools_str_dump_region(h5tools_str_t *str, hid_t region, const h5dump_t *info) +h5tools_str_dump_region(h5tools_str_t *str, hid_t region, const h5tool_format_t *info) { hssize_t nblocks, npoints; hsize_t alloc_size; @@ -461,7 +461,7 @@ h5tools_str_dump_region(h5tools_str_t *str, hid_t region, const h5dump_t *info) *------------------------------------------------------------------------- */ void -h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch) +h5tools_print_char(h5tools_str_t *str, const h5tool_format_t *info, unsigned char ch) { if (info->str_locale == ESCAPE_HTML) { if (ch <= ' ' || ch > '~') @@ -564,7 +564,7 @@ h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch) *------------------------------------------------------------------------- */ char * -h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, +h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, hid_t type, void *vp, h5tools_context_t *ctx) { size_t n, offset, size=0, nelmts, start; @@ -859,7 +859,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, /* Print object type and close object */ switch (otype) { case H5G_GROUP: - h5tools_str_append(str, GROUPNAME); + h5tools_str_append(str, GROUP); H5Gclose(obj); break; case H5G_DATASET: diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index db7c1b3..19872a1 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -31,12 +31,12 @@ extern char *h5tools_str_append(h5tools_str_t *str, const char *fmt, ...); extern char *h5tools_str_reset(h5tools_str_t *str); extern char *h5tools_str_trunc(h5tools_str_t *str, size_t size); extern char *h5tools_str_fmt(h5tools_str_t *str, size_t start, const char *fmt); -extern char *h5tools_str_prefix(h5tools_str_t *str, const h5dump_t *info, +extern char *h5tools_str_prefix(h5tools_str_t *str, const h5tool_format_t *info, hsize_t elmtno, int ndims, hsize_t min_idx[], hsize_t max_idx[], h5tools_context_t *ctx); -extern int h5tools_str_dump_region(h5tools_str_t *, hid_t, const h5dump_t *); -extern void h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch); -extern char *h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, +extern int h5tools_str_dump_region(h5tools_str_t *, hid_t, const h5tool_format_t *); +extern void h5tools_print_char(h5tools_str_t *str, const h5tool_format_t *info, unsigned char ch); +extern char *h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, hid_t type, void *vp, h5tools_context_t *ctx); diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index 3e63c56..9eba7c5 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -591,7 +591,7 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table, init_table(type_table); /* Init the find_objs_t */ - info->prefix = ""; + info->prefix = (char *)""; info->group_table = *group_table; info->type_table = *type_table; info->dset_table = *dset_table; diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 5030e37..b59162a 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -17,14 +17,14 @@ #include "H5private.h" /* functions for traversal */ -int traverse( hid_t loc_id, +static int traverse( hid_t loc_id, const char *group_name, trav_table_t *table, trav_info_t *info, int *idx, int print); -herr_t get_nnames( hid_t loc_id, +static hssize_t get_nnames( hid_t loc_id, const char *group_name ); herr_t get_name_type( hid_t loc_id, @@ -159,36 +159,6 @@ void h5trav_freeinfo( trav_info_t *info, int nobjs ) /*------------------------------------------------------------------------- - * Function: count_names - * - * Purpose: operator function - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 10, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -static herr_t count_names( hid_t loc_id, const char *name, void *op_data) -{ - - H5G_stat_t statbuf; - - if (H5Gget_objinfo( loc_id, name, 0, &statbuf) < 0 ) - return 1; - - (*(int *)op_data)++; - - /* Define a default zero value for return. This will cause the iterator to continue */ - return 0; -} - -/*------------------------------------------------------------------------- * Function: get_nnames * * Purpose: Counts the number of names in the group GROUP_NAME @@ -209,15 +179,24 @@ static herr_t count_names( hid_t loc_id, const char *name, void *op_data) *------------------------------------------------------------------------- */ -herr_t get_nnames( hid_t loc_id, const char *group_name ) +static hssize_t get_nnames( hid_t loc_id, const char *group_name ) { + hid_t gid; + hsize_t nobjs = 0; - int nobjs = 0; + /* Open the group */ + if((gid = H5Gopen(loc_id, group_name)) < 0) + return(-1); - if ( H5Giterate( loc_id, group_name, NULL, count_names, (void *)&nobjs ) < 0 ) - return -1; + /* Retrieve the number of objects in it */ + if(H5Gget_num_objs(gid, &nobjs) < 0) + return(-1); - return nobjs; + /* Close the group */ + if(H5Gclose(gid) < 0) + return(-1); + + return((hssize_t)nobjs); } @@ -242,7 +221,7 @@ static herr_t opget_info( hid_t loc_id, const char *name, void *op_data) H5G_stat_t statbuf; - if (H5Gget_objinfo( loc_id, name, 0, &statbuf) < 0 ) + if (H5Gget_objinfo( loc_id, name, FALSE, &statbuf) < 0 ) return -1; ((trav_info_t *)op_data)->type = statbuf.type; @@ -306,7 +285,7 @@ herr_t get_name_type( hid_t loc_id, *------------------------------------------------------------------------- */ -int traverse( hid_t loc_id, +static int traverse( hid_t loc_id, const char *group_name, trav_table_t *table, trav_info_t *info, @@ -323,7 +302,7 @@ int traverse( hid_t loc_id, int i, j; /* get the number of names */ - if (( n_names = get_nnames( loc_id, group_name )) < 0 ) + if (( n_names = (int)get_nnames( loc_id, group_name )) < 0 ) return -1; for ( i = 0; i < n_names; i++) @@ -332,13 +311,13 @@ int traverse( hid_t loc_id, return -1; /* allocate path buffer */ - path = (char*) HDmalloc(strlen(group_name) + strlen(name) + 2); + path = (char*) HDmalloc(HDstrlen(group_name) + HDstrlen(name) + 2); /* initialize path */ - strcpy( path, group_name ); - if ( strcmp(group_name,"/")!=0 ) - strcat( path, "/" ); - strcat( path, name ); + HDstrcpy( path, group_name ); + if ( HDstrcmp(group_name, "/") != 0 ) + HDstrcat( path, "/" ); + HDstrcat( path, name ); /* disable error reporting */ H5E_BEGIN_TRY { @@ -483,22 +462,22 @@ int traverse( hid_t loc_id, case H5G_LINK: { - char *targbuf=NULL; - /* increment */ inserted_objs++; /* add object to table */ - trav_table_add(statbuf.u.obj.objno, path, H5G_LINK, table ); + trav_table_add(HADDR_UNDEF, path, H5G_LINK, table ); if (statbuf.u.slink.linklen>0) { - targbuf=malloc(statbuf.u.slink.linklen); + char *targbuf; + + targbuf = HDmalloc(statbuf.u.slink.linklen); + assert(targbuf); H5Gget_linkval(loc_id,path,statbuf.u.slink.linklen,targbuf); if (print) printf(" %-10s %s -> %s\n", "link", path, targbuf); - if (targbuf) - free(targbuf); + free(targbuf); } else { @@ -511,6 +490,8 @@ int traverse( hid_t loc_id, default: + HDfprintf(stderr, "traverse: Unknown object!\n"); + return (-1); break; } diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h index cd38a9b..40fa63d 100644 --- a/tools/lib/h5trav.h +++ b/tools/lib/h5trav.h @@ -17,19 +17,14 @@ #include "hdf5.h" -#if 0 -#define H5_TRAV_DEBUG -#endif - - /*------------------------------------------------------------------------- * public struct to store name and type of an object * the TYPE can be: * H5G_UNKNOWN = -1, - * H5G_LINK, Object is a symbolic link * H5G_GROUP, Object is a group * H5G_DATASET, Object is a dataset * H5G_TYPE, Object is a named data type + * H5G_LINK, Object is a symbolic link *------------------------------------------------------------------------- */ |