summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-09-22 15:27:26 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-09-22 15:27:26 (GMT)
commit6d9af583912f6cd35cdac05283740fdccc489cc4 (patch)
tree9c55a12cac6cdc6e7db890ce9f12e8fbbdd0bd39 /tools
parentb20de8612aac8f94916dd7813bec0c398c9bff4f (diff)
downloadhdf5-6d9af583912f6cd35cdac05283740fdccc489cc4.zip
hdf5-6d9af583912f6cd35cdac05283740fdccc489cc4.tar.gz
hdf5-6d9af583912f6cd35cdac05283740fdccc489cc4.tar.bz2
[svn-r714] Changes since 19980911
---------------------- This checkin is to fix a couple bugs for Jim Reus. Some features are not fully implemented but it shouldn't break anything. ./config/conclude.in ./test/Makefile.in `make clean' removes object files from the test directory as well as a couple more *.h5 temp files. ./config/hpux9.03 [NEW] New config file for HP/UX 9.03 ./src/H5B.c ./src/H5Bprivate.h ./src/H5Fistore.c ./src/H5G.c ./src/H5Gnode.c ./src/H5Gpkg.h ./src/H5Gprivate.h ./src/H5Gstab.c Not-yet-complete version of object removal. ./src/H5Fistore.c ./src/H5Fprivate.h Experimental optimizations, disabled by default. ./src/H5Fprivate.h Default low-level driver was changed to H5F_LOW_SEC instead of H5F_LOW_STDIO because the sec2 driver is much easier to debug. ./src/H5Fsplit.c ./src/H5G.c ./src/H5Z.c Changed a couple return statements to HRETURN. ./src/H5Odtype.c Removed a check for nested compound data types from back when they weren't implemented that raised an error. ./tools/h5tools.c Increased temp buffer sizes and added a check for buffer overflow so we fail an assertion (hopefully). This really needs to be fixed sometime. Added support for printing H5T_STRING data types.
Diffstat (limited to 'tools')
-rw-r--r--tools/h5tools.c100
1 files changed, 97 insertions, 3 deletions
diff --git a/tools/h5tools.c b/tools/h5tools.c
index 3994c57..d3cc110 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -108,14 +108,19 @@ static void
h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
{
size_t i, n, offset, size, dims[4], nelmts;
- char temp[1024], *name;
+ unsigned overflow = 0xaaaaaaaa;
+ char temp[8192];
+ char *name, quote='\0';
hid_t memb;
int nmembs, j, k, ndims;
+ const int repeat_threshold = 8;
if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
sprintf(temp, "%g", *((double*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
sprintf(temp, "%g", *((float*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_CHAR) ||
H5Tequal(type, H5T_NATIVE_UCHAR)) {
switch (*((char*)vp)) {
@@ -145,18 +150,93 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
else sprintf(temp, "\\%03o", *((unsigned char*)vp));
break;
}
+
+ } else if (H5T_STRING==H5Tget_class(type)) {
+ size = H5Tget_size(type);
+ temp[0] = '\0';
+ quote = '\0';
+
+ for (i=0; i<size; i++) {
+
+ /* Count how many times the next character repeats */
+ j=1;
+ while (i+j<size && ((char*)vp)[i]==((char*)vp)[i+j]) j++;
+
+ /*
+ * Print the opening quote. If the repeat count is high enough
+ * to warrant printing the number of repeats instead of
+ * enumerating the characters, then make sure the character to be
+ * repeated is in it's own quote.
+ */
+ if (j>repeat_threshold) {
+ if (quote) sprintf(temp+strlen(temp), "%c", quote);
+ quote = '\'';
+ sprintf(temp+strlen(temp), "%s%c", i?" ":"", quote);
+ } else if (!quote) {
+ quote = '"';
+ sprintf(temp+strlen(temp), "%s%c", i?" ":"", quote);
+ }
+
+ /* Print the character */
+ switch (((char*)vp)[i]) {
+ case '"':
+ strcat(temp, "\\\"");
+ break;
+ case '\\':
+ strcat(temp, "\\\\");
+ break;
+ case '\b':
+ strcat(temp, "\\b");
+ break;
+ case '\f':
+ strcat(temp, "\\f");
+ break;
+ case '\n':
+ strcat(temp, "\\n");
+ break;
+ case '\r':
+ strcat(temp, "\\r");
+ break;
+ case '\t':
+ strcat(temp, "\\t");
+ break;
+ default:
+ if (isprint(((char*)vp)[i])) {
+ sprintf(temp+strlen(temp), "%c", ((char*)vp)[i]);
+ } else {
+ sprintf(temp+strlen(temp), "\\%03o",
+ ((unsigned char*)vp)[i]);
+ }
+ break;
+ }
+
+ /* Print the repeat count */
+ if (j>repeat_threshold) {
+ sprintf(temp+strlen(temp), "%c repeats %d times", quote, j-1);
+ quote = '\0';
+ i += j-1;
+ }
+ }
+ if (quote) sprintf(temp+strlen(temp), "%c", quote);
+
} else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
sprintf(temp, "%d", *((short*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
sprintf(temp, "%u", *((unsigned short*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_INT)) {
sprintf(temp, "%d", *((int*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_UINT)) {
sprintf(temp, "%u", *((unsigned*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_LONG)) {
sprintf(temp, "%ld", *((long*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
sprintf(temp, "%lu", *((unsigned long*)vp));
+
} else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) {
if (sizeof(hssize_t)==sizeof(long)) {
sprintf(temp, "%ld", *((long*)vp));
@@ -167,6 +247,7 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
strcat(fmt, "d");
sprintf(temp, fmt, *((long long*)vp));
}
+
} else if (H5Tequal(type, H5T_NATIVE_HSIZE)) {
if (sizeof(hsize_t)==sizeof(long)) {
sprintf(temp, "%lu", *((unsigned long*)vp));
@@ -177,6 +258,7 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
strcat(fmt, "u");
sprintf(temp, fmt, *((unsigned long long*)vp));
}
+
} else if (H5T_COMPOUND==H5Tget_class(type)) {
nmembs = H5Tget_nmembers(type);
strcpy(temp, OPT(info->cmpd_pre, "{"));
@@ -206,6 +288,7 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
H5Tclose(memb);
}
strcat(temp, OPT(info->cmpd_suf, "}"));
+
} else {
strcpy(temp, "0x");
n = H5Tget_size(type);
@@ -215,6 +298,12 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
}
sprintf(s, OPT(info->elmt_fmt, "%s"), temp);
+
+ /*
+ * We should really fix this so it's not possible to overflow the `temp'
+ * buffer.
+ */
+ assert(overflow==0xaaaaaaaa);
}
@@ -250,7 +339,7 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type)
hsize_t p_max_idx[8]; /*max selected index */
size_t p_type_nbytes; /*size of memory type */
hsize_t p_nelmts; /*total selected elmts */
- char p_buf[256]; /*output string */
+ char p_buf[8192]; /*output string */
size_t p_column=0; /*output column */
size_t p_ncolumns=80; /*default num columns */
char p_prefix[1024]; /*line prefix string */
@@ -444,6 +533,12 @@ h5dump_fixtype(hid_t f_type)
}
break;
+ case H5T_STRING:
+ m_type = H5Tcopy(f_type);
+ H5Tset_cset(m_type, H5T_CSET_ASCII);
+ H5Tset_strpad(m_type, H5T_STR_NULLPAD);
+ break;
+
case H5T_COMPOUND:
/*
* We have to do this in two steps. The first step scans the file
@@ -494,7 +589,6 @@ h5dump_fixtype(hid_t f_type)
break;
case H5T_TIME:
- case H5T_STRING:
case H5T_BITFIELD:
case H5T_OPAQUE:
/*