diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/h5dump/h5dump_ddl.c | 17 | ||||
-rw-r--r-- | tools/h5dump/testh5dump.sh.in | 2 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 49 | ||||
-rw-r--r-- | tools/lib/h5tools_str.h | 2 | ||||
-rw-r--r-- | tools/testfiles/tarray6.h5 | bin | 6400 -> 6400 bytes | |||
-rw-r--r-- | tools/testfiles/tattr-1.ddl | 2 | ||||
-rw-r--r-- | tools/testfiles/tattr-2.ddl | 4 | ||||
-rw-r--r-- | tools/testfiles/tattr-3.ddl | 6 | ||||
-rw-r--r-- | tools/testfiles/tattr.h5 | bin | 3024 -> 3024 bytes | |||
-rw-r--r-- | tools/testfiles/tattr.h5.xml | 2 |
11 files changed, 72 insertions, 14 deletions
diff --git a/tools/h5dump/CMakeLists.txt b/tools/h5dump/CMakeLists.txt index e16b319..70b1b56 100644 --- a/tools/h5dump/CMakeLists.txt +++ b/tools/h5dump/CMakeLists.txt @@ -937,7 +937,7 @@ IF (BUILD_TESTING) # test for displaying attributes ADD_H5_TEST (tattr-1 0 --enable-error-stack tattr.h5) # test for displaying the selected attributes of string type and scalar space - ADD_H5_TEST (tattr-2 0 --enable-error-stack -a /attr1 --attribute /attr4 --attribute=/attr5 tattr.h5) + ADD_H5_TEST (tattr-2 0 --enable-error-stack -a "/\/attr1" --attribute /attr4 --attribute=/attr5 tattr.h5) # test for header and error messages ADD_H5_MASK_TEST (tattr-3 1 --enable-error-stack --header -a /attr2 --attribute=/attr tattr.h5) # test for displaying attributes in shared datatype (also in group and dataset) diff --git a/tools/h5dump/h5dump_ddl.c b/tools/h5dump/h5dump_ddl.c index be56c9b..b8deaf9 100644 --- a/tools/h5dump/h5dump_ddl.c +++ b/tools/h5dump/h5dump_ddl.c @@ -1322,7 +1322,7 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe hid_t oid = -1; hid_t attr_id = -1; char *obj_name; - const char *attr_name; + char *attr_name; int j; h5tools_str_t buffer; /* string into which to render */ h5tools_context_t ctx; /* print context */ @@ -1337,7 +1337,7 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe /* find the last / */ while(j >= 0) { - if (attr[j] == '/') + if (attr[j] == '/' && (j==0 || (j>0 && attr[j-1]!='\\'))) break; j--; } @@ -1372,9 +1372,12 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe string_dataformat.do_escape = display_escape; outputformat = &string_dataformat; - attr_name = attr + j + 1; + //attr_name = attr + j + 1; + // need to replace escape characters + attr_name = h5tools_str_replace(attr + j + 1, "\\/", "/"); - /* Open the object with the attribute */ + + /* handle error case: cannot open the object with the attribute */ if((oid = H5Oopen(fid, obj_name, H5P_DEFAULT)) < 0) { /* setup */ HDmemset(&buffer, 0, sizeof(h5tools_str_t)); @@ -1415,7 +1418,7 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe attr_data_output = display_attr_data; h5dump_type_table = type_table; - h5tools_dump_attribute(rawoutstream, outputformat, &ctx, oid, attr, attr_id, display_ai, display_char); + h5tools_dump_attribute(rawoutstream, outputformat, &ctx, oid, attr_name, attr_id, display_ai, display_char); h5dump_type_table = NULL; if(attr_id < 0) { @@ -1428,6 +1431,7 @@ handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int UNUSED pe } /* end if */ HDfree(obj_name); + HDfree(attr_name); dump_indent -= COL; return; @@ -1435,6 +1439,9 @@ error: h5tools_setstatus(EXIT_FAILURE); if(obj_name) HDfree(obj_name); + + if (attr_name) + HDfree(attr_name); H5E_BEGIN_TRY { H5Oclose(oid); diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in index 1141cf7..63c81ed 100644 --- a/tools/h5dump/testh5dump.sh.in +++ b/tools/h5dump/testh5dump.sh.in @@ -718,7 +718,7 @@ TOOLTEST3 tdset-2.ddl --enable-error-stack -H -d dset1 -d /dset2 --dataset=dset3 # test for displaying attributes TOOLTEST tattr-1.ddl --enable-error-stack tattr.h5 # test for displaying the selected attributes of string type and scalar space -TOOLTEST tattr-2.ddl --enable-error-stack -a /attr1 --attribute /attr4 --attribute=/attr5 tattr.h5 +TOOLTEST tattr-2.ddl --enable-error-stack -a "/\/attr1" --attribute /attr4 --attribute=/attr5 tattr.h5 # test for header and error messages TOOLTEST3 tattr-3.ddl --enable-error-stack --header -a /attr2 --attribute=/attr tattr.h5 # test for displaying at least 9 attributes on root from a BE machine diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index b0a3ed8..795107a 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -1363,3 +1363,52 @@ h5tools_str_is_zero(const void *_mem, size_t size) return TRUE; } + +/*------------------------------------------------------------------------- + * Function: h5tools_str_replace + * + * Purpose: replace all occurrences of substring. + * + * Return: char * + * + * Programmer: Peter Cao + * March 8, 2012 + * + * Notes: + * Applications need to call free() to free the memoery allocated for + * the return string + * + *------------------------------------------------------------------------- + */ +char * +h5tools_str_replace ( const char *string, const char *substr, const char *replacement ) +{ + char *tok = NULL; + char *newstr = NULL; + char *oldstr = NULL; + char *head = NULL; + + if ( substr == NULL || replacement == NULL ) + return strdup (string); + + newstr = strdup (string); + head = newstr; + while ( (tok = strstr ( head, substr ))){ + oldstr = newstr; + newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) + 1 ); + + if ( newstr == NULL ){ + free (oldstr); + return NULL; + } + memcpy ( newstr, oldstr, tok - oldstr ); + memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) ); + memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) ); + memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) , 0, 1 ); + /* move back head right after the last replacement */ + head = newstr + (tok - oldstr) + strlen( replacement ); + free (oldstr); + } + + return newstr; +} diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index 9527a56..38697c6 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -47,5 +47,7 @@ H5TOOLS_DLL void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_ H5TOOLS_DLL 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); +H5TOOLS_DLL char *h5tools_str_replace ( const char *string, const char *substr, + const char *replacement ); #endif /* H5TOOLS_STR_H__ */ diff --git a/tools/testfiles/tarray6.h5 b/tools/testfiles/tarray6.h5 Binary files differindex b4af19b..7eb078c 100644 --- a/tools/testfiles/tarray6.h5 +++ b/tools/testfiles/tarray6.h5 diff --git a/tools/testfiles/tattr-1.ddl b/tools/testfiles/tattr-1.ddl index d353577..b58731b 100644 --- a/tools/testfiles/tattr-1.ddl +++ b/tools/testfiles/tattr-1.ddl @@ -1,6 +1,6 @@ HDF5 "tattr.h5" { GROUP "/" { - ATTRIBUTE "attr1" { + ATTRIBUTE "/attr1" { DATATYPE H5T_STD_I8BE DATASPACE SIMPLE { ( 24 ) / ( 24 ) } DATA { diff --git a/tools/testfiles/tattr-2.ddl b/tools/testfiles/tattr-2.ddl index 79ba8c3..328b54f 100644 --- a/tools/testfiles/tattr-2.ddl +++ b/tools/testfiles/tattr-2.ddl @@ -7,14 +7,14 @@ ATTRIBUTE "/attr1" { (14): 111, 111, 116, 32, 103, 114, 111, 117, 112, 0 } } -ATTRIBUTE "/attr4" { +ATTRIBUTE "attr4" { DATATYPE H5T_STD_I32BE DATASPACE SCALAR DATA { (0): 100 } } -ATTRIBUTE "/attr5" { +ATTRIBUTE "attr5" { DATATYPE H5T_STRING { STRSIZE 17; STRPAD H5T_STR_NULLTERM; diff --git a/tools/testfiles/tattr-3.ddl b/tools/testfiles/tattr-3.ddl index c0dd123..a19f69a 100644 --- a/tools/testfiles/tattr-3.ddl +++ b/tools/testfiles/tattr-3.ddl @@ -1,9 +1,9 @@ HDF5 "tattr.h5" { -ATTRIBUTE "/attr2" { +ATTRIBUTE "attr2" { DATATYPE H5T_STD_I32BE DATASPACE SIMPLE { ( 10 ) / ( 10 ) } } -ATTRIBUTE "/attr" { +ATTRIBUTE "attr" { } } HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): @@ -13,4 +13,4 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): #001: (file name) line (number) in H5O_attr_open_by_name(): can't locate attribute: 'attr' major: Attribute minor: Object not found -h5dump error: unable to open attribute "/attr" +h5dump error: unable to open attribute "attr" diff --git a/tools/testfiles/tattr.h5 b/tools/testfiles/tattr.h5 Binary files differindex fd14b58..d61def5 100644 --- a/tools/testfiles/tattr.h5 +++ b/tools/testfiles/tattr.h5 diff --git a/tools/testfiles/tattr.h5.xml b/tools/testfiles/tattr.h5.xml index 57fa276..fceea99 100644 --- a/tools/testfiles/tattr.h5.xml +++ b/tools/testfiles/tattr.h5.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <hdf5:HDF5-File xmlns:hdf5="http://hdfgroup.org/HDF5/XML/schema/HDF5-File" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hdfgroup.org/HDF5/XML/schema/HDF5-File http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd"> <hdf5:RootGroup OBJ-XID="xid_928" H5Path="/"> - <hdf5:Attribute Name="attr1"> + <hdf5:Attribute Name="/attr1"> <hdf5:Dataspace> <hdf5:SimpleDataspace Ndims="1"> <hdf5:Dimension DimSize="24" MaxDimSize="24"/> |