summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/h5dump.c865
1 files changed, 497 insertions, 368 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index dcae975..e7d3bdb 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -1,10 +1,7 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 1998 - 2001
- * National Center for Supercomputing Applications
- * All rights reserved.
+/*
+ * Copyright (C) 1998-2001 National Center for Supercomputing Applications
+ * All rights reserved.
*
- *-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
@@ -14,16 +11,23 @@
#include "h5tools.h"
/* module-scoped variables */
-static int display_oid = 0;
-static int display_data = 1;
-static int d_status = EXIT_SUCCESS;
-static int unamedtype = 0; /* shared data type with no name */
-static int prefix_len = 1024;
-static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;
-static char *prefix;
+static const char *progname = "h5dump";
+
+static int d_status = EXIT_SUCCESS;
+static int unamedtype = 0; /* shared data type with no name */
+static int prefix_len = 1024;
+static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;
+static char *prefix;
static const dump_header *dump_header_format;
+/* things to display or which are set via command line parameters */
+static int display_all = TRUE;
+static int display_bb = FALSE;
+static int display_oid = FALSE;
+static int display_data = TRUE;
+static int usingdasho = FALSE;
+
/**
** Added for XML **
**/
@@ -355,7 +359,7 @@ static void dump_datatype(hid_t type);
static herr_t dump_attr(hid_t attr, const char *attr_name,
void UNUSED * op_data);
-/* XML format: same interface, alternaive output */
+/* XML format: same interface, alternative output */
static void xml_dump_group(hid_t, const char *);
static void xml_dump_dataset(hid_t ds, const char *dsname);
@@ -420,7 +424,7 @@ struct subset_t {
/* a structure for handling the order command-line parameters come in */
struct handler_t {
- void (*func)(hid_t, char *);
+ void (*func)(hid_t, char *, void *);
char *obj;
struct subset_t *subset_info;
};
@@ -430,10 +434,23 @@ struct handler_t {
* parameters. The long-named ones can be partially spelled. When
* adding more, make sure that they don't clash with each other.
*/
+#if 0
+ /* binary: not implemented yet */
+static const char *s_opts = "hbBHvVa:d:g:l:t:w:xD:o:s:T:c:k:";
+#else
static const char *s_opts = "hBHvVa:d:g:l:t:w:xD:o:s:T:c:k:";
+#endif /* 0 */
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
{ "hel", no_arg, 'h' },
+#if 0
+ /* binary: not implemented yet */
+ { "binary", no_arg, 'b' },
+ { "binar", no_arg, 'b' },
+ { "bina", no_arg, 'b' },
+ { "bin", no_arg, 'b' },
+ { "bi", no_arg, 'b' },
+#endif /* 0 */
{ "boot-block", no_arg, 'B' },
{ "boot-bloc", no_arg, 'B' },
{ "boot-blo", no_arg, 'B' },
@@ -532,10 +549,10 @@ static struct long_options l_opts[] = {
*-------------------------------------------------------------------------
*/
static void
-usage(const char *progname)
+usage(const char *prog)
{
fflush(stdout);
- fprintf(stderr, "\
+ fprintf(stdout, "\
usage: %s [OPTIONS] file\n\
OPTIONS\n\
-h, --help Print a usage message and exit\n\
@@ -549,14 +566,14 @@ usage: %s [OPTIONS] file\n\
-l P, --soft-link=P Print the value(s) of the specified soft link\n\
-o F, --output=F Output raw data into file F\n\
-t T, --datatype=T Print the specified named data type\n\
- -w #, --width=# Set the number of columns of output\n\
+ -w N, --width=N Set the number of columns of output\n\
-x, --xml Output in XML\n\
-D U, --xml-dtd=U Use the DTD at U\n\
\n\
P - is the full path from the root group to the object.\n\
T - is the name of the data type.\n\
F - is a filename.\n\
- # - is an integer greater than 1.\n\
+ N - is an integer greater than 1.\n\
U - is a URI reference (as defined in [IETF RFC 2396],\n\
updated by [IETF RFC 2732])\n\
\n\
@@ -565,7 +582,7 @@ usage: %s [OPTIONS] file\n\
Attribute foo of the group /bar_none in file quux.h5\n\
\n\
h5dump -a /bar_none/foo quux.h5\n\
-\n", progname);
+\n", prog);
}
/*-------------------------------------------------------------------------
@@ -584,15 +601,15 @@ usage: %s [OPTIONS] file\n\
static void
print_datatype(hid_t type)
{
- char *fname;
- hid_t nmembers, mtype, str_type;
- int i, j, ndims, perm[H5DUMP_MAX_RANK];
- size_t size;
- hsize_t dims[H5DUMP_MAX_RANK];
- H5T_str_t str_pad;
- H5T_cset_t cset;
- H5G_stat_t statbuf;
- hid_t super;
+ char *fname;
+ hid_t nmembers, mtype, str_type;
+ int i, j, ndims, perm[H5DUMP_MAX_RANK];
+ size_t size;
+ hsize_t dims[H5DUMP_MAX_RANK];
+ H5T_str_t str_pad;
+ H5T_cset_t cset;
+ H5G_stat_t statbuf;
+ hid_t super;
switch (H5Tget_class(type)) {
case H5T_INTEGER:
@@ -786,8 +803,7 @@ print_datatype(hid_t type)
else
printf("\"%s\"", type_table->objs[i].objname);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unknown committed type.\n");
+ error_msg(progname, "unknown committed type.\n");
d_status = EXIT_FAILURE;
}
} else {
@@ -837,7 +853,6 @@ print_datatype(hid_t type)
case H5T_VLEN:
printf("H5T_VLEN %s ", dump_header_format->vlenblockbegin);
-
super = H5Tget_super(type);
print_datatype(super);
H5Tclose(super);
@@ -922,7 +937,7 @@ dump_datatype(hid_t type)
indentation(indent);
printf("%s %s ", dump_header_format->datatypebegin,
- dump_header_format->datatypeblockbegin);
+ dump_header_format->datatypeblockbegin);
print_datatype(type);
@@ -930,7 +945,7 @@ dump_datatype(hid_t type)
indentation(indent);
printf(" %s %s\n", dump_header_format->datatypeblockend,
- dump_header_format->datatypeend);
+ dump_header_format->datatypeend);
indent -= COL;
}
@@ -951,11 +966,10 @@ dump_datatype(hid_t type)
static void
dump_dataspace(hid_t space)
{
- hsize_t size[H5DUMP_MAX_RANK];
- hsize_t maxsize[H5DUMP_MAX_RANK];
- int ndims =
- H5Sget_simple_extent_dims(space, size, maxsize);
- int i;
+ hsize_t size[H5DUMP_MAX_RANK];
+ hsize_t maxsize[H5DUMP_MAX_RANK];
+ int ndims = H5Sget_simple_extent_dims(space, size, maxsize);
+ int i;
indentation(indent + COL);
printf("%s ", dump_header_format->dataspacebegin);
@@ -982,7 +996,7 @@ dump_dataspace(hid_t space)
"H5S_UNLIMITED");
else
HDfprintf(stdout, "%s %Hu",
- dump_header_format->dataspacedimbegin, maxsize[0]);
+ dump_header_format->dataspacedimbegin, maxsize[0]);
for (i = 1; i < ndims; i++)
if (maxsize[i] == H5S_UNLIMITED)
@@ -1018,14 +1032,22 @@ dump_dataspace(hid_t space)
static herr_t
dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
{
- hid_t attr_id, type, space;
- herr_t ret = SUCCEED;
+ hid_t attr_id, type, space;
+ herr_t ret = SUCCEED;
indentation(indent);
begin_obj(dump_header_format->attributebegin, attr_name,
dump_header_format->attributeblockbegin);
- if ((attr_id = H5Aopen_name(attr, attr_name)) >= 0) {
+ if ((attr_id = H5Aopen_name(attr, attr_name)) < 0) {
+ indentation(indent + COL);
+ error_msg(progname, "unable to open attribute \"%s\"\n", attr_name);
+ indentation(indent);
+ end_obj(dump_header_format->attributeend,
+ dump_header_format->attributeblockend);
+ d_status = EXIT_FAILURE;
+ ret = FAIL;
+ } else {
type = H5Aget_type(attr_id);
space = H5Aget_space(attr_id);
dump_datatype(type);
@@ -1043,15 +1065,6 @@ dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
indentation(indent);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
- } else {
- indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open attribute \"%s\"\n", attr_name);
- indentation(indent);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- ret = FAIL;
}
return ret;
@@ -1093,7 +1106,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
strcpy(obj_name, "/");
} else {
strncpy(obj_name, name, (size_t)j + 1);
- obj_name[j+1] = '\0';
+ obj_name[j + 1] = '\0';
}
attr_name = name + j + 1;
@@ -1105,8 +1118,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
case H5G_GROUP:
if ((oid = H5Gopen(loc_id, obj_name)) < 0) {
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open group \"%s\"\n", obj_name);
+ error_msg(progname, "unable to open group \"%s\"\n", obj_name);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
d_status = EXIT_FAILURE;
@@ -1117,8 +1129,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
case H5G_DATASET:
if ((oid = H5Dopen(loc_id, obj_name)) < 0) {
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open dataset \"%s\"\n", obj_name);
+ error_msg(progname, "unable to open dataset \"%s\"\n", obj_name);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
d_status = EXIT_FAILURE;
@@ -1129,8 +1140,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
case H5G_TYPE:
if ((oid = H5Topen(loc_id, obj_name)) < 0) {
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open datatype \"%s\"\n", obj_name);
+ error_msg(progname, "unable to open datatype \"%s\"\n", obj_name);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
d_status = EXIT_FAILURE;
@@ -1140,8 +1150,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
default:
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open unknown \"%s\"\n", obj_name);
+ error_msg(progname, "unable to open unknown \"%s\"\n", obj_name);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
d_status = EXIT_FAILURE;
@@ -1167,8 +1176,7 @@ dump_selected_attr(hid_t loc_id, const char *name)
dump_header_format->attributeblockend);
} else {
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open attribute \"%s\"\n", obj_name);
+ error_msg(progname, "unable to open attribute \"%s\"\n", obj_name);
end_obj(dump_header_format->attributeend,
dump_header_format->attributeblockend);
d_status = EXIT_FAILURE;
@@ -1216,7 +1224,8 @@ dump_selected_attr(hid_t loc_id, const char *name)
* Programmer: Ruey-Hsia Li
*
* Modifications:
- * 11/00 Added XML support. Also, optionally checks the op_data
+ * RMcG, November 2000
+ * Added XML support. Also, optionally checks the op_data
* argument.
*
*-------------------------------------------------------------------------
@@ -1224,16 +1233,18 @@ dump_selected_attr(hid_t loc_id, const char *name)
static herr_t
dump_all(hid_t group, const char *name, void * op_data)
{
- hid_t obj;
- char *buf, *tmp, *tmp2;
- H5G_stat_t statbuf;
- int i;
+ hid_t obj;
+ char *buf, *tmp = NULL;
+ H5G_stat_t statbuf;
+ int i;
+ herr_t ret = SUCCEED;
H5Gget_objinfo(group, name, FALSE, &statbuf);
- if ((*(int *)op_data != H5G_UNKNOWN) &&
- (statbuf.type != *(int *) op_data))
- return SUCCEED;
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
+
+ if (*(int *)op_data != H5G_UNKNOWN && statbuf.type != *(int *) op_data)
+ goto done;
+
+ tmp = malloc(strlen(prefix) + strlen(name) + 1);
strcpy(tmp, prefix);
switch (statbuf.type) {
@@ -1247,34 +1258,45 @@ dump_all(hid_t group, const char *name, void * op_data)
indentation(indent + COL);
}
- if (H5Gget_linkval(group, name, statbuf.linklen, buf) >= 0) {
+ if (H5Gget_linkval(group, name, statbuf.linklen, buf) < 0) {
+ error_msg(progname, "unable to get link value\n");
+ d_status = EXIT_FAILURE;
+ ret = FAIL;
+ } else {
/* print the value of a soft link */
if (!doxml) {
- /* Standard DDL: no modification */
+ /* Standard DDL: no modification */
printf("LINKTARGET \"%s\"\n", buf);
} else {
/* XML */
- tmp2 = (char *) malloc(strlen(prefix) + statbuf.linklen + 2);
+ char *t_name = xml_escape_the_name(name);
+ char *t_buf = xml_escape_the_name(buf);
+ char *t_prefix = xml_escape_the_name(prefix);
+ char *tmp2, *t_tmp2, *t_tmp;
+
+ tmp2 = malloc(strlen(prefix) + statbuf.linklen + 1);
strcpy(tmp2, prefix);
- if (buf && buf[0] == '/') {
- strcat(tmp2, buf);
- } else {
- strcat(strcat(tmp2, "/"), buf);
- }
- strcat(strcat(tmp, "/"), name);
- printf
- ("<SoftLink LinkName=\"%s\" Target=\"%s\" TargetObj=\"%s\" OBJ-XID=\"%s\" Source=\"%s\"/>\n",
- xml_escape_the_name(name),
- xml_escape_the_name(buf),
- xml_escape_the_name(tmp2),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
- free(tmp2);
+
+ if (buf && buf[0] == '/')
+ strcat(tmp2, buf);
+ else
+ strcat(strcat(tmp2, "/"), buf);
+
+ t_tmp = xml_escape_the_name(strcat(strcat(tmp, "/"), name));
+ t_tmp2 = xml_escape_the_name(tmp2);
+
+ printf("<SoftLink LinkName=\"%s\" Target=\"%s\" "
+ "TargetObj=\"%s\" OBJ-XID=\"%s\" Source=\"%s\"/>\n",
+ t_name, t_buf, t_tmp2, t_tmp,
+ (strcmp(prefix, "") ? t_prefix : "root"));
+
+ free(t_name);
+ free(t_buf);
+ free(t_prefix);
+ free(t_tmp);
+ free(t_tmp2);
+ free(tmp2);
}
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get link value\n");
- d_status = EXIT_FAILURE;
}
if (!doxml) {
@@ -1287,15 +1309,15 @@ dump_all(hid_t group, const char *name, void * op_data)
break;
case H5G_GROUP:
- if ((obj = H5Gopen(group, name)) >= 0) {
+ if ((obj = H5Gopen(group, name)) < 0) {
+ error_msg(progname, "unable to dump group \"%s\"\n", name);
+ d_status = EXIT_FAILURE;
+ ret = FAIL;
+ } else {
strcat(strcat(prefix, "/"), name);
dump_function_table->dump_group_function(obj, name);
strcpy(prefix, tmp);
H5Gclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump group \"%s\"\n", name);
- d_status = EXIT_FAILURE;
}
break;
@@ -1313,12 +1335,14 @@ dump_all(hid_t group, const char *name, void * op_data)
begin_obj(dump_header_format->datasetbegin, name,
dump_header_format->datasetblockbegin);
indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
+ error_msg(progname,
+ "internal error (file %s:line %d)\n",
+ __FILE__, __LINE__);
indentation(indent);
end_obj(dump_header_format->datasetend,
dump_header_format->datasetblockend);
d_status = EXIT_FAILURE;
+ ret = FAIL;
H5Dclose(obj);
goto done;
} else if (dset_table->objs[i].displayed) {
@@ -1334,20 +1358,26 @@ dump_all(hid_t group, const char *name, void * op_data)
dump_header_format->datasetblockend);
} else {
/* the XML version */
- strcat(strcat(tmp, "/"), name);
- printf
- ("<Dataset Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix)
- : "root"));
+ char *t_name = xml_escape_the_name(name);
+ char *t_tmp = xml_escape_the_name(strcat(strcat(tmp, "/"), name));
+ char *t_prefix = xml_escape_the_name(prefix);
+ char *t_objname = xml_escape_the_name(dset_table->objs[i].objname);
+
+ printf("<Dataset Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
+ t_name, t_tmp,
+ (strcmp(prefix, "") ? t_prefix : "root"));
indentation(indent + COL);
- printf("<DatasetPtr OBJ-XID=\"%s\"/>\n",
- xml_escape_the_name(dset_table->objs[i].objname));
+ printf("<DatasetPtr OBJ-XID=\"%s\"/>\n", t_objname);
indentation(indent);
printf("%s\n", dump_header_format->datasetend);
+
+ free(t_name);
+ free(t_tmp);
+ free(t_prefix);
+ free(t_objname);
}
+
H5Dclose(obj);
goto done;
} else {
@@ -1361,34 +1391,34 @@ dump_all(hid_t group, const char *name, void * op_data)
dump_function_table->dump_dataset_function(obj, name);
H5Dclose(obj);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump dataset \"%s\"\n", name);
+ error_msg(progname, "unable to dump dataset \"%s\"\n", name);
d_status = EXIT_FAILURE;
+ ret = FAIL;
}
+
break;
case H5G_TYPE:
- if ((obj = H5Topen(group, name)) >= 0) {
+ if ((obj = H5Topen(group, name)) < 0) {
+ error_msg(progname, "unable to dump data type \"%s\"\n", name);
+ d_status = EXIT_FAILURE;
+ ret = FAIL;
+ } else {
dump_function_table->dump_named_datatype_function(obj, name);
H5Tclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump data type \"%s\"\n", name);
- d_status = EXIT_FAILURE;
}
break;
default:
- fflush(stdout);
- fprintf(stderr, "h5dump error: unknown object \"%s\"\n", name);
+ error_msg(progname, "unknown object \"%s\"\n", name);
d_status = EXIT_FAILURE;
- return FAIL;
+ ret = FAIL;
}
- done:
+done:
free(tmp);
- return SUCCEED;
+ return ret;
}
/*-------------------------------------------------------------------------
@@ -1412,7 +1442,7 @@ dump_named_datatype(hid_t type, const char *name)
dump_header_format->datatypeblockbegin);
if (H5Tget_class(type) == H5T_COMPOUND) {
- hid_t temp_type = H5Tcopy(type);
+ hid_t temp_type = H5Tcopy(type);
print_datatype(temp_type);
H5Tclose(temp_type);
@@ -1445,11 +1475,10 @@ dump_named_datatype(hid_t type, const char *name)
static void
dump_group(hid_t gid, const char *name)
{
- H5G_stat_t statbuf;
- hid_t dset, type;
- char typename[1024], *tmp;
- int i;
- int xtype = H5G_UNKNOWN; /* dump all */
+ H5G_stat_t statbuf;
+ hid_t dset, type;
+ char typename[1024], *tmp;
+ int i, xtype = H5G_UNKNOWN; /* dump all */
tmp = malloc(strlen(prefix) + strlen(name) + 2);
strcpy(tmp, prefix);
@@ -1482,8 +1511,8 @@ dump_group(hid_t gid, const char *name)
if (i < 0) {
indentation(indent);
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
+ error_msg(progname, "internal error (file %s:line %d)\n",
+ __FILE__, __LINE__);
d_status = EXIT_FAILURE;
} else if (group_table->objs[i].displayed) {
indentation(indent);
@@ -1521,7 +1550,7 @@ dump_group(hid_t gid, const char *name)
static void
dump_dataset(hid_t did, const char *name)
{
- hid_t type, space;
+ hid_t type, space;
indentation(indent);
begin_obj(dump_header_format->datasetbegin, name,
@@ -1568,7 +1597,6 @@ dump_dataset(hid_t did, const char *name)
dump_header_format->datasetblockend);
}
-#if H5DUMP_DEBUG
/*-------------------------------------------------------------------------
* Function: dump_tables
*
@@ -1585,7 +1613,8 @@ dump_dataset(hid_t did, const char *name)
static void
dump_tables(void)
{
- int i;
+#ifdef H5DUMP_DEBUG
+ register int i;
printf("group_table: # of entries = %d\n", group_table->nobjs);
@@ -1610,8 +1639,10 @@ dump_tables(void)
type_table->objs[i].objno[1],
type_table->objs[i].objname,
type_table->objs[i].displayed, type_table->objs[i].recorded);
+#else
+ return;
+#endif /* H5DUMP_DEBUG */
}
-#endif /* H5DUMP_DEBUG */
/*-------------------------------------------------------------------------
* Function: dump_data
@@ -1681,8 +1712,7 @@ dump_data(hid_t obj_id, int obj_data)
if (status < 0) {
indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to print data\n");
+ error_msg(progname, "unable to print data\n");
d_status = EXIT_FAILURE;
}
@@ -1730,7 +1760,7 @@ static int
set_output_file(const char *fname)
{
FILE *f; /* temporary holding place for the stream pointer
- so that rawdatastream is changed only when succeeded */
+ * so that rawdatastream is changed only when succeeded */
if ((f = fopen(fname, "w")) != NULL) {
rawdatastream = f;
@@ -1755,7 +1785,7 @@ set_output_file(const char *fname)
*-------------------------------------------------------------------------
*/
static void
-handle_attributes(hid_t fid, char *attr)
+handle_attributes(hid_t fid, char *attr, void UNUSED *data)
{
dump_selected_attr(fid, attr);
}
@@ -1785,9 +1815,9 @@ handle_attributes(hid_t fid, char *attr)
static hsize_t *
parse_hsize_list(const char *h_list)
{
- hsize_t *p_list;
- const char *ptr;
- unsigned int size_count = 0, i = 0, last_digit = 0;
+ hsize_t *p_list;
+ const char *ptr;
+ unsigned int size_count = 0, i = 0, last_digit = 0;
if (!h_list || !*h_list || *h_list == ';')
return NULL;
@@ -1844,7 +1874,7 @@ static struct subset_t *
parse_subset_params(char *dset)
{
struct subset_t *s = NULL;
- register char *brace;
+ register char *brace;
if ((brace = strrchr(dset, '[')) != NULL) {
char *slash = strrchr(dset, '/');
@@ -1904,17 +1934,17 @@ parse_subset_params(char *dset)
*-------------------------------------------------------------------------
*/
static void
-handle_datasets(hid_t fid, char *dset)
+handle_datasets(hid_t fid, char *dset, void *data)
{
- H5G_stat_t statbuf;
- hid_t dsetid;
+ H5G_stat_t statbuf;
+ hid_t dsetid;
+ struct subset_t *sset = (struct subset_t *)data;
if ((dsetid = H5Dopen(fid, dset)) < 0) {
begin_obj(dump_header_format->datasetbegin, dset,
dump_header_format->datasetblockbegin);
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open dataset \"%s\"\n", dset);
+ error_msg(progname, "unable to open dataset \"%s\"\n", dset);
end_obj(dump_header_format->datasetend,
dump_header_format->datasetblockend);
d_status = EXIT_FAILURE;
@@ -1966,17 +1996,16 @@ handle_datasets(hid_t fid, char *dset)
*-------------------------------------------------------------------------
*/
static void
-handle_groups(hid_t fid, char *group)
+handle_groups(hid_t fid, char *group, void UNUSED *data)
{
- H5G_stat_t statbuf;
- hid_t gid;
+ H5G_stat_t statbuf;
+ hid_t gid;
if ((gid = H5Gopen(fid, group)) < 0) {
begin_obj(dump_header_format->groupbegin, group,
dump_header_format->groupblockbegin);
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open group \"%s\"\n", group);
+ error_msg(progname, "unable to open group \"%s\"\n", group);
end_obj(dump_header_format->groupend,
dump_header_format->groupblockend);
d_status = EXIT_FAILURE;
@@ -2005,16 +2034,15 @@ handle_groups(hid_t fid, char *group)
*-------------------------------------------------------------------------
*/
static void
-handle_links(hid_t fid, char *links)
+handle_links(hid_t fid, char *links, void UNUSED *data)
{
- H5G_stat_t statbuf;
+ H5G_stat_t statbuf;
if (H5Gget_objinfo(fid, links, FALSE, &statbuf) < 0) {
begin_obj(dump_header_format->softlinkbegin, links,
dump_header_format->softlinkblockbegin);
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get obj info from \"%s\"\n", links);
+ error_msg(progname, "unable to get obj info from \"%s\"\n", links);
end_obj(dump_header_format->softlinkend,
dump_header_format->softlinkblockend);
d_status = EXIT_FAILURE;
@@ -2028,9 +2056,8 @@ handle_links(hid_t fid, char *links)
if (H5Gget_linkval(fid, links, statbuf.linklen, buf) >= 0) {
printf("LINKTARGET \"%s\"\n", buf);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get link value for \"%s\"\n",
- links);
+ error_msg(progname, "h5dump error: unable to get link value for \"%s\"\n",
+ links);
d_status = EXIT_FAILURE;
}
@@ -2041,8 +2068,7 @@ handle_links(hid_t fid, char *links)
begin_obj(dump_header_format->softlinkbegin, links,
dump_header_format->softlinkblockbegin);
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: \"%s\" is not a link\n", links);
+ error_msg(progname, "\"%s\" is not a link\n", links);
end_obj(dump_header_format->softlinkend,
dump_header_format->softlinkblockend);
d_status = EXIT_FAILURE;
@@ -2064,9 +2090,9 @@ handle_links(hid_t fid, char *links)
*-------------------------------------------------------------------------
*/
static void
-handle_datatypes(hid_t fid, char *type)
+handle_datatypes(hid_t fid, char *type, void UNUSED *data)
{
- hid_t typeid;
+ hid_t typeid;
if ((typeid = H5Topen(fid, type)) < 0) {
/* check if type is unamed data type */
@@ -2097,8 +2123,7 @@ handle_datatypes(hid_t fid, char *type)
begin_obj(dump_header_format->datatypebegin, type,
dump_header_format->datatypeblockbegin);
indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open datatype \"%s\"\n", type);
+ error_msg(progname, "unable to open datatype \"%s\"\n", type);
end_obj(dump_header_format->datatypeend,
dump_header_format->datatypeblockend);
d_status = EXIT_FAILURE;
@@ -2117,59 +2142,36 @@ handle_datatypes(hid_t fid, char *type)
}
}
+
/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: HDF5 dumper
+ * Function: parse_command_line
*
- * Return: Success: 0
- * Failure: 1
+ * Purpose: Parse the command line for the h5dumper.
*
- * Programmer: Ruey-Hsia Li
+ * Return: Success: A pointer to an array of handler_t structures.
+ * These contain all the information needed to dump
+ * the necessary object.
*
- * Modifications:
- * Albert Cheng, 30. September 2000
- * Add the -o option--output file for datasets raw data
+ * Failure: Exits program with EXIT_FAILURE value.
*
- * REMcG, November 2000
- * Changes to support XML.
+ * Programmer: Bill Wendling
+ * Tuesday, 20. February 2001
*
- * Bill Wendling
- * Wednesday, 10. January 2001
- * Modified the way command line parameters are interpreted. They go
- * through one function call now (get_option).
+ * Modifications:
*
*-------------------------------------------------------------------------
*/
-int
-main(int argc, const char *argv[])
+static struct handler_t *
+parse_command_line(int argc, const char *argv[])
{
- hid_t fid, gid;
- const char *progname = "h5dump";
- const char *fname = NULL;
- int i, display_bb = 0, display_all = 1, newwidth = 0;
- void *edata;
- hid_t (*func)(void*);
- find_objs_t info;
- int opt;
struct handler_t *hand, *last_dset;
- int usingdasho = FALSE, last_was_dset = FALSE;
+ int i, opt, last_was_dset = FALSE;
if (argc < 2) {
usage(progname);
exit(EXIT_FAILURE);
}
- dump_header_format = &standardformat;
- dump_function_table = &ddl_function_table;
-
- /* Disable error reporting */
- H5Eget_auto(&func, &edata);
- H5Eset_auto(NULL, NULL);
-
- /* Initialize h5tools lib */
- h5tools_init();
-
/* this will be plenty big enough to hold the info */
hand = calloc((size_t)argc, sizeof(struct handler_t));
@@ -2291,14 +2293,17 @@ parse_start:
struct subset_t *s;
if (!last_was_dset) {
- fprintf(stderr, "%s error: option `-%c' can only be used after --dataset option\n",
- progname, opt);
+ error_msg(progname,
+ "option `-%c' can only be used after --dataset option\n",
+ opt);
exit(EXIT_FAILURE);
}
if (last_dset->subset_info) {
- /* this overrides the "terse" syntax if they actually mixed
- * the two */
+ /*
+ * This overrides the "terse" syntax if they actually mixed
+ * the two.
+ */
s = last_dset->subset_info;
} else {
last_dset->subset_info = s = calloc(1, sizeof(struct subset_t));
@@ -2309,11 +2314,11 @@ parse_start:
* for subsetting: "--start", "--stride", "--count", and "--block"
* which can come in any order. If we run out of parameters (EOF)
* or run into one which isn't a subsetting parameter (NOT s, T,
- * c, or K), then we exit the do-while look, set hte subset_info
+ * c, or K), then we exit the do-while look, set the subset_info
* to the structure we've been filling. If we've reached the end
* of the options, we exit the parsing (goto parse_end) otherwise,
* since we've "read" the next option, we need to parse it. So we
- * just to the beginning of the switch statement (goto parse_start).
+ * jump to the beginning of the switch statement (goto parse_start).
*/
do {
switch ((char)opt) {
@@ -2346,44 +2351,135 @@ end_collect:
}
parse_end:
- /* check for conflicting options */
+ return hand;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: free_handler
+ *
+ * Purpose: Convenience function to free the handler_t structures. Needs a
+ * length variable (LEN) to know how many in the array it needs
+ * to free
+ *
+ * Return: Nothing
+ *
+ * Programmer: Bill Wendling
+ * Tuesday, 20. February 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+free_handler(struct handler_t *hand, int len)
+{
+ register int i;
+
+ for (i = 0; i < len; i++) {
+ free(hand[i].obj);
+
+ if (hand[i].subset_info) {
+ free(hand[i].subset_info->start);
+ free(hand[i].subset_info->stride);
+ free(hand[i].subset_info->count);
+ free(hand[i].subset_info->block);
+ free(hand[i].subset_info);
+ }
+ }
+
+ free(hand);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: HDF5 dumper
+ *
+ * Return: Success: 0
+ * Failure: 1
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ * Albert Cheng
+ * 30. September 2000
+ * Add the -o option--output file for datasets raw data
+ *
+ * REMcG
+ * November 2000
+ * Changes to support XML.
+ *
+ * Bill Wendling
+ * Wednesday, 10. January 2001
+ * Modified the way command line parameters are interpreted. They go
+ * through one function call now (get_option).
+ *
+ * Bill Wendling
+ * Tuesday, 20. February 2001
+ * Moved command line parsing to separate function. Made various
+ * "display_*" flags global.
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main(int argc, const char *argv[])
+{
+ hid_t fid, gid;
+ const char *fname = NULL;
+ void *edata;
+ hid_t (*func)(void*);
+ find_objs_t info;
+ struct handler_t *hand;
+ int i;
+
+ if (argc < 2) {
+ usage(progname);
+ exit(EXIT_FAILURE);
+ }
+
+ dump_header_format = &standardformat;
+ dump_function_table = &ddl_function_table;
+
+ /* Disable error reporting */
+ H5Eget_auto(&func, &edata);
+ H5Eset_auto(NULL, NULL);
+
+ /* Initialize h5tools lib */
+ h5tools_init();
+ hand = parse_command_line(argc, argv);
+
+ /* Check for conflicting options */
if (doxml) {
if (!display_all) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "to display selected objects");
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "to display selected objects");
exit(EXIT_FAILURE);
} else if (display_bb) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--boot-block");
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "--boot-block");
exit(EXIT_FAILURE);
} else if (!display_data) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--header");
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "--header");
exit(EXIT_FAILURE);
} else if (display_oid == 1) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--object-ids");
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "--object-ids");
exit(EXIT_FAILURE);
} else if (usingdasho) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--output");
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "--output");
exit(EXIT_FAILURE);
}
} else {
- if (xml_dtd_uri != NULL) {
- fflush(stdout);
- fprintf(stderr,
- "h5dump warning: option \"%s\" only applies with XML: %s\n",
- "--xml-dtd", xml_dtd_uri);
+ if (xml_dtd_uri) {
+ warn_msg(progname, "option \"%s\" only applies with XML: %s\n",
+ "--xml-dtd", xml_dtd_uri);
}
}
- if (argv[argc - 1][0] == '\\')
+ if (argv[opt_ind][0] == '\\')
fname = &argv[opt_ind][1];
else
fname = argv[opt_ind];
@@ -2391,8 +2487,7 @@ parse_end:
fid = h5dump_fopen(fname, NULL, 0);
if (fid < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open file \"%s\"\n", fname);
+ error_msg(progname, "unable to open file \"%s\"\n", fname);
exit(EXIT_FAILURE);
}
@@ -2417,8 +2512,7 @@ parse_end:
/* find all objects that might be targets of a refernce */
if ((gid = H5Gopen(fid, "/")) < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open root group\n");
+ error_msg(progname, "unable to open root group\n");
d_status = EXIT_FAILURE;
goto done;
}
@@ -2443,13 +2537,11 @@ parse_end:
if (type_table->objs[i].recorded == 0)
unamedtype = 1;
-#ifdef H5DUMP_DEBUG
dump_tables();
-#endif /* H5DUMP_DEBUG */
if (info.status) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
+ error_msg(progname, "internal error (file %s:line %d)\n",
+ __FILE__, __LINE__);
d_status = EXIT_FAILURE;
goto done;
}
@@ -2468,35 +2560,30 @@ parse_end:
if (display_bb)
dump_bb();
- if (newwidth)
- sscanf(argv[newwidth + 1], "%d", &nCols);
-
if (display_all) {
- if ((gid = H5Gopen (fid, "/")) < 0 ) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open root group\n");
+ if ((gid = H5Gopen(fid, "/")) < 0) {
+ error_msg(progname, "unable to open root group\n");
d_status = EXIT_FAILURE;
} else {
dump_function_table->dump_group_function(gid, "/");
}
- if (H5Gclose (gid) < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to close root group\n");
+ if (H5Gclose(gid) < 0) {
+ error_msg(progname, "unable to close root group\n");
d_status = EXIT_FAILURE;
}
} else {
if (doxml) {
- /* Note: this option is not supported for XML */
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
+ /* Note: this option is not supported for XML */
+ error_msg(progname, "internal error (file %s:line %d)\n",
+ __FILE__, __LINE__);
d_status = EXIT_FAILURE;
goto done;
}
for (i = 0; i < argc; i++)
if (hand[i].func)
- hand[i].func(fid, hand[i].obj);
+ hand[i].func(fid, hand[i].obj, hand[i].subset_info);
}
if (!doxml) {
@@ -2510,19 +2597,7 @@ done:
if (H5Fclose(fid) < 0)
d_status = EXIT_FAILURE;
- for (i = 0; i < argc; i++) {
- free(hand[i].obj);
-
- if (hand[i].subset_info) {
- free(hand[i].subset_info->start);
- free(hand[i].subset_info->stride);
- free(hand[i].subset_info->count);
- free(hand[i].subset_info->block);
- free(hand[i].subset_info);
- }
- }
-
- free(hand);
+ free_handler(hand, argc);
free(group_table->objs);
free(dset_table->objs);
@@ -2845,13 +2920,17 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
H5Gget_objinfo(group, name, FALSE, &statbuf);
tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
+
if (tmp == NULL)
return FAIL;
+
thepath = (char *) malloc(strlen(prefix) + strlen(name) + 2);
+
if (thepath == NULL) {
free(tmp);
return FAIL;
}
+
strcpy(tmp, prefix);
strcpy(thepath, prefix);
@@ -2867,8 +2946,7 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
}
H5Dclose(obj);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get dataset \"%s\"\n", name);
+ error_msg(progname, "unable to get dataset \"%s\"\n", name);
d_status = EXIT_FAILURE;
}
break;
@@ -2883,8 +2961,7 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
}
H5Gclose(obj);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump group \"%s\"\n", name);
+ error_msg(progname, "unable to dump group \"%s\"\n", name);
d_status = EXIT_FAILURE;
}
break;
@@ -2896,13 +2973,13 @@ fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
}
H5Tclose(obj);
} else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get dataset \"%s\"\n", name);
+ error_msg(progname, "unable to get dataset \"%s\"\n", name);
d_status = EXIT_FAILURE;
}
break;
default:;
}
+
free(tmp);
free(thepath);
return 0;
@@ -2938,7 +3015,7 @@ xml_escape_the_name(const char *str)
char *ncp;
char *rcp;
- if (str == NULL)
+ if (!str)
return NULL;
cp = str;
@@ -2957,44 +3034,47 @@ xml_escape_the_name(const char *str)
} else if (*cp == '&') {
extra += (strlen(amp) - 1);
}
+
cp++;
}
- if (extra == 0) {
- return (char *) str;
- } else {
- cp = str;
- rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
- if (ncp == NULL)
- return NULL; /* ?? */
- for (i = 0; i < len; i++) {
- if (*cp == '\'') {
- strncpy(ncp, apos, strlen(apos));
- ncp += strlen(apos);
- cp++;
- } else if (*cp == '<') {
- strncpy(ncp, lt, strlen(lt));
- ncp += strlen(lt);
- cp++;
- } else if (*cp == '>') {
- strncpy(ncp, gt, strlen(gt));
- ncp += strlen(gt);
- cp++;
- } else if (*cp == '\"') {
- strncpy(ncp, quote, strlen(quote));
- ncp += strlen(quote);
- cp++;
- } else if (*cp == '&') {
- strncpy(ncp, amp, strlen(amp));
- ncp += strlen(amp);
- cp++;
- } else {
- *ncp++ = *cp++;
- }
- }
- *ncp = '\0';
- return rcp;
+ if (extra == 0)
+ return strdup(str);
+
+ cp = str;
+ rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
+
+ if (!ncp)
+ return NULL; /* ?? */
+
+ for (i = 0; i < len; i++) {
+ if (*cp == '\'') {
+ strncpy(ncp, apos, strlen(apos));
+ ncp += strlen(apos);
+ cp++;
+ } else if (*cp == '<') {
+ strncpy(ncp, lt, strlen(lt));
+ ncp += strlen(lt);
+ cp++;
+ } else if (*cp == '>') {
+ strncpy(ncp, gt, strlen(gt));
+ ncp += strlen(gt);
+ cp++;
+ } else if (*cp == '\"') {
+ strncpy(ncp, quote, strlen(quote));
+ ncp += strlen(quote);
+ cp++;
+ } else if (*cp == '&') {
+ strncpy(ncp, amp, strlen(amp));
+ ncp += strlen(amp);
+ cp++;
+ } else {
+ *ncp++ = *cp++;
+ }
}
+
+ *ncp = '\0';
+ return rcp;
}
/*-------------------------------------------------------------------------
@@ -3021,16 +3101,18 @@ xml_escape_the_string(const char *str, int slen)
char *ncp;
char *rcp;
- if (str == NULL)
+ if (!str)
return NULL;
cp = str;
- if (slen < 0) {
+
+ if (slen < 0)
len = strlen(str);
- } else {
+ else
len = slen;
- }
+
extra = 0;
+
for (i = 0; i < len; i++) {
if (*cp == '\\') {
extra++;
@@ -3050,8 +3132,10 @@ xml_escape_the_string(const char *str, int slen)
cp = str;
rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
+
if (ncp == NULL)
return NULL; /* ?? */
+
for (i = 0; i < len; i++) {
if (*cp == '\\') {
*ncp++ = '\\';
@@ -3079,6 +3163,7 @@ xml_escape_the_string(const char *str, int slen)
*ncp++ = *cp++;
}
}
+
*ncp = '\0';
return rcp;
}
@@ -3169,7 +3254,7 @@ xml_print_datatype(hid_t type)
/* <FloatType ByteOrder="bo" Size="bytes"
SignBitLocation="bytes"
ExponentBits="eb" ExponentLocation="el"
- MatissaBits="mb" MatissaLocation="ml" /> */
+ MantissaBits="mb" MantissaLocation="ml" /> */
ord = H5Tget_order(type);
indentation(indent);
printf("<AtomicType>\n");
@@ -3296,17 +3381,15 @@ xml_print_datatype(hid_t type)
if (!type_table->objs[i].recorded) {
/* 'anonymous' NDT. Use it's object num.
as it's name. */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("/#%lu:%lu",
+ printf("<NamedDataTypePtr OBJ-XID=\"/#%lu:%lu\"/>\n",
type_table->objs[i].objno[0],
type_table->objs[i].objno[1]);
- printf("\"/>\n");
} else {
/* point to the NDT by name */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("%s",
- xml_escape_the_name(type_table->objs[i].objname));
- printf("\"/>\n");
+ char *t_objname = xml_escape_the_name(type_table->objs[i].objname);
+
+ printf("<NamedDataTypePtr OBJ-XID=\"%s\"/>\n", t_objname);
+ free(t_objname);
}
} else {
printf("<!-- h5dump error: unknown committed type. -->\n");
@@ -3325,13 +3408,16 @@ xml_print_datatype(hid_t type)
/* <DataType > */
indent += COL;
for (i = 0; i < nmembers; i++) {
+ char *t_fname;
+
fname = H5Tget_member_name(type, i);
mtype = H5Tget_member_type(type, i);
indentation(indent);
- printf("<Field FieldName=\"%s\">\n",
- xml_escape_the_name(fname));
+ t_fname = xml_escape_the_name(fname);
+ printf("<Field FieldName=\"%s\">\n", t_fname);
free(fname);
+ free(t_fname);
indent += COL;
indentation(indent);
printf("<DataType>\n");
@@ -3492,17 +3578,15 @@ xml_dump_datatype(hid_t type)
practice:
use it's object ref as its name
*/
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("/#%lu:%lu",
+ printf("<NamedDataTypePtr OBJ-XID=\"/#%lu:%lu\"/>\n",
type_table->objs[i].objno[0],
type_table->objs[i].objno[1]);
- printf("\"/>\n");
} else {
/* pointer to a named data type already in XML */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("%s",
- xml_escape_the_name(type_table->objs[i].objname));
- printf("\"/>\n");
+ char *t_objname = xml_escape_the_name(type_table->objs[i].objname);
+
+ printf("<NamedDataTypePtr OBJ-XID=\"%s\"/>\n", t_objname);
+ free(t_objname);
}
} else {
printf("<!-- h5dump error: unknown committed type. -->\n");
@@ -3612,7 +3696,6 @@ xml_dump_data(hid_t obj_id, int obj_data)
int stdindent = COL; /* should be 3 */
outputformat->line_ncols = nCols;
-
indent += COL;
/*
@@ -3708,10 +3791,12 @@ xml_dump_data(hid_t obj_id, int obj_data)
static herr_t
xml_dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
{
- hid_t attr_id, type, space;
+ hid_t attr_id, type, space;
+ char *t_aname = xml_escape_the_name(attr_name);
indentation(indent);
- printf("<Attribute Name=\"%s\">\n", xml_escape_the_name(attr_name));
+ printf("<Attribute Name=\"%s\">\n", t_aname);
+ free(t_aname);
if ((attr_id = H5Aopen_name(attr, attr_name)) >= 0) {
type = H5Aget_type(attr_id);
@@ -3729,8 +3814,7 @@ xml_dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
case H5T_OPAQUE:
case H5T_ENUM:
case H5T_ARRAY:
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
+ dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA);
break;
case H5T_TIME:
@@ -3748,10 +3832,8 @@ xml_dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
case H5T_COMPOUND:
indentation(indent);
- printf
- ("<!-- Note: format of compound data not specified -->\n");
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
+ printf("<!-- Note: format of compound data not specified -->\n");
+ dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA);
break;
case H5T_REFERENCE:
@@ -3768,8 +3850,7 @@ xml_dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
case H5T_VLEN:
printf("<!-- Note: format of VL data not specified -->\n");
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
+ dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA);
break;
default:
indentation(indent);
@@ -3831,7 +3912,7 @@ xml_dump_named_datatype(hid_t type, const char *name)
char *fname;
char *tmp;
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
+ tmp = malloc(strlen(prefix) + strlen(name) + 2);
strcpy(tmp, prefix);
strcat(tmp, "/");
strcat(tmp, name);
@@ -3846,18 +3927,28 @@ xml_dump_named_datatype(hid_t type, const char *name)
in the event we want to do something else in
the future.
*/
+ char *t_tmp = xml_escape_the_name(tmp);
+ char *t_prefix = xml_escape_the_name(prefix);
+
printf("<NamedDataType Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- name,
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
+ name, t_tmp, (strcmp(prefix, "") ? t_prefix : "root"));
+ free(t_tmp);
+ free(t_prefix);
} else {
+ char *t_name = xml_escape_the_name(name);
+ char *t_prefix = xml_escape_the_name(prefix);
+ char *t_tmp = xml_escape_the_name(tmp);
+
printf("<NamedDataType Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
+ t_name, t_tmp, (strcmp(prefix, "") ? t_prefix : "root"));
+
+ free(t_name);
+ free(t_prefix);
+ free(t_tmp);
}
indent += COL;
+
if (H5Tget_class(type) == H5T_COMPOUND) {
/* Dump this here for sure. */
nmembers = H5Tget_nmembers(type);
@@ -3867,11 +3958,15 @@ xml_dump_named_datatype(hid_t type, const char *name)
indent += COL;
for (x = 0; x < nmembers; x++) {
+ char *t_fname;
+
fname = H5Tget_member_name(type, x);
mtype = H5Tget_member_type(type, x);
indentation(indent);
- printf("<Field FieldName=\"%s\">\n", xml_escape_the_name(fname));
+ t_fname = xml_escape_the_name(fname);
+ printf("<Field FieldName=\"%s\">\n", t_fname);
free(fname);
+ free(t_fname);
if ((H5Tget_class(mtype) == H5T_COMPOUND)
|| (H5Tget_class(mtype) == H5T_VLEN)
@@ -3960,15 +4055,23 @@ xml_dump_group(hid_t gid, const char *name)
}
}
}
+
indentation(indent);
+
if (isRoot) {
printf("<RootGroup OBJ-XID=\"root\">\n");
} else {
+ char *t_name = xml_escape_the_name(name);
+ char *t_tmp = xml_escape_the_name(tmp);
+ char *t_par = xml_escape_the_name(par);
+
printf("<Group Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\" >\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(par) : "root"));
+ t_name, t_tmp, (strcmp(prefix, "") ? t_par : "root"));
+ free(t_name);
+ free(t_tmp);
+ free(t_par);
}
+
indent += COL;
H5Gget_objinfo(gid, ".", TRUE, &statbuf);
@@ -3978,13 +4081,16 @@ xml_dump_group(hid_t gid, const char *name)
if (i < 0) {
indentation(indent);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
+ error_msg(progname, "internal error (file %s:line %d)\n",
+ __FILE__, __LINE__);
d_status = EXIT_FAILURE;
} else if (group_table->objs[i].displayed) {
/* already seen: enter a groupptr */
+ char *t_objname = xml_escape_the_name(group_table->objs[i].objname);
+
indentation(indent + COL);
- printf("<GroupPtr OBJ-XID=\"%s\"/>\n",
- xml_escape_the_name(group_table->objs[i].objname));
+ printf("<GroupPtr OBJ-XID=\"%s\"/>\n", t_objname);
+ free(t_objname);
} else {
/* first time this group has been seen -- describe it */
strcpy(group_table->objs[i].objname, prefix);
@@ -4008,8 +4114,7 @@ xml_dump_group(hid_t gid, const char *name)
sprintf(typename, "#%lu:%lu",
type_table->objs[i].objno[0],
type_table->objs[i].objno[1]);
- dump_function_table->dump_named_datatype_function
- (type, typename);
+ dump_function_table->dump_named_datatype_function(type, typename);
H5Tclose(type);
H5Dclose(dset);
}
@@ -4022,14 +4127,13 @@ xml_dump_group(hid_t gid, const char *name)
}
} else {
/* 1. do all the attributes of the group */
- H5Aiterate(gid, NULL, dump_function_table->dump_attribute_function,
- NULL);
+ H5Aiterate(gid, NULL, dump_function_table->dump_attribute_function, NULL);
- /* iterate through all the members */
- xtype = H5G_GROUP;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_DATASET;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
+ /* iterate through all the members */
+ xtype = H5G_GROUP;
+ H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
+ xtype = H5G_DATASET;
+ H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
if (!strcmp(name, "/") && unamedtype) {
/* Very special case: dump unamed type in root group */
for (i = 0; i < type_table->nobjs; i++) {
@@ -4039,8 +4143,7 @@ xml_dump_group(hid_t gid, const char *name)
sprintf(typename, "#%lu:%lu",
type_table->objs[i].objno[0],
type_table->objs[i].objno[1]);
- dump_function_table->dump_named_datatype_function(type,
- typename);
+ dump_function_table->dump_named_datatype_function(type, typename);
H5Tclose(type);
H5Dclose(dset);
}
@@ -4144,13 +4247,19 @@ xml_print_refs(hid_t did, int source)
for (i = 0; i < ssiz; i++) {
path = lookup_ref_path(refbuf);
indentation(indent + COL);
- if (path == NULL) {
+
+ if (!path) {
printf("\"%s\"\n", "NULL");
} else {
- printf("\"%s\"\n", xml_escape_the_string(path, -1));
+ char *t_path = xml_escape_the_string(path, -1);
+
+ printf("\"%s\"\n", t_path);
+ free(t_path);
}
+
refbuf++;
}
+
return SUCCEED;
}
@@ -4234,11 +4343,16 @@ xml_print_strs(hid_t did, int source)
for (i = 0; i < ssiz; i++) {
strncpy(onestring, bp, tsiz);
indentation(indent + COL);
- if (onestring == NULL) {
+
+ if (!onestring) {
printf("\"%s\"\n", "NULL");
} else {
+ char *t_onestring = xml_escape_the_string(onestring, (int)tsiz);
+
printf("\"%s\"\n", xml_escape_the_string(onestring, (int)tsiz));
+ free(t_onestring);
}
+
bp += tsiz;
}
return SUCCEED;
@@ -4312,15 +4426,24 @@ xml_dump_dataset(hid_t did, const char *name)
int ndims;
int i;
char *tmp;
+ char *t_name, *t_tmp, *t_prefix;
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
+ tmp = malloc(strlen(prefix) + strlen(name) + 2);
strcpy(tmp, prefix);
strcat(tmp, "/");
strcat(tmp, name);
indentation(indent);
+
+ t_name = xml_escape_the_name(name);
+ t_tmp = xml_escape_the_name(tmp);
+ t_prefix = xml_escape_the_name(prefix);
+
printf("<Dataset Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name), xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
+ t_name, t_tmp, (strcmp(prefix, "") ? t_prefix : "root"));
+
+ free(t_name);
+ free(t_tmp);
+ free(t_prefix);
dcpl = H5Dget_create_plist(did);
type = H5Dget_type(did);
@@ -4343,10 +4466,12 @@ xml_dump_dataset(hid_t did, const char *name)
check_compression(dcpl);
indent += COL;
+
for (i = 0; i < ndims; i++) {
indentation(indent);
- HDfprintf(stdout,"<ChunkDimension DimSize=\"%Hu\" />\n", chsize[i]);
+ HDfprintf(stdout, "<ChunkDimension DimSize=\"%Hu\" />\n", chsize[i]);
}
+
indent -= COL;
indentation(indent);
@@ -4366,6 +4491,7 @@ xml_dump_dataset(hid_t did, const char *name)
H5Aiterate(did, NULL, dump_function_table->dump_attribute_function, NULL);
indent -= COL;
i = H5Dget_storage_size(did);
+
if (display_data && (i > 0)) {
switch (H5Tget_class(type)) {
case H5T_INTEGER:
@@ -4510,10 +4636,13 @@ xml_print_enum(hid_t type)
/* Print members */
indent += COL;
for (i = 0; i < nmembs; i++) {
+ char *t_name = xml_escape_the_name(name[i]);
+
indentation(indent);
printf("<EnumElement>\n");
indentation(indent + COL);
- printf("%s\n", xml_escape_the_name(name[i]));
+ printf("%s\n", t_name);
+ free(t_name);
indentation(indent);
printf("</EnumElement>\n");
indentation(indent);