diff options
author | Robb Matzke <matzke@llnl.gov> | 1999-09-30 16:14:14 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1999-09-30 16:14:14 (GMT) |
commit | bdf0dbf7ed9a671cf915de65006ae5a5379c6941 (patch) | |
tree | 2117c72f7f589bd030d32dbc398c836e8a4524c8 /tools/h5tools.c | |
parent | 03d438979b7bc6a08d25d121676bbd2083254c80 (diff) | |
download | hdf5-bdf0dbf7ed9a671cf915de65006ae5a5379c6941.zip hdf5-bdf0dbf7ed9a671cf915de65006ae5a5379c6941.tar.gz hdf5-bdf0dbf7ed9a671cf915de65006ae5a5379c6941.tar.bz2 |
[svn-r1697] Changes since 19990915
----------------------
./src/H5public.h
We undefine a bunch of things that could get redefined in the config
file because some customers have applications that include headers
from multiple packages, all of which might be using autoconf.
Include <stdint.h> for the C9x types.
./test/h5test.h
More flushing of stdout for when testing is redirected down a pipe.
./tools/h5ls.c
Added a `-S' or `--simple' switch which causes the output to be
simplified somewhat for easier parsing by other scripts. For instance,
characters are escaped using a very simple mechanism instead of C's
more complicated backslash notation, data doesn't have `{}' or `[]'
characters interspersed for compound and array types, and data is
printed with exactly one element per line. This switch is now used by
an HDF5-to-HTML CGI script being developed for the DMF people.
./tools/h5tools.c
./tools/h5tools.h
The repeat threshold which controls how strings are printed when a
character repeats a bunch of times is now settable at runtime instead
of compile time. The default is to show all characters, like
"abceeeeeeeeeeeeeeeeeeeeeeeeeeeeeefgh"
But if you set it to something like 5 then any sequence of 5 or more
characters is replaced by something shorter, like:
"abc" 'e'x30 "fgh" or
Added an `str_locale' property which describes how to escape special
characters in strings. The default is C-like escapes but an
alternative is ESCAPE_HTML which replaces all non-alphanumeric
characters with a 3-character HTML escape of the form `%XX'
Fixed a bug where empty strings didn't even have the quote characters
printed. Now empty strings show up as `""' instead of absolutely
nothing.
Added a `per_line' property which controls the maximum number of
elements which will appear per line of output. The default is infinity
but in practice the right margin causes line breaks. By setting the
`per_line' value to one and the right margin to a very large value one
can achieve output with exactly one element per line.
Diffstat (limited to 'tools/h5tools.c')
-rw-r--r-- | tools/h5tools.c | 177 |
1 files changed, 101 insertions, 76 deletions
diff --git a/tools/h5tools.c b/tools/h5tools.c index 36ce038..5dbb7ff 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -61,12 +61,6 @@ int print_data(hid_t oid, hid_t _p_type, int obj_data); #define REPEAT_VERBOSE /* - * This is the original value of the repeat_threshold in the h5dump_sprint - * function. - */ -#define H5DEFAULT_REPEAT_THRESHOLD 8 - -/* * The output functions need a temporary buffer to hold a piece of the * dataset while it's being printed. This constant sets the limit on the * size of that temporary buffer in bytes. For efficiency's sake, choose the @@ -97,6 +91,7 @@ typedef struct h5dump_str_t { /* Output variables */ typedef struct h5dump_context_t { size_t cur_column; /*current column for output */ + size_t cur_elmt; /*current element/output line */ int need_prefix; /*is line prefix needed? */ int ndims; /*dimensionality */ hsize_t p_min_idx[H5S_MAX_RANK]; /*min selected index */ @@ -613,11 +608,6 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, static char fmt_llong[8], fmt_ullong[8]; H5T_str_t pad; H5G_stat_t sb; - int repeat_threshold = H5DEFAULT_REPEAT_THRESHOLD; - - if (programtype == H5DUMP){ - repeat_threshold = -1; /*-1 means any amount of repeat allowed*/ - } /* Build default formats for long long types */ if (!fmt_llong[0]) { @@ -645,37 +635,45 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, } else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) || H5Tequal(type, H5T_NATIVE_UCHAR))) { - switch (*((char*)vp)) { - case '"': - h5dump_str_append(str, "\\\""); - break; - case '\\': - h5dump_str_append(str, "\\\\"); - break; - case '\b': - h5dump_str_append(str, "\\b"); - break; - case '\f': - h5dump_str_append(str, "\\f"); - break; - case '\n': - h5dump_str_append(str, "\\n"); - break; - case '\r': - h5dump_str_append(str, "\\r"); - break; - case '\t': - h5dump_str_append(str, "\\t"); - break; - default: - if (isprint((int)(*((char*)vp)))) { - h5dump_str_append(str, "%c", *((char*)vp)); + if (ESCAPE_HTML==info->str_locale) { + if (*((char*)vp)<=' ' || *((char*)vp)>'~') { + h5dump_str_append(str, "%%%02X", *((unsigned char*)vp)); } else { - h5dump_str_append(str, "\\%03o", *((unsigned char*)vp)); + h5dump_str_append(str, "%c", *((char*)vp)); + } + } else { + switch (*((char*)vp)) { + case '"': + h5dump_str_append(str, "\\\""); + break; + case '\\': + h5dump_str_append(str, "\\\\"); + break; + case '\b': + h5dump_str_append(str, "\\b"); + break; + case '\f': + h5dump_str_append(str, "\\f"); + break; + case '\n': + h5dump_str_append(str, "\\n"); + break; + case '\r': + h5dump_str_append(str, "\\r"); + break; + case '\t': + h5dump_str_append(str, "\\t"); + break; + default: + if (isprint(*((char*)vp))) { + h5dump_str_append(str, "%c", *((char*)vp)); + } else { + h5dump_str_append(str, "\\%03o", *((unsigned char*)vp)); + } + break; } - break; } - + } else if (H5T_STRING==H5Tget_class(type)) { size = H5Tget_size(type); quote = '\0'; @@ -687,14 +685,12 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, /* * Count how many times the next character repeats. If the - * threshold is negative then that means it can repeat any number + * threshold is zero then that means it can repeat any number * of times. */ - if (repeat_threshold >= 0) { - j=1; + j=1; + if (info->str_repeat>0) { while (i+j<size && ((char*)vp)[i]==((char*)vp)[i+j]) j++; - } else { - j = repeat_threshold - 1; } /* @@ -703,7 +699,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, * the characters, then make sure the character to be repeated is * in it's own quote. */ - if (j>repeat_threshold) { + if (info->str_repeat>0 && j>info->str_repeat) { if (quote) h5dump_str_append(str, "%c", quote); quote = '\''; h5dump_str_append(str, "%s%c", i?" ":"", quote); @@ -713,39 +709,48 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, } /* Print the character */ - switch (((char*)vp)[i]) { - case '"': - h5dump_str_append(str, "\\\""); - break; - case '\\': - h5dump_str_append(str, "\\\\"); - break; - case '\b': - h5dump_str_append(str, "\\b"); - break; - case '\f': - h5dump_str_append(str, "\\f"); - break; - case '\n': - h5dump_str_append(str, "\\n"); - break; - case '\r': - h5dump_str_append(str, "\\r"); - break; - case '\t': - h5dump_str_append(str, "\\t"); - break; - default: - if (isprint((int)((char*)vp)[i])) { - h5dump_str_append(str, "%c", ((char*)vp)[i]); + if (ESCAPE_HTML==info->str_locale) { + if (((char*)vp)[i]<=' ' || ((char*)vp)[i]>'~') { + h5dump_str_append(str, "%%%02X", ((unsigned char*)vp)[i]); } else { - h5dump_str_append(str, "\\%03o", ((unsigned char*)vp)[i]); + h5dump_str_append(str, "%c", ((char*)vp)[i]); + } + } else { + switch (((char*)vp)[i]) { + case '"': + h5dump_str_append(str, "\\\""); + break; + case '\\': + h5dump_str_append(str, "\\\\"); + break; + case '\b': + h5dump_str_append(str, "\\b"); + break; + case '\f': + h5dump_str_append(str, "\\f"); + break; + case '\n': + h5dump_str_append(str, "\\n"); + break; + case '\r': + h5dump_str_append(str, "\\r"); + break; + case '\t': + h5dump_str_append(str, "\\t"); + break; + default: + if (isprint(((char*)vp)[i])) { + h5dump_str_append(str, "%c", ((char*)vp)[i]); + } else { + h5dump_str_append(str, "\\%03o", + ((unsigned char*)vp)[i]); + } + break; } - break; } - + /* Print the repeat count */ - if (j>repeat_threshold) { + if (info->str_repeat && j>info->str_repeat) { #ifdef REPEAT_VERBOSE h5dump_str_append(str, "%c repeats %d times", quote, j-1); #else @@ -756,6 +761,11 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, } } if (quote) h5dump_str_append(str, "%c", quote); + + if (0==i) { + h5dump_str_append(str, "\"\""); /*empty string*/ + } + } else if (H5Tequal(type, H5T_NATIVE_INT)) { h5dump_str_append(str, OPT(info->fmt_int, "%d"), @@ -1001,7 +1011,9 @@ h5dump_ncols(const char *s) * Monday, April 26, 1999 * * Modifications: - * + * Robb Matzke, 1999-09-29 + * If a new prefix is printed then the current element number is + * set back to zero. *------------------------------------------------------------------------- */ static void @@ -1036,6 +1048,7 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info, stream); } ctx->cur_column = ctx->prev_prefix_len = h5dump_str_len(&prefix); + ctx->cur_elmt = 0; ctx->need_prefix = 0; /* Free string */ @@ -1065,6 +1078,10 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info, * The `container' argument is the optional dataset for * reference types. * + * Robb Matzke, 1999-09-29 + * Understands the `per_line' property which indicates that + * every Nth element should begin a new line. + * *------------------------------------------------------------------------- */ static void @@ -1087,7 +1104,7 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, if (info->line_ncols>0) ncols = info->line_ncols; h5dump_simple_prefix(stream, info, ctx, 0, 0); - for (i=0; i<nelmts; i++) { + for (i=0; i<nelmts; i++, ctx->cur_elmt++) { /* Render the element */ h5dump_str_reset(&buffer); @@ -1135,6 +1152,14 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, strlen(OPT(info->line_suf, ""))) > ncols) { ctx->need_prefix = TRUE; } + + /* + * If too many elements have already been printed then we need to + * start a new line. + */ + if (info->line_per_line>0 && ctx->cur_elmt>=info->line_per_line) { + ctx->need_prefix = TRUE; + } /* * Each OPTIONAL_LINE_BREAK embedded in the rendered string can cause |