summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-08-20 19:28:40 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-08-20 19:28:40 (GMT)
commitb7d43b0cf0c750031b60937b7dc2eaf0d8a803eb (patch)
treea451641fa5cb4965b40103576ec53beef49e66e4 /tools
parent96b3c145b7b8e033fff6504a5dbb88c78c42219b (diff)
downloadhdf5-b7d43b0cf0c750031b60937b7dc2eaf0d8a803eb.zip
hdf5-b7d43b0cf0c750031b60937b7dc2eaf0d8a803eb.tar.gz
hdf5-b7d43b0cf0c750031b60937b7dc2eaf0d8a803eb.tar.bz2
[svn-r11283] Purpose:
Code cleanup Description: Clean up code somewhat: - Move from HDmemset() -> H5G_ent_reset() to clear out group entry info - Simplify H5G_unlink() call - Use portability macros instead of direct system calls in more places - Improve readbility by neatening whitespace, etc. - Move some macros into source code module instead of header files Platforms tested: FreeBSD 4.11 (sleipnir) Linux 2.4
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump.c104
-rw-r--r--tools/h5dump/h5dump.h15
-rw-r--r--tools/h5ls/h5ls.c218
3 files changed, 169 insertions, 168 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index b4a8728..b6e3856 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -25,6 +25,23 @@
/* module-scoped variables */
const char *progname = "h5dump";
+/* Macros for displaying objects */
+#define begin_obj(obj,name,begin) \
+ if (name) \
+ printf("%s \"%s\" %s\n", (obj), (name), (begin)); \
+ else \
+ printf("%s %s\n", (obj), (begin));
+
+#define end_obj(obj,end) \
+ if(HDstrlen(end)) { \
+ printf("%s", end); \
+ if(HDstrlen(obj)) \
+ printf(" "); \
+ } \
+ if(HDstrlen(obj)) \
+ printf("%s", obj); \
+ printf("\n");
+
/* 3 private values: can't be set, but can be read.
Note: these are defined in H5Zprivate, they are
duplicated here.
@@ -3542,7 +3559,7 @@ main(int argc, const char *argv[])
goto done;
}
- /* start to dump */
+ /* start to dump - display file header information */
if (!doxml) {
begin_obj(dump_header_format->filebegin, fname,
dump_header_format->fileblockbegin);
@@ -3550,40 +3567,39 @@ main(int argc, const char *argv[])
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
/* alternative first element, depending on schema or DTD. */
if (useschema) {
- if (strcmp(xmlnsprefix,"") == 0) {
- printf("<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n",
- xml_dtd_uri);
- } else {
+ if (strcmp(xmlnsprefix,"") == 0) {
+ printf("<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n",
+ xml_dtd_uri);
+ } else {
/* TO DO: make -url option work in this case (may need new option) */
- char * ns;
- char *indx;
- ns = strdup(xmlnsprefix);
- indx = strrchr(ns,(int)':');
- if (indx) *indx = '\0';
-
- printf("<%sHDF5-File xmlns:%s=\"http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File\" "
- "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
- "xsi:schemaLocation=\"http://hdf.ncsa.uiuc.edu/DTDs/HDF5File "
- "http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File.xsd\">\n",xmlnsprefix,ns);
- }
+ char * ns;
+ char *indx;
+
+ ns = strdup(xmlnsprefix);
+ indx = strrchr(ns,(int)':');
+ if (indx) *indx = '\0';
+
+ printf("<%sHDF5-File xmlns:%s=\"http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File\" "
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xsi:schemaLocation=\"http://hdf.ncsa.uiuc.edu/DTDs/HDF5File "
+ "http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File.xsd\">\n",xmlnsprefix,ns);
+ }
} else {
- printf("<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n",
- xml_dtd_uri);
- printf("<HDF5-File>\n");
+ printf("<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n",
+ xml_dtd_uri);
+ printf("<HDF5-File>\n");
}
}
- if (!doxml)
- {
- if (display_fi)
- {
- dump_fcontents(fid);
- end_obj(dump_header_format->fileend,dump_header_format->fileblockend);
- goto done;
- }
+ if (!doxml) {
+ if (display_fi) {
+ dump_fcontents(fid);
+ end_obj(dump_header_format->fileend,dump_header_format->fileblockend);
+ goto done;
+ }
- if (display_bb)
- dump_fcpl(fid);
+ if (display_bb)
+ dump_fcpl(fid);
}
@@ -3866,7 +3882,7 @@ xml_escape_the_name(const char *str)
return HDstrdup(str);
cp = str;
- rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
+ rcp = ncp = HDmalloc(len + extra + 1);
if (!ncp)
return NULL; /* ?? */
@@ -4053,14 +4069,12 @@ xml_print_datatype(hid_t type, unsigned in_group)
/* 'anonymous' NDT. Use it's object num.
as it's name. */
printf("<%sNamedDataTypePtr OBJ-XID=\"/%s\"/>\n",
- xmlnsprefix,
- dtxid);
+ xmlnsprefix, dtxid);
} else {
/* point to the NDT by name */
char *t_objname = xml_escape_the_name(type_table->objs[ret].objname);
printf("<%sNamedDataTypePtr OBJ-XID=\"%s\" H5Path=\"%s\"/>\n",
- xmlnsprefix,
- dtxid,t_objname);
+ xmlnsprefix, dtxid,t_objname);
free(t_objname);
}
free(dtxid);
@@ -4423,15 +4437,13 @@ xml_dump_datatype(hid_t type)
use it's object ref as its name
*/
printf("<%sNamedDataTypePtr OBJ-XID=\"%s\"/>\n",
- xmlnsprefix,
- dtxid);
+ xmlnsprefix, dtxid);
} else {
/* pointer to a named data type already in XML */
char *t_objname = xml_escape_the_name(type_table->objs[i].objname);
printf("<%sNamedDataTypePtr OBJ-XID=\"%s\" H5Path=\"%s\" />\n",
- xmlnsprefix,
- dtxid,t_objname);
+ xmlnsprefix, dtxid,t_objname);
free(t_objname);
}
free(dtxid);
@@ -5081,7 +5093,6 @@ xml_print_refs(hid_t did, int source)
hid_t type, space;
char *buf;
hobj_ref_t *refbuf;
- char *path;
hsize_t ssiz;
hsize_t i;
@@ -5139,6 +5150,8 @@ xml_print_refs(hid_t did, int source)
ssiz = H5Sget_simple_extent_npoints(space);
for (i = 0; i < ssiz; i++) {
+ const char *path;
+
path = lookup_ref_path(*refbuf);
indentation(indent + COL);
@@ -5419,7 +5432,8 @@ check_filters(hid_t dcpl)
}
}
-static void xml_dump_fill_value(hid_t dcpl, hid_t type)
+static void
+xml_dump_fill_value(hid_t dcpl, hid_t type)
{
size_t sz;
size_t i;
@@ -5533,11 +5547,11 @@ char * name;
break;
}
}
- free(buf);
- indent -= COL;
- indentation(indent);
- printf("</%sData>\n",xmlnsprefix);
- indent -= COL;
+ free(buf);
+ indent -= COL;
+ indentation(indent);
+ printf("</%sData>\n",xmlnsprefix);
+ indent -= COL;
}
/*-------------------------------------------------------------------------
* Function: xml_dump_group
diff --git a/tools/h5dump/h5dump.h b/tools/h5dump/h5dump.h
index ba1eab2..96e7d71 100644
--- a/tools/h5dump/h5dump.h
+++ b/tools/h5dump/h5dump.h
@@ -18,19 +18,4 @@
#define H5DUMP_MAX_RANK H5S_MAX_RANK
-#define begin_obj(obj,name,begin) \
- if (name) \
- printf("%s \"%s\" %s\n", (obj), (name), (begin)); \
- else \
- printf("%s %s\n", (obj), (begin));
-
-#define end_obj(obj,end) \
- if(HDstrlen(end)) \
- printf("%s", end); \
- if(HDstrlen(end) && HDstrlen(obj)) \
- printf(" "); \
- if(HDstrlen(obj)) \
- printf("%s", obj); \
- printf("\n");
-
#endif /* !H5DUMP_H__ */
diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c
index 7957383..cd2de6f 100644
--- a/tools/h5ls/h5ls.c
+++ b/tools/h5ls/h5ls.c
@@ -154,16 +154,15 @@ sym_insert(H5G_stat_t *sb, const char *name)
/* Extend the table */
if (idtab_g.nobjs>=idtab_g.nalloc) {
- idtab_g.nalloc = MAX(256, 2*idtab_g.nalloc);
- idtab_g.obj = realloc(idtab_g.obj,
- idtab_g.nalloc*sizeof(idtab_g.obj[0]));
+ idtab_g.nalloc = MAX(256, 2*idtab_g.nalloc);
+ idtab_g.obj = realloc(idtab_g.obj,
+ idtab_g.nalloc*sizeof(idtab_g.obj[0]));
}
/* Insert the entry */
n = idtab_g.nobjs++;
idtab_g.obj[n].id = sb->objno;
- idtab_g.obj[n].name = malloc(strlen(name)+1);
- strcpy(idtab_g.obj[n].name, name);
+ idtab_g.obj[n].name = HDstrdup(name);
}
@@ -190,8 +189,8 @@ sym_lookup(H5G_stat_t *sb)
if (sb->nlink<2) return NULL; /*only one name possible*/
for (n=0; n<idtab_g.nobjs; n++) {
- if (idtab_g.obj[n].id==sb->objno)
- return idtab_g.obj[n].name;
+ if (idtab_g.obj[n].id==sb->objno)
+ return idtab_g.obj[n].name;
}
return NULL;
}
@@ -219,56 +218,56 @@ display_string(FILE *stream, const char *s, hbool_t escape_spaces)
int nprint=0;
for (/*void*/; s && *s; s++) {
- switch (*s) {
- case '"':
- if (stream) fprintf(stream, "\\\"");
- nprint += 2;
- break;
- case '\\':
- if (stream) fprintf(stream, "\\\\");
- nprint += 2;
- break;
- case '\b':
- if (stream) fprintf(stream, "\\b");
- nprint += 2;
- break;
- case '\f':
- if (stream) fprintf(stream, "\\f");
- nprint += 2;
- break;
- case '\n':
- if (stream) fprintf(stream, "\\n");
- nprint += 2;
- break;
- case '\r':
- if (stream) fprintf(stream, "\\r");
- nprint += 2;
- break;
- case '\t':
- if (stream) fprintf(stream, "\\t");
- nprint += 2;
- break;
- case ' ':
- if (escape_spaces) {
- if (stream) fprintf(stream, "\\ ");
- nprint += 2;
- } else {
- if (stream) fprintf(stream, " ");
- nprint++;
- }
- break;
- default:
- if (isprint((int)*s)) {
- if (stream) putc(*s, stream);
- nprint++;
- } else {
- if (stream) {
- fprintf(stream, "\\%03o", *((const unsigned char*)s));
- }
- nprint += 4;
- }
- break;
- }
+ switch (*s) {
+ case '"':
+ if (stream) fprintf(stream, "\\\"");
+ nprint += 2;
+ break;
+ case '\\':
+ if (stream) fprintf(stream, "\\\\");
+ nprint += 2;
+ break;
+ case '\b':
+ if (stream) fprintf(stream, "\\b");
+ nprint += 2;
+ break;
+ case '\f':
+ if (stream) fprintf(stream, "\\f");
+ nprint += 2;
+ break;
+ case '\n':
+ if (stream) fprintf(stream, "\\n");
+ nprint += 2;
+ break;
+ case '\r':
+ if (stream) fprintf(stream, "\\r");
+ nprint += 2;
+ break;
+ case '\t':
+ if (stream) fprintf(stream, "\\t");
+ nprint += 2;
+ break;
+ case ' ':
+ if (escape_spaces) {
+ if (stream) fprintf(stream, "\\ ");
+ nprint += 2;
+ } else {
+ if (stream) fprintf(stream, " ");
+ nprint++;
+ }
+ break;
+ default:
+ if (isprint((int)*s)) {
+ if (stream) putc(*s, stream);
+ nprint++;
+ } else {
+ if (stream) {
+ fprintf(stream, "\\%03o", *((const unsigned char*)s));
+ }
+ nprint += 4;
+ }
+ break;
+ }
}
return nprint;
}
@@ -1670,8 +1669,8 @@ group_list2(hid_t grp, const char *name)
iter_t iter;
if (recursive_g) {
- iter.container = name;
- H5Giterate(grp, ".", NULL, list, &iter);
+ iter.container = name;
+ H5Giterate(grp, ".", NULL, list, &iter);
}
return 0;
}
@@ -1773,51 +1772,51 @@ list (hid_t group, const char *name, void *_iter)
/* Print the object name, either full name or base name */
fullname = fix_name(iter->container, name);
if (fullname_g) {
- n = display_string(stdout, fullname, TRUE);
- printf("%*s ", MAX(0, 24-n), "");
+ n = display_string(stdout, fullname, TRUE);
+ printf("%*s ", MAX(0, 24-n), "");
} else {
- n = display_string(stdout, name, TRUE);
- printf("%*s ", MAX(0, 24-n), "");
+ n = display_string(stdout, name, TRUE);
+ printf("%*s ", MAX(0, 24-n), "");
}
/* Get object information */
H5E_BEGIN_TRY {
- status = H5Gget_objinfo(group, name, FALSE, &sb);
+ status = H5Gget_objinfo(group, name, FALSE, &sb);
} H5E_END_TRY;
if (status<0) {
- puts("**NOT FOUND**");
- return 0;
+ puts("**NOT FOUND**");
+ return 0;
} else if (sb.type<0 || sb.type>=H5G_NTYPES) {
- printf("Unknown type(%d)", sb.type);
- sb.type = H5G_UNKNOWN;
+ printf("Unknown type(%d)", sb.type);
+ sb.type = H5G_UNKNOWN;
}
if (sb.type>=0 && dispatch_g[sb.type].name) {
- fputs(dispatch_g[sb.type].name, stdout);
+ fputs(dispatch_g[sb.type].name, stdout);
}
/* If the object has already been printed then just show the object ID
* and return. */
if ((s=sym_lookup(&sb))) {
- printf(", same as ");
- display_string(stdout, s, TRUE);
- printf("\n");
- goto done;
+ printf(", same as ");
+ display_string(stdout, s, TRUE);
+ printf("\n");
+ goto done;
} else {
- sym_insert(&sb, fullname);
+ sym_insert(&sb, fullname);
}
/* Open the object. Not all objects can be opened. If this is the case
* then return right away. */
if (sb.type>=0 &&
- (NULL==dispatch_g[sb.type].open ||
- (obj=(dispatch_g[sb.type].open)(group, name))<0)) {
- printf(" *ERROR*\n");
- goto done;
+ (NULL==dispatch_g[sb.type].open ||
+ (obj=(dispatch_g[sb.type].open)(group, name))<0)) {
+ printf(" *ERROR*\n");
+ goto done;
}
/* List the first line of information for the object. */
if (sb.type>=0 && dispatch_g[sb.type].list1) {
- (dispatch_g[sb.type].list1)(obj);
+ (dispatch_g[sb.type].list1)(obj);
}
putchar('\n');
@@ -1832,27 +1831,27 @@ list (hid_t group, const char *name, void *_iter)
if (simple_output_g) tm=gmtime(&(sb.mtime));
else tm=localtime(&(sb.mtime));
if (tm) {
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
- printf(" %-10s %s\n", "Modified:", buf);
- }
- }
- comment[0] = '\0';
- H5Gget_comment(group, name, sizeof(comment), comment);
- strcpy(comment+sizeof(comment)-4, "...");
- if (comment[0]) {
- printf(" %-10s \"", "Comment:");
- display_string(stdout, comment, FALSE);
- puts("\"");
- }
+ strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
+ printf(" %-10s %s\n", "Modified:", buf);
+ }
+ }
+ comment[0] = '\0';
+ H5Gget_comment(group, name, sizeof(comment), comment);
+ strcpy(comment+sizeof(comment)-4, "...");
+ if (comment[0]) {
+ printf(" %-10s \"", "Comment:");
+ display_string(stdout, comment, FALSE);
+ puts("\"");
+ }
}
if (sb.type>=0 && dispatch_g[sb.type].list2) {
- (dispatch_g[sb.type].list2)(obj, fullname);
+ (dispatch_g[sb.type].list2)(obj, fullname);
}
/* Close the object. */
- done:
+done:
if (sb.type>=0 && obj>=0 && dispatch_g[sb.type].close) {
- (dispatch_g[sb.type].close)(obj);
+ (dispatch_g[sb.type].close)(obj);
}
if (fullname) free(fullname);
return 0;
@@ -1880,25 +1879,28 @@ list (hid_t group, const char *name, void *_iter)
static char *
fix_name(const char *path, const char *base)
{
- size_t n = (path?strlen(path):0) + (base?strlen(base):0) + 3;
- char *s = malloc(n), prev='\0';
- int len=0;
+ size_t n = (path ? HDstrlen(path) : 0) + (base ? HDstrlen(base) : 0) + 3;
+ char *s = HDmalloc(n), prev='\0';
+ size_t len = 0;
if (path) {
- /* Path, followed by slash */
- for (/*void*/; *path; path++) {
- if ('/'!=*path || '/'!=prev) prev = s[len++] = *path;
- }
- if ('/'!=prev) prev = s[len++] = '/';
+ /* Path, followed by slash */
+ for (/*void*/; *path; path++)
+ if ('/'!=*path || '/'!=prev)
+ prev = s[len++] = *path;
+ if ('/' != prev)
+ prev = s[len++] = '/';
}
if (base) {
- /* Base name w/o trailing slashes */
- const char *end = base + strlen(base);
- while (end>base && '/'==end[-1]) --end;
- for (/*void*/; base<end; base++) {
- if ('/'!=*base || '/'!=prev) prev = s[len++] = *base;
- }
+ /* Base name w/o trailing slashes */
+ const char *end = base + HDstrlen(base);
+ while (end > base && '/' == end[-1])
+ --end;
+
+ for (/*void*/; base < end; base++)
+ if ('/' != *base || '/' != prev)
+ prev = s[len++] = *base;
}
s[len] = '\0';