diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2012-02-17 21:41:58 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2012-02-17 21:41:58 (GMT) |
commit | fb762aa6b01d50f18534f447459e0b3557d9fea6 (patch) | |
tree | 02f2971dc00028aa32ffc986e10e1fbe04e31bc3 /tools/h5ls | |
parent | 5b03d4b08d4babdc88e0938bd9165c52e0227a51 (diff) | |
download | hdf5-fb762aa6b01d50f18534f447459e0b3557d9fea6.zip hdf5-fb762aa6b01d50f18534f447459e0b3557d9fea6.tar.gz hdf5-fb762aa6b01d50f18534f447459e0b3557d9fea6.tar.bz2 |
[svn-r21953] HDDFV-7560: h5dump refactoring
Tested: local linux
Diffstat (limited to 'tools/h5ls')
-rw-r--r-- | tools/h5ls/h5ls.c | 1450 |
1 files changed, 1332 insertions, 118 deletions
diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 66e588f..6b4d5f0 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -27,12 +27,86 @@ #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 */ + + ",", /*vlen_sep */ + "(", /*vlen_pre */ + ")", /*vlen_suf */ + "", /*vlen_end */ + + "%s", /*elmt_fmt */ + ",", /*elmt_suf1 */ + " ", /*elmt_suf2 */ + + "%lu", /*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 +155,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); @@ -1229,6 +1304,1090 @@ display_type(hid_t type, int ind) (unsigned long)H5Tget_size(type), (unsigned)data_class); } + +/*------------------------------------------------------------------------- + * 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 + * be. + * + * Return: Number of characters printed. + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +print_string(h5tools_str_t *buffer, const char *s, hbool_t escape_spaces) +{ + int nprint=0; + + for (/*void*/; s && *s; s++) { + switch (*s) { + case '"': + h5tools_str_append(buffer, "\\\""); + nprint += 2; + break; + case '\\': + h5tools_str_append(buffer, "\\\\"); + nprint += 2; + break; + case '\b': + h5tools_str_append(buffer, "\\b"); + nprint += 2; + break; + case '\f': + h5tools_str_append(buffer, "\\f"); + nprint += 2; + break; + case '\n': + h5tools_str_append(buffer, "\\n"); + nprint += 2; + break; + case '\r': + h5tools_str_append(buffer, "\\r"); + nprint += 2; + break; + case '\t': + h5tools_str_append(buffer, "\\t"); + nprint += 2; + break; + case ' ': + if (escape_spaces) { + h5tools_str_append(buffer, "\\ "); + nprint += 2; + } + else { + h5tools_str_append(buffer, " "); + nprint++; + } + break; + default: + if (isprint((int)*s)) { + h5tools_str_append(buffer, "%c", *s); + nprint++; + } else { + h5tools_str_append(buffer, "\\%03o", *((const unsigned char*)s)); + nprint += 4; + } + break; + } + } + return nprint; +} + + +/*------------------------------------------------------------------------- + * Function: print_obj_name + * + * Purpose: Print an object name and another string. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Quincey Koziol + * Tuesday, November 6, 2007 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +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 */ + const char *name = fullname; /* Pointer to buffer for printing */ + int n; + + if(show_file_name_g) + sprintf(fullname, "%s/%s", iter->fname, oname + iter->name_start); + else + name = oname + iter->name_start; + + /* Print the object name, either full name or base name */ + if(fullname_g) + n = print_string(buffer, name, TRUE); + else { + const char *last_sep; /* The location of the last group separator */ + + /* Find the last component of the path name */ + if(NULL == (last_sep = HDstrrchr(name, '/'))) + last_sep = name; + else { + last_sep++; + } /* end else */ + n = print_string(buffer, last_sep, TRUE); + } /* end else */ + h5tools_str_append(buffer, "%*s ", MAX(0, (24 - n)), s); + + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_native_type + * + * Purpose: Prints the name of a native C data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed. + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * Robb Matzke, 1999-06-11 + * Added the C9x types, but we still prefer to display the types + * from the C language itself (like `int' vs. `int32_t'). + * + *------------------------------------------------------------------------- + */ +static hbool_t +print_native_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) +{ + if (H5Tequal(type, H5T_NATIVE_SCHAR)==TRUE) { + h5tools_str_append(buffer, "native signed char"); + } else if (H5Tequal(type, H5T_NATIVE_UCHAR)==TRUE) { + h5tools_str_append(buffer, "native unsigned char"); + } else if (H5Tequal(type, H5T_NATIVE_INT)==TRUE) { + h5tools_str_append(buffer, "native int"); + } else if (H5Tequal(type, H5T_NATIVE_UINT)==TRUE) { + h5tools_str_append(buffer, "native unsigned int"); + } else if (H5Tequal(type, H5T_NATIVE_SHORT)==TRUE) { + h5tools_str_append(buffer, "native short"); + } else if (H5Tequal(type, H5T_NATIVE_USHORT)==TRUE) { + h5tools_str_append(buffer, "native unsigned short"); + } else if (H5Tequal(type, H5T_NATIVE_LONG)==TRUE) { + h5tools_str_append(buffer, "native long"); + } else if (H5Tequal(type, H5T_NATIVE_ULONG)==TRUE) { + h5tools_str_append(buffer, "native unsigned long"); + } else if (H5Tequal(type, H5T_NATIVE_LLONG)==TRUE) { + h5tools_str_append(buffer, "native long long"); + } else if (H5Tequal(type, H5T_NATIVE_ULLONG)==TRUE) { + h5tools_str_append(buffer, "native unsigned long long"); + } else if (H5Tequal(type, H5T_NATIVE_FLOAT)==TRUE) { + h5tools_str_append(buffer, "native float"); + } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)==TRUE) { + h5tools_str_append(buffer, "native double"); +#if H5_SIZEOF_LONG_DOUBLE !=0 + } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)==TRUE) { + h5tools_str_append(buffer, "native long double"); +#endif + } else if (H5Tequal(type, H5T_NATIVE_INT8)==TRUE) { + h5tools_str_append(buffer, "native int8_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT8)==TRUE) { + h5tools_str_append(buffer, "native uint8_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT16)==TRUE) { + h5tools_str_append(buffer, "native int16_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT16)==TRUE) { + h5tools_str_append(buffer, "native uint16_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT32)==TRUE) { + h5tools_str_append(buffer, "native int32_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT32)==TRUE) { + h5tools_str_append(buffer, "native uint32_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT64)==TRUE) { + h5tools_str_append(buffer, "native int64_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT64)==TRUE) { + h5tools_str_append(buffer, "native uint64_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8)==TRUE) { + h5tools_str_append(buffer, "native int_least8_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8)==TRUE) { + h5tools_str_append(buffer, "native uint_least8_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16)==TRUE) { + h5tools_str_append(buffer, "native int_least16_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16)==TRUE) { + h5tools_str_append(buffer, "native uint_least16_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32)==TRUE) { + h5tools_str_append(buffer, "native int_least32_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32)==TRUE) { + h5tools_str_append(buffer, "native uint_least32_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64)==TRUE) { + h5tools_str_append(buffer, "native int_least64_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64)==TRUE) { + h5tools_str_append(buffer, "native uint_least64_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_FAST8)==TRUE) { + h5tools_str_append(buffer, "native int_fast8_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8)==TRUE) { + h5tools_str_append(buffer, "native uint_fast8_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_FAST16)==TRUE) { + h5tools_str_append(buffer, "native int_fast16_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16)==TRUE) { + h5tools_str_append(buffer, "native uint_fast16_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_FAST32)==TRUE) { + h5tools_str_append(buffer, "native int_fast32_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32)==TRUE) { + h5tools_str_append(buffer, "native uint_fast32_t"); + } else if (H5Tequal(type, H5T_NATIVE_INT_FAST64)==TRUE) { + h5tools_str_append(buffer, "native int_fast64_t"); + } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64)==TRUE) { + h5tools_str_append(buffer, "native uint_fast64_t"); + } else if (H5Tequal(type, H5T_NATIVE_B8)==TRUE) { + h5tools_str_append(buffer, "native 8-bit field"); + } else if (H5Tequal(type, H5T_NATIVE_B16)==TRUE) { + h5tools_str_append(buffer, "native 16-bit field"); + } else if (H5Tequal(type, H5T_NATIVE_B32)==TRUE) { + h5tools_str_append(buffer, "native 32-bit field"); + } else if (H5Tequal(type, H5T_NATIVE_B64)==TRUE) { + h5tools_str_append(buffer, "native 64-bit field"); + } else if (H5Tequal(type, H5T_NATIVE_HSIZE)==TRUE) { + h5tools_str_append(buffer, "native hsize_t"); + } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)==TRUE) { + h5tools_str_append(buffer, "native hssize_t"); + } else if (H5Tequal(type, H5T_NATIVE_HERR)==TRUE) { + h5tools_str_append(buffer, "native herr_t"); + } else if (H5Tequal(type, H5T_NATIVE_HBOOL)==TRUE) { + h5tools_str_append(buffer, "native hbool_t"); + } else { + return FALSE; + } + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_ieee_type + * + * Purpose: Print the name of an IEEE floating-point data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +print_ieee_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) +{ + if (H5Tequal(type, H5T_IEEE_F32BE)==TRUE) { + 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; +} + + +/*------------------------------------------------------------------------- + * Function: print_precision + * + * Purpose: Prints information on the next line about precision and + * padding if the precision is less than the total data type + * size. + * + * Return: void + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void +print_precision(h5tools_str_t *buffer, hid_t type, int ind) +{ + size_t prec; /* precision */ + H5T_pad_t plsb, pmsb; /* lsb and msb padding */ + const char *plsb_s=NULL; /* lsb padding string */ + const char *pmsb_s=NULL; /* msb padding string */ + size_t nbits; /* number of bits */ + + /* If the precision is less than the total size then show the precision + * and offset on the following line. Also display the padding + * information. */ + if (8*H5Tget_size(type)!=(prec=H5Tget_precision(type))) { + 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)); + + H5Tget_pad(type, &plsb, &pmsb); + if (H5Tget_offset(type)>0) { + switch (plsb) { + case H5T_PAD_ZERO: + plsb_s = "zero"; + break; + case H5T_PAD_ONE: + plsb_s = "one"; + break; + case H5T_PAD_BACKGROUND: + plsb_s = "bkg"; + break; + case H5T_PAD_ERROR: + case H5T_NPAD: + plsb_s = "unknown"; + break; + default: + ; + break; + } + } + if (H5Tget_offset(type)+prec<8*H5Tget_size(type)) { + switch (pmsb) { + case H5T_PAD_ZERO: + pmsb_s = "zero"; + break; + case H5T_PAD_ONE: + pmsb_s = "one"; + break; + case H5T_PAD_BACKGROUND: + pmsb_s = "bkg"; + break; + case H5T_PAD_ERROR: + case H5T_NPAD: + pmsb_s = "unknown"; + break; + default: + ; + break; + } + } + if (plsb_s || pmsb_s) { + h5tools_str_append(buffer, "\n%*s(", ind, ""); + if (plsb_s) { + nbits = H5Tget_offset(type); + h5tools_str_append(buffer, "%lu %s bit%s at bit 0", + (unsigned long)nbits, plsb_s, 1==nbits?"":"s"); + } + if (plsb_s && pmsb_s) h5tools_str_append(buffer, ", "); + if (pmsb_s) { + nbits = 8*H5Tget_size(type)-(H5Tget_offset(type)+prec); + 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)); + } + h5tools_str_append(buffer, ")"); + } + } +} + + +/*------------------------------------------------------------------------- + * 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 + * the first line. Additional information might appear in + * parentheses on the following lines. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +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 */ + H5T_sign_t sign; /* sign scheme value */ + const char *sign_s=NULL; /* sign scheme string */ + + if (H5T_INTEGER!=H5Tget_class(type)) return FALSE; + + /* Byte order */ + if (H5Tget_size(type)>1) { + order = H5Tget_order(type); + if (H5T_ORDER_LE==order) { + order_s = " little-endian"; + } + else if (H5T_ORDER_BE==order) { + order_s = " big-endian"; + } + else if (H5T_ORDER_VAX==order) { + order_s = " mixed-endian"; + } + else { + order_s = " unknown-byte-order"; + } + } + else { + order_s = ""; + } + + /* Sign */ + if ((sign=H5Tget_sign(type))>=0) { + if (H5T_SGN_NONE==sign) { + sign_s = " unsigned"; + } + else if (H5T_SGN_2==sign) { + sign_s = ""; + } + else { + sign_s = " unknown-sign"; + } + } + else { + sign_s = " unknown-sign"; + } + + /* Print size, order, and sign on first line, precision and padding + * information on the subsequent lines */ + h5tools_str_append(buffer, "%lu-bit%s%s integer", + (unsigned long)(8*H5Tget_size(type)), order_s, sign_s); + print_precision(buffer, type, ind); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_float_type + * + * Purpose: Print info about a floating point data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +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 */ + size_t spos; /* sign bit position */ + size_t esize, epos; /* exponent size and position */ + size_t msize, mpos; /* significand size and position */ + size_t ebias; /* exponent bias */ + H5T_norm_t norm; /* significand normalization */ + const char *norm_s=NULL; /* normalization string */ + H5T_pad_t pad; /* internal padding value */ + const char *pad_s=NULL; /* internal padding string */ + + if (H5T_FLOAT!=H5Tget_class(type)) return FALSE; + + /* Byte order */ + if (H5Tget_size(type)>1) { + order = H5Tget_order(type); + if (H5T_ORDER_LE==order) { + order_s = " little-endian"; + } + else if (H5T_ORDER_BE==order) { + order_s = " big-endian"; + } + else if (H5T_ORDER_VAX==order) { + order_s = " mixed-endian"; + } + else { + order_s = " unknown-byte-order"; + } + } + else { + order_s = ""; + } + + /* Print size and byte order on first line, precision and padding on + * subsequent lines. */ + h5tools_str_append(buffer, "%lu-bit%s floating-point", + (unsigned long)(8*H5Tget_size(type)), order_s); + print_precision(buffer, type, ind); + + /* Print sizes, locations, and other information about each field */ + H5Tget_fields (type, &spos, &epos, &esize, &mpos, &msize); + ebias = H5Tget_ebias(type); + norm = H5Tget_norm(type); + switch (norm) { + case H5T_NORM_IMPLIED: + norm_s = ", msb implied"; + break; + case H5T_NORM_MSBSET: + norm_s = ", msb always set"; + break; + case H5T_NORM_NONE: + norm_s = ", no normalization"; + break; + case H5T_NORM_ERROR: + norm_s = ", unknown normalization"; + break; + default: + ; + break; + } + 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); + 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); + h5tools_str_append(buffer, "\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos); + + /* Display internal padding */ + if (1+esize+msize<H5Tget_precision(type)) { + pad = H5Tget_inpad(type); + switch (pad) { + case H5T_PAD_ZERO: + pad_s = "zero"; + break; + case H5T_PAD_ONE: + pad_s = "one"; + break; + case H5T_PAD_BACKGROUND: + pad_s = "bkg"; + break; + case H5T_PAD_ERROR: + case H5T_NPAD: + pad_s = "unknown"; + break; + default: + ; + break; + } + h5tools_str_append(buffer, "\n%*s(internal padding bits are %s)", ind, "", pad_s); + } + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_cmpd_type + * + * Purpose: Print info about a compound data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +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 */ + hid_t subtype; /* member data type */ + unsigned nmembs; /* number of members */ + int n; /* miscellaneous counters */ + unsigned i; /* miscellaneous counters */ + + if (H5T_COMPOUND!=H5Tget_class(type)) return FALSE; + h5tools_str_append(buffer, "struct {"); + nmembs=H5Tget_nmembers(type); + for (i=0; i<nmembs; i++) { + + /* Name and offset */ + name = H5Tget_member_name(type, i); + 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); + + /* Member's type */ + subtype = H5Tget_member_type(type, i); + print_type(buffer, subtype, ind+4); + H5Tclose(subtype); + } + size = H5Tget_size(type); + h5tools_str_append(buffer, "\n%*s} %lu byte%s", + ind, "", (unsigned long)size, 1==size?"":"s"); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_enum_type + * + * Purpose: Print info about an enumeration data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Wednesday, December 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) +{ + char **name=NULL; /* member names */ + unsigned char *value=NULL; /* value array */ + unsigned char *copy = NULL; /* a pointer to value array */ + unsigned nmembs; /* number of members */ + int nchars; /* number of output characters */ + hid_t super; /* enum base integer type */ + hid_t native=-1; /* native integer data type */ + size_t dst_size; /* destination value type size */ + unsigned i; /* miscellaneous counters */ + size_t j; + + if (H5T_ENUM!=H5Tget_class(type)) return FALSE; + nmembs = H5Tget_nmembers(type); + assert(nmembs>0); + super = H5Tget_super(type); + 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: + * 1. long long -- the largest native signed integer + * 2. unsigned long long -- the largest native unsigned integer + * 3. raw format */ + if (H5Tget_size(type)<=sizeof(long long)) { + dst_size = sizeof(long long); + if (H5T_SGN_NONE==H5Tget_sign(type)) { + native = H5T_NATIVE_ULLONG; + } else { + native = H5T_NATIVE_LLONG; + } + } else { + dst_size = H5Tget_size(type); + } + + /* 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)); + for (i=0; i<nmembs; i++) { + name[i] = H5Tget_member_name(type, i); + H5Tget_member_value(type, i, value+i*H5Tget_size(type)); + } + + /* Convert values to native data type */ + if (native>0) H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT); + + /* Sort members by increasing value */ + /*not implemented yet*/ + + /* Print members */ + for (i=0; i<nmembs; i++) { + 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) { + h5tools_str_append(buffer, "0x"); + for (j=0; j<dst_size; j++) + 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, "%"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; + 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); + H5Tclose(super); + + if (0==nmembs) h5tools_str_append(buffer, "\n%*s <empty>", ind+4, ""); + h5tools_str_append(buffer, "\n%*s}", ind, ""); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_string_type + * + * Purpose: Print information about a string data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +print_string_type(h5tools_str_t *buffer, hid_t type, int UNUSED ind) +{ + H5T_str_t pad; + const char *pad_s=NULL; + H5T_cset_t cset; + const char *cset_s=NULL; + + if (H5T_STRING!=H5Tget_class(type)) return FALSE; + + /* Padding */ + pad = H5Tget_strpad(type); + switch (pad) { + case H5T_STR_NULLTERM: + pad_s = "null-terminated"; + break; + case H5T_STR_NULLPAD: + pad_s = "null-padded"; + break; + case H5T_STR_SPACEPAD: + pad_s = "space-padded"; + break; + case H5T_STR_RESERVED_3: + case H5T_STR_RESERVED_4: + case H5T_STR_RESERVED_5: + case H5T_STR_RESERVED_6: + case H5T_STR_RESERVED_7: + case H5T_STR_RESERVED_8: + case H5T_STR_RESERVED_9: + case H5T_STR_RESERVED_10: + case H5T_STR_RESERVED_11: + case H5T_STR_RESERVED_12: + case H5T_STR_RESERVED_13: + case H5T_STR_RESERVED_14: + case H5T_STR_RESERVED_15: + case H5T_STR_ERROR: + pad_s = "unknown-format"; + break; + default: + ; + break; + } + + /* Character set */ + cset = H5Tget_cset(type); + switch (cset) { + case H5T_CSET_ASCII: + cset_s = "ASCII"; + break; + case H5T_CSET_UTF8: + cset_s = "UTF-8"; + break; + case H5T_CSET_RESERVED_2: + case H5T_CSET_RESERVED_3: + case H5T_CSET_RESERVED_4: + case H5T_CSET_RESERVED_5: + case H5T_CSET_RESERVED_6: + case H5T_CSET_RESERVED_7: + case H5T_CSET_RESERVED_8: + case H5T_CSET_RESERVED_9: + case H5T_CSET_RESERVED_10: + case H5T_CSET_RESERVED_11: + case H5T_CSET_RESERVED_12: + case H5T_CSET_RESERVED_13: + case H5T_CSET_RESERVED_14: + case H5T_CSET_RESERVED_15: + case H5T_CSET_ERROR: + cset_s = "unknown-character-set"; + break; + default: + ; + break; + } + + if (H5Tis_variable_str(type)) { + h5tools_str_append(buffer, "variable-length"); + } + else { + h5tools_str_append(buffer, "%lu-byte", (unsigned long)H5Tget_size(type)); + } + h5tools_str_append(buffer, " %s %s string", pad_s, cset_s); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_reference_type + * + * Purpose: Prints information about a reference data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * Robb Matzke, 1999-06-04 + * Knows about object and dataset region references. + * + *------------------------------------------------------------------------- + */ +static hbool_t +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) { + 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)); + } + + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_opaque_type + * + * Purpose: Prints information about an opaque data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Monday, June 7, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +print_opaque_type(h5tools_str_t *buffer, hid_t type, int ind) +{ + char *tag; + size_t size; + + if (H5T_OPAQUE!=H5Tget_class(type)) return FALSE; + + size = H5Tget_size(type); + h5tools_str_append(buffer, "%lu-byte opaque type", (unsigned long)size); + if ((tag=H5Tget_tag(type))) { + h5tools_str_append(buffer, "\n%*s(tag = \"", ind, ""); + print_string(buffer, tag, FALSE); + h5tools_str_append(buffer, "\")"); + free(tag); + } + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_vlen_type + * + * Purpose: Print information about a variable-length type + * + * Return: Success: TRUE + * + * Failure: FALSE + * + * Programmer: Robb Matzke + * Friday, December 1, 2000 + * + * Modifications: + *------------------------------------------------------------------------- + */ +static hbool_t +print_vlen_type(h5tools_str_t *buffer, hid_t type, int ind) +{ + hid_t super; + + if (H5T_VLEN!=H5Tget_class(type)) return FALSE; + + h5tools_str_append(buffer, "variable length of\n%*s", ind+4, ""); + super = H5Tget_super(type); + print_type(buffer, super, ind+4); + H5Tclose(super); + return TRUE; +} + + +/*--------------------------------------------------------------------------- + * Purpose: Print information about an array type + * + * Return: Success: TRUE + * + * Failure: FALSE + * + * Programmer: Robb Matzke + * Thursday, January 31, 2002 + * + * Modifications: + *--------------------------------------------------------------------------- + */ +static hbool_t +print_array_type(h5tools_str_t *buffer, hid_t type, int ind) +{ + hid_t super; + int ndims, i; + hsize_t *dims=NULL; + + if (H5T_ARRAY!=H5Tget_class(type)) return FALSE; + ndims = H5Tget_array_ndims(type); + if (ndims) { + dims = (hsize_t *)malloc(ndims*sizeof(dims[0])); + H5Tget_array_dims2(type, dims); + + /* Print dimensions */ + for (i=0; i<ndims; i++) + h5tools_str_append(buffer, "%s%lu" , i?",":"[", dims[i]); + h5tools_str_append(buffer, "]"); + + free(dims); + } + else { + h5tools_str_append(buffer, " [SCALAR]\n", stdout); + } + + + /* Print parent type */ + h5tools_str_append(buffer, " "); + super = H5Tget_super(type); + print_type(buffer, super, ind+4); + H5Tclose(super); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_bitfield_type + * + * Purpose: Print information about a bitfield type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Pedro Vicente + * Tuesday, May 20, 2003 + * + * Modifications: + * Robb Matzke, LLNL 2003-06-05 + * Generalized Pedro's original if/then/else. Also display + * precision/offset information. + *------------------------------------------------------------------------- + */ +static hbool_t +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 */ + + if (H5T_BITFIELD!=H5Tget_class(type)) return FALSE; + if (H5Tget_size(type)>1) { + order = H5Tget_order(type); + if (H5T_ORDER_LE==order) { + order_s = " little-endian"; + } else if (H5T_ORDER_BE==order) { + order_s = " big-endian"; + } else if (H5T_ORDER_VAX==order) { + order_s = " mixed-endian"; + } else { + order_s = "unknown-byte-order"; + } + } else { + order_s = ""; + } + + h5tools_str_append(buffer, "%lu-bit%s bitfield", + (unsigned long)(8*H5Tget_size(type)), order_s); + print_precision(buffer, type, ind); + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: print_type + * + * Purpose: Prints a data type definition. The definition is printed + * without any leading space or trailing line-feed (although + * there might be line-feeds inside the type definition). The + * first line is assumed to have IND characters before it on + * the same line (printed by the caller). + * + * Return: void + * + * Programmer: Robb Matzke + * Thursday, November 5, 1998 + * + * Modifications: + * Robb Matzke, 1999-06-11 + * Prints the OID of shared data types. + * + *------------------------------------------------------------------------- + */ +static void +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) { + h5tools_str_append(buffer,"<ERROR>"); + return; + } + + /* Shared? If so then print the type's OID */ + if(H5Tcommitted(type)) { + H5O_info_t oi; + + if(H5Oget_info(type, &oi) >= 0) + h5tools_str_append(buffer,"shared-%lu:"H5_PRINTF_HADDR_FMT" ", + oi.fileno, oi.addr); + else + h5tools_str_append(buffer,"shared "); + } /* end if */ + + /* Print the type */ + 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 */ + h5tools_str_append(buffer,"%lu-byte class-%u unknown", + (unsigned long)H5Tget_size(type), (unsigned)data_class); +} + /*------------------------------------------------------------------------- * Function: dump_dataset_values @@ -1249,98 +2408,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(stdout, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + ctx.need_prefix = TRUE; + ctx.cur_column = curr_pos; + if (h5tools_dump_dset(stdout, info, &ctx, dset, -1, NULL) < 0) { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, " Unable to print data."); + h5tools_render_element(stdout, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0); + } H5Tclose(f_type); + + fprintf(stdout, "\n"); + + h5tools_str_close(&buffer); } @@ -1364,18 +2540,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,74 +2577,89 @@ 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(stdout, 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%lu", i?", ":"", size[i]); nelmts *= size[i]; } - puts("}"); + h5tools_str_append(&buffer, "}\n"); + h5tools_render_element(stdout, 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(stdout, 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(stdout, 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(stdout, 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(stdout, 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 reference type formats */ - info.dset_format = "DSET-%s "; - info.dset_hidefileno = 1; - info.dset_blockformat_pre = "%sBlk%lu: "; - info.dset_ptformat_pre = "%sPt%lu: "; - 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); @@ -1474,8 +2679,12 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo, 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); + if(H5Aread(attr, p_type, buf) >= 0) { + ctx.need_prefix = TRUE; + ctx.indent_level = 2; + ctx.cur_column = curr_pos; + h5tools_dump_mem(stdout, info, &ctx, attr, p_type, space, buf); + } /* Reclaim any VL memory, if necessary */ if (vl_data) @@ -1484,12 +2693,17 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo, free(buf); H5Tclose(p_type); } /* end if */ + fprintf(stdout, "\n"); H5Sclose(space); H5Tclose(type); H5Aclose(attr); - } else - putchar('\n'); + } + else { + fprintf(stdout, "\n"); + } + + h5tools_str_close(&buffer); return 0; } |