summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/lib/h5tools.c10
-rw-r--r--tools/lib/h5tools_str.c53
-rw-r--r--tools/testfiles/tbitfields.h5.xml4
-rw-r--r--tools/testfiles/topaque.h5.xml4
4 files changed, 45 insertions, 26 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 50ec051..4200c50 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -445,6 +445,11 @@ h5tools_simple_prefix(FILE *stream, const h5dump_t *info,
* Robb Matzke, 1999-09-29
* Understands the `per_line' property which indicates that every Nth
* element should begin a new line.
+ *
+ * Robb Matzke, LLNL, 2003-06-05
+ * Do not dereference the memory for a variable-length string here.
+ * Deref in h5tools_str_sprint() instead so recursive types are
+ * handled correctly.
*-------------------------------------------------------------------------
*/
static void
@@ -481,11 +486,6 @@ h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) {
/* Render the element */
h5tools_str_reset(&buffer);
- if(H5Tis_variable_str(type)) {
- tmp = ((unsigned char**)mem)[i];
- h5tools_str_sprint(&buffer, info, container, type, tmp, ctx);
-
- } else
h5tools_str_sprint(&buffer, info, container, type, mem + i * size, ctx);
if (i + 1 < nelmts || (flags & END_OF_DATA) == 0)
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"));
diff --git a/tools/testfiles/tbitfields.h5.xml b/tools/testfiles/tbitfields.h5.xml
index f249fa7..4e71669 100644
--- a/tools/testfiles/tbitfields.h5.xml
+++ b/tools/testfiles/tbitfields.h5.xml
@@ -38,8 +38,8 @@ Expected output for 'h5dump --xml tbitfields.h5'
</DataType>
<Data>
<DataFromFile>
- 0xfffe 0xfdfc 0xfbfa 0xf9f8 0xf7f6 0xf5f4 0xf3f2 0xf1f0 0xefee
- 0xedec 0xebea 0xe9e8 0xe7e6 0xe5e4 0xe3e2 0xe1e0
+ ff:fe fd:fc fb:fa f9:f8 f7:f6 f5:f4 f3:f2 f1:f0 ef:ee ed:ec eb:ea
+ e9:e8 e7:e6 e5:e4 e3:e2 e1:e0
</DataFromFile>
</Data>
</Dataset>
diff --git a/tools/testfiles/topaque.h5.xml b/tools/testfiles/topaque.h5.xml
index 688f2b8..639c608 100644
--- a/tools/testfiles/topaque.h5.xml
+++ b/tools/testfiles/topaque.h5.xml
@@ -18,8 +18,8 @@ Expected output for 'h5dump --xml topaque.h5'
</DataType>
<Data>
<DataFromFile>
- 0x0063016202610360045f055e065d075c085b095a0a590b580c570d560e550f541053115212511350144f154e164d174c184b194a1a491b481c471d461e451f442043214222412340243f253e263d273c283b293a2a392b382c372d362e352f343033313232313330342f352e362d372c382b392a3a293b283c273d263e253f244023412242214320441f451e461d471c481b491a4a194b184c174d164e154f145013511252115310540f550e560d570c580b590a5a095b085c075d065e055f046003610262016300
- 0x3800002c3c000027340001ea04000012000000000008a4640000000000000000000000000000000000000000ef7ec9c000000001effffa84effffa8c0003fc000000000000000000effffa2000012e84effffa2000012e5800000003effffa8400000004effffa8c00000005effffaf0000000000000000000000001effffa84effffa8c0003fc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ 00:63:01:62:02:61:03:60:04:5f:05:5e:06:5d:07:5c:08:5b:09:5a:0a:59:0b:58:0c:57:0d:56:0e:55:0f:54:10:53:11:52:12:51:13:50:14:4f:15:4e:16:4d:17:4c:18:4b:19:4a:1a:49:1b:48:1c:47:1d:46:1e:45:1f:44:20:43:21:42:22:41:23:40:24:3f:25:3e:26:3d:27:3c:28:3b:29:3a:2a:39:2b:38:2c:37:2d:36:2e:35:2f:34:30:33:31:32:32:31:33:30:34:2f:35:2e:36:2d:37:2c:38:2b:39:2a:3a:29:3b:28:3c:27:3d:26:3e:25:3f:24:40:23:41:22:42:21:43:20:44:1f:45:1e:46:1d:47:1c:48:1b:49:1a:4a:19:4b:18:4c:17:4d:16:4e:15:4f:14:50:13:51:12:52:11:53:10:54:0f:55:0e:56:0d:57:0c:58:0b:59:0a:5a:09:5b:08:5c:07:5d:06:5e:05:5f:04:60:03:61:02:62:01:63:00
+ 38:00:00:2c:3c:00:00:27:34:00:01:ea:04:00:00:12:00:00:00:00:00:08:a4:64:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:ef:7e:c9:c0:00:00:00:01:ef:ff:fa:84:ef:ff:fa:8c:00:03:fc:00:00:00:00:00:00:00:00:00:ef:ff:fa:20:00:01:2e:84:ef:ff:fa:20:00:01:2e:58:00:00:00:03:ef:ff:fa:84:00:00:00:04:ef:ff:fa:8c:00:00:00:05:ef:ff:fa:f0:00:00:00:00:00:00:00:00:00:00:00:01:ef:ff:fa:84:ef:ff:fa:8c:00:03:fc:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
</DataFromFile>
</Data>
</Dataset>