diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2012-03-21 15:10:17 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2012-03-21 15:10:17 (GMT) |
commit | eb89d7b53ab95623ab454186a602e1cafc7391f0 (patch) | |
tree | ceafe458b3011e38853e765352d3c7e59bbecce1 /tools/h5ls | |
parent | 3e468e6ff65d540a439e99ea568a6bff7add7cea (diff) | |
download | hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.zip hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.tar.gz hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.tar.bz2 |
[svn-r22105] Description:
Bring r20557:22085 from trunk to this branch, also fixing some other
issues/failures in the branch simultaneously. The h5repack tests are still
failing, but Neil will be checking into those, so the branch can be fully
functional again.
Tested on:
Mac OSX/64 10.7.3 (amazon) w/debug
Diffstat (limited to 'tools/h5ls')
-rw-r--r-- | tools/h5ls/CMakeLists.txt | 249 | ||||
-rw-r--r-- | tools/h5ls/Makefile.in | 3 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 1142 | ||||
-rw-r--r-- | tools/h5ls/testh5ls.sh.in | 209 |
4 files changed, 1034 insertions, 569 deletions
diff --git a/tools/h5ls/CMakeLists.txt b/tools/h5ls/CMakeLists.txt index 6956c4e..0dec21c 100644 --- a/tools/h5ls/CMakeLists.txt +++ b/tools/h5ls/CMakeLists.txt @@ -1,11 +1,10 @@ -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 2.8.6) PROJECT (HDF5_TOOLS_H5LS) #----------------------------------------------------------------------------- # Setup include Directories #----------------------------------------------------------------------------- INCLUDE_DIRECTORIES (${HDF5_TOOLS_SRC_DIR}/lib) -INCLUDE_DIRECTORIES (${HDF5_PROJECT_DIR}/test) #----------------------------------------------------------------------------- # Add the h5ls executable @@ -13,6 +12,7 @@ INCLUDE_DIRECTORIES (${HDF5_PROJECT_DIR}/test) ADD_EXECUTABLE (h5ls ${HDF5_TOOLS_H5LS_SOURCE_DIR}/h5ls.c) TARGET_NAMING (h5ls ${LIB_TYPE}) TARGET_LINK_LIBRARIES (h5ls ${HDF5_TOOLS_LIB_TARGET} ${HDF5_LIB_TARGET}) +SET_TARGET_PROPERTIES (h5ls PROPERTIES FOLDER tools) SET (H5_DEP_EXECUTABLES h5ls @@ -26,108 +26,107 @@ SET (H5_DEP_EXECUTABLES IF (BUILD_TESTING) # -------------------------------------------------------------------- - # Copy all the HDF5 files from the test directory into the source directory + # Copy all the test files from source directory to test directory # -------------------------------------------------------------------- - SET (HDF5_REFERENCE_FILES - help-1.ls - help-2.ls - help-3.ls - nosuchfile.ls - tall-1.ls - tall-2.ls - tarray1.ls - tattr2.ls - tcomp-1.ls - tdataregbe.ls - tdataregle.ls - tdset-1.ls - tempty.ls - textlink-1.ls - textlinksrc-1.ls - textlinksrc-2.ls - textlinksrc-3.ls - textlinksrc-4.ls - textlinksrc-5.ls - textlinksrc-6.ls - textlinksrc-7.ls - textlinksrc-1-old.ls - textlinksrc-2-old.ls - textlinksrc-3-old.ls - textlinksrc-6-old.ls - textlinksrc-7-old.ls - tsoftlinks-1.ls - tsoftlinks-2.ls - tsoftlinks-3.ls - tsoftlinks-4.ls - tsoftlinks-5.ls - textlinksrc-nodangle-1.ls - textlinksrc-nodangle-2.ls - tgrp_comments.ls - tsoftlinks-nodangle-1.ls - thlinks-nodangle-1.ls - tgroup.ls - tgroup-1.ls - tgroup-2.ls - tgroup-3.ls - thlink-1.ls - tloop-1.ls - tnestcomp-1.ls - tnestcomp-2.ls - tnestcomp-3.ls - tnestcomp-4.ls - tsaf.ls - tslink-1.ls - tstr-1.ls - tudlink-1.ls - tvldtypes1.ls - tvldtypes2le.ls - tvldtypes2be.ls + SET (LIST_HDF5_TEST_FILES + ${HDF5_TOOLS_SRC_DIR}/testfiles/tall.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tarray1.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tattr2.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tattrreg.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tcompound.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tdatareg.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tdset.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tempty.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlink.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinktar.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgroup.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgrp_comments.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/thlink.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tloop.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tnestedcomp.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsaf.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tslink.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tstr.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tudlink.h5 + ${HDF5_TOOLS_SRC_DIR}/testfiles/tvldtypes1.h5 ) - SET (HDF5_REFERENCE_TEST_FILES - tall.h5 - tarray1.h5 - tattr2.h5 - tcompound.h5 - tdatareg.h5 - tdset.h5 - tempty.h5 - textlink.h5 - textlinksrc.h5 - textlinktar.h5 - tgroup.h5 - tgrp_comments.h5 - thlink.h5 - tloop.h5 - tnestedcomp.h5 - tsaf.h5 - tslink.h5 - tsoftlinks.h5 - tstr.h5 - tudlink.h5 - tvldtypes1.h5 + + SET (LIST_OTHER_TEST_FILES + ${HDF5_TOOLS_SRC_DIR}/testfiles/help-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/help-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/help-3.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/nosuchfile.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tall-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tall-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tarray1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tattr2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tattrreg_le.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tattrreg_be.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tcomp-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tdataregbe.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tdataregle.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tdset-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tempty.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlink-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-3.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-4.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-5.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-6.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-7.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-1-old.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-2-old.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-3-old.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-6-old.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-7-old.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-3.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-4.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-5.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-nodangle-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/textlinksrc-nodangle-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgrp_comments.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsoftlinks-nodangle-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/thlinks-nodangle-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgroup.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgroup-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgroup-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tgroup-3.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/thlink-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tloop-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tmultifile.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tnestcomp-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tnestcomp-2.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tnestcomp-3.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tnestcomp-4.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tsaf.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tslink-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tstr-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tudlink-1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tvldtypes1.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tvldtypes2le.ls + ${HDF5_TOOLS_SRC_DIR}/testfiles/tvldtypes2be.ls ) - FOREACH (ls_file ${HDF5_REFERENCE_FILES}) - SET (lsdest "${PROJECT_BINARY_DIR}/${ls_file}") - #MESSAGE (STATUS " Translating ${ls_file}") - ADD_CUSTOM_COMMAND ( - TARGET h5ls - POST_BUILD - COMMAND ${XLATE_UTILITY} - ARGS ${HDF5_TOOLS_SRC_DIR}/testfiles/${ls_file} ${lsdest} -l3 - ) - ENDFOREACH (ls_file ${HDF5_REFERENCE_FILES}) + FILE (MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles") - FOREACH (h5_file ${HDF5_REFERENCE_TEST_FILES}) - SET (dest "${PROJECT_BINARY_DIR}/${h5_file}") - #MESSAGE (STATUS " Copying ${h5_file}") + # copy the list of test files + FOREACH (listfiles ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES}) + GET_FILENAME_COMPONENT(fname "${listfiles}" NAME) + SET (dest "${PROJECT_BINARY_DIR}/testfiles/${fname}") + #MESSAGE (STATUS " Copying ${listfiles} to ${dest}") ADD_CUSTOM_COMMAND ( TARGET h5ls POST_BUILD COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different ${HDF5_TOOLS_SRC_DIR}/testfiles/${h5_file} ${dest} + ARGS -E copy_if_different ${listfiles} ${dest} ) - ENDFOREACH (h5_file ${HDF5_REFERENCE_TEST_FILES}) + ENDFOREACH (listfiles ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES}) + ############################################################################## ############################################################################## @@ -139,26 +138,33 @@ IF (BUILD_TESTING) # If using memchecker add tests without using scripts IF (HDF5_ENABLE_USING_MEMCHECKER) ADD_TEST (NAME H5LS-${resultfile} COMMAND $<TARGET_FILE:h5ls> ${ARGN}) + SET_TESTS_PROPERTIES (H5LS-${resultfile} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles") IF (${resultcode} STREQUAL "1") SET_TESTS_PROPERTIES (H5LS-${resultfile} PROPERTIES WILL_FAIL "true") ENDIF (${resultcode} STREQUAL "1") + IF (NOT "${last_test}" STREQUAL "") + SET_TESTS_PROPERTIES (H5LS-${resultfile} PROPERTIES DEPENDS ${last_test}) + ENDIF (NOT "${last_test}" STREQUAL "") + SET (last_test "H5LS-${resultfile}") ELSE (HDF5_ENABLE_USING_MEMCHECKER) ADD_TEST ( + NAME H5LS-clear-${resultfile}-objects + COMMAND ${CMAKE_COMMAND} + -E remove ./testfiles/${resultfile}.out ./testfiles/${resultfile}.out.err + ) + ADD_TEST ( NAME H5LS-${resultfile} COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=$<TARGET_FILE:h5ls>" -D "TEST_ARGS=${ARGN}" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" -D "TEST_OUTPUT=${resultfile}.out" -D "TEST_EXPECT=${resultcode}" -D "TEST_REFERENCE=${resultfile}.ls" -P "${HDF5_RESOURCES_DIR}/runTest.cmake" ) + SET_TESTS_PROPERTIES (H5LS-${resultfile} PROPERTIES DEPENDS "H5LS-clear-${resultfile}-objects") ENDIF (HDF5_ENABLE_USING_MEMCHECKER) - IF (NOT "${last_test}" STREQUAL "") - SET_TESTS_PROPERTIES (H5LS-${resultfile} PROPERTIES DEPENDS ${last_test}) - ENDIF (NOT "${last_test}" STREQUAL "") - SET (last_test "H5LS-${resultfile}") ENDMACRO (ADD_H5_TEST file) ############################################################################## @@ -167,8 +173,9 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## - # Remove any output file left over from previous test run - ADD_TEST ( + IF (HDF5_ENABLE_USING_MEMCHECKER) + # Remove any output file left over from previous test run + ADD_TEST ( NAME H5LS-clearall-objects COMMAND ${CMAKE_COMMAND} -E remove @@ -278,11 +285,12 @@ IF (BUILD_TESTING) tvldtypes2le.out.err tvldtypes2be.out tvldtypes2be.out.err - ) - IF (NOT "${last_test}" STREQUAL "") - SET_TESTS_PROPERTIES (H5LS-clearall-objects PROPERTIES DEPENDS ${last_test}) - ENDIF (NOT "${last_test}" STREQUAL "") - SET (last_test "H5LS-clearall-objects") + ) + IF (NOT "${last_test}" STREQUAL "") + SET_TESTS_PROPERTIES (H5LS-clearall-objects PROPERTIES DEPENDS ${last_test}) + ENDIF (NOT "${last_test}" STREQUAL "") + SET (last_test "H5LS-clearall-objects") + ENDIF (HDF5_ENABLE_USING_MEMCHECKER) # test the help syntax ADD_H5_TEST (help-1 0 -w80 -h) @@ -347,6 +355,11 @@ IF (BUILD_TESTING) # when used file with no dangling links - expected exit code 0 ADD_H5_TEST (thlinks-nodangle-1 0 -w80 --follow-symlinks --no-dangling-links thlink.h5) +# test for wildcards in filename (does not work with cmake) +# ADD_H5_TEST (tstarfile 0 -w80 t*link.h5) +# ADD_H5_TEST (tqmarkfile 0 -w80 t?link.h5) + ADD_H5_TEST (tmultifile 0 -w80 thlink.h5 tslink.h5) + # tests for hard links ADD_H5_TEST (thlink-1 0 -w80 thlink.h5) @@ -384,18 +397,30 @@ IF (BUILD_TESTING) # enable -S for avoiding printing NATIVE types ADD_H5_TEST (tattr2 0 -w80 -v -S tattr2.h5) + # test for attribute with region references wo verbose mode + # ( HDFFV-7838, ) + IF (H5_WORDS_BIGENDIAN) + ADD_H5_TEST (tattrreg_be 0 -w80 -v -d tattrreg.h5) + ELSE (H5_WORDS_BIGENDIAN) + ADD_H5_TEST (tattrreg_le 0 -w80 -v -d tattrreg.h5) + ENDIF (H5_WORDS_BIGENDIAN) + # test for non-existing file ADD_H5_TEST (nosuchfile 1 nosuchfile.h5) - IF (WORDS_BIGENDIAN) - # test for variable length data types in verbose mode + # test for variable length data types in verbose mode + IF (H5_WORDS_BIGENDIAN) ADD_H5_TEST (tvldtypes2be 0 -v tvldtypes1.h5) - # test for dataset region references data types in verbose mode - ADD_H5_TEST (tdataregbe 0 -v tdatareg.h5) - ELSE (WORDS_BIGENDIAN) + ELSE (H5_WORDS_BIGENDIAN) ADD_H5_TEST (tvldtypes2le 0 -v tvldtypes1.h5) + ENDIF (H5_WORDS_BIGENDIAN) + + # test for dataset region references data types in verbose mode + IF (H5_WORDS_BIGENDIAN) + ADD_H5_TEST (tdataregbe 0 -v tdatareg.h5) + ELSE (H5_WORDS_BIGENDIAN) ADD_H5_TEST (tdataregle 0 -v tdatareg.h5) - ENDIF (WORDS_BIGENDIAN) + ENDIF (H5_WORDS_BIGENDIAN) ENDIF (BUILD_TESTING) diff --git a/tools/h5ls/Makefile.in b/tools/h5ls/Makefile.in index 0912c71..1a33335 100644 --- a/tools/h5ls/Makefile.in +++ b/tools/h5ls/Makefile.in @@ -175,6 +175,7 @@ F9XMODEXT = @F9XMODEXT@ F9XMODFLAG = @F9XMODFLAG@ F9XSUFFIXFLAG = @F9XSUFFIXFLAG@ FC = @FC@ +FC2003 = @FC2003@ FCFLAGS = @FCFLAGS@ FCFLAGS_f90 = @FCFLAGS_f90@ FCLIBS = @FCLIBS@ @@ -195,10 +196,12 @@ H5_LONE_COLON = @H5_LONE_COLON@ H5_VERSION = @H5_VERSION@ HADDR_T = @HADDR_T@ HAVE_DMALLOC = @HAVE_DMALLOC@ +HAVE_FORTRAN_2003 = @HAVE_FORTRAN_2003@ HDF5_HL = @HDF5_HL@ HDF5_INTERFACES = @HDF5_INTERFACES@ HDF_CXX = @HDF_CXX@ HDF_FORTRAN = @HDF_FORTRAN@ +HDF_FORTRAN2003 = @HDF_FORTRAN2003@ HID_T = @HID_T@ HL = @HL@ HL_FOR = @HL_FOR@ diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 722f45c..e7a0304 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -27,12 +27,87 @@ #include "H5private.h" #include "h5tools.h" #include "h5tools_utils.h" +#include "h5tools_dump.h" #include "h5trav.h" /* Name of tool */ #define PROGRAMNAME "h5ls" #define NAME_BUF_SIZE 2048 +/* + * Alternative formating for data dumped by H5LS + * + * This table only affects H5LS output. + */ +static h5tool_format_t ls_dataformat = { + 0, /*raw */ + + "", /*fmt_raw */ + "%d", /*fmt_int */ + "%u", /*fmt_uint */ + "%hhd", /*fmt_schar */ + "%u", /*fmt_uchar */ + "%d", /*fmt_short */ + "%u", /*fmt_ushort */ + "%ld", /*fmt_long */ + "%lu", /*fmt_ulong */ + NULL, /*fmt_llong */ + NULL, /*fmt_ullong */ + "%g", /*fmt_double */ + "%g", /*fmt_float */ + + 0, /*ascii */ + 0, /*str_locale */ + 0, /*str_repeat */ + + "[", /*arr_pre */ + ",", /*arr_sep */ + "]", /*arr_suf */ + 1, /*arr_linebreak */ + + "", /*cmpd_name */ + ",", /*cmpd_sep */ + "{", /*cmpd_pre */ + "}", /*cmpd_suf */ + "", /*cmpd_end */ + NULL, /* cmpd_listv */ + + ",", /*vlen_sep */ + "(", /*vlen_pre */ + ")", /*vlen_suf */ + "", /*vlen_end */ + + "%s", /*elmt_fmt */ + ",", /*elmt_suf1 */ + " ", /*elmt_suf2 */ + + HSIZE_T_FORMAT, /*idx_n_fmt */ + ",", /*idx_sep */ + "(%s)", /*idx_fmt */ + + 65535, /*line_ncols *//*standard default columns */ + 0, /*line_per_line */ + "", /*line_pre */ + "%s", /*line_1st */ + "%s", /*line_cont */ + "", /*line_suf */ + "", /*line_sep */ + 1, /*line_multi_new */ + "", /*line_indent */ + + 0, /*skip_first */ + + 0, /*obj_hidefileno */ + "-%lu:"H5_PRINTF_HADDR_FMT, /*obj_format */ + + 0, /*dset_hidefileno */ + "DSET-%s ", /*dset_format */ + "%sBlk%lu: ", /*dset_blockformat_pre */ + "%sPt%lu: ", /*dset_ptformat_pre */ + "%s", /*dset_ptformat */ + 1, /*array indices */ + 1 /*escape non printable characters */ +}; /* Struct to pass through to visitors */ typedef struct { @@ -81,6 +156,7 @@ static struct dispatch_t { } static void display_type(hid_t type, int ind); +static void print_type(h5tools_str_t *buffer, hid_t type, int ind); static herr_t visit_obj(hid_t file, const char *oname, iter_t *iter); @@ -101,7 +177,7 @@ static herr_t visit_obj(hid_t file, const char *oname, iter_t *iter); static void usage (void) { - fprintf(stderr, "\ + HDfprintf(rawerrorstream, "\ usage: %s [OPTIONS] [OBJECTS...]\n\ OPTIONS\n\ -h, -?, --help Print a usage message and exit\n\ @@ -164,8 +240,9 @@ usage: %s [OPTIONS] [OBJECTS...]\n\ } + /*------------------------------------------------------------------------- - * Function: display_string + * Function: print_string * * Purpose: Print a string value by escaping unusual characters. If * STREAM is null then we only count how large the output would @@ -181,57 +258,57 @@ usage: %s [OPTIONS] [OBJECTS...]\n\ *------------------------------------------------------------------------- */ static int -display_string(FILE *stream, const char *s, hbool_t escape_spaces) +print_string(h5tools_str_t *buffer, const char *s, hbool_t escape_spaces) { int nprint=0; for (/*void*/; s && *s; s++) { switch (*s) { case '"': - if (stream) fprintf(stream, "\\\""); + if (buffer) h5tools_str_append(buffer, "\\\""); nprint += 2; break; case '\\': - if (stream) fprintf(stream, "\\\\"); + if (buffer) h5tools_str_append(buffer, "\\\\"); nprint += 2; break; case '\b': - if (stream) fprintf(stream, "\\b"); + if (buffer) h5tools_str_append(buffer, "\\b"); nprint += 2; break; case '\f': - if (stream) fprintf(stream, "\\f"); + if (buffer) h5tools_str_append(buffer, "\\f"); nprint += 2; break; case '\n': - if (stream) fprintf(stream, "\\n"); + if (buffer) h5tools_str_append(buffer, "\\n"); nprint += 2; break; case '\r': - if (stream) fprintf(stream, "\\r"); + if (buffer) h5tools_str_append(buffer, "\\r"); nprint += 2; break; case '\t': - if (stream) fprintf(stream, "\\t"); + if (buffer) h5tools_str_append(buffer, "\\t"); nprint += 2; break; case ' ': if (escape_spaces) { - if (stream) fprintf(stream, "\\ "); + if (buffer) h5tools_str_append(buffer, "\\ "); nprint += 2; - } else { - if (stream) fprintf(stream, " "); + } + else { + if (buffer) h5tools_str_append(buffer, " "); nprint++; } break; default: if (isprint((int)*s)) { - if (stream) putc(*s, stream); + if (buffer) h5tools_str_append(buffer, "%c", *s); nprint++; - } else { - if (stream) { - fprintf(stream, "\\%03o", *((const unsigned char*)s)); - } + } + else { + if (buffer) h5tools_str_append(buffer, "\\%03o", *((const unsigned char*)s)); nprint += 4; } break; @@ -242,7 +319,7 @@ display_string(FILE *stream, const char *s, hbool_t escape_spaces) /*------------------------------------------------------------------------- - * Function: display_obj_name + * Function: print_obj_name * * Purpose: Print an object name and another string. * @@ -258,7 +335,7 @@ display_string(FILE *stream, const char *s, hbool_t escape_spaces) *------------------------------------------------------------------------- */ static int -display_obj_name(FILE *stream, const iter_t *iter, const char *oname, +print_obj_name(h5tools_str_t *buffer, const iter_t *iter, const char *oname, const char *s) { static char fullname[NAME_BUF_SIZE]; /* Buffer for file and/or object name */ @@ -272,7 +349,7 @@ display_obj_name(FILE *stream, const iter_t *iter, const char *oname, /* Print the object name, either full name or base name */ if(fullname_g) - n = display_string(stream, name, TRUE); + n = print_string(buffer, name, TRUE); else { const char *last_sep; /* The location of the last group separator */ @@ -282,16 +359,16 @@ display_obj_name(FILE *stream, const iter_t *iter, const char *oname, else { last_sep++; } /* end else */ - n = display_string(stream, last_sep, TRUE); + n = print_string(buffer, last_sep, TRUE); } /* end else */ - printf("%*s ", MAX(0, (24 - n)), s); + h5tools_str_append(buffer, "%*s ", MAX(0, (24 - n)), s); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_native_type + * Function: print_native_type * * Purpose: Prints the name of a native C data type. * @@ -310,100 +387,100 @@ display_obj_name(FILE *stream, const iter_t *iter, const char *oname, *------------------------------------------------------------------------- */ static hbool_t -display_native_type(hid_t type, int UNUSED ind) +print_native_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) { if (H5Tequal(type, H5T_NATIVE_SCHAR)==TRUE) { - printf("native signed char"); + h5tools_str_append(buffer, "native signed char"); } else if (H5Tequal(type, H5T_NATIVE_UCHAR)==TRUE) { - printf("native unsigned char"); + h5tools_str_append(buffer, "native unsigned char"); } else if (H5Tequal(type, H5T_NATIVE_INT)==TRUE) { - printf("native int"); + h5tools_str_append(buffer, "native int"); } else if (H5Tequal(type, H5T_NATIVE_UINT)==TRUE) { - printf("native unsigned int"); + h5tools_str_append(buffer, "native unsigned int"); } else if (H5Tequal(type, H5T_NATIVE_SHORT)==TRUE) { - printf("native short"); + h5tools_str_append(buffer, "native short"); } else if (H5Tequal(type, H5T_NATIVE_USHORT)==TRUE) { - printf("native unsigned short"); + h5tools_str_append(buffer, "native unsigned short"); } else if (H5Tequal(type, H5T_NATIVE_LONG)==TRUE) { - printf("native long"); + h5tools_str_append(buffer, "native long"); } else if (H5Tequal(type, H5T_NATIVE_ULONG)==TRUE) { - printf("native unsigned long"); + h5tools_str_append(buffer, "native unsigned long"); } else if (H5Tequal(type, H5T_NATIVE_LLONG)==TRUE) { - printf("native long long"); + h5tools_str_append(buffer, "native long long"); } else if (H5Tequal(type, H5T_NATIVE_ULLONG)==TRUE) { - printf("native unsigned long long"); + h5tools_str_append(buffer, "native unsigned long long"); } else if (H5Tequal(type, H5T_NATIVE_FLOAT)==TRUE) { - printf("native float"); + h5tools_str_append(buffer, "native float"); } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)==TRUE) { - printf("native double"); + h5tools_str_append(buffer, "native double"); #if H5_SIZEOF_LONG_DOUBLE !=0 } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)==TRUE) { - printf("native long double"); + h5tools_str_append(buffer, "native long double"); #endif } else if (H5Tequal(type, H5T_NATIVE_INT8)==TRUE) { - printf("native int8_t"); + h5tools_str_append(buffer, "native int8_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT8)==TRUE) { - printf("native uint8_t"); + h5tools_str_append(buffer, "native uint8_t"); } else if (H5Tequal(type, H5T_NATIVE_INT16)==TRUE) { - printf("native int16_t"); + h5tools_str_append(buffer, "native int16_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT16)==TRUE) { - printf("native uint16_t"); + h5tools_str_append(buffer, "native uint16_t"); } else if (H5Tequal(type, H5T_NATIVE_INT32)==TRUE) { - printf("native int32_t"); + h5tools_str_append(buffer, "native int32_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT32)==TRUE) { - printf("native uint32_t"); + h5tools_str_append(buffer, "native uint32_t"); } else if (H5Tequal(type, H5T_NATIVE_INT64)==TRUE) { - printf("native int64_t"); + h5tools_str_append(buffer, "native int64_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT64)==TRUE) { - printf("native uint64_t"); + h5tools_str_append(buffer, "native uint64_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8)==TRUE) { - printf("native int_least8_t"); + h5tools_str_append(buffer, "native int_least8_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8)==TRUE) { - printf("native uint_least8_t"); + h5tools_str_append(buffer, "native uint_least8_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16)==TRUE) { - printf("native int_least16_t"); + h5tools_str_append(buffer, "native int_least16_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16)==TRUE) { - printf("native uint_least16_t"); + h5tools_str_append(buffer, "native uint_least16_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32)==TRUE) { - printf("native int_least32_t"); + h5tools_str_append(buffer, "native int_least32_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32)==TRUE) { - printf("native uint_least32_t"); + h5tools_str_append(buffer, "native uint_least32_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64)==TRUE) { - printf("native int_least64_t"); + h5tools_str_append(buffer, "native int_least64_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64)==TRUE) { - printf("native uint_least64_t"); + h5tools_str_append(buffer, "native uint_least64_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_FAST8)==TRUE) { - printf("native int_fast8_t"); + h5tools_str_append(buffer, "native int_fast8_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8)==TRUE) { - printf("native uint_fast8_t"); + h5tools_str_append(buffer, "native uint_fast8_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_FAST16)==TRUE) { - printf("native int_fast16_t"); + h5tools_str_append(buffer, "native int_fast16_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16)==TRUE) { - printf("native uint_fast16_t"); + h5tools_str_append(buffer, "native uint_fast16_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_FAST32)==TRUE) { - printf("native int_fast32_t"); + h5tools_str_append(buffer, "native int_fast32_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32)==TRUE) { - printf("native uint_fast32_t"); + h5tools_str_append(buffer, "native uint_fast32_t"); } else if (H5Tequal(type, H5T_NATIVE_INT_FAST64)==TRUE) { - printf("native int_fast64_t"); + h5tools_str_append(buffer, "native int_fast64_t"); } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64)==TRUE) { - printf("native uint_fast64_t"); + h5tools_str_append(buffer, "native uint_fast64_t"); } else if (H5Tequal(type, H5T_NATIVE_B8)==TRUE) { - printf("native 8-bit field"); + h5tools_str_append(buffer, "native 8-bit field"); } else if (H5Tequal(type, H5T_NATIVE_B16)==TRUE) { - printf("native 16-bit field"); + h5tools_str_append(buffer, "native 16-bit field"); } else if (H5Tequal(type, H5T_NATIVE_B32)==TRUE) { - printf("native 32-bit field"); + h5tools_str_append(buffer, "native 32-bit field"); } else if (H5Tequal(type, H5T_NATIVE_B64)==TRUE) { - printf("native 64-bit field"); + h5tools_str_append(buffer, "native 64-bit field"); } else if (H5Tequal(type, H5T_NATIVE_HSIZE)==TRUE) { - printf("native hsize_t"); + h5tools_str_append(buffer, "native hsize_t"); } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)==TRUE) { - printf("native hssize_t"); + h5tools_str_append(buffer, "native hssize_t"); } else if (H5Tequal(type, H5T_NATIVE_HERR)==TRUE) { - printf("native herr_t"); + h5tools_str_append(buffer, "native herr_t"); } else if (H5Tequal(type, H5T_NATIVE_HBOOL)==TRUE) { - printf("native hbool_t"); + h5tools_str_append(buffer, "native hbool_t"); } else { return FALSE; } @@ -412,7 +489,7 @@ display_native_type(hid_t type, int UNUSED ind) /*------------------------------------------------------------------------- - * Function: display_ieee_type + * Function: print_ieee_type * * Purpose: Print the name of an IEEE floating-point data type. * @@ -428,17 +505,21 @@ display_native_type(hid_t type, int UNUSED ind) *------------------------------------------------------------------------- */ static hbool_t -display_ieee_type(hid_t type, int UNUSED ind) +print_ieee_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) { if (H5Tequal(type, H5T_IEEE_F32BE)==TRUE) { - printf("IEEE 32-bit big-endian float"); - } else if (H5Tequal(type, H5T_IEEE_F32LE)==TRUE) { - printf("IEEE 32-bit little-endian float"); - } else if (H5Tequal(type, H5T_IEEE_F64BE)==TRUE) { - printf("IEEE 64-bit big-endian float"); - } else if (H5Tequal(type, H5T_IEEE_F64LE)==TRUE) { - printf("IEEE 64-bit little-endian float"); - } else { + h5tools_str_append(buffer, "IEEE 32-bit big-endian float"); + } + else if (H5Tequal(type, H5T_IEEE_F32LE)==TRUE) { + h5tools_str_append(buffer, "IEEE 32-bit little-endian float"); + } + else if (H5Tequal(type, H5T_IEEE_F64BE)==TRUE) { + h5tools_str_append(buffer, "IEEE 64-bit big-endian float"); + } + else if (H5Tequal(type, H5T_IEEE_F64LE)==TRUE) { + h5tools_str_append(buffer, "IEEE 64-bit little-endian float"); + } + else { return FALSE; } return TRUE; @@ -446,7 +527,7 @@ display_ieee_type(hid_t type, int UNUSED ind) /*------------------------------------------------------------------------- - * Function: display_precision + * Function: print_precision * * Purpose: Prints information on the next line about precision and * padding if the precision is less than the total data type @@ -462,7 +543,7 @@ display_ieee_type(hid_t type, int UNUSED ind) *------------------------------------------------------------------------- */ static void -display_precision(hid_t type, int ind) +print_precision(h5tools_str_t *buffer, hid_t type, int ind) { size_t prec; /* precision */ H5T_pad_t plsb, pmsb; /* lsb and msb padding */ @@ -474,7 +555,7 @@ display_precision(hid_t type, int ind) * and offset on the following line. Also display the padding * information. */ if (8*H5Tget_size(type)!=(prec=H5Tget_precision(type))) { - printf("\n%*s(%lu bit%s of precision beginning at bit %lu)", + h5tools_str_append(buffer, "\n%*s(%lu bit%s of precision beginning at bit %lu)", ind, "", (unsigned long)prec, 1==prec?"":"s", (unsigned long)H5Tget_offset(type)); @@ -520,27 +601,27 @@ display_precision(hid_t type, int ind) } } if (plsb_s || pmsb_s) { - printf("\n%*s(", ind, ""); + h5tools_str_append(buffer, "\n%*s(", ind, ""); if (plsb_s) { nbits = H5Tget_offset(type); - printf("%lu %s bit%s at bit 0", + h5tools_str_append(buffer, "%lu %s bit%s at bit 0", (unsigned long)nbits, plsb_s, 1==nbits?"":"s"); } - if (plsb_s && pmsb_s) printf(", "); + if (plsb_s && pmsb_s) h5tools_str_append(buffer, ", "); if (pmsb_s) { nbits = 8*H5Tget_size(type)-(H5Tget_offset(type)+prec); - printf("%lu %s bit%s at bit %lu", + h5tools_str_append(buffer, "%lu %s bit%s at bit %lu", (unsigned long)nbits, pmsb_s, 1==nbits?"":"s", (unsigned long)(8*H5Tget_size(type)-nbits)); } - printf(")"); + h5tools_str_append(buffer, ")"); } } } /*------------------------------------------------------------------------- - * Function: display_int_type + * Function: print_int_type * * Purpose: Print the name of an integer data type. Common information * like number of bits, byte order, and sign scheme appear on @@ -559,7 +640,7 @@ display_precision(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_int_type(hid_t type, int ind) +print_int_type(h5tools_str_t *buffer, hid_t type, int ind) { H5T_order_t order; /* byte order value */ const char *order_s=NULL; /* byte order string */ @@ -573,14 +654,18 @@ display_int_type(hid_t type, int ind) order = H5Tget_order(type); if (H5T_ORDER_LE==order) { order_s = " little-endian"; - } else if (H5T_ORDER_BE==order) { + } + else if (H5T_ORDER_BE==order) { order_s = " big-endian"; - } else if (H5T_ORDER_VAX==order) { + } + else if (H5T_ORDER_VAX==order) { order_s = " mixed-endian"; - } else { + } + else { order_s = " unknown-byte-order"; } - } else { + } + else { order_s = ""; } @@ -588,26 +673,29 @@ display_int_type(hid_t type, int ind) if ((sign=H5Tget_sign(type))>=0) { if (H5T_SGN_NONE==sign) { sign_s = " unsigned"; - } else if (H5T_SGN_2==sign) { + } + else if (H5T_SGN_2==sign) { sign_s = ""; - } else { + } + else { sign_s = " unknown-sign"; } - } else { + } + else { sign_s = " unknown-sign"; } /* Print size, order, and sign on first line, precision and padding * information on the subsequent lines */ - printf("%lu-bit%s%s integer", + h5tools_str_append(buffer, "%lu-bit%s%s integer", (unsigned long)(8*H5Tget_size(type)), order_s, sign_s); - display_precision(type, ind); + print_precision(buffer, type, ind); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_float_type + * Function: print_float_type * * Purpose: Print info about a floating point data type. * @@ -623,7 +711,7 @@ display_int_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_float_type(hid_t type, int ind) +print_float_type(h5tools_str_t *buffer, hid_t type, int ind) { H5T_order_t order; /* byte order value */ const char *order_s=NULL; /* byte order string */ @@ -643,22 +731,26 @@ display_float_type(hid_t type, int ind) order = H5Tget_order(type); if (H5T_ORDER_LE==order) { order_s = " little-endian"; - } else if (H5T_ORDER_BE==order) { + } + else if (H5T_ORDER_BE==order) { order_s = " big-endian"; - } else if (H5T_ORDER_VAX==order) { + } + else if (H5T_ORDER_VAX==order) { order_s = " mixed-endian"; - } else { + } + else { order_s = " unknown-byte-order"; } - } else { + } + else { order_s = ""; } /* Print size and byte order on first line, precision and padding on * subsequent lines. */ - printf("%lu-bit%s floating-point", + h5tools_str_append(buffer, "%lu-bit%s floating-point", (unsigned long)(8*H5Tget_size(type)), order_s); - display_precision(type, ind); + print_precision(buffer, type, ind); /* Print sizes, locations, and other information about each field */ H5Tget_fields (type, &spos, &epos, &esize, &mpos, &msize); @@ -681,13 +773,13 @@ display_float_type(hid_t type, int ind) ; break; } - printf("\n%*s(significant for %lu bit%s at bit %lu%s)", ind, "", + h5tools_str_append(buffer, "\n%*s(significant for %lu bit%s at bit %lu%s)", ind, "", (unsigned long)msize, 1==msize?"":"s", (unsigned long)mpos, norm_s); - printf("\n%*s(exponent for %lu bit%s at bit %lu, bias is 0x%lx)", + h5tools_str_append(buffer, "\n%*s(exponent for %lu bit%s at bit %lu, bias is 0x%lx)", ind, "", (unsigned long)esize, 1==esize?"":"s", (unsigned long)epos, (unsigned long)ebias); - printf("\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos); + h5tools_str_append(buffer, "\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos); /* Display internal padding */ if (1+esize+msize<H5Tget_precision(type)) { @@ -710,14 +802,14 @@ display_float_type(hid_t type, int ind) ; break; } - printf("\n%*s(internal padding bits are %s)", ind, "", pad_s); + h5tools_str_append(buffer, "\n%*s(internal padding bits are %s)", ind, "", pad_s); } return TRUE; } /*------------------------------------------------------------------------- - * Function: display_cmpd_type + * Function: print_cmpd_type * * Purpose: Print info about a compound data type. * @@ -733,7 +825,7 @@ display_float_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_cmpd_type(hid_t type, int ind) +print_cmpd_type(h5tools_str_t *buffer, hid_t type, int ind) { char *name=NULL; /* member name */ size_t size; /* total size of type in bytes */ @@ -743,32 +835,32 @@ display_cmpd_type(hid_t type, int ind) unsigned i; /* miscellaneous counters */ if (H5T_COMPOUND!=H5Tget_class(type)) return FALSE; - printf("struct {"); + h5tools_str_append(buffer, "struct {"); nmembs=H5Tget_nmembers(type); for (i=0; i<nmembs; i++) { /* Name and offset */ name = H5Tget_member_name(type, i); - printf("\n%*s\"", ind+4, ""); - n = display_string(stdout, name, FALSE); - printf("\"%*s +%-4lu ", MAX(0, 16-n), "", + h5tools_str_append(buffer, "\n%*s\"", ind+4, ""); + n = print_string(buffer, name, FALSE); + h5tools_str_append(buffer, "\"%*s +%-4lu ", MAX(0, 16-n), "", (unsigned long)H5Tget_member_offset(type, i)); - free(name); + HDfree(name); /* Member's type */ subtype = H5Tget_member_type(type, i); - display_type(subtype, ind+4); + print_type(buffer, subtype, ind+4); H5Tclose(subtype); } size = H5Tget_size(type); - printf("\n%*s} %lu byte%s", - ind, "", (unsigned long)size, 1==size?"":"s"); + h5tools_str_append(buffer, "\n%*s} %lu byte%s", + ind, "", (unsigned long)size, 1==size?"":"s"); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_enum_type + * Function: print_enum_type * * Purpose: Print info about an enumeration data type. * @@ -784,7 +876,7 @@ display_cmpd_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_enum_type(hid_t type, int ind) +print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) { char **name=NULL; /* member names */ unsigned char *value=NULL; /* value array */ @@ -799,11 +891,11 @@ display_enum_type(hid_t type, int ind) if (H5T_ENUM!=H5Tget_class(type)) return FALSE; nmembs = H5Tget_nmembers(type); - assert(nmembs>0); + HDassert(nmembs>0); super = H5Tget_super(type); - printf("enum "); - display_type(super, ind+4); - printf(" {"); + h5tools_str_append(buffer, "enum "); + print_type(buffer, super, ind+4); + h5tools_str_append(buffer, " {"); /* Determine what data type to use for the native values. To simplify * things we entertain three possibilities: @@ -822,8 +914,8 @@ display_enum_type(hid_t type, int ind) } /* Get the names and raw values of all members */ - name = calloc(nmembs, sizeof(char*)); - value = (unsigned char *)calloc(nmembs, MAX(H5Tget_size(type), dst_size)); + name = HDcalloc(nmembs, sizeof(char*)); + value = (unsigned char *)HDcalloc(nmembs, MAX(H5Tget_size(type), dst_size)); for (i=0; i<nmembs; i++) { name[i] = H5Tget_member_name(type, i); H5Tget_member_value(type, i, value+i*H5Tget_size(type)); @@ -837,43 +929,44 @@ display_enum_type(hid_t type, int ind) /* Print members */ for (i=0; i<nmembs; i++) { - printf("\n%*s", ind+4, ""); - nchars = display_string(stdout, name[i], TRUE); - printf("%*s = ", MAX(0, 16-nchars), ""); + h5tools_str_append(buffer, "\n%*s", ind+4, ""); + nchars = print_string(buffer, name[i], TRUE); + h5tools_str_append(buffer, "%*s = ", MAX(0, 16-nchars), ""); if (native<0) { - printf("0x"); + h5tools_str_append(buffer, "0x"); for (j=0; j<dst_size; j++) - printf("%02x", value[i*dst_size+j]); - } else if (H5T_SGN_NONE==H5Tget_sign(native)) { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value+i*dst_size; - HDfprintf(stdout,"%"H5_PRINTF_LL_WIDTH"u", - *((unsigned long long*)((void*)copy))); - } else { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value+i*dst_size; - HDfprintf(stdout,"%"H5_PRINTF_LL_WIDTH"d", - *((long long*)((void*)copy))); + h5tools_str_append(buffer, "%02x", value[i*dst_size+j]); + } + else if (H5T_SGN_NONE==H5Tget_sign(native)) { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value+i*dst_size; + h5tools_str_append(buffer, HSIZE_T_FORMAT, *((unsigned long long*)((void*)copy))); + } + else { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value+i*dst_size; + h5tools_str_append(buffer, "%"H5_PRINTF_LL_WIDTH"d", + *((long long*)((void*)copy))); } } /* Release resources */ - for (i=0; i<nmembs; i++) free(name[i]); - free(name); - free(value); + for (i=0; i<nmembs; i++) HDfree(name[i]); + HDfree(name); + HDfree(value); H5Tclose(super); - if (0==nmembs) printf("\n%*s <empty>", ind+4, ""); - printf("\n%*s}", ind, ""); + if (0==nmembs) h5tools_str_append(buffer, "\n%*s <empty>", ind+4, ""); + h5tools_str_append(buffer, "\n%*s}", ind, ""); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_string_type + * Function: print_string_type * * Purpose: Print information about a string data type. * @@ -889,7 +982,7 @@ display_enum_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_string_type(hid_t type, int UNUSED ind) +print_string_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) { H5T_str_t pad; const char *pad_s=NULL; @@ -963,17 +1056,18 @@ display_string_type(hid_t type, int UNUSED ind) } if (H5Tis_variable_str(type)) { - printf("variable-length"); - } else { - printf("%lu-byte", (unsigned long)H5Tget_size(type)); + h5tools_str_append(buffer, "variable-length"); + } + else { + h5tools_str_append(buffer, "%lu-byte", (unsigned long)H5Tget_size(type)); } - printf(" %s %s string", pad_s, cset_s); + h5tools_str_append(buffer, " %s %s string", pad_s, cset_s); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_reference_type + * Function: print_reference_type * * Purpose: Prints information about a reference data type. * @@ -991,16 +1085,18 @@ display_string_type(hid_t type, int UNUSED ind) *------------------------------------------------------------------------- */ static hbool_t -display_reference_type(hid_t type, int UNUSED ind) +print_reference_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) { if (H5T_REFERENCE!=H5Tget_class(type)) return FALSE; if (H5Tequal(type, H5T_STD_REF_OBJ)==TRUE) { - printf("object reference"); - } else if (H5Tequal(type, H5T_STD_REF_DSETREG)==TRUE) { - printf("dataset region reference"); - } else { - printf("%lu-byte unknown reference", + h5tools_str_append(buffer, "object reference"); + } + else if (H5Tequal(type, H5T_STD_REF_DSETREG)==TRUE) { + h5tools_str_append(buffer, "dataset region reference"); + } + else { + h5tools_str_append(buffer, "%lu-byte unknown reference", (unsigned long)H5Tget_size(type)); } @@ -1009,7 +1105,7 @@ display_reference_type(hid_t type, int UNUSED ind) /*------------------------------------------------------------------------- - * Function: display_opaque_type + * Function: print_opaque_type * * Purpose: Prints information about an opaque data type. * @@ -1025,7 +1121,7 @@ display_reference_type(hid_t type, int UNUSED ind) *------------------------------------------------------------------------- */ static hbool_t -display_opaque_type(hid_t type, int ind) +print_opaque_type(h5tools_str_t *buffer, hid_t type, int ind) { char *tag; size_t size; @@ -1033,19 +1129,19 @@ display_opaque_type(hid_t type, int ind) if (H5T_OPAQUE!=H5Tget_class(type)) return FALSE; size = H5Tget_size(type); - printf("%lu-byte opaque type", (unsigned long)size); + h5tools_str_append(buffer, "%lu-byte opaque type", (unsigned long)size); if ((tag=H5Tget_tag(type))) { - printf("\n%*s(tag = \"", ind, ""); - display_string(stdout, tag, FALSE); - printf("\")"); - free(tag); + h5tools_str_append(buffer, "\n%*s(tag = \"", ind, ""); + print_string(buffer, tag, FALSE); + h5tools_str_append(buffer, "\")"); + HDfree(tag); } return TRUE; } /*------------------------------------------------------------------------- - * Function: display_vlen_type + * Function: print_vlen_type * * Purpose: Print information about a variable-length type * @@ -1060,15 +1156,15 @@ display_opaque_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_vlen_type(hid_t type, int ind) +print_vlen_type(h5tools_str_t *buffer, hid_t type, int ind) { hid_t super; if (H5T_VLEN!=H5Tget_class(type)) return FALSE; - printf("variable length of\n%*s", ind+4, ""); + h5tools_str_append(buffer, "variable length of\n%*s", ind+4, ""); super = H5Tget_super(type); - display_type(super, ind+4); + print_type(buffer, super, ind+4); H5Tclose(super); return TRUE; } @@ -1088,7 +1184,7 @@ display_vlen_type(hid_t type, int ind) *--------------------------------------------------------------------------- */ static hbool_t -display_array_type(hid_t type, int ind) +print_array_type(h5tools_str_t *buffer, hid_t type, int ind) { hid_t super; int ndims, i; @@ -1097,31 +1193,32 @@ display_array_type(hid_t type, int ind) if (H5T_ARRAY!=H5Tget_class(type)) return FALSE; ndims = H5Tget_array_ndims(type); if (ndims) { - dims = (hsize_t *)malloc(ndims*sizeof(dims[0])); + dims = (hsize_t *)HDmalloc(ndims*sizeof(dims[0])); H5Tget_array_dims2(type, dims); /* Print dimensions */ for (i=0; i<ndims; i++) - HDfprintf(stdout, "%s%Hu" , i?",":"[", dims[i]); - putchar(']'); + h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT , i?",":"[", dims[i]); + h5tools_str_append(buffer, "]"); - free(dims); - } else { - fputs(" [SCALAR]", stdout); + HDfree(dims); + } + else { + h5tools_str_append(buffer, " [SCALAR]\n", rawoutstream); } /* Print parent type */ - putchar(' '); + h5tools_str_append(buffer, " "); super = H5Tget_super(type); - display_type(super, ind+4); + print_type(buffer, super, ind+4); H5Tclose(super); return TRUE; } /*------------------------------------------------------------------------- - * Function: display_bitfield_type + * Function: print_bitfield_type * * Purpose: Print information about a bitfield type. * @@ -1139,7 +1236,7 @@ display_array_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static hbool_t -display_bitfield_type(hid_t type, int ind) +print_bitfield_type(h5tools_str_t *buffer, hid_t type, int ind) { H5T_order_t order; /* byte order value */ const char *order_s=NULL; /* byte order string */ @@ -1160,15 +1257,15 @@ display_bitfield_type(hid_t type, int ind) order_s = ""; } - printf("%lu-bit%s bitfield", + h5tools_str_append(buffer, "%lu-bit%s bitfield", (unsigned long)(8*H5Tget_size(type)), order_s); - display_precision(type, ind); + print_precision(buffer, type, ind); return TRUE; } - + /*------------------------------------------------------------------------- - * Function: display_type + * Function: print_type * * Purpose: Prints a data type definition. The definition is printed * without any leading space or trailing line-feed (although @@ -1188,13 +1285,13 @@ display_bitfield_type(hid_t type, int ind) *------------------------------------------------------------------------- */ static void -display_type(hid_t type, int ind) +print_type(h5tools_str_t *buffer, hid_t type, int ind) { H5T_class_t data_class = H5Tget_class(type); /* Bad data type */ if (type<0) { - printf("<ERROR>"); + h5tools_str_append(buffer,"<ERROR>"); return; } @@ -1203,29 +1300,29 @@ display_type(hid_t type, int ind) H5O_info_t oi; if(H5Oget_info(type, &oi) >= 0) - printf("shared-%lu:"H5_PRINTF_HADDR_FMT" ", + h5tools_str_append(buffer,"shared-%lu:"H5_PRINTF_HADDR_FMT" ", oi.fileno, oi.addr); else - printf("shared "); + h5tools_str_append(buffer,"shared "); } /* end if */ /* Print the type */ - if((!simple_output_g && display_native_type(type, ind)) || - display_ieee_type(type, ind) || - display_int_type(type, ind) || - display_float_type(type, ind) || - display_cmpd_type(type, ind) || - display_enum_type(type, ind) || - display_string_type(type, ind) || - display_reference_type(type, ind) || - display_vlen_type(type, ind) || - display_array_type(type, ind) || - display_opaque_type(type, ind) || - display_bitfield_type(type, ind)) + if((!simple_output_g && print_native_type(buffer, type, ind)) || + print_ieee_type(buffer, type, ind) || + print_int_type(buffer, type, ind) || + print_float_type(buffer, type, ind) || + print_cmpd_type(buffer, type, ind) || + print_enum_type(buffer, type, ind) || + print_string_type(buffer, type, ind) || + print_reference_type(buffer, type, ind) || + print_vlen_type(buffer, type, ind) || + print_array_type(buffer, type, ind) || + print_opaque_type(buffer, type, ind) || + print_bitfield_type(buffer, type, ind)) return; /* Unknown type */ - printf("%lu-byte class-%u unknown", + h5tools_str_append(buffer,"%lu-byte class-%u unknown", (unsigned long)H5Tget_size(type), (unsigned)data_class); } @@ -1249,98 +1346,115 @@ display_type(hid_t type, int ind) static void dump_dataset_values(hid_t dset) { + char string_prefix[64]; + static char fmt_double[16]; + static char fmt_float[16]; + hsize_t curr_pos = 0; /* total data element position */ + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t outputformat; + h5tool_format_t *info = &ls_dataformat; + hid_t f_type = H5Dget_type(dset); size_t size = H5Tget_size(f_type); - h5tool_format_t info; - char string_prefix[64]; - static char fmt_double[16], fmt_float[16]; - /* Set to all default values and then override */ - memset(&info, 0, sizeof info); + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + outputformat = *info; + outputformat.line_1st = NULL; if (simple_output_g) { - info.idx_fmt = ""; - info.line_ncols = 65535; /*something big*/ - info.line_per_line = 1; - info.line_multi_new = 0; - info.line_pre = " "; - info.line_cont = " "; - - info.arr_pre = ""; - info.arr_suf = ""; - info.arr_sep = " "; - - if (label_g) - { - info.cmpd_pre = "{"; - info.cmpd_suf = "}"; + outputformat.idx_fmt = ""; + outputformat.line_per_line = 1; + outputformat.line_multi_new = 0; + outputformat.line_pre = " "; + outputformat.line_cont = " "; + + outputformat.arr_pre = ""; + outputformat.arr_suf = ""; + outputformat.arr_sep = " "; + + if (!label_g) { + outputformat.cmpd_pre = ""; + outputformat.cmpd_suf = ""; } - else - { - info.cmpd_pre = ""; - info.cmpd_suf = ""; - } - info.cmpd_sep = " "; + outputformat.cmpd_sep = " "; - if (label_g) info.cmpd_name = "%s="; + if (label_g) outputformat.cmpd_name = "%s="; - info.elmt_suf1 = " "; - info.str_locale = ESCAPE_HTML; + outputformat.elmt_suf1 = " "; + outputformat.str_locale = ESCAPE_HTML; - } else { - info.idx_fmt = "(%s)"; + } + else { if (no_line_wrap_g) { - info.line_ncols = 65535; - info.line_per_line = 1; + outputformat.line_per_line = 1; } - else - info.line_ncols = width_g; - info.line_multi_new = 1; - if (label_g) info.cmpd_name = "%s="; - info.line_pre = " %s "; - info.line_cont = " %s "; - info.str_repeat = 8; + else { + outputformat.line_ncols = width_g; + } + if (label_g) outputformat.cmpd_name = "%s="; + outputformat.line_pre = " %s "; + outputformat.line_cont = " %s "; + outputformat.str_repeat = 8; + + outputformat.arr_pre = NULL; + outputformat.arr_suf = NULL; + outputformat.arr_sep = NULL; + + outputformat.cmpd_pre = NULL; + outputformat.cmpd_suf = NULL; + outputformat.cmpd_sep = NULL; + + outputformat.vlen_sep = NULL; + outputformat.vlen_pre = NULL; + outputformat.vlen_suf = NULL; + outputformat.vlen_end = NULL; } - + outputformat.arr_linebreak = 0; /* Floating point types should display full precision */ sprintf(fmt_float, "%%1.%dg", FLT_DIG); - info.fmt_float = fmt_float; + outputformat.fmt_float = fmt_float; sprintf(fmt_double, "%%1.%dg", DBL_DIG); - info.fmt_double = fmt_double; - - info.dset_format = "DSET-%s "; - info.dset_hidefileno = 0; - - info.obj_format = "-%lu:"H5_PRINTF_HADDR_FMT; - info.obj_hidefileno = 0; - - info.dset_blockformat_pre = "%sBlk%lu: "; - info.dset_ptformat_pre = "%sPt%lu: "; - - info.line_indent = ""; + outputformat.fmt_double = fmt_double; if (hexdump_g) { /* Print all data in hexadecimal format if the `-x' or `--hexdump' * command line switch was given. */ - info.raw = TRUE; - } else if (string_g && 1==size && H5T_INTEGER==H5Tget_class(f_type)) { + outputformat.raw = TRUE; + } + else if (string_g && 1==size && H5T_INTEGER==H5Tget_class(f_type)) { /* Print 1-byte integer data as an ASCI character string instead of * integers if the `-s' or `--string' command-line option was given. */ - info.ascii = TRUE; - info.elmt_suf1 = ""; - info.elmt_suf2 = ""; - strcpy(string_prefix, info.line_pre); + outputformat.ascii = TRUE; + outputformat.elmt_suf1 = ""; + outputformat.elmt_suf2 = ""; + strcpy(string_prefix, outputformat.line_pre); strcat(string_prefix, "\""); - info.line_pre = string_prefix; - info.line_suf = "\""; + outputformat.line_pre = string_prefix; + outputformat.line_suf = "\""; } + info = &outputformat; + ctx.indent_level = 2; + ctx.cur_column = curr_pos; /* Print all the values. */ - printf(" Data:\n"); - if (h5tools_dump_dset(stdout, &info, dset, -1, NULL, -1) < 0) - printf(" Unable to print data.\n"); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Data:\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + ctx.need_prefix = TRUE; + ctx.cur_column = curr_pos; + if (h5tools_dump_dset(rawoutstream, info, &ctx, dset, -1, NULL) < 0) { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Unable to print data."); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + } H5Tclose(f_type); + + h5tools_str_close(&buffer); + + HDfprintf(rawoutstream, "\n"); } @@ -1364,18 +1478,32 @@ static herr_t list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo, void UNUSED *op_data) { - hid_t attr, space, type, p_type; - hsize_t size[H5S_MAX_RANK], nelmts = 1; - int ndims, i, n; - size_t need; - hsize_t temp_need; - void *buf; - h5tool_format_t info; - H5S_class_t space_type; - - printf(" Attribute: "); - n = display_string(stdout, attr_name, TRUE); - printf("%*s", MAX(0, (9 - n)), ""); + hid_t attr = -1; + hid_t space = -1; + hid_t type = -1; + hid_t p_type = -1; + hsize_t size[H5S_MAX_RANK]; + hsize_t nelmts = 1; + hsize_t temp_need; + size_t need; + int ndims; + int i; + int n; + void *buf; + H5S_class_t space_type; + hsize_t curr_pos = 0; /* total data element position */ + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Attribute: "); + + n = print_string(&buffer, attr_name, TRUE); if((attr = H5Aopen(obj, attr_name, H5P_DEFAULT))) { space = H5Aget_space(attr); @@ -1387,69 +1515,90 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo, switch(space_type) { case H5S_SCALAR: /* scalar dataspace */ - puts(" scalar"); + h5tools_str_append(&buffer, " scalar\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); break; case H5S_SIMPLE: /* simple dataspace */ - printf(" {"); + h5tools_str_append(&buffer, " {"); for (i=0; i<ndims; i++) { - HDfprintf(stdout, "%s%Hu", i?", ":"", size[i]); + h5tools_str_append(&buffer, "%s" HSIZE_T_FORMAT, i?", ":"", size[i]); nelmts *= size[i]; } - puts("}"); + h5tools_str_append(&buffer, "}\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); break; case H5S_NULL: /* null dataspace */ - puts(" null"); + h5tools_str_append(&buffer, " null\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); break; default: /* Unknown dataspace type */ - puts(" unknown"); + h5tools_str_append(&buffer, " unknown\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); break; } /* end switch */ /* Data type */ - printf(" Type: "); - display_type(type, 15); - putchar('\n'); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Type: "); + print_type(&buffer, type, 15); + h5tools_str_append(&buffer, "\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Data */ - memset(&info, 0, sizeof info); - info.line_multi_new = 1; + outputformat = *info; + if(nelmts < 5) { - info.idx_fmt = ""; - info.line_1st = " Data: "; - info.line_pre = " "; - info.line_cont = " "; - info.str_repeat = 8; + outputformat.idx_fmt = ""; + outputformat.line_1st = " Data: "; + outputformat.line_pre = " "; + outputformat.line_cont = " "; + outputformat.str_repeat = 8; - } else { - printf(" Data:\n"); - info.idx_fmt = "(%s)"; - info.line_pre = " %s "; - info.line_cont = " %s "; - info.str_repeat = 8; + } + else { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Data:\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + outputformat.line_1st = NULL; + outputformat.line_pre = " %s "; + outputformat.line_cont = " %s "; + outputformat.str_repeat = 8; } - info.line_ncols = width_g; + outputformat.line_ncols = width_g; if(label_g) - info.cmpd_name = "%s="; + outputformat.cmpd_name = "%s="; if(string_g && 1==H5Tget_size(type) && H5T_INTEGER==H5Tget_class(type)) { - info.ascii = TRUE; - info.elmt_suf1 = ""; - info.elmt_suf2 = ""; - info.idx_fmt = "(%s)"; - info.line_pre = " %s \""; - info.line_suf = "\""; + outputformat.ascii = TRUE; + outputformat.elmt_suf1 = ""; + outputformat.elmt_suf2 = ""; + outputformat.line_pre = " %s \""; + outputformat.line_suf = "\""; } /* end if */ - /* values of type reference */ - info.obj_format = "-%lu:"H5_PRINTF_HADDR_FMT; - info.obj_hidefileno = 0; + + outputformat.arr_pre = NULL; + outputformat.arr_suf = NULL; + outputformat.arr_sep = NULL; + + outputformat.cmpd_pre = NULL; + outputformat.cmpd_suf = NULL; + outputformat.cmpd_sep = NULL; + + outputformat.vlen_sep = NULL; + outputformat.vlen_pre = NULL; + outputformat.vlen_suf = NULL; + outputformat.vlen_end = NULL; + + info = &outputformat; + if(hexdump_g) p_type = H5Tcopy(type); else @@ -1464,26 +1613,32 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo, vl_data = TRUE; temp_need= nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); - assert(temp_need == (hsize_t)((size_t)temp_need)); + HDassert(temp_need == (hsize_t)((size_t)temp_need)); need = (size_t)temp_need; - buf = malloc(need); - assert(buf); - if(H5Aread(attr, p_type, buf) >= 0) - h5tools_dump_mem(stdout, &info, attr, p_type, space, buf, -1); + buf = HDmalloc(need); + HDassert(buf); + if(H5Aread(attr, p_type, buf) >= 0) { + ctx.need_prefix = TRUE; + ctx.indent_level = 2; + ctx.cur_column = curr_pos; + h5tools_dump_mem(rawoutstream, info, &ctx, attr, p_type, space, buf); + } /* Reclaim any VL memory, if necessary */ if (vl_data) H5Dvlen_reclaim(p_type, space, H5P_DEFAULT, buf); - free(buf); + HDfree(buf); H5Tclose(p_type); } /* end if */ H5Sclose(space); H5Tclose(type); H5Aclose(attr); - } else - putchar('\n'); + } + h5tools_str_close(&buffer); + + HDfprintf(rawoutstream, "\n"); return 0; } @@ -1517,26 +1672,41 @@ dataset_list1(hid_t dset) int ndims; /* dimensionality */ H5S_class_t space_type; /* type of dataspace */ int i; + hsize_t curr_pos = 0; /* total data element position */ + h5tool_link_info_t lnk_info; + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); /* Information that goes on the same row as the name. The name has * already been printed. */ space = H5Dget_space(dset); space_type = H5Sget_simple_extent_type(space); ndims = H5Sget_simple_extent_dims(space, cur_size, max_size); - printf (" {"); + h5tools_str_append(&buffer, " {"); for (i=0; i<ndims; i++) { - HDfprintf (stdout, "%s%Hu", i?", ":"", cur_size[i]); + h5tools_str_append(&buffer, "%s"HSIZE_T_FORMAT, i?", ":"", cur_size[i]); if (max_size[i]==H5S_UNLIMITED) { - HDfprintf (stdout, "/%s", "Inf"); - } else if (max_size[i]!=cur_size[i] || verbose_g>0) { - HDfprintf(stdout, "/%Hu", max_size[i]); + h5tools_str_append(&buffer, "/%s", "Inf"); + } + else if (max_size[i]!=cur_size[i] || verbose_g>0) { + h5tools_str_append(&buffer, "/"HSIZE_T_FORMAT, max_size[i]); } } - if (space_type==H5S_SCALAR) printf("SCALAR"); - else if (space_type==H5S_NULL) printf("NULL"); - putchar('}'); + if (space_type==H5S_SCALAR) h5tools_str_append(&buffer, "SCALAR"); + else if (space_type==H5S_NULL) h5tools_str_append(&buffer, "NULL"); + h5tools_str_append(&buffer, "}"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); H5Sclose (space); + h5tools_str_close(&buffer); + return 0; } @@ -1580,6 +1750,16 @@ dataset_list2(hid_t dset, const char UNUSED *name) double utilization; /* percent utilization of storage */ H5T_class_t tclass; /* datatype class identifier */ int i; + hsize_t curr_pos = 0; /* total data element position */ + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); if(verbose_g > 0) { dcpl = H5Dget_create_plist(dset); @@ -1591,87 +1771,87 @@ dataset_list2(hid_t dset, const char UNUSED *name) hsize_t chsize[64]; /* chunk size in elements */ ndims = H5Pget_chunk(dcpl, NELMTS(chsize), chsize/*out*/); - printf(" %-10s {", "Chunks:"); + h5tools_str_append(&buffer, " %-10s {", "Chunks:"); total = H5Tget_size(type); for (i=0; i<ndims; i++) { - printf("%s%lu", i?", ":"", (unsigned long)(chsize[i])); + h5tools_str_append(&buffer, "%s"HSIZE_T_FORMAT, i?", ":"", chsize[i]); total *= chsize[i]; } - printf("} %lu bytes\n", (unsigned long)total); + h5tools_str_append(&buffer, "} "HSIZE_T_FORMAT" bytes\n", total); } /* Print total raw storage size */ total = H5Sget_simple_extent_npoints(space) * H5Tget_size(type); used = H5Dget_storage_size(dset); tclass = H5Tget_class(type); - printf(" %-10s ", "Storage:"); + h5tools_str_append(&buffer, " %-10s ", "Storage:"); switch (tclass) { case H5T_VLEN: - printf("information not available"); + h5tools_str_append(&buffer, "information not available"); break; case H5T_REFERENCE: if ( H5Tequal(type, H5T_STD_REF_DSETREG)) { - printf("information not available"); + h5tools_str_append(&buffer, "information not available"); } break; default: - printf("%lu logical byte%s, %lu allocated byte%s", - (unsigned long)total, 1==total?"":"s", - (unsigned long)used, 1==used?"":"s"); + h5tools_str_append(&buffer, HSIZE_T_FORMAT" logical byte%s, "HSIZE_T_FORMAT" allocated byte%s", + total, 1==total?"":"s", + used, 1==used?"":"s"); if (used>0) { utilization = (total*100.0)/used; - printf(", %1.2f%% utilization", utilization); + h5tools_str_append(&buffer, ", %1.2f%% utilization", utilization); } - } - - putchar('\n'); + h5tools_str_append(&buffer, "\n"); /* Print information about external strorage */ if((nf = H5Pget_external_count(dcpl)) > 0) { for(i = 0, max_len = 0; i < nf; i++) { H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, NULL, NULL); - n = display_string(NULL, f_name, TRUE); + n = print_string(NULL, f_name, TRUE); max_len = MAX(max_len, n); } /* end for */ - printf(" %-10s %d external file%s\n", + h5tools_str_append(&buffer, " %-10s %d external file%s\n", "Extern:", nf, 1==nf?"":"s"); - printf(" %4s %10s %10s %10s %s\n", + h5tools_str_append(&buffer, " %4s %10s %10s %10s %s\n", "ID", "DSet-Addr", "File-Addr", "Bytes", "File"); - printf(" %4s %10s %10s %10s ", + h5tools_str_append(&buffer, " %4s %10s %10s %10s ", "----", "----------", "----------", "----------"); - for (i=0; i<max_len; i++) putchar('-'); - putchar('\n'); + for (i=0; i<max_len; i++) h5tools_str_append(&buffer, "-"); + h5tools_str_append(&buffer, "\n"); for (i=0, total=0; i<nf; i++) { if (H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, &f_offset, &f_size)<0) { - HDfprintf(stdout, - " #%03d %10Hu %10s %10s ***ERROR*** %s\n", + h5tools_str_append(&buffer, + " #%03d %10"HSIZE_T_FORMAT"u %10s %10s ***ERROR*** %s\n", i, total, "", "", i+1<nf?"Following addresses are incorrect":""); - } else if (H5S_UNLIMITED==f_size) { - HDfprintf(stdout, " #%03d %10Hu %10Hu %10s ", + } + else if (H5S_UNLIMITED==f_size) { + h5tools_str_append(&buffer, " #%03d %10"HSIZE_T_FORMAT"u %10"HSIZE_T_FORMAT"u %10s ", i, total, (hsize_t)f_offset, "INF"); - display_string(stdout, f_name, TRUE); - } else { - HDfprintf(stdout, " #%03d %10Hu %10Hu %10Hu ", + print_string(&buffer, f_name, TRUE); + } + else { + h5tools_str_append(&buffer, " #%03d %10"HSIZE_T_FORMAT"u %10"HSIZE_T_FORMAT"u %10"HSIZE_T_FORMAT"u ", i, total, (hsize_t)f_offset, f_size); - display_string(stdout, f_name, TRUE); + print_string(&buffer, f_name, TRUE); } - putchar('\n'); + h5tools_str_append(&buffer, "\n"); total += f_size; } - printf(" %4s %10s %10s %10s ", + h5tools_str_append(&buffer, " %4s %10s %10s %10s ", "----", "----------", "----------", "----------"); for (i=0; i<max_len; i++) - putchar('-'); - putchar('\n'); + h5tools_str_append(&buffer, "-"); + h5tools_str_append(&buffer, "\n"); } /* end if */ /* Print information about raw data filters */ @@ -1682,20 +1862,21 @@ dataset_list2(hid_t dset, const char UNUSED *name) cd_values, sizeof(f_name), f_name, NULL); f_name[sizeof(f_name) - 1] = '\0'; sprintf(s, "Filter-%d:", i); - printf(" %-10s %s-%u %s {", s, + h5tools_str_append(&buffer, " %-10s %s-%u %s {", s, (f_name[0] ? f_name : "method"), (unsigned)filt_id, ((filt_flags & H5Z_FLAG_OPTIONAL) ? "OPT" : "")); for(cd_num = 0; cd_num < cd_nelmts; cd_num++) - printf("%s%u", (cd_num ? ", " : ""), cd_values[cd_num]); - printf("}\n"); + h5tools_str_append(&buffer, "%s%u", (cd_num ? ", " : ""), cd_values[cd_num]); + h5tools_str_append(&buffer, "}\n"); } /* end for */ } /* end if */ /* Print data type */ - printf(" %-10s ", "Type:"); - display_type(type, 15); - printf("\n"); + h5tools_str_append(&buffer, " %-10s ", "Type:"); + print_type(&buffer, type, 15); + h5tools_str_append(&buffer, "\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Print address information */ if(address_g) @@ -1707,6 +1888,8 @@ dataset_list2(hid_t dset, const char UNUSED *name) H5Pclose(dcpl); } /* end if */ + h5tools_str_close(&buffer); + if(data_g) dump_dataset_values(dset); @@ -1735,9 +1918,23 @@ static herr_t datatype_list2(hid_t type, const char UNUSED *name) { if (verbose_g>0) { - printf(" %-10s ", "Type:"); - display_type(type, 15); - printf("\n"); + hsize_t curr_pos = 0; /* total data element position */ + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); + + h5tools_str_append(&buffer, " %-10s ", "Type:"); + print_type(&buffer, type, 15); + h5tools_str_append(&buffer, "\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + + h5tools_str_close(&buffer); } return 0; } @@ -1760,29 +1957,43 @@ datatype_list2(hid_t type, const char UNUSED *name) static herr_t list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void *_iter) { - H5O_type_t obj_type = oinfo->type; /* Type of the object */ - iter_t *iter = (iter_t*)_iter; + H5O_type_t obj_type = oinfo->type; /* Type of the object */ + iter_t *iter = (iter_t*)_iter; + hsize_t curr_pos = 0; /* total data element position */ + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); /* Print the link's name, either full name or base name */ if(!iter->symlink_target) - display_obj_name(stdout, iter, name, ""); + print_obj_name(&buffer, iter, name, ""); /* Check object information */ if(oinfo->type < 0 || oinfo->type >= H5O_TYPE_NTYPES) { - printf("Unknown type(%d)", (int)oinfo->type); + h5tools_str_append(&buffer, "Unknown type(%d)", (int)oinfo->type); obj_type = H5O_TYPE_UNKNOWN; } if(iter->symlink_target) - fputc('{', stdout); + h5tools_str_append(&buffer, "{"); if(obj_type >= 0 && dispatch_g[obj_type].name) - fputs(dispatch_g[obj_type].name, stdout); + h5tools_str_append(&buffer, "%s", dispatch_g[obj_type].name); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Check if we've seen this object before */ if(first_seen) { - printf(", same as "); - display_string(stdout, first_seen, TRUE); - if(!iter->symlink_target) - printf("\n"); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, ", same as "); + print_string(&buffer, first_seen, TRUE); + if(!iter->symlink_target) { + h5tools_str_append(&buffer, "\n"); + } + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); } /* end if */ else { hid_t obj = (-1); /* ID of object opened */ @@ -1791,15 +2002,20 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void * then return right away. */ if(obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) { - printf(" *ERROR*\n"); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " *ERROR*\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); goto done; } /* end if */ /* List the first line of information for the object. */ if(obj_type >= 0 && dispatch_g[obj_type].list1) (dispatch_g[obj_type].list1)(obj); - if(!iter->symlink_target || (verbose_g > 0)) - putchar('\n'); + if(!iter->symlink_target || (verbose_g > 0)) { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + } /* Show detailed information about the object, beginning with information * which is common to all objects. */ @@ -1813,8 +2029,10 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void H5Aiterate2(obj, H5_INDEX_NAME, H5_ITER_INC, NULL, list_attr, NULL); /* Object location & reference count */ - printf(" %-10s %lu:"H5_PRINTF_HADDR_FMT"\n", "Location:", oinfo->fileno, oinfo->addr); - printf(" %-10s %u\n", "Links:", (unsigned)oinfo->rc); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " %-10s %lu:"H5_PRINTF_HADDR_FMT"\n", "Location:", oinfo->fileno, oinfo->addr); + h5tools_str_append(&buffer, " %-10s %u\n", "Links:", (unsigned)oinfo->rc); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Modification time */ if(oinfo->mtime > 0) { @@ -1827,7 +2045,9 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void tm = HDlocaltime(&(oinfo->mtime)); if(tm) { HDstrftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm); - printf(" %-10s %s\n", "Modified:", buf); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " %-10s %s\n", "Modified:", buf); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); } /* end if */ } /* end if */ @@ -1838,13 +2058,16 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void * H5Oget_comment again with the correct value. * If the call to H5Oget_comment returned an error, skip this block */ if (cmt_bufsize > 0) { - comment = (char *)HDmalloc((size_t)cmt_bufsize); /* new_size including null terminator */ + comment = (char *)HDmalloc((size_t)cmt_bufsize + 1); /* new_size including null terminator */ if(comment) { cmt_bufsize = H5Oget_comment(obj, comment, cmt_bufsize); if(cmt_bufsize > 0) { - printf(" %-10s \"", "Comment:"); - display_string(stdout, comment, FALSE); - puts("\""); + comment[cmt_bufsize] = 0; + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " %-10s \"", "Comment:"); + print_string(&buffer, comment, FALSE); + h5tools_str_append(&buffer, "\"\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); } /* end if */ HDfree(comment); } @@ -1862,9 +2085,13 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void done: if(iter->symlink_target) { - fputs("}\n", stdout); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "}\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); iter->symlink_target = FALSE; } + h5tools_str_close(&buffer); + return 0; } /* end list_obj() */ @@ -1890,24 +2117,34 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) char *buf=NULL; iter_t *iter = (iter_t*)_iter; int ret; + hsize_t curr_pos = 0; /* total data element position */ h5tool_link_info_t lnk_info; + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); /* init linkinfo struct */ - memset(&lnk_info, 0, sizeof(h5tool_link_info_t)); + HDmemset(&lnk_info, 0, sizeof(h5tool_link_info_t)); /* if verbose, make H5tools_get_symlink_info() display more */ if (verbose_g) lnk_info.opt.msg_mode=1; /* Print the link's name, either full name or base name */ - display_obj_name(stdout, iter, name, ""); + print_obj_name(&buffer, iter, name, ""); switch(linfo->type) { case H5L_TYPE_SOFT: ret = H5tools_get_symlink_info(iter->fid, name, &lnk_info, follow_symlink_g); /* lnk_info.trg_path is malloced in H5tools_get_symlink_info() * so it will be freed via buf later */ - buf = lnk_info.trg_path; + buf = (char*)lnk_info.trg_path; /* error */ if (ret < 0) goto done; @@ -1915,20 +2152,24 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) else if (no_dangling_link_g && ret == 0) iter->symlink_list->dangle_link = TRUE; - HDfputs("Soft Link {", stdout); - HDfputs(buf, stdout); - HDfputc('}', stdout); + h5tools_str_append(&buffer, "Soft Link {"); + h5tools_str_append(&buffer, buf); + h5tools_str_append(&buffer, "}"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); if(follow_symlink_g) { hbool_t orig_grp_literal = grp_literal_g; - HDfputc(' ', stdout); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " "); /* Check if we have already seen this softlink */ if(symlink_is_visited(iter->symlink_list, linfo->type, NULL, buf)) { - HDfputs("{Already Visited}\n", stdout); + h5tools_str_append(&buffer, "{Already Visited}\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); goto done; } + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Add this link to the list of seen softlinks */ if(symlink_visit_add(iter->symlink_list, linfo->type, NULL, buf) < 0) @@ -1951,8 +2192,11 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) grp_literal_g = orig_grp_literal; } - else - HDfputc('\n', stdout); + else { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + } break; @@ -1965,7 +2209,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) ret = H5tools_get_symlink_info(iter->fid, name, &lnk_info, follow_link); /* lnk_info.trg_path is malloced in H5tools_get_symlink_info() * so it will be freed via buf later */ - buf = lnk_info.trg_path; + buf = (char*)lnk_info.trg_path; /* error */ if (ret < 0) goto done; @@ -1976,27 +2220,31 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) if(H5Lunpack_elink_val(buf, linfo->u.val_size, NULL, &filename, &path) < 0) goto done; - HDfputs("External Link {", stdout); - HDfputs(filename, stdout); - HDfputc('/', stdout); + h5tools_str_append(&buffer, "External Link {"); + h5tools_str_append(&buffer, filename); + h5tools_str_append(&buffer, "/"); if(*path != '/') - HDfputc('/', stdout); - HDfputs(path, stdout); - HDfputc('}', stdout); + h5tools_str_append(&buffer, "/"); + h5tools_str_append(&buffer, path); + h5tools_str_append(&buffer, "}"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Recurse through the external link */ /* keep the follow_elink_g for backward compatibility with -E */ if(follow_link) { hbool_t orig_grp_literal = grp_literal_g; - HDfputc(' ', stdout); + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " "); /* Check if we have already seen this elink */ if(symlink_is_visited(iter->symlink_list, linfo->type, filename, path)) { - HDfputs("{Already Visited}\n", stdout); + h5tools_str_append(&buffer, "{Already Visited}\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); goto done; } + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); /* Add this link to the list of seen elinks */ if(symlink_visit_add(iter->symlink_list, linfo->type, filename, path) < 0) @@ -2022,17 +2270,19 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) grp_literal_g = orig_grp_literal; } else - HDfputc('\n', stdout); - + HDfprintf(rawoutstream, "\n"); } break; default: - HDfputs("UD Link {cannot follow UD links}\n", stdout); + h5tools_str_append(&buffer, "UD Link {cannot follow UD links}\n"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); break; } /* end switch */ done: + h5tools_str_close(&buffer); + if (buf) HDfree(buf); return 0; @@ -2057,25 +2307,40 @@ done: static herr_t visit_obj(hid_t file, const char *oname, iter_t *iter) { + int retval = 0; H5O_info_t oi; /* Information for object */ + hsize_t curr_pos = 0; /* total data element position */ + h5tool_link_info_t lnk_info; + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); /* Retrieve info for object to list */ if(H5Oget_info_by_name(file, oname, &oi, H5P_DEFAULT) < 0) { if(iter->symlink_target) { - HDfputs("{**NOT FOUND**}\n", stdout); + h5tools_str_append(&buffer, "{**NOT FOUND**}\n"); iter->symlink_target = FALSE; } else - display_obj_name(stdout, iter, oname, "**NOT FOUND**"); - return -1; + print_obj_name(&buffer, iter, oname, "**NOT FOUND**"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + retval = -1; + goto done; } /* end if */ /* Check for group iteration */ if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) { /* Get ID for group */ if(!iter->symlink_target && (iter->gid = H5Gopen2(file, oname, H5P_DEFAULT)) < 0) { - fprintf(stderr, "%s: unable to open '%s' as group\n", iter->fname, oname); - return 0; /* Previously "continue", when this code was in main(). + h5tools_str_append(&buffer, "%s: unable to open '%s' as group\n", iter->fname, oname); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + goto done; /* Previously "continue", when this code was in main(). * We don't "continue" here in order to close the file * and free the file name properly. */ } /* end if */ @@ -2099,7 +2364,10 @@ visit_obj(hid_t file, const char *oname, iter_t *iter) list_obj(oname, &oi, NULL, iter); } /* end else */ - return 0; +done: + h5tools_str_close(&buffer); + + return retval; } @@ -2130,8 +2398,8 @@ get_width(void) /* Try to get it from the COLUMNS environment variable first since it's * value is sometimes wrong. */ - if ((s=getenv("COLUMNS")) && *s && isdigit((int)*s)) - width = (int)strtol(s, NULL, 0); + if ((s=HDgetenv("COLUMNS")) && *s && isdigit((int)*s)) + width = (int)HDstrtol(s, NULL, 0); #if defined(H5_HAVE_STRUCT_VIDEOCONFIG) && defined(H5_HAVE__GETVIDEOCONFIG) { @@ -2202,14 +2470,14 @@ is_valid_args(void) if(recursive_g && grp_literal_g) { - fprintf(stderr, "Error: 'recursive' option not compatible with 'group info' option!\n\n"); + HDfprintf(rawerrorstream, "Error: 'recursive' option not compatible with 'group info' option!\n\n"); ret = FALSE; goto out; } if(no_dangling_link_g && !follow_symlink_g) { - fprintf(stderr, "Error: --no-dangling-links must be used along with --follow-symlinks option!\n\n"); + HDfprintf(rawerrorstream, "Error: --no-dangling-links must be used along with --follow-symlinks option!\n\n"); ret = FALSE; goto out; } @@ -2238,7 +2506,7 @@ leave(int ret) { h5tools_close(); - exit(ret); + HDexit(ret); } @@ -2490,7 +2758,7 @@ main(int argc, const char *argv[]) if(file >= 0) { if(verbose_g) - printf("Opened \"%s\" with %s driver.\n", fname, drivername); + HDfprintf(rawoutstream, "Opened \"%s\" with %s driver.\n", fname, drivername); break; /*success*/ } /* end if */ @@ -2505,7 +2773,7 @@ main(int argc, const char *argv[]) } /* end while */ if(file < 0) { - fprintf(stderr, "%s: unable to open file\n", argv[argno-1]); + HDfprintf(rawerrorstream, "%s: unable to open file\n", argv[argno-1]); HDfree(fname); err_exit = 1; continue; @@ -2518,7 +2786,7 @@ main(int argc, const char *argv[]) iter.base_len -= oname[iter.base_len-1] == '/'; x = oname; if(NULL == (oname = HDstrdup(oname))) { - fprintf(stderr, "memory allocation failed\n"); + HDfprintf(rawerrorstream, "memory allocation failed\n"); leave(EXIT_FAILURE); } *x = '\0'; @@ -2552,7 +2820,19 @@ main(int argc, const char *argv[]) if(HDstrcmp(oname, root_name)) { /* Check the type of link given */ if(H5Lget_info(file, oname, &li, H5P_DEFAULT) < 0) { - display_obj_name(stdout, &iter, oname, "**NOT FOUND**"); + hsize_t curr_pos = 0; /* total data element position */ + h5tool_link_info_t lnk_info; + h5tools_str_t buffer; /* string into which to render */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t *info = &ls_dataformat; + h5tool_format_t outputformat; + + HDmemset(&ctx, 0, sizeof(ctx)); + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + h5tools_str_reset(&buffer); + print_obj_name(&buffer, &iter, oname, "**NOT FOUND**"); + h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); leave(EXIT_FAILURE); } /* end if */ } /* end if */ diff --git a/tools/h5ls/testh5ls.sh.in b/tools/h5ls/testh5ls.sh.in index f9b68d7..dc78174 100644 --- a/tools/h5ls/testh5ls.sh.in +++ b/tools/h5ls/testh5ls.sh.in @@ -24,19 +24,129 @@ H5LS_BIN=`pwd`/$H5LS # The path of the tool binary CMP='cmp -s' DIFF='diff -c' -NLINES=20 # Max. lines of output to display if test fails +CP='cp' +NLINES=20 # Max. lines of output to display if test fails WORDS_BIGENDIAN="@WORDS_BIGENDIAN@" nerrors=0 verbose=yes -h5haveexitcode=yes # default is yes - +h5haveexitcode=yes # default is yes # The build (current) directory might be different than the source directory. if test -z "$srcdir"; then srcdir=. fi -test -d ../testfiles || mkdir ../testfiles +# source dirs +SRC_TOOLS="$srcdir/.." +SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" +# testfiles source dirs for tools +SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES" +SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES" +SRC_H5DIFF_TESTFILES="$SRC_TOOLS/h5diff/testfiles" +SRC_H5COPY_TESTFILES="$SRC_TOOLS/h5copy/testfiles" +SRC_H5REPACK_TESTFILES="$SRC_TOOLS/h5repack/testfiles" +SRC_H5JAM_TESTFILES="$SRC_TOOLS/h5jam/testfiles" +SRC_H5STAT_TESTFILES="$SRC_TOOLS/h5stat/testfiles" +SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/h5import/testfiles" + +TESTDIR=./testfiles +test -d $TESTDIR || mkdir $TESTDIR + +###################################################################### +# test files +# -------------------------------------------------------------------- +# All the test files copy from source directory to test directory +# NOTE: Keep this framework to add/remove test files. +# Any test files from other tools can be used in this framework. +# This list are also used for checking exist. +# Comment '#' without space can be used. +# -------------------------------------------------------------------- +LIST_HDF5_TEST_FILES=" +$SRC_H5LS_TESTFILES/tall.h5 +$SRC_H5LS_TESTFILES/tarray1.h5 +$SRC_H5LS_TESTFILES/tattr2.h5 +$SRC_H5LS_TESTFILES/tattrreg.h5 +$SRC_H5LS_TESTFILES/tcompound.h5 +$SRC_H5LS_TESTFILES/tdatareg.h5 +$SRC_H5LS_TESTFILES/tdset.h5 +$SRC_H5LS_TESTFILES/tempty.h5 +$SRC_H5LS_TESTFILES/textlink.h5 +$SRC_H5LS_TESTFILES/textlinksrc.h5 +$SRC_H5LS_TESTFILES/textlinktar.h5 +$SRC_H5LS_TESTFILES/tgroup.h5 +$SRC_H5LS_TESTFILES/tgrp_comments.h5 +$SRC_H5LS_TESTFILES/thlink.h5 +$SRC_H5LS_TESTFILES/tloop.h5 +$SRC_H5LS_TESTFILES/tnestedcomp.h5 +$SRC_H5LS_TESTFILES/tsaf.h5 +$SRC_H5LS_TESTFILES/tslink.h5 +$SRC_H5LS_TESTFILES/tsoftlinks.h5 +$SRC_H5LS_TESTFILES/tstr.h5 +$SRC_H5LS_TESTFILES/tudlink.h5 +$SRC_H5LS_TESTFILES/tvldtypes1.h5 +$SRC_H5LS_TESTFILES/tdset_idx.h5 +" + +LIST_OTHER_TEST_FILES=" +$SRC_H5LS_TESTFILES/help-1.ls +$SRC_H5LS_TESTFILES/help-2.ls +$SRC_H5LS_TESTFILES/help-3.ls +$SRC_H5LS_TESTFILES/nosuchfile.ls +$SRC_H5LS_TESTFILES/tall-1.ls +$SRC_H5LS_TESTFILES/tall-2.ls +$SRC_H5LS_TESTFILES/tarray1.ls +$SRC_H5LS_TESTFILES/tattr2.ls +$SRC_H5LS_TESTFILES/tattrreg_le.ls +$SRC_H5LS_TESTFILES/tattrreg_be.ls +$SRC_H5LS_TESTFILES/tcomp-1.ls +$SRC_H5LS_TESTFILES/tdataregbe.ls +$SRC_H5LS_TESTFILES/tdataregle.ls +$SRC_H5LS_TESTFILES/tdset-1.ls +$SRC_H5LS_TESTFILES/tempty.ls +$SRC_H5LS_TESTFILES/textlink-1.ls +$SRC_H5LS_TESTFILES/textlinksrc-1.ls +$SRC_H5LS_TESTFILES/textlinksrc-2.ls +$SRC_H5LS_TESTFILES/textlinksrc-3.ls +$SRC_H5LS_TESTFILES/textlinksrc-4.ls +$SRC_H5LS_TESTFILES/textlinksrc-5.ls +$SRC_H5LS_TESTFILES/textlinksrc-6.ls +$SRC_H5LS_TESTFILES/textlinksrc-7.ls +$SRC_H5LS_TESTFILES/textlinksrc-1-old.ls +$SRC_H5LS_TESTFILES/textlinksrc-2-old.ls +$SRC_H5LS_TESTFILES/textlinksrc-3-old.ls +$SRC_H5LS_TESTFILES/textlinksrc-6-old.ls +$SRC_H5LS_TESTFILES/textlinksrc-7-old.ls +$SRC_H5LS_TESTFILES/tsoftlinks-1.ls +$SRC_H5LS_TESTFILES/tsoftlinks-2.ls +$SRC_H5LS_TESTFILES/tsoftlinks-3.ls +$SRC_H5LS_TESTFILES/tsoftlinks-4.ls +$SRC_H5LS_TESTFILES/tsoftlinks-5.ls +$SRC_H5LS_TESTFILES/textlinksrc-nodangle-1.ls +$SRC_H5LS_TESTFILES/textlinksrc-nodangle-2.ls +$SRC_H5LS_TESTFILES/tgrp_comments.ls +$SRC_H5LS_TESTFILES/tsoftlinks-nodangle-1.ls +$SRC_H5LS_TESTFILES/thlinks-nodangle-1.ls +$SRC_H5LS_TESTFILES/tgroup.ls +$SRC_H5LS_TESTFILES/tgroup-1.ls +$SRC_H5LS_TESTFILES/tgroup-2.ls +$SRC_H5LS_TESTFILES/tgroup-3.ls +$SRC_H5LS_TESTFILES/thlink-1.ls +$SRC_H5LS_TESTFILES/tloop-1.ls +$SRC_H5LS_TESTFILES/tmultifile.ls +$SRC_H5LS_TESTFILES/tnestcomp-1.ls +$SRC_H5LS_TESTFILES/tnestcomp-2.ls +$SRC_H5LS_TESTFILES/tnestcomp-3.ls +$SRC_H5LS_TESTFILES/tnestcomp-4.ls +$SRC_H5LS_TESTFILES/tsaf.ls +$SRC_H5LS_TESTFILES/tslink-1.ls +$SRC_H5LS_TESTFILES/tstr-1.ls +$SRC_H5LS_TESTFILES/tudlink-1.ls +$SRC_H5LS_TESTFILES/tvldtypes1.ls +$SRC_H5LS_TESTFILES/tvldtypes2le.ls +$SRC_H5LS_TESTFILES/tvldtypes2be.ls +$SRC_H5LS_TESTFILES/tdset_idx.ls +" + # RUNSERIAL is used. Check if it can return exit code from executalbe correctly. if [ -n "$RUNSERIAL_NOEXITCODE" ]; then @@ -45,6 +155,31 @@ if [ -n "$RUNSERIAL_NOEXITCODE" ]; then h5haveexitcode=no fi +# +# copy test files and expected output files from source dirs to test dir +# +COPY_TESTFILES="$LIST_HDF5_TEST_FILES $LIST_OTHER_TEST_FILES" + +COPY_TESTFILES_TO_TESTDIR() +{ + # copy test files. Used -f to make sure get a new copy + for tstfile in $COPY_TESTFILES + do + # ignore '#' comment + echo $tstfile | tr -d ' ' | grep '^#' > /dev/null + RET=$? + if [ $RET -eq 1 ]; then + if [ -a $tstfile ]; then + $CP -f $tstfile $TESTDIR + else + echo "Error: FAILED to copy $tstfile" + echo " $tstfile doesn't exist!" + exit $EXIT_FAILURE + fi + fi + done +} + # Print a line-line message left justified in a field of 70 characters # beginning with the word "Testing". TESTING() { @@ -52,6 +187,9 @@ TESTING() { echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\012' } +# Source in the output filter function definitions. +. $srcdir/../../bin/output_filter.sh + # Run a test and print PASS or *FAIL*. For now, if h5ls can complete # with exit status 0, consider it pass. If a test fails then increment # the `nerrors' global variable and (if $verbose is set) display up to $NLINS @@ -61,9 +199,11 @@ TESTING() { # $1 -- actual output filename to use # $2 and on -- argument for the h5ls tool TOOLTEST() { - expect="$srcdir/../testfiles/$1" - actual="../testfiles/`basename $1 .ls`.out" - actual_err="../testfiles/`basename $1 .ls`.err" + expect="$TESTDIR/$1" + actual="$TESTDIR/`basename $1 .ls`.out" + actual_err="$TESTDIR/`basename $1 .ls`.err" + actual_sav=${actual}-sav + actual_err_sav=${actual_err}-sav shift retvalexpect=$1 shift @@ -73,49 +213,53 @@ TOOLTEST() { # any unexpected output from that stream too. TESTING $H5LS $@ ( - echo "#############################" - echo " output for '$H5LS $@'" - echo "#############################" - cd $srcdir/../testfiles + cd $TESTDIR $RUNSERIAL $H5LS_BIN "$@" ) >$actual 2>$actual_err exitcode=$? + # save actual and actual_err in case they are needed later. + cp $actual $actual_sav + STDOUT_FILTER $actual + cp $actual_err $actual_err_sav + STDERR_FILTER $actual_err cat $actual_err >> $actual if [ $h5haveexitcode = 'yes' -a $exitcode -ne $retvalexpect ]; then - echo "*FAILED*" - nerrors="`expr $nerrors + 1`" - if [ yes = "$verbose" ]; then - echo "test returned with exit code $exitcode" - echo "test output: (up to $NLINES lines)" - head -$NLINES $actual - echo "***end of test output***" - echo "" - fi + echo "*FAILED*" + nerrors="`expr $nerrors + 1`" + if [ yes = "$verbose" ]; then + echo "test returned with exit code $exitcode" + echo "test output: (up to $NLINES lines)" + head -$NLINES $actual + echo "***end of test output***" + echo "" + fi elif [ ! -f $expect ]; then - # Create the expect file if it doesn't yet exist. + # Create the expect file if it doesn't yet exist. echo " CREATED" cp $actual $expect elif $CMP $expect $actual; then echo " PASSED" else echo "*FAILED*" - echo " Expected result differs from actual result" - nerrors="`expr $nerrors + 1`" - test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' + echo " Expected result differs from actual result" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' fi # Clean up output file if test -z "$HDF5_NOCLEANUP"; then - rm -f $actual $actual_err + rm -f $actual $actual_err $actual_sav $actual_err_sav fi } ############################################################################## ############################################################################## -### T H E T E S T S ### +### T H E T E S T S ### ############################################################################## ############################################################################## +# prepare for test +COPY_TESTFILES_TO_TESTDIR # Toss in a bunch of tests. Not sure if they are the right kinds. # test the help syntax @@ -181,6 +325,11 @@ TOOLTEST tsoftlinks-nodangle-1.ls 1 -w80 --follow-symlinks --no-dangling-links t # when used file with no dangling links - expected exit code 0 TOOLTEST thlinks-nodangle-1.ls 0 -w80 --follow-symlinks --no-dangling-links thlink.h5 +# test for wildcards in filename (does not work with cmake) +# this h5ls test script does not pass the filename properly like the h5dump test script??? +#TOOLTEST tstarfile 0 -w80 t*link.h5 +#TOOLTEST tqmarkfile 0 -w80 t?link.h5 +TOOLTEST tmultifile 0 -w80 thlink.h5 tslink.h5 # tests for hard links TOOLTEST thlink-1.ls 0 -w80 thlink.h5 @@ -219,6 +368,14 @@ TOOLTEST tempty.ls 0 -w80 -d tempty.h5 # enable -S for avoiding printing NATIVE types TOOLTEST tattr2.ls 0 -w80 -v -S tattr2.h5 +# test for attribute with region references without verbose mode +# ( HDFFV-7838, ) +if test $WORDS_BIGENDIAN != "yes"; then +TOOLTEST tattrreg_le.ls 0 -w80 -v -d tattrreg.h5 +else +TOOLTEST tattrreg_be.ls 0 -w80 -v -d tattrreg.h5 +fi + # tests for error handling. # test for non-existing file TOOLTEST nosuchfile.ls 1 nosuchfile.h5 |