summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5tools.c72
-rw-r--r--tools/lib/h5tools.h7
-rw-r--r--tools/lib/h5tools_dump.c6
-rw-r--r--tools/lib/h5tools_utils.c18
4 files changed, 68 insertions, 35 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 3e29cbd..254c8b4 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -40,6 +40,7 @@ hid_t H5tools_ERR_CLS_g = -1;
hid_t H5E_tools_g = -1;
hid_t H5E_tools_min_id_g = -1;
int compound_data;
+FILE *rawattrstream; /* should initialize to stdout but gcc moans about it */
FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */
FILE *rawoutstream; /* should initialize to stdout but gcc moans about it */
FILE *rawerrorstream; /* should initialize to stderr but gcc moans about it */
@@ -119,6 +120,8 @@ h5tools_init(void)
H5tools_ERR_STACK_g = H5Ecreate_stack();
H5TOOLS_INIT_ERROR()
+ if (!rawattrstream)
+ rawattrstream = stdout;
if (!rawdatastream)
rawdatastream = stdout;
if (!rawoutstream)
@@ -157,6 +160,12 @@ h5tools_close(void)
H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
if(tools_func!=NULL)
H5Eprint2(H5tools_ERR_STACK_g, rawerrorstream);
+ if (rawattrstream && rawattrstream != stdout) {
+ if (fclose(rawattrstream))
+ perror("closing rawattrstream");
+ else
+ rawattrstream = NULL;
+ }
if (rawdatastream && rawdatastream != stdout) {
if (fclose(rawdatastream))
perror("closing rawdatastream");
@@ -573,6 +582,9 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
size_t templength = 0;
int i, indentlevel = 0;
+ if (stream == NULL)
+ return;
+
if (!ctx->need_prefix)
return;
@@ -581,9 +593,9 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
/* Terminate previous line, if any */
if (ctx->cur_column) {
- HDfputs(OPT(info->line_suf, ""), stream);
+ PUTSTREAM(OPT(info->line_suf, ""), stream);
HDputc('\n', stream);
- HDfputs(OPT(info->line_sep, ""), stream);
+ PUTSTREAM(OPT(info->line_sep, ""), stream);
}
/* Calculate new prefix */
@@ -607,23 +619,26 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
the prefix is printed one indentation level before */
if (info->pindex) {
for (i = 0; i < indentlevel - 1; i++) {
- HDfputs(h5tools_str_fmt(&str, 0, info->line_indent), stream);
+ PUTSTREAM(h5tools_str_fmt(&str, 0, info->line_indent), stream);
}
}
- if (elmtno == 0 && secnum == 0 && info->line_1st)
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream);
- else if (secnum && info->line_cont)
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream);
- else
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream);
+ if (elmtno == 0 && secnum == 0 && info->line_1st) {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_1st), stream);
+ }
+ else if (secnum && info->line_cont) {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_cont), stream);
+ }
+ else {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_pre), stream);
+ }
templength = h5tools_str_len(&prefix);
for (i = 0; i < indentlevel; i++) {
/*we already made the indent for the array indices case */
if (!info->pindex) {
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream);
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_indent), stream);
templength += h5tools_str_len(&prefix);
}
else {
@@ -662,6 +677,9 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
size_t templength = 0;
int i, indentlevel = 0;
+ if (stream == NULL)
+ return;
+
if (!ctx->need_prefix)
return;
@@ -670,9 +688,9 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
/* Terminate previous line, if any */
if (ctx->cur_column) {
- HDfputs(OPT(info->line_suf, ""), stream);
+ PUTSTREAM(OPT(info->line_suf, ""), stream);
HDputc('\n', stream);
- HDfputs(OPT(info->line_sep, ""), stream);
+ PUTSTREAM(OPT(info->line_sep, ""), stream);
}
/* Calculate new prefix */
@@ -696,23 +714,26 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
the prefix is printed one indentation level before */
if (info->pindex) {
for (i = 0; i < indentlevel - 1; i++) {
- HDfputs(h5tools_str_fmt(&str, 0, info->line_indent), stream);
+ PUTSTREAM(h5tools_str_fmt(&str, 0, info->line_indent), stream);
}
}
- if (elmtno == 0 && secnum == 0 && info->line_1st)
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream);
- else if (secnum && info->line_cont)
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream);
- else
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream);
+ if (elmtno == 0 && secnum == 0 && info->line_1st) {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_1st), stream);
+ }
+ else if (secnum && info->line_cont) {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_cont), stream);
+ }
+ else {
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_pre), stream);
+ }
templength = h5tools_str_len(&prefix);
for (i = 0; i < indentlevel; i++) {
/*we already made the indent for the array indices case */
if (!info->pindex) {
- HDfputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream);
+ PUTSTREAM(h5tools_str_fmt(&prefix, 0, info->line_indent), stream);
templength += h5tools_str_len(&prefix);
}
else {
@@ -766,6 +787,9 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info,
int secnum; /*section sequence number */
int multiline; /*datum was multiline */
+ if (stream == NULL)
+ return dimension_break;
+
s = h5tools_str_fmt(buffer, 0, "%s");
/*
@@ -870,12 +894,12 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info,
h5tools_simple_prefix(stream, info, ctx, *curr_pos, secnum);
}
else if ((local_elmt_counter || ctx->continuation) && secnum == 0) {
- HDfputs(OPT(info->elmt_suf2, " "), stream);
+ PUTSTREAM(OPT(info->elmt_suf2, " "), stream);
ctx->cur_column += HDstrlen(OPT(info->elmt_suf2, " "));
}
/* Print the section */
- HDfputs(section, stream);
+ PUTSTREAM(section, stream);
ctx->cur_column += HDstrlen(section);
}
@@ -1026,12 +1050,12 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
h5tools_region_simple_prefix(stream, info, ctx, local_elmt_counter, ptdata, secnum);
}
else if ((local_elmt_counter || ctx->continuation) && secnum == 0) {
- HDfputs(OPT(info->elmt_suf2, " "), stream);
+ PUTSTREAM(OPT(info->elmt_suf2, " "), stream);
ctx->cur_column += HDstrlen(OPT(info->elmt_suf2, " "));
}
/* Print the section */
- HDfputs(section, stream);
+ PUTSTREAM(section, stream);
ctx->cur_column += HDstrlen(section);
}
diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h
index 4fbd84f..efadba4 100644
--- a/tools/lib/h5tools.h
+++ b/tools/lib/h5tools.h
@@ -36,6 +36,12 @@
#define H5TOOLS_DUMP_MAX_RANK H5S_MAX_RANK
+/* Stream macros */
+#define FLUSHSTREAM(S) if(S != NULL) HDfflush(S)
+#define PRINTSTREAM(S, F, ...) if(S != NULL) HDfprintf(S, F, __VA_ARGS__)
+#define PRINTVALSTREAM(S, V) if(S != NULL) HDfprintf(S, V)
+#define PUTSTREAM(X,S) if(S != NULL) HDfputs(X, S);
+
/*
* Strings for output - these were duplicated from the h5dump.h
* file in order to support region reference data display
@@ -524,6 +530,7 @@ H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display
H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */
H5TOOLS_DLLVAR int packed_data_length; /* lengtht of packed bits to display */
H5TOOLS_DLLVAR unsigned long long packed_data_mask; /* mask in which packed bits to display */
+H5TOOLS_DLLVAR FILE *rawattrstream; /* output stream for raw attribute data */
H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */
H5TOOLS_DLLVAR FILE *rawoutstream; /* output stream for raw output */
H5TOOLS_DLLVAR FILE *rawerrorstream; /* output stream for raw error */
diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c
index c68c699..f83c664 100644
--- a/tools/lib/h5tools_dump.c
+++ b/tools/lib/h5tools_dump.c
@@ -283,9 +283,9 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
*to the ctx->size_last_dim. */
/* binary dump */
- if (bin_output) {
+ if (bin_output && (rawdatastream != NULL)) {
if (render_bin_output(rawdatastream, container, type, _mem, nelmts) < 0) {
- HDfprintf(rawoutstream,"\nError in writing binary stream\n");
+ PRINTVALSTREAM(rawoutstream, "\nError in writing binary stream\n");
}
} /* end if */
else {
@@ -1834,7 +1834,7 @@ h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *c
if (H5Sis_simple(space) <= 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sis_simple failed")
- H5_LEAVE(h5tools_dump_simple_mem(stream, info, ctx, obj_id, type, space, mem))
+ H5_LEAVE(h5tools_dump_simple_mem(rawattrstream, info, ctx, obj_id, type, space, mem))
CATCH
return ret_value;
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index 79322bc..d45eab2 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -152,8 +152,9 @@ error_msg(const char *fmt, ...)
va_list ap;
HDva_start(ap, fmt);
- HDfflush(rawdatastream);
- HDfflush(rawoutstream);
+ FLUSHSTREAM(rawattrstream);
+ FLUSHSTREAM(rawdatastream);
+ FLUSHSTREAM(rawoutstream);
HDfprintf(rawerrorstream, "%s error: ", h5tools_getprogname());
HDvfprintf(rawerrorstream, fmt, ap);
@@ -182,8 +183,9 @@ warn_msg(const char *fmt, ...)
va_list ap;
HDva_start(ap, fmt);
- HDfflush(rawdatastream);
- HDfflush(rawoutstream);
+ FLUSHSTREAM(rawattrstream);
+ FLUSHSTREAM(rawdatastream);
+ FLUSHSTREAM(rawoutstream);
HDfprintf(rawerrorstream, "%s warning: ", h5tools_getprogname());
HDvfprintf(rawerrorstream, fmt, ap);
HDva_end(ap);
@@ -388,7 +390,7 @@ indentation(int x)
{
if (x < h5tools_nCols) {
while (x-- > 0)
- HDfprintf(rawoutstream, " ");
+ PRINTVALSTREAM(rawoutstream, " ");
}
else {
HDfprintf(rawerrorstream, "error: the indentation exceeds the number of cols.\n");
@@ -414,7 +416,7 @@ indentation(int x)
void
print_version(const char *progname)
{
- HDfprintf(rawoutstream, "%s: Version %u.%u.%u%s%s\n",
+ PRINTSTREAM(rawoutstream, "%s: Version %u.%u.%u%s%s\n",
progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE,
((char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE);
}
@@ -494,9 +496,9 @@ dump_table(char* tablename, table_t *table)
{
unsigned u;
- HDfprintf(rawoutstream,"%s: # of entries = %d\n", tablename,table->nobjs);
+ PRINTSTREAM(rawoutstream,"%s: # of entries = %d\n", tablename,table->nobjs);
for (u = 0; u < table->nobjs; u++)
- HDfprintf(rawoutstream,"%a %s %d %d\n", table->objs[u].objno,
+ PRINTSTREAM(rawoutstream,"%a %s %d %d\n", table->objs[u].objno,
table->objs[u].objname,
table->objs[u].displayed, table->objs[u].recorded);
}