summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_opttable.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2013-09-09 18:30:25 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2013-09-09 18:30:25 (GMT)
commitf79eac6049aaf951cbd109214b8c45f6174fd4e7 (patch)
treedf87f689dab0f2bc8cee13b8d1161434d01f6956 /tools/h5repack/h5repack_opttable.c
parent6b54dac504ccaad3ec512b57ba8b92609a74490b (diff)
downloadhdf5-f79eac6049aaf951cbd109214b8c45f6174fd4e7.zip
hdf5-f79eac6049aaf951cbd109214b8c45f6174fd4e7.tar.gz
hdf5-f79eac6049aaf951cbd109214b8c45f6174fd4e7.tar.bz2
[svn-r24116] Correct indentation and create single exit point.
Tested : local linux
Diffstat (limited to 'tools/h5repack/h5repack_opttable.c')
-rw-r--r--tools/h5repack/h5repack_opttable.c530
1 files changed, 241 insertions, 289 deletions
diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c
index bcddbb9..b54e887 100644
--- a/tools/h5repack/h5repack_opttable.c
+++ b/tools/h5repack/h5repack_opttable.c
@@ -1,4 +1,4 @@
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
@@ -27,21 +27,19 @@
*-------------------------------------------------------------------------
*/
-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;
- 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;
+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;
+ 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;
}
/*-------------------------------------------------------------------------
@@ -54,19 +52,16 @@ void init_packobject(pack_info_t *obj)
*-------------------------------------------------------------------------
*/
-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
- {
- error_msg("cannot insert the filter in this object.\
+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 {
+ error_msg(
+ "cannot insert the filter in this object.\
Maximum capacity exceeded\n");
- }
+ }
}
/*-------------------------------------------------------------------------
@@ -79,33 +74,28 @@ static void aux_tblinsert_filter(pack_opttbl_t *table,
*-------------------------------------------------------------------------
*/
-static void aux_tblinsert_layout(pack_opttbl_t *table,
- unsigned int I,
- pack_info_t *pack)
-{
- int k;
-
- table->objs[I].layout = pack->layout;
- if (H5D_CHUNKED==pack->layout)
- {
- /* -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].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];
- }
- }
+static void aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I,
+ pack_info_t *pack) {
+ int k;
+
+ table->objs[I].layout = pack->layout;
+ if (H5D_CHUNKED == pack->layout) {
+ /* -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].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];
+ }
+ }
}
-
/*-------------------------------------------------------------------------
* Function: aux_inctable
*
@@ -116,21 +106,20 @@ static void aux_tblinsert_layout(pack_opttbl_t *table,
*-------------------------------------------------------------------------
*/
-static int aux_inctable(pack_opttbl_t *table, int n_objs )
-{
- unsigned int i;
-
- table->size += n_objs;
- table->objs = (pack_info_t*)HDrealloc(table->objs, table->size * sizeof(pack_info_t));
- if (table->objs==NULL) {
- error_msg("not enough memory for options table\n");
- return -1;
- }
- for (i = table->nelems; i < table->size; i++)
- {
- init_packobject(&table->objs[i]);
- }
- return 0;
+static int aux_inctable(pack_opttbl_t *table, int n_objs) {
+ unsigned int i;
+
+ table->size += n_objs;
+ table->objs =
+ (pack_info_t*) HDrealloc(table->objs, table->size * sizeof(pack_info_t));
+ if (table->objs == NULL) {
+ error_msg("not enough memory for options table\n");
+ return -1;
+ }
+ for (i = table->nelems; i < table->size; i++) {
+ init_packobject(&table->objs[i]);
+ }
+ return 0;
}
@@ -143,31 +132,29 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs )
*
*-------------------------------------------------------------------------
*/
-int options_table_init( pack_opttbl_t **tbl )
-{
- unsigned int i;
- pack_opttbl_t *table;
-
- if(NULL == (table = (pack_opttbl_t *)HDmalloc(sizeof(pack_opttbl_t))))
- {
- error_msg("not enough memory for options table\n");
- return -1;
- }
-
- table->size = 30;
- table->nelems = 0;
- if(NULL == (table->objs = (pack_info_t*)HDmalloc(table->size * sizeof(pack_info_t))))
- {
- error_msg("not enough memory for options table\n");
- HDfree(table);
- return -1;
- }
-
- for(i = 0; i < table->size; i++)
- init_packobject(&table->objs[i]);
-
- *tbl = table;
- return 0;
+int options_table_init(pack_opttbl_t **tbl) {
+ unsigned int i;
+ pack_opttbl_t *table;
+
+ if (NULL == (table = (pack_opttbl_t *) HDmalloc(sizeof(pack_opttbl_t)))) {
+ error_msg("not enough memory for options table\n");
+ return -1;
+ }
+
+ table->size = 30;
+ table->nelems = 0;
+ if (NULL == (table->objs =
+ (pack_info_t*) HDmalloc(table->size * sizeof(pack_info_t)))) {
+ error_msg("not enough memory for options table\n");
+ HDfree(table);
+ return -1;
+ }
+
+ for (i = 0; i < table->size; i++)
+ init_packobject(&table->objs[i]);
+
+ *tbl = table;
+ return 0;
}
@@ -181,11 +168,10 @@ int options_table_init( pack_opttbl_t **tbl )
*-------------------------------------------------------------------------
*/
-int options_table_free( pack_opttbl_t *table )
-{
- HDfree(table->objs);
- HDfree(table);
- return 0;
+int options_table_free(pack_opttbl_t *table) {
+ HDfree(table->objs);
+ HDfree(table);
+ return 0;
}
/*-------------------------------------------------------------------------
@@ -198,95 +184,81 @@ int options_table_free( pack_opttbl_t *table )
*-------------------------------------------------------------------------
*/
-
-int options_add_layout( obj_list_t *obj_list,
- int n_objs,
- pack_info_t *pack,
- pack_opttbl_t *table )
-{
- unsigned int i, I;
- int j, added=0, found=0;
-
- /* increase the size of the collection by N_OBJS if necessary */
- if (table->nelems+n_objs >= table->size)
- {
- if (aux_inctable(table,n_objs)<0)
- return -1;
- }
-
- /* search if this object is already in the table; "path" is the key */
- if (table->nelems>0)
- {
- /* go tru the supplied list of names */
- for (j = 0; j < n_objs; j++)
- {
- /* 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)
- {
- /* already chunk info inserted for this one; exit */
- if (table->objs[i].chunk.rank>0)
- {
- error_msg("chunk information already inserted for <%s>\n",obj_list[j].obj);
- HDexit(EXIT_FAILURE);
- }
- /* insert the layout info */
- else
- {
- aux_tblinsert_layout(table,i,pack);
- found=1;
- break;
- }
- } /* if */
- } /* i */
-
- if (found==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);
- }
- /* cases where we have an already inserted name but there is a new name also
- example:
- -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20
- dset1 is already inserted, but dset2 must also be
- */
- else if (found==1 && 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 */
- else
- {
- /* go tru the supplied list of names */
- for (j = 0; j < n_objs; j++)
- {
- I = table->nelems + added;
- added++;
- HDstrcpy(table->objs[I].path,obj_list[j].obj);
- aux_tblinsert_layout(table,I,pack);
-
- }
- }
-
- table->nelems+= added;
-
- return 0;
+int options_add_layout(obj_list_t *obj_list, int n_objs, pack_info_t *pack,
+ pack_opttbl_t *table) {
+ unsigned int i, I;
+ int j, added = 0, found = 0;
+
+ /* increase the size of the collection by N_OBJS if necessary */
+ if (table->nelems + n_objs >= table->size) {
+ if (aux_inctable(table, n_objs) < 0)
+ return -1;
+ }
+
+ /* search if this object is already in the table; "path" is the key */
+ if (table->nelems > 0) {
+ /* go tru the supplied list of names */
+ for (j = 0; j < n_objs; j++) {
+ /* 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) {
+ /* already chunk info inserted for this one; exit */
+ if (table->objs[i].chunk.rank > 0) {
+ error_msg(
+ "chunk information already inserted for <%s>\n",
+ obj_list[j].obj);
+ HDexit(EXIT_FAILURE);
+ }
+ /* insert the layout info */
+ else {
+ aux_tblinsert_layout(table, i, pack);
+ found = 1;
+ break;
+ }
+ } /* if */
+ } /* i */
+
+ if (found == 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);
+ }
+ /* cases where we have an already inserted name but there is a new name also
+ example:
+ -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20
+ dset1 is already inserted, but dset2 must also be
+ */
+ else if (found == 1
+ && 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 */
+ else {
+ /* go tru the supplied list of names */
+ for (j = 0; j < n_objs; j++) {
+ I = table->nelems + added;
+ added++;
+ HDstrcpy(table->objs[I].path, obj_list[j].obj);
+ aux_tblinsert_layout(table, I, pack);
+
+ }
+ }
+
+ table->nelems += added;
+
+ return 0;
}
-
-
/*-------------------------------------------------------------------------
* Function: options_add_filter
*
@@ -297,81 +269,70 @@ int options_add_layout( obj_list_t *obj_list,
*-------------------------------------------------------------------------
*/
-int options_add_filter(obj_list_t *obj_list,
- int n_objs,
- filter_info_t filt,
- pack_opttbl_t *table )
-{
-
- unsigned int i, I;
- int j, added=0, found=0;
-
- /* increase the size of the collection by N_OBJS if necessary */
- if (table->nelems+n_objs >= table->size)
- {
- if (aux_inctable(table,n_objs)<0)
- return -1;
- }
-
- /* search if this object is already in the table; "path" is the key */
- if (table->nelems>0)
- {
- /* go tru the supplied list of names */
- for (j = 0; j < n_objs; j++)
- {
- /* 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)
- {
- /* insert */
- aux_tblinsert_filter(table,i,filt);
- found=1;
- break;
- } /* if */
- } /* i */
-
- if (found==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);
- }
- /* cases where we have an already inserted name but there is a new name also
- example:
- -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1
- dset1 is already inserted, but dset2 must also be
- */
- else if (found==1 && 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 */
- }
-
- /* first time insertion */
- else
- {
- /* go tru the supplied list of names */
- for (j = 0; j < n_objs; j++)
- {
- I = table->nelems + added;
- added++;
- HDstrcpy(table->objs[I].path,obj_list[j].obj);
- aux_tblinsert_filter(table,I,filt);
- }
- }
-
- table->nelems+= added;
-
- return 0;
+int options_add_filter(obj_list_t *obj_list, int n_objs, filter_info_t filt,
+ pack_opttbl_t *table) {
+
+ unsigned int i, I;
+ int j, added = 0, found = 0;
+
+ /* increase the size of the collection by N_OBJS if necessary */
+ if (table->nelems + n_objs >= table->size) {
+ if (aux_inctable(table, n_objs) < 0)
+ return -1;
+ }
+
+ /* search if this object is already in the table; "path" is the key */
+ if (table->nelems > 0) {
+ /* go tru the supplied list of names */
+ for (j = 0; j < n_objs; j++) {
+ /* 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) {
+ /* insert */
+ aux_tblinsert_filter(table, i, filt);
+ found = 1;
+ break;
+ } /* if */
+ } /* i */
+
+ if (found == 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);
+ }
+ /* cases where we have an already inserted name but there is a new name also
+ example:
+ -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1
+ dset1 is already inserted, but dset2 must also be
+ */
+ else if (found == 1
+ && 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 */
+ }
+
+ /* first time insertion */
+ else {
+ /* go tru the supplied list of names */
+ for (j = 0; j < n_objs; j++) {
+ I = table->nelems + added;
+ added++;
+ HDstrcpy(table->objs[I].path, obj_list[j].obj);
+ aux_tblinsert_filter(table, I, filt);
+ }
+ }
+
+ table->nelems += added;
+
+ return 0;
}
/*-------------------------------------------------------------------------
@@ -384,34 +345,25 @@ int options_add_filter(obj_list_t *obj_list,
*-------------------------------------------------------------------------
*/
-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 */
-
-
- for ( i = 0; i < table->nelems; i++)
- {
- /* make full path (start with "/") to compare correctly */
- if (HDstrncmp(table->objs[i].path, "/", 1))
- {
- HDstrcpy(tbl_path, "/");
- HDstrcat(tbl_path, table->objs[i].path);
- }
- else
- HDstrcpy(tbl_path, table->objs[i].path);
-
- /* found it */
- if (HDstrcmp(tbl_path, path)==0)
- {
- return (&table->objs[i]);
- }
- }
-
- return NULL;
+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 */
+
+ for (i = 0; i < table->nelems; i++) {
+ /* make full path (start with "/") to compare correctly */
+ if (HDstrncmp(table->objs[i].path, "/", 1)) {
+ HDstrcpy(tbl_path, "/");
+ HDstrcat(tbl_path, table->objs[i].path);
+ }
+ else
+ HDstrcpy(tbl_path, table->objs[i].path);
+
+ /* found it */
+ if (HDstrcmp(tbl_path, path) == 0) {
+ return (&table->objs[i]);
+ }
+ }
+
+ return NULL;
}
-
-
-