summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c189
1 files changed, 97 insertions, 92 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index a6050ca..9f5fa0a 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -52,13 +52,13 @@ error_msg(const char *progname, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- fflush(stdout);
+ HDfflush(stdout);
#ifdef WIN32
- fprintf(stdout, "%s error: ", progname);
- vfprintf(stdout, fmt, ap);
+ HDfprintf(stdout, "%s error: ", progname);
+ HDvfprintf(stdout, fmt, ap);
#else
- fprintf(stderr, "%s error: ", progname);
- vfprintf(stderr, fmt, ap);
+ HDfprintf(stderr, "%s error: ", progname);
+ HDvfprintf(stderr, fmt, ap);
#endif
va_end(ap);
@@ -86,9 +86,14 @@ warn_msg(const char *progname, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- fflush(stdout);
- fprintf(stderr, "%s warning: ", progname);
- vfprintf(stderr, fmt, ap);
+ HDfflush(stdout);
+#ifdef WIN32
+ HDfprintf(stdout, "%s warning: ", progname);
+ HDvfprintf(stdout, fmt, ap);
+#else /* WIN32 */
+ HDfprintf(stderr, "%s warning: ", progname);
+ HDvfprintf(stderr, fmt, ap);
+#endif /* WIN32 */
va_end(ap);
}
@@ -122,7 +127,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
/* check for more flag-like tokens */
if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0') {
return EOF;
- } else if (strcmp(argv[opt_ind], "--") == 0) {
+ } else if (HDstrcmp(argv[opt_ind], "--") == 0) {
opt_ind++;
return EOF;
}
@@ -131,12 +136,12 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-') {
/* long command line option */
const char *arg = &argv[opt_ind][2];
- register int i;
+ int i;
for (i = 0; l_opts && l_opts[i].name; i++) {
- size_t len = strlen(l_opts[i].name);
+ size_t len = HDstrlen(l_opts[i].name);
- if (strncmp(arg, l_opts[i].name, len) == 0) {
+ if (HDstrncmp(arg, l_opts[i].name, len) == 0) {
/* we've found a matching long command line flag */
opt_opt = l_opts[i].shortval;
@@ -147,7 +152,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
opt_arg = argv[++opt_ind];
} else if (l_opts[i].has_arg == require_arg) {
if (opt_err)
- fprintf(stderr,
+ HDfprintf(stderr,
"%s: option required for \"--%s\" flag\n",
argv[0], arg);
@@ -156,7 +161,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
} else {
if (arg[len] == '=') {
if (opt_err)
- fprintf(stderr,
+ HDfprintf(stderr,
"%s: no option required for \"%s\" flag\n",
argv[0], arg);
@@ -173,7 +178,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)
- fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
+ HDfprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
opt_opt = '?';
}
@@ -188,7 +193,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0) {
if (opt_err)
- fprintf(stderr, "%s: unknown option \"%c\"\n",
+ HDfprintf(stderr, "%s: unknown option \"%c\"\n",
argv[0], opt_opt);
/* if no chars left in this token, move to next token */
@@ -207,7 +212,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
opt_arg = &argv[opt_ind++][sp + 1];
} else if (++opt_ind >= argc) {
if (opt_err)
- fprintf(stderr,
+ HDfprintf(stderr,
"%s: value expected for option \"%c\"\n",
argv[0], opt_opt);
@@ -255,7 +260,7 @@ indentation(int x)
while (x-- > 0)
printf(" ");
} else {
- fprintf(stderr, "error: the indentation exceeds the number of cols.\n");
+ HDfprintf(stderr, "error: the indentation exceeds the number of cols.\n");
exit(1);
}
}
@@ -302,11 +307,11 @@ void
init_table(table_t **tbl)
{
int i;
- table_t *table = malloc(sizeof(table_t));
+ table_t *table = HDmalloc(sizeof(table_t));
table->size = 20;
table->nobjs = 0;
- table->objs = malloc(table->size * sizeof(obj_t));
+ table->objs = HDmalloc(table->size * sizeof(obj_t));
for (i = 0; i < table->size; i++) {
table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
@@ -334,7 +339,7 @@ void
init_prefix(char **prefix, int prefix_len)
{
assert(prefix_len > 0);
- *prefix = calloc((size_t)prefix_len, 1);
+ *prefix = HDcalloc((size_t)prefix_len, 1);
}
@@ -377,7 +382,7 @@ free_table(table_t **table)
int
search_obj(table_t *table, unsigned long *objno)
{
- register int i;
+ int i;
for (i = 0; i < table->nobjs; i++)
if (table->objs[i].objno[0] == *objno && table->objs[i].objno[1] == *(objno + 1))
@@ -409,7 +414,7 @@ find_objs(hid_t group, const char *name, void *op_data)
H5G_stat_t statbuf;
char *tmp;
find_objs_t *info = (find_objs_t*)op_data;
- register int i;
+ int i;
if (info->threshold > 1)
/*will get an infinite loop if greater than 1*/
@@ -417,93 +422,93 @@ find_objs(hid_t group, const char *name, void *op_data)
H5Gget_objinfo(group, name, TRUE, &statbuf);
- tmp = malloc(strlen(info->prefix) + strlen(name) + 2);
- strcpy(tmp, info->prefix);
+ tmp = HDmalloc(HDstrlen(info->prefix) + HDstrlen(name) + 2);
+ HDstrcpy(tmp, info->prefix);
switch (statbuf.type) {
- case H5G_GROUP:
- if ((obj = H5Gopen(group, name)) >= 0) {
- if (info->prefix_len < (int)(strlen(info->prefix) + strlen(name) + 2)) {
- info->prefix_len *= 2;
- info->prefix = realloc(info->prefix,
- info->prefix_len * sizeof(char));
- }
+ case H5G_GROUP:
+ if ((obj = H5Gopen(group, name)) >= 0) {
+ if (info->prefix_len < (int)(HDstrlen(info->prefix) + HDstrlen(name) + 2)) {
+ info->prefix_len *= 2;
+ info->prefix = HDrealloc(info->prefix,
+ info->prefix_len * sizeof(char));
+ }
- strcat(strcat(info->prefix,"/"), name);
+ HDstrcat(HDstrcat(info->prefix,"/"), name);
- if (statbuf.nlink > info->threshold) {
- if (search_obj(info->group_table, statbuf.objno) == FAIL) {
- add_obj(info->group_table, statbuf.objno, info->prefix);
- H5Giterate(obj, ".", NULL, find_objs, (void *)info);
+ if (statbuf.nlink > info->threshold) {
+ if (search_obj(info->group_table, statbuf.objno) == FAIL) {
+ add_obj(info->group_table, statbuf.objno, info->prefix);
+ H5Giterate(obj, ".", NULL, find_objs, (void *)info);
+ }
+ } else {
+ H5Giterate (obj, ".", NULL, find_objs, (void *)info);
}
- } else {
- H5Giterate (obj, ".", NULL, find_objs, (void *)info);
- }
- strcpy(info->prefix, tmp);
- H5Gclose (obj);
- } else {
- info->status = 1;
- }
+ HDstrcpy(info->prefix, tmp);
+ H5Gclose (obj);
+ } else {
+ info->status = 1;
+ }
- break;
+ break;
- case H5G_DATASET:
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the data set */
+ case H5G_DATASET:
+ HDstrcat(tmp,"/");
+ HDstrcat(tmp,name); /* absolute name of the data set */
- if (statbuf.nlink > info->threshold &&
- search_obj(info->dset_table, statbuf.objno) == FAIL)
- add_obj(info->dset_table, statbuf.objno, tmp);
+ if (statbuf.nlink > info->threshold &&
+ search_obj(info->dset_table, statbuf.objno) == FAIL)
+ add_obj(info->dset_table, statbuf.objno, tmp);
- if ((obj = H5Dopen (group, name)) >= 0) {
- type = H5Dget_type(obj);
+ if ((obj = H5Dopen (group, name)) >= 0) {
+ type = H5Dget_type(obj);
- if (H5Tcommitted(type) > 0) {
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
+ if (H5Tcommitted(type) > 0) {
+ H5Gget_objinfo(type, ".", TRUE, &statbuf);
- if (search_obj(info->type_table, statbuf.objno) == FAIL) {
- add_obj(info->type_table, statbuf.objno, tmp);
- info->type_table->objs[info->type_table->nobjs - 1].objflag = 0;
+ if (search_obj(info->type_table, statbuf.objno) == FAIL) {
+ add_obj(info->type_table, statbuf.objno, tmp);
+ info->type_table->objs[info->type_table->nobjs - 1].objflag = 0;
+ }
}
- }
- H5Tclose(type);
- H5Dclose (obj);
- } else {
- info->status = 1;
- }
-
- break;
+ H5Tclose(type);
+ H5Dclose (obj);
+ } else {
+ info->status = 1;
+ }
+
+ break;
- case H5G_TYPE:
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the type */
- i = search_obj(info->type_table, statbuf.objno);
+ case H5G_TYPE:
+ HDstrcat(tmp,"/");
+ HDstrcat(tmp,name); /* absolute name of the type */
+ i = search_obj(info->type_table, statbuf.objno);
- if (i == FAIL) {
- add_obj(info->type_table, statbuf.objno, tmp) ;
+ if (i == FAIL) {
+ add_obj(info->type_table, statbuf.objno, tmp) ;
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].recorded = 1;
+ /* named data type */
+ info->type_table->objs[info->type_table->nobjs-1].recorded = 1;
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
- } else {
- strcpy (info->type_table->objs[i].objname, tmp);
- info->type_table->objs[i].recorded = 1;
+ /* named data type */
+ info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
+ } else {
+ strcpy (info->type_table->objs[i].objname, tmp);
+ info->type_table->objs[i].recorded = 1;
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
- }
+ /* named data type */
+ info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
+ }
- break;
+ break;
- default:
- break;
+ default:
+ break;
}
- free(tmp);
+ HDfree(tmp);
return SUCCEED;
}
@@ -524,7 +529,7 @@ find_objs(hid_t group, const char *name, void *op_data)
void
dump_table(char* tablename, table_t *table)
{
- register int i;
+ int i;
printf("%s: # of entries = %d\n", tablename,table->nobjs);
@@ -612,7 +617,7 @@ set_tableflag(table_t *table, int idx)
char *
get_objectname(table_t *table, int idx)
{
- return strdup(table->objs[idx].objname);
+ return HDstrdup(table->objs[idx].objname);
}
@@ -633,11 +638,11 @@ get_objectname(table_t *table, int idx)
static void
add_obj(table_t *table, unsigned long *objno, char *objname)
{
- register int i;
+ int i;
if (table->nobjs == table->size) {
table->size *= 2;
- table->objs = realloc(table->objs, table->size * sizeof(obj_t));
+ table->objs = HDrealloc(table->objs, table->size * sizeof(obj_t));
for (i = table->nobjs; i < table->size; i++) {
table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
@@ -650,5 +655,5 @@ add_obj(table_t *table, unsigned long *objno, char *objname)
i = table->nobjs++;
table->objs[i].objno[0] = objno[0];
table->objs[i].objno[1] = objno[1];
- strcpy(table->objs[i].objname, objname);
+ HDstrcpy(table->objs[i].objname, objname);
}