diff options
Diffstat (limited to 'tools/h5repack/h5repack_opttable.c')
-rw-r--r-- | tools/h5repack/h5repack_opttable.c | 136 |
1 files changed, 73 insertions, 63 deletions
diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index b816176..2fd39fd 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -6,7 +6,7 @@ * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -21,23 +21,25 @@ * Purpose: initialize a pack_info_t structure * * Return: void - *------------------------------------------------------------------------- + *------------------------------------------------------------------------- */ -void init_packobject(pack_info_t *obj) { +void +init_packobject(pack_info_t *obj) +{ int j, k; HDstrcpy(obj->path, "\0"); for (j = 0; j < H5_REPACK_MAX_NFILTERS; j++) { - obj->filter[j].filtn = -1; + obj->filter[j].filtn = -1; obj->filter[j].cd_nelmts = CD_VALUES; for (k = 0; k < CD_VALUES; k++) obj->filter[j].cd_values[k] = 0; } obj->chunk.rank = -1; - obj->refobj_id = -1; - obj->layout = H5D_LAYOUT_ERROR; - obj->nfilters = 0; + obj->refobj_id = -1; + obj->layout = H5D_LAYOUT_ERROR; + obj->nfilters = 0; } /*------------------------------------------------------------------------- @@ -49,11 +51,13 @@ void init_packobject(pack_info_t *obj) { *------------------------------------------------------------------------- */ -static void aux_tblinsert_filter(pack_opttbl_t *table, unsigned int I, filter_info_t filt) { +static void +aux_tblinsert_filter(pack_opttbl_t *table, unsigned int I, filter_info_t filt) +{ if (table->objs[I].nfilters < H5_REPACK_MAX_NFILTERS) table->objs[I].filter[table->objs[I].nfilters++] = filt; else - H5TOOLS_INFO(H5E_tools_min_id_g, "cannot insert the filter in this object. Maximum capacity exceeded"); + H5TOOLS_INFO("cannot insert the filter in this object. Maximum capacity exceeded"); } /*------------------------------------------------------------------------- @@ -64,7 +68,9 @@ static void aux_tblinsert_filter(pack_opttbl_t *table, unsigned int I, filter_in * Return: void *------------------------------------------------------------------------- */ -static void aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I, pack_info_t *pack) { +static void +aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I, pack_info_t *pack) +{ int k; table->objs[I].layout = pack->layout; @@ -72,15 +78,14 @@ static void aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I, pack_info /* -2 means the NONE option, remove chunking and set the layout to contiguous */ if (pack->chunk.rank == -2) { - table->objs[I].layout = H5D_CONTIGUOUS; + table->objs[I].layout = H5D_CONTIGUOUS; table->objs[I].chunk.rank = -2; } /* otherwise set the chunking type */ else { table->objs[I].chunk.rank = pack->chunk.rank; for (k = 0; k < pack->chunk.rank; k++) - table->objs[I].chunk.chunk_lengths[k] = - pack->chunk.chunk_lengths[k]; + table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k]; } } } @@ -97,54 +102,56 @@ static int aux_inctable(pack_opttbl_t *table, unsigned n_objs) { unsigned u; + int ret_value = 0; table->size += n_objs; - table->objs = (pack_info_t*) HDrealloc(table->objs, table->size * sizeof(pack_info_t)); + table->objs = (pack_info_t *)HDrealloc(table->objs, table->size * sizeof(pack_info_t)); if (table->objs == NULL) { - H5TOOLS_INFO(H5E_tools_min_id_g, "not enough memory for options table"); - return -1; + H5TOOLS_INFO("not enough memory for options table"); + ret_value = -1; + } + else { + for (u = table->nelems; u < table->size; u++) + init_packobject(&table->objs[u]); } - for (u = table->nelems; u < table->size; u++) - init_packobject(&table->objs[u]); - - return 0; + return ret_value; } - /*------------------------------------------------------------------------- * Function: options_table_init * * Purpose: init options table * * Return: 0, ok, -1, fail - *------------------------------------------------------------------------- + *------------------------------------------------------------------------- */ -int options_table_init(pack_opttbl_t **tbl) { - unsigned int i; +int +options_table_init(pack_opttbl_t **tbl) +{ + unsigned int i; pack_opttbl_t *table; + int ret_value = 0; - if (NULL == (table = (pack_opttbl_t *) HDmalloc(sizeof(pack_opttbl_t)))) { - H5TOOLS_INFO(H5E_tools_min_id_g, "not enough memory for options table"); - return -1; + if (NULL == (table = (pack_opttbl_t *)HDmalloc(sizeof(pack_opttbl_t)))) { + H5TOOLS_GOTO_ERROR((-1), "not enough memory for options table"); } - table->size = 30; + table->size = 30; table->nelems = 0; - if (NULL == (table->objs = (pack_info_t*) HDmalloc(table->size * sizeof(pack_info_t)))) { - H5TOOLS_INFO(H5E_tools_min_id_g, "not enough memory for options table"); + if (NULL == (table->objs = (pack_info_t *)HDmalloc(table->size * sizeof(pack_info_t)))) { HDfree(table); - return -1; + H5TOOLS_GOTO_ERROR((-1), "not enough memory for options table"); } for (i = 0; i < table->size; i++) init_packobject(&table->objs[i]); *tbl = table; - return 0; +done: + return ret_value; } - /*------------------------------------------------------------------------- * Function: options_table_free * @@ -154,7 +161,9 @@ int options_table_init(pack_opttbl_t **tbl) { *------------------------------------------------------------------------- */ -int options_table_free(pack_opttbl_t *table) { +int +options_table_free(pack_opttbl_t *table) +{ HDfree(table->objs); HDfree(table); return 0; @@ -166,14 +175,15 @@ int options_table_free(pack_opttbl_t *table) { * Purpose: add a layout option to the option list * * Return: 0, ok, -1, fail - *------------------------------------------------------------------------- + *------------------------------------------------------------------------- */ int -options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pack_opttbl_t *table) +options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pack_opttbl_t *table) { unsigned i, j, I; - unsigned added = 0; - int found = FALSE; + unsigned added = 0; + hbool_t found = FALSE; + int ret_value = 0; /* increase the size of the collection by N_OBJS if necessary */ if (table->nelems + n_objs >= table->size) @@ -187,10 +197,10 @@ options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pa /* linear table search */ for (i = 0; i < table->nelems; i++) { /*already on the table */ - if (HDstrcmp(obj_list[j].obj,table->objs[i].path) == 0) { + if (HDstrcmp(obj_list[j].obj, table->objs[i].path) == 0) { /* already chunk info inserted for this one; exit */ if (table->objs[i].chunk.rank > 0) { - H5TOOLS_INFO(H5E_tools_min_id_g, "chunk information already inserted for <%s>\n", obj_list[j].obj); + H5TOOLS_INFO("chunk information already inserted for <%s>\n", obj_list[j].obj); HDexit(EXIT_FAILURE); } /* insert the layout info */ @@ -200,7 +210,7 @@ options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pa break; } } /* if */ - } /* i */ + } /* i */ if (!found) { /* keep the grow in a temp var */ @@ -214,14 +224,13 @@ options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pa -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 dset1 is already inserted, but dset2 must also be */ - else - if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_layout(table, I, pack); - } + else if (found && HDstrcmp(obj_list[j].obj, table->objs[i].path) != 0) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_layout(table, I, pack); + } } /* j */ } /* first time insertion */ @@ -237,7 +246,7 @@ options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pa table->nelems += added; - return 0; + return ret_value; } /*------------------------------------------------------------------------- @@ -252,8 +261,8 @@ int options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, pack_opttbl_t *table) { unsigned int i, j, I; - unsigned added = 0; - int found = FALSE; + unsigned added = 0; + hbool_t found = FALSE; /* increase the size of the collection by N_OBJS if necessary */ if (table->nelems + n_objs >= table->size) @@ -273,7 +282,7 @@ options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, pa found = TRUE; break; } /* if */ - } /* i */ + } /* i */ if (!found) { /* keep the grow in a temp var */ @@ -287,14 +296,13 @@ options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, pa -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 dset1 is already inserted, but dset2 must also be */ - else - if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_filter(table, I, filt); - } + else if (found && HDstrcmp(obj_list[j].obj, table->objs[i].path) != 0) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_filter(table, I, filt); + } } /* j */ } @@ -323,9 +331,11 @@ options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, pa *------------------------------------------------------------------------- */ -pack_info_t* options_get_object(const char *path, pack_opttbl_t *table) { +pack_info_t * +options_get_object(const char *path, pack_opttbl_t *table) +{ unsigned int i; - char tbl_path[MAX_NC_NAME + 1]; /* +1 for start with "/" case */ + char tbl_path[MAX_NC_NAME + 1]; /* +1 for start with "/" case */ for (i = 0; i < table->nelems; i++) { /* make full path (start with "/") to compare correctly */ |