summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2012-02-24 21:14:47 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2012-02-24 21:14:47 (GMT)
commit202c36682b47239079f547f274fe5d4e9f78f27b (patch)
treeb8b5ea94e4017b9588795a93a6de23a3ca33ab1c /tools/lib
parent2dffa66ef78426ea1eef3aaa2d5abcb11d0c26f8 (diff)
downloadhdf5-202c36682b47239079f547f274fe5d4e9f78f27b.zip
hdf5-202c36682b47239079f547f274fe5d4e9f78f27b.tar.gz
hdf5-202c36682b47239079f547f274fe5d4e9f78f27b.tar.bz2
[svn-r21985] Tools must call h5tools_init before command_line parsing or using tools_mesg functions.
Tools library uses alais variables for stdout, stderr and tools library uses HDfprintf() functions. Tested: local linux
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5tools.c22
-rw-r--r--tools/lib/h5tools.h4
-rw-r--r--tools/lib/h5tools_dump.c6
-rw-r--r--tools/lib/h5tools_utils.c39
4 files changed, 47 insertions, 24 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index ef32cde..30b8f33 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -40,6 +40,8 @@ hid_t H5E_tools_g = -1;
hid_t H5E_tools_min_id_g = -1;
int compound_data;
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 */
int bin_output; /* binary output */
int bin_form; /* binary form */
int region_output; /* region output */
@@ -117,6 +119,10 @@ h5tools_init(void)
if (!rawdatastream)
rawdatastream = stdout;
+ if (!rawoutstream)
+ rawoutstream = stdout;
+ if (!rawerrorstream)
+ rawerrorstream = stderr;
h5tools_dump_init();
@@ -150,6 +156,18 @@ h5tools_close(void)
else
rawdatastream = NULL;
}
+ if (rawoutstream && rawoutstream != stdout) {
+ if (fclose(rawoutstream))
+ perror("closing rawoutstream");
+ else
+ rawoutstream = NULL;
+ }
+ if (rawerrorstream && rawerrorstream != stderr) {
+ if (fclose(rawerrorstream))
+ perror("closing rawerrorstream");
+ else
+ rawerrorstream = NULL;
+ }
/* Clean up the reference path table, if it's been used */
term_ref_path_table();
@@ -1047,7 +1065,7 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims)
*-------------------------------------------------------------------------
*/
int
-do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem)
+do_bin_output(FILE *stream, FILE *err_stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem)
{
HERR_INIT(int, SUCCEED)
unsigned char *mem = (unsigned char*)_mem;
@@ -1059,7 +1077,7 @@ do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_m
for (i = 0; i < nelmts; i++) {
if (render_bin_output(stream, container, tid, mem + i * size) < 0) {
- printf("\nError in writing binary stream\n");
+ HDfprintf(err_stream,"\nError in writing binary stream\n");
return FAIL;
}
}
diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h
index a8f43b3..0f4b271 100644
--- a/tools/lib/h5tools.h
+++ b/tools/lib/h5tools.h
@@ -525,6 +525,8 @@ 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 *rawdatastream; /* output stream for raw data */
+H5TOOLS_DLLVAR FILE *rawoutstream; /* output stream for raw output */
+H5TOOLS_DLLVAR FILE *rawerrorstream; /* output stream for raw error */
H5TOOLS_DLLVAR int bin_output; /* binary output */
H5TOOLS_DLLVAR int bin_form; /* binary form */
H5TOOLS_DLLVAR int region_output; /* region output */
@@ -558,7 +560,7 @@ H5TOOLS_DLL void h5tools_simple_prefix(FILE *stream, const h5tool_format_t *i
H5TOOLS_DLL void h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum);
-H5TOOLS_DLL int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem);
+H5TOOLS_DLL int do_bin_output(FILE *stream, FILE *err_stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem);
H5TOOLS_DLL int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem);
H5TOOLS_DLL int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream,
hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata);
diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c
index 98945aa..9657b50 100644
--- a/tools/lib/h5tools_dump.c
+++ b/tools/lib/h5tools_dump.c
@@ -297,7 +297,7 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
/* binary dump */
if (bin_output) {
- do_bin_output(rawdatastream, container, nelmts, type, _mem);
+ do_bin_output(rawdatastream, rawoutstream, container, nelmts, type, _mem);
} /* end if */
else {
/* setup */
@@ -1754,7 +1754,7 @@ h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *
h5tool_format_t info_dflt;
/* Use default values */
if (!stream)
- stream = stdout;
+ stream = rawoutstream;
if (!info) {
HDmemset(&info_dflt, 0, sizeof info_dflt);
@@ -1826,7 +1826,7 @@ h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *c
/* Use default values */
if (!stream)
- stream = stdout;
+ stream = rawoutstream;
if (!info) {
HDmemset(&info_dflt, 0, sizeof(info_dflt));
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index dbe1875..4505609 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "h5tools.h"
#include "h5tools_utils.h"
#include "H5private.h"
#include "h5trav.h"
@@ -115,7 +116,7 @@ void parallel_print(const char* format, ...)
overflow_file = HDtmpfile();
if(overflow_file == NULL)
- HDfprintf(stderr, "warning: could not create overflow file. Output may be truncated.\n");
+ HDfprintf(rawerrorstream, "warning: could not create overflow file. Output may be truncated.\n");
else
bytes_written = HDvfprintf(overflow_file, format, ap);
}
@@ -151,9 +152,10 @@ error_msg(const char *fmt, ...)
va_list ap;
HDva_start(ap, fmt);
- HDfflush(stdout);
- HDfprintf(stderr, "%s error: ", h5tools_getprogname());
- HDvfprintf(stderr, fmt, ap);
+ HDfflush(rawdatastream);
+ HDfflush(rawoutstream);
+ HDfprintf(rawerrorstream, "%s error: ", h5tools_getprogname());
+ HDvfprintf(rawerrorstream, fmt, ap);
HDva_end(ap);
}
@@ -180,9 +182,10 @@ warn_msg(const char *fmt, ...)
va_list ap;
HDva_start(ap, fmt);
- HDfflush(stdout);
- HDfprintf(stderr, "%s warning: ", h5tools_getprogname());
- HDvfprintf(stderr, fmt, ap);
+ HDfflush(rawdatastream);
+ HDfflush(rawoutstream);
+ HDfprintf(rawerrorstream, "%s warning: ", h5tools_getprogname());
+ HDvfprintf(rawerrorstream, fmt, ap);
HDva_end(ap);
}
@@ -266,7 +269,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
}
else if (l_opts[i].has_arg == require_arg) {
if (opt_err)
- HDfprintf(stderr,
+ HDfprintf(rawerrorstream,
"%s: option required for \"--%s\" flag\n",
argv[0], arg);
@@ -276,7 +279,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
else {
if (arg[len] == '=') {
if (opt_err)
- HDfprintf(stderr,
+ HDfprintf(rawerrorstream,
"%s: no option required for \"%s\" flag\n",
argv[0], arg);
@@ -291,7 +294,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (l_opts[i].name == NULL) {
/* exhausted all of the l_opts we have and still didn't match */
if (opt_err)
- HDfprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
+ HDfprintf(rawerrorstream, "%s: unknown option \"%s\"\n", argv[0], arg);
opt_opt = '?';
}
@@ -307,7 +310,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (opt_opt == ':' || (cp = HDstrchr(opts, opt_opt)) == 0) {
if (opt_err)
- HDfprintf(stderr, "%s: unknown option \"%c\"\n",
+ HDfprintf(rawerrorstream, "%s: unknown option \"%c\"\n",
argv[0], opt_opt);
/* if no chars left in this token, move to next token */
@@ -326,7 +329,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
}
else if (++opt_ind >= argc) {
if (opt_err)
- HDfprintf(stderr,
+ HDfprintf(rawerrorstream,
"%s: value expected for option \"%c\"\n",
argv[0], opt_opt);
@@ -385,10 +388,10 @@ indentation(int x)
{
if (x < h5tools_nCols) {
while (x-- > 0)
- printf(" ");
+ HDfprintf(rawoutstream, " ");
}
else {
- HDfprintf(stderr, "error: the indentation exceeds the number of cols.\n");
+ HDfprintf(rawerrorstream, "error: the indentation exceeds the number of cols.\n");
HDexit(1);
}
}
@@ -411,7 +414,7 @@ indentation(int x)
void
print_version(const char *progname)
{
- printf("%s: Version %u.%u.%u%s%s\n",
+ HDfprintf(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);
}
@@ -491,9 +494,9 @@ dump_table(char* tablename, table_t *table)
{
unsigned u;
- printf("%s: # of entries = %d\n", tablename,table->nobjs);
+ HDfprintf(rawoutstream,"%s: # of entries = %d\n", tablename,table->nobjs);
for (u = 0; u < table->nobjs; u++)
- HDfprintf(stdout,"%a %s %d %d\n", table->objs[u].objno,
+ HDfprintf(rawoutstream,"%a %s %d %d\n", table->objs[u].objno,
table->objs[u].objname,
table->objs[u].displayed, table->objs[u].recorded);
}
@@ -914,7 +917,7 @@ int h5tools_getenv_update_hyperslab_bufsize(void)
{
/* TODO: later when pubilshed
- printf("Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str);
+ HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str);
*/
goto error;