summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_str.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-06-09 19:29:28 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-06-09 19:29:28 (GMT)
commit103f7b4c921220c0d5401a46b5a095c32f1f8540 (patch)
tree6bda3bcead23564f554772247557ecb34089d786 /tools/lib/h5tools_str.c
parent19488a94fda323c639a6cdc8595102f44c921281 (diff)
downloadhdf5-103f7b4c921220c0d5401a46b5a095c32f1f8540.zip
hdf5-103f7b4c921220c0d5401a46b5a095c32f1f8540.tar.gz
hdf5-103f7b4c921220c0d5401a46b5a095c32f1f8540.tar.bz2
[svn-r7006] Purpose:
Bug fix/new feature Description: Teach h5dump/h5ls to display variable-length datatypes correctly. Change "raw byte" output of array elements from "0xde8141b1a818" to "de:81:41:b1:a8:18" so that it's easier for users to read. Platforms tested: FreeBSD 4.8 (sleipnir) h5committest Misc. update: Patch provided by Robb Matzke (matzke@llnl.gov)
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r--tools/lib/h5tools_str.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
index 4ccaf7c..6553c5a 100644
--- a/tools/lib/h5tools_str.c
+++ b/tools/lib/h5tools_str.c
@@ -495,6 +495,15 @@ h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch)
* Added support for printing raw data. If info->raw is non-zero
* then data is printed in hexadecimal format.
*
+ * Robb Matzke, 2003-01-10
+ * Binary output format is dd:dd:... instead of 0xdddd... so it
+ * doesn't look like a hexadecimal integer, and thus users will
+ * be less likely to complain that HDF5 didn't properly byte
+ * swap their data during type conversion.
+ *
+ * Robb Matzke, LLNL, 2003-06-05
+ * If TYPE is a variable length string then the pointer to
+ * the value to pring (VP) is a pointer to a `char*'.
*-------------------------------------------------------------------------
*/
char *
@@ -537,12 +546,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
if (info->raw) {
size_t i;
-
- h5tools_str_append(str, "0x");
n = H5Tget_size(type);
-
- for (i = 0; i < n; i++)
+ if (1==n) {
+ h5tools_str_append(str, OPT(info->fmt_raw, "0x%02x"), ucp_vp[0]);
+ } else {
+ for (i = 0; i < n; i++) {
+ if (i) h5tools_str_append(str, ":");
h5tools_str_append(str, OPT(info->fmt_raw, "%02x"), ucp_vp[i]);
+ }
+ }
} else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
memcpy(&tempfloat, vp, sizeof(float));
h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat);
@@ -554,16 +566,21 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
h5tools_print_char(str, info, (unsigned char)(*ucp_vp));
} else if (H5T_STRING == H5Tget_class(type)) {
unsigned int i;
+ char *s;
quote = '\0';
if(H5Tis_variable_str(type)) {
- size = HDstrlen(cp_vp);
+ /* cp_vp is the pointer into the struct where a `char*' is stored. So we have
+ * to dereference the pointer to get the `char*' to pass to HDstrlen(). */
+ s = *(char**)cp_vp;
+ size = HDstrlen(s);
} else {
+ s = cp_vp;
size = H5Tget_size(type);
}
pad = H5Tget_strpad(type);
- for (i = 0; i < size && (cp_vp[i] != '\0' || pad != H5T_STR_NULLTERM); i++) {
+ for (i=0; i<size && (s[i] || pad!=H5T_STR_NULLTERM); i++) {
int j = 1;
/*
@@ -572,7 +589,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
* of times.
*/
if (info->str_repeat > 0)
- while (i + j < size && cp_vp[i] == cp_vp[i + j])
+ while (i + j < size && s[i] == s[i + j])
j++;
/*
@@ -593,7 +610,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
}
/* Print the character */
- h5tools_print_char(str, info, (unsigned char)(ucp_vp[i]));
+ h5tools_print_char(str, info, (unsigned char)(s[i]));
/* Print the repeat count */
if (info->str_repeat && j > info->str_repeat) {
@@ -730,12 +747,13 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
h5tools_str_append(str, h5tools_escape(enum_name, sizeof(enum_name), TRUE));
} else {
size_t i;
-
- h5tools_str_append(str, "0x");
n = H5Tget_size(type);
-
+ if (1==n) {
+ h5tools_str_append(str, "0x%02x", ucp_vp[0]);
+ } else {
for (i = 0; i < n; i++)
- h5tools_str_append(str, "%02x", ucp_vp[i]);
+ h5tools_str_append(str, "%s%02x", i?":":"", ucp_vp[i]);
+ }
}
} else if (H5Tequal(type, H5T_STD_REF_DSETREG)) {
/*
@@ -897,12 +915,13 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
} else {
/* All other types get printed as hexadecimal */
size_t i;
-
- h5tools_str_append(str, "0x");
n = H5Tget_size(type);
-
- for (i = 0; i < n; i++)
- h5tools_str_append(str, "%02x", ucp_vp[i]);
+ if (1==n) {
+ h5tools_str_append(str, "0x%02x", ucp_vp[0]);
+ } else {
+ for (i = 0; i < n; i++)
+ h5tools_str_append(str, "%s%02x", i?":":"", ucp_vp[i]);
+ }
}
return h5tools_str_fmt(str, start, OPT(info->elmt_fmt, "%s"));