summaryrefslogtreecommitdiffstats
path: root/tools/h5repack
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2016-09-27 21:39:41 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2016-09-27 21:39:52 (GMT)
commitd8e0019b3ecd7707c4e586db88469f7878176d29 (patch)
treec3dce3c16cd6a767eaa0a6bfc368d963cc1fe0ce /tools/h5repack
parentb2cb046d514861c54bd33a1ac85aa67ded3e240d (diff)
downloadhdf5-d8e0019b3ecd7707c4e586db88469f7878176d29.zip
hdf5-d8e0019b3ecd7707c4e586db88469f7878176d29.tar.gz
hdf5-d8e0019b3ecd7707c4e586db88469f7878176d29.tar.bz2
HDFFV-9974: Correct parsing of UD filter parameters.
Verified by user, who reported issue. merge from https://bitbucket.hdfgroup.org/projects/HDFFV/repos/hdf5/commits/b947f7e911e498f5455a78836a6f82a042dd5b33
Diffstat (limited to 'tools/h5repack')
-rw-r--r--tools/h5repack/CMakeTests.cmake9
-rw-r--r--tools/h5repack/h5repack_parse.c776
-rw-r--r--tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst9
3 files changed, 356 insertions, 438 deletions
diff --git a/tools/h5repack/CMakeTests.cmake b/tools/h5repack/CMakeTests.cmake
index b87de7b..804c455 100644
--- a/tools/h5repack/CMakeTests.cmake
+++ b/tools/h5repack/CMakeTests.cmake
@@ -91,6 +91,7 @@
${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/plugin_test.h5repack_layout.h5.tst
${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.UD.h5-plugin_none.ddl
${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/plugin_none.h5repack_layout.UD.h5.tst
+ ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.h5-plugin_zero.tst
)
foreach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES})
@@ -208,7 +209,7 @@
-D "TEST_OUTPUT=${resultfile}-${testname}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_FILTER:STRING=${testfilter}"
- -D "TEST_REFERENCE=${resultfile}.tst"
+ -D "TEST_REFERENCE=${resultfile}-${testname}.tst"
-P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
)
endif (HDF5_ENABLE_USING_MEMCHECKER)
@@ -988,6 +989,12 @@
##############################################################################
ADD_H5_UD_TEST (plugin_test 0 h5repack_layout.h5 -v -f UD=257,1,9)
ADD_H5_UD_TEST (plugin_none 0 h5repack_layout.UD.h5 -v -f NONE)
+ # check for no parameters
+ set (TESTRETVAL 255)
+ if (WIN32)
+ set (TESTRETVAL -1)
+ endif()
+ ADD_H5_CMP_TEST (plugin_zero "" "TEST" ${TESTRETVAL} h5repack_layout.h5 -v -f UD=250,0)
if (HDF5_TEST_VFD)
# Run test with different Virtual File Driver
diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c
index 1d71c13..004b9e4 100644
--- a/tools/h5repack/h5repack_parse.c
+++ b/tools/h5repack/h5repack_parse.c
@@ -31,493 +31,425 @@
* FLET, to apply the HDF5 checksum filter
* NBIT, to apply the HDF5 NBIT filter (NBIT compression)
* SOFF, to apply the HDF5 scale+offset filter (compression)
- * UD, to apply a User Defined filter k, m, n1[,…,nm]
+ * UD, to apply a User Defined filter k,m,n1[,…,nm]
* NONE, to remove the filter
*
* Examples:
* "GZIP=6"
* "A,B:NONE"
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September, 23, 2003
- *
*-------------------------------------------------------------------------
*/
-
-
-obj_list_t* parse_filter(const char *str,
- int *n_objs,
- filter_info_t *filt,
- pack_opt_t *options,
- int *is_glb)
-{
- unsigned i, u;
+obj_list_t* parse_filter(const char *str, unsigned *n_objs, filter_info_t *filt,
+ pack_opt_t *options, int *is_glb) {
+ size_t i, m, u;
char c;
- size_t len=HDstrlen(str);
- int j, m, n, k, l, p, r, q, end_obj=-1, no_param=0;
+ size_t len = HDstrlen(str);
+ int k, l, p, q, end_obj = -1, no_param = 0;
+ unsigned j, n;
char sobj[MAX_NC_NAME];
char scomp[10];
char stype[6];
char smask[3];
- obj_list_t* obj_list=NULL;
+ obj_list_t* obj_list = NULL;
unsigned pixels_per_block;
-
/* initialize compression info */
- HDmemset(filt,0,sizeof(filter_info_t));
+ HDmemset(filt, 0, sizeof(filter_info_t));
*is_glb = 0;
/* check for the end of object list and number of objects */
- for ( i = 0, n = 0; i < len; i++)
- {
+ for (i = 0, n = 0; i < len; i++) {
c = str[i];
- if ( c==':' )
- {
- end_obj=i;
- }
- if ( c==',' )
- {
+ if (c == ':')
+ end_obj = (int) i;
+ if (c == ',')
n++;
- }
}
- if (end_obj==-1) /* missing : */
- {
+ /* Check for missing : */
+ if (end_obj == -1) {
/* apply to all objects */
- options->all_filter=1;
+ options->all_filter = 1;
*is_glb = 1;
}
n++;
- obj_list = (obj_list_t*) HDmalloc(n*sizeof(obj_list_t));
- if (obj_list==NULL)
- {
+ obj_list = (obj_list_t *) HDmalloc(n * sizeof(obj_list_t));
+ if (obj_list == NULL) {
error_msg("could not allocate object list\n");
return NULL;
}
- *n_objs=n;
+ *n_objs = n;
/* get object list */
- for ( j = 0, k = 0, n = 0; j < end_obj; j++, k++)
- {
- c = str[j];
- sobj[k] = c;
- if ( c==',' || j==end_obj-1)
- {
- if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0';
- HDstrcpy(obj_list[n].obj,sobj);
- HDmemset(sobj,0,sizeof(sobj));
- n++;
- k=-1;
+ if (end_obj > 0)
+ for (j = 0, k = 0, n = 0; j < (unsigned) end_obj; j++, k++) {
+ c = str[j];
+ sobj[k] = c;
+ if (c == ',' || j == (unsigned) (end_obj - 1)) {
+ if (c == ',')
+ sobj[k] = '\0';
+ else
+ sobj[k + 1] = '\0';
+ HDstrcpy(obj_list[n].obj, sobj);
+ HDmemset(sobj, 0, sizeof(sobj));
+ n++;
+ k = -1;
+ }
}
- }
/* nothing after : */
- if (end_obj+1==(int)len)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("input Error: Invalid compression type in <%s>\n",str);
+ if (end_obj + 1 == (int) len) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("input Error: Invalid compression type in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
-
/* get filter additional parameters */
- m=0;
- for ( i=end_obj+1, k=0, j=0; i<len; i++,k++)
- {
+ m = 0;
+ for (i = (size_t)(end_obj + 1), k = 0, j = 0; i < len; i++, k++) {
c = str[i];
- scomp[k]=c;
- if ( c=='=' || i==len-1)
- {
- if ( c=='=') /*one more parameter */
- {
- scomp[k]='\0'; /*cut space */
+ scomp[k] = c;
+ if (c == '=' || i == len - 1) {
+ if (c == '=') { /*one more parameter */
+ scomp[k] = '\0'; /*cut space */
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SZIP
- * szip has the format SZIP=<pixels per block,coding>
- * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN'
- * example SZIP=8,NN
- *-------------------------------------------------------------------------
- */
- if (HDstrcmp(scomp,"SZIP")==0)
- {
- l=-1; /* mask index check */
- for ( m=0,u=i+1; u<len; u++,m++)
- {
- if (str[u]==',')
- {
- stype[m]='\0'; /* end digit of szip */
- l=0; /* start EC or NN search */
- u++; /* skip ',' */
+ * H5Z_FILTER_SZIP
+ * szip has the format SZIP=<pixels per block,coding>
+ * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN'
+ * example SZIP=8,NN
+ *-------------------------------------------------------------------------
+ */
+ if (HDstrcmp(scomp, "SZIP") == 0) {
+ l = -1; /* mask index check */
+ for (m = 0, u = i + 1; u < len; u++, m++) {
+ if (str[u] == ',') {
+ stype[m] = '\0'; /* end digit of szip */
+ l = 0; /* start EC or NN search */
+ u++; /* skip ',' */
}
c = str[u];
- if (!isdigit(c) && l==-1)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("compression parameter not digit in <%s>\n",str);
+ if (!HDisdigit(c) && l == -1) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("compression parameter not digit in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- if (l==-1)
- stype[m]=c;
- else
- {
- smask[l]=c;
+ if (l == -1)
+ stype[m] = c;
+ else {
+ smask[l] = c;
l++;
- if (l==2)
- {
- smask[l]='\0';
- i=len-1; /* end */
+ if (l == 2) {
+ smask[l] = '\0';
+ i = len - 1; /* end */
(*n_objs)--; /* we counted an extra ',' */
- if (HDstrcmp(smask,"NN")==0)
- filt->cd_values[j++]=H5_SZIP_NN_OPTION_MASK;
- else if (HDstrcmp(smask,"EC")==0)
- filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK;
- else
- {
+ if (HDstrcmp(smask,"NN") == 0)
+ filt->cd_values[j++] = H5_SZIP_NN_OPTION_MASK;
+ else if (HDstrcmp(smask,"EC") == 0)
+ filt->cd_values[j++] = H5_SZIP_EC_OPTION_MASK;
+ else {
error_msg("szip mask must be 'NN' or 'EC' \n");
HDexit(EXIT_FAILURE);
}
-
-
}
}
-
- } /* u */
+ } /* u */
} /*if */
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SCALEOFFSET
- * scaleoffset has the format SOFF=<scale_factor,scale_type>
- * scale_type can be
- * integer datatype, H5Z_SO_INT (IN)
- * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS)
- * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented
- * for integer datatypes, scale_factor denotes Minimum Bits
- * for float datatypes, scale_factor denotes decimal scale factor
- * examples
- * SOFF=31,IN
- * SOFF=3,DF
- *-------------------------------------------------------------------------
- */
-
- else if (HDstrcmp(scomp,"SOFF")==0)
- {
- l=-1; /* mask index check */
- for ( m=0,u=i+1; u<len; u++,m++)
- {
- if (str[u]==',')
- {
- stype[m]='\0'; /* end digit */
- l=0; /* start 'IN' , 'DS', or 'ES' search */
- u++; /* skip ',' */
+ * H5Z_FILTER_SCALEOFFSET
+ * scaleoffset has the format SOFF=<scale_factor,scale_type>
+ * scale_type can be
+ * integer datatype, H5Z_SO_INT (IN)
+ * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS)
+ * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented
+ * for integer datatypes, scale_factor denotes Minimum Bits
+ * for float datatypes, scale_factor denotes decimal scale factor
+ * examples
+ * SOFF=31,IN
+ * SOFF=3,DF
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "SOFF") == 0) {
+ l = -1; /* mask index check */
+ for (m = 0, u = i + 1; u < len; u++, m++) {
+ if (str[u] == ',') {
+ stype[m] = '\0'; /* end digit */
+ l = 0; /* start 'IN' , 'DS', or 'ES' search */
+ u++; /* skip ',' */
}
c = str[u];
- if (!isdigit(c) && l==-1)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("compression parameter is not a digit in <%s>\n",str);
+ if (!HDisdigit(c) && l == -1) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("compression parameter is not a digit in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- if (l==-1)
- stype[m]=c;
- else
- {
- smask[l]=c;
+ if (l == -1)
+ stype[m] = c;
+ else {
+ smask[l] = c;
l++;
- if (l==2)
- {
- smask[l]='\0';
- i=len-1; /* end */
+ if (l == 2) {
+ smask[l] = '\0';
+ i = len - 1; /* end */
(*n_objs)--; /* we counted an extra ',' */
- if (HDstrcmp(smask,"IN")==0)
- filt->cd_values[j++]=H5Z_SO_INT;
- else if (HDstrcmp(smask,"DS")==H5Z_SO_FLOAT_DSCALE)
- filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE;
- else
- {
+ if (HDstrcmp(smask,"IN") == 0)
+ filt->cd_values[j++] = H5Z_SO_INT;
+ else if (HDstrcmp(smask, "DS") == H5Z_SO_FLOAT_DSCALE)
+ filt->cd_values[j++] = H5Z_SO_FLOAT_DSCALE;
+ else {
error_msg("scale type must be 'IN' or 'DS' \n");
HDexit(EXIT_FAILURE);
}
-
}
}
-
- } /* u */
+ } /* u */
} /*if */
+
/*-------------------------------------------------------------------------
- * User Defined
- * has the format UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>
- * BZIP2 example
- * UD=307,1,9
- *-------------------------------------------------------------------------
- */
-
- else if (HDstrcmp(scomp,"UD")==0)
- {
- l=-1; /* filter number index check */
- p=-1; /* CD_VAL count check */
- r=-1; /* CD_VAL check */
- for ( m=0,q=0,u=i+1; u<len; u++,m++,q++)
- {
- if (str[u]==',')
- {
- stype[q]='\0'; /* end digit */
- if (l==-1)
- {
- filt->filtn=atoi(stype);
- l=0;
+ * User Defined
+ * has the format UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>
+ * BZIP2 example
+ * UD=307,1,9
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "UD") == 0) {
+ l = -1; /* filter number index check */
+ p = -1; /* CD_VAL count check */
+ for (m = 0, q = 0, u = i + 1; u < len; u++, m++, q++) {
+ if (str[u] == ',') {
+ stype[q] = '\0'; /* end digit */
+ if (l == -1) {
+ filt->filtn = HDatoi(stype);
+ l = 0;
}
- else if (p==-1)
- {
- filt->cd_nelmts=atoi(stype);
- p=0;
+ else if (p == -1) {
+ filt->cd_nelmts = HDstrtoull(stype, NULL, 0);
+ p = 0;
}
else
- r=0;
- q=0;
- u++; /* skip ',' */
+ filt->cd_values[j++] = (unsigned)HDstrtoul(stype, NULL, 0);
+ q = 0;
+ u++; /* skip ',' */
}
c = str[u];
- if (!isdigit(c) && l==-1)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("filter number parameter is not a digit in <%s>\n",str);
+ if (!HDisdigit(c) && l == -1) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("filter number parameter is not a digit in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- stype[q]=c;
- if (l==0 && p==0)
- {
- if (r==0)
- filt->cd_values[j++]=atoi(stype);
- }
-
- } /* u */
-
- stype[q]='\0';
+ stype[q] = c;
+ } /* for u */
+ stype[q] = '\0';
} /*if */
-
/*-------------------------------------------------------------------------
- * all other filters
- *-------------------------------------------------------------------------
- */
-
- else
- {
+ * all other filters
+ *-------------------------------------------------------------------------
+ */
+ else {
/* here we could have 1 or 2 digits */
- for ( m=0,u=i+1; u<len; u++,m++)
- {
+ for (m = 0, u = i + 1; u < len; u++, m++) {
c = str[u];
- if (!isdigit(c)){
- if (obj_list) HDfree(obj_list);
- error_msg("compression parameter is not a digit in <%s>\n",str);
+ if (!HDisdigit(c)) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("compression parameter is not a digit in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- stype[m]=c;
+ stype[m] = c;
} /* u */
- stype[m]='\0';
+ stype[m] = '\0';
} /*if */
-
-
- filt->cd_values[j++]=atoi(stype);
- i+=m; /* jump */
+ filt->cd_values[j++] = (unsigned) HDstrtoul(stype, NULL, 0);
+ if(filt->cd_nelmts == 0)
+ j = 0;
+ i += m; /* jump */
}
- else if (i==len-1)
- { /*no more parameters */
- scomp[k+1]='\0';
- no_param=1;
+ else if (i == len - 1) { /*no more parameters */
+ scomp[k + 1] = '\0';
+ no_param = 1;
}
/*-------------------------------------------------------------------------
- * translate from string to filter symbol
- *-------------------------------------------------------------------------
- */
+ * translate from string to filter symbol
+ *-------------------------------------------------------------------------
+ */
/*-------------------------------------------------------------------------
- * H5Z_FILTER_NONE
- *-------------------------------------------------------------------------
- */
- if (HDstrcmp(scomp,"NONE")==0)
- {
- filt->filtn=H5Z_FILTER_NONE;
+ * H5Z_FILTER_NONE
+ *-------------------------------------------------------------------------
+ */
+ if (HDstrcmp(scomp, "NONE") == 0) {
+ filt->filtn = H5Z_FILTER_NONE;
filt->cd_nelmts = 0;
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_DEFLATE
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"GZIP")==0)
- {
- filt->filtn=H5Z_FILTER_DEFLATE;
+ * H5Z_FILTER_DEFLATE
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "GZIP") == 0) {
+ filt->filtn = H5Z_FILTER_DEFLATE;
filt->cd_nelmts = 1;
- if (no_param)
- { /*no more parameters, GZIP must have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("missing compression parameter in <%s>\n",str);
+ if (no_param) { /*no more parameters, GZIP must have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("missing compression parameter in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SZIP
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"SZIP")==0)
- {
- filt->filtn=H5Z_FILTER_SZIP;
+ * H5Z_FILTER_SZIP
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "SZIP") == 0) {
+ filt->filtn = H5Z_FILTER_SZIP;
filt->cd_nelmts = 2;
- if (no_param)
- { /*no more parameters, SZIP must have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("missing compression parameter in <%s>\n",str);
+ if (no_param) { /*no more parameters, SZIP must have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("missing compression parameter in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SHUFFLE
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"SHUF")==0)
- {
- filt->filtn=H5Z_FILTER_SHUFFLE;
+ * H5Z_FILTER_SHUFFLE
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "SHUF") == 0) {
+ filt->filtn = H5Z_FILTER_SHUFFLE;
filt->cd_nelmts = 0;
- if (m>0)
- { /*shuffle does not have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("extra parameter in SHUF <%s>\n",str);
+ if (m > 0) { /*shuffle does not have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("extra parameter in SHUF <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_FLETCHER32
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"FLET")==0)
- {
- filt->filtn=H5Z_FILTER_FLETCHER32;
+ * H5Z_FILTER_FLETCHER32
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "FLET") == 0) {
+ filt->filtn = H5Z_FILTER_FLETCHER32;
filt->cd_nelmts = 0;
- if (m>0)
- { /*shuffle does not have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("extra parameter in FLET <%s>\n",str);
+ if (m > 0) { /*shuffle does not have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("extra parameter in FLET <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_NBIT
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"NBIT")==0)
- {
- filt->filtn=H5Z_FILTER_NBIT;
+ * H5Z_FILTER_NBIT
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "NBIT") == 0) {
+ filt->filtn = H5Z_FILTER_NBIT;
filt->cd_nelmts = 0;
- if (m>0)
- { /*nbit does not have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("extra parameter in NBIT <%s>\n",str);
+ if (m > 0) { /*nbit does not have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("extra parameter in NBIT <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SCALEOFFSET
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"SOFF")==0)
- {
- filt->filtn=H5Z_FILTER_SCALEOFFSET;
+ * H5Z_FILTER_SCALEOFFSET
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "SOFF") == 0) {
+ filt->filtn = H5Z_FILTER_SCALEOFFSET;
filt->cd_nelmts = 2;
- if (no_param)
- { /*no more parameters, SOFF must have parameter */
- if (obj_list) HDfree(obj_list);
- error_msg("missing compression parameter in <%s>\n",str);
+ if (no_param) { /*no more parameters, SOFF must have parameter */
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("missing compression parameter in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
/*-------------------------------------------------------------------------
- * User Defined Filter
- *-------------------------------------------------------------------------
- */
- else if (HDstrcmp(scomp,"UD")==0)
- {
- if (filt->cd_nelmts != j)
- { /* parameters does not match count */
- if (obj_list) HDfree(obj_list);
- error_msg("incorrect number of compression parameters in <%s>\n",str);
+ * User Defined Filter
+ *-------------------------------------------------------------------------
+ */
+ else if (HDstrcmp(scomp, "UD") == 0) {
+ /* parameters does not match count */
+ if (filt->cd_nelmts != j) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("incorrect number of compression parameters in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
else {
- if (obj_list) HDfree(obj_list);
- error_msg("invalid filter type in <%s>\n",str);
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("invalid filter type in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
} /*i*/
/*-------------------------------------------------------------------------
- * check valid parameters
- *-------------------------------------------------------------------------
- */
-
- switch (filt->filtn)
- {
+ * check valid parameters
+ *-------------------------------------------------------------------------
+ */
+ switch (filt->filtn) {
/*-------------------------------------------------------------------------
- * H5Z_FILTER_DEFLATE
- *-------------------------------------------------------------------------
- */
-
+ * H5Z_FILTER_DEFLATE
+ *-------------------------------------------------------------------------
+ */
case H5Z_FILTER_DEFLATE:
- if (filt->cd_values[0]>9 )
- {
- if (obj_list) HDfree(obj_list);
- error_msg("invalid compression parameter in <%s>\n",str);
+ if (filt->cd_values[0] > 9) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("invalid compression parameter in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
break;
-
/*-------------------------------------------------------------------------
- * H5Z_FILTER_SZIP
- *-------------------------------------------------------------------------
- */
-
+ * H5Z_FILTER_SZIP
+ *-------------------------------------------------------------------------
+ */
case H5Z_FILTER_SZIP:
- pixels_per_block=filt->cd_values[0];
- if ((pixels_per_block%2)==1)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("pixels_per_block is not even in <%s>\n",str);
+ pixels_per_block = filt->cd_values[0];
+ if ((pixels_per_block % 2) == 1) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("pixels_per_block is not even in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("pixels_per_block is too large in <%s>\n",str);
+ if (pixels_per_block > H5_SZIP_MAX_PIXELS_PER_BLOCK) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("pixels_per_block is too large in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
- if ( (HDstrcmp(smask,"NN")!=0) && (HDstrcmp(smask,"EC")!=0) )
- {
- if (obj_list) HDfree(obj_list);
+ if ((HDstrcmp(smask,"NN") != 0) && (HDstrcmp(smask,"EC") != 0)) {
+ if (obj_list)
+ HDfree(obj_list);
error_msg("szip mask must be 'NN' or 'EC' \n");
HDexit(EXIT_FAILURE);
}
break;
default:
break;
-
-
};
return obj_list;
}
-
-
+
/*-------------------------------------------------------------------------
* Function: parse_layout
*
@@ -539,176 +471,146 @@ obj_list_t* parse_filter(const char *str,
*
*-------------------------------------------------------------------------
*/
-obj_list_t* parse_layout(const char *str,
- int *n_objs,
- pack_info_t *pack, /* info about layout needed */
- pack_opt_t *options)
-{
- obj_list_t* obj_list=NULL;
- unsigned i;
+obj_list_t* parse_layout(const char *str, unsigned *n_objs, pack_info_t *pack, /* info about layout needed */
+pack_opt_t *options) {
+ obj_list_t* obj_list = NULL;
+ unsigned i, j, n;
char c;
- size_t len=HDstrlen(str);
- int j, n, k, end_obj=-1, c_index;
+ size_t len = HDstrlen(str);
+ int k, end_obj = -1, c_index;
char sobj[MAX_NC_NAME];
char sdim[10];
char slayout[10];
-
HDmemset(sdim, '\0', sizeof(sdim));
HDmemset(sobj, '\0', sizeof(sobj));
HDmemset(slayout, '\0', sizeof(slayout));
/* check for the end of object list and number of objects */
- for ( i=0, n=0; i<len; i++)
- {
+ for (i = 0, n = 0; i < len; i++) {
c = str[i];
- if ( c==':' )
- {
- end_obj=i;
- }
- if ( c==',' )
- {
+ if (c == ':')
+ end_obj = (int) i;
+ if (c == ',')
n++;
- }
}
- if (end_obj==-1) { /* missing : chunk all */
- options->all_layout=1;
+ if (end_obj == -1) { /* missing : chunk all */
+ options->all_layout = 1;
}
n++;
- obj_list = (obj_list_t*) HDmalloc(n*sizeof(obj_list_t));
- if (obj_list==NULL)
- {
+ obj_list = (obj_list_t*) HDmalloc(n * sizeof(obj_list_t));
+ if (obj_list == NULL) {
error_msg("could not allocate object list\n");
return NULL;
}
- *n_objs=n;
+ *n_objs = n;
/* get object list */
- for ( j=0, k=0, n=0; j<end_obj; j++,k++)
- {
- c = str[j];
- sobj[k]=c;
- if ( c==',' || j==end_obj-1)
- {
- if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0';
- HDstrcpy(obj_list[n].obj,sobj);
- HDmemset(sobj,0,sizeof(sobj));
- n++;
- k=-1;
+ if (end_obj > 0)
+ for (j = 0, k = 0, n = 0; j < (unsigned) end_obj; j++, k++) {
+ c = str[j];
+ sobj[k] = c;
+ if (c == ',' || j == (unsigned) (end_obj - 1)) {
+ if (c == ',')
+ sobj[k] = '\0';
+ else
+ sobj[k + 1] = '\0';
+ HDstrcpy(obj_list[n].obj, sobj);
+ HDmemset(sobj, 0, sizeof(sobj));
+ n++;
+ k = -1;
+ }
}
- }
/* nothing after : */
- if (end_obj+1==(int)len)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("in parse layout, no characters after : in <%s>\n",str);
+ if (end_obj + 1 == (int) len) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("in parse layout, no characters after : in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
/* get layout info */
- for ( j=end_obj+1, n=0; n<=5; j++,n++)
- {
- if (n==5)
- {
- slayout[n]='\0'; /*cut string */
- if (HDstrcmp(slayout,"COMPA")==0)
- pack->layout=H5D_COMPACT;
- else if (HDstrcmp(slayout,"CONTI")==0)
- pack->layout=H5D_CONTIGUOUS;
- else if (HDstrcmp(slayout,"CHUNK")==0)
- pack->layout=H5D_CHUNKED;
+ for (j = (unsigned) (end_obj + 1), n = 0; n <= 5; j++, n++) {
+ if (n == 5) {
+ slayout[n] = '\0'; /*cut string */
+ if (HDstrcmp(slayout, "COMPA") == 0)
+ pack->layout = H5D_COMPACT;
+ else if (HDstrcmp(slayout, "CONTI") == 0)
+ pack->layout = H5D_CONTIGUOUS;
+ else if (HDstrcmp(slayout, "CHUNK") == 0)
+ pack->layout = H5D_CHUNKED;
else {
- error_msg("in parse layout, not a valid layout in <%s>\n",str);
+ error_msg("in parse layout, not a valid layout in <%s>\n", str);
HDexit(EXIT_FAILURE);
}
}
- else
- {
+ else {
c = str[j];
- slayout[n]=c;
+ slayout[n] = c;
}
} /* j */
-
- if ( pack->layout==H5D_CHUNKED )
- {
-
+ if (pack->layout == H5D_CHUNKED) {
/*-------------------------------------------------------------------------
- * get chunk info
- *-------------------------------------------------------------------------
- */
- k=0;
-
- if (j>(int)len)
- {
- if (obj_list) HDfree(obj_list);
- error_msg("in parse layout, <%s> Chunk dimensions missing\n",str);
+ * get chunk info
+ *-------------------------------------------------------------------------
+ */
+ k = 0;
+ if (j > len) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("in parse layout, <%s> Chunk dimensions missing\n", str);
HDexit(EXIT_FAILURE);
}
- for ( i=j, c_index=0; i<len; i++)
- {
+ for (i = j, c_index = 0; i < len; i++) {
c = str[i];
- sdim[k]=c;
+ sdim[k] = c;
k++; /*increment sdim index */
- if (!isdigit(c) && c!='x'
- && c!='N' && c!='O' && c!='N' && c!='E'
- ){
- if (obj_list) HDfree(obj_list);
- error_msg("in parse layout, <%s> Not a valid character in <%s>\n",
- sdim,str);
+ if (!HDisdigit(c) && c != 'x' && c != 'N' && c != 'O' && c != 'N' && c != 'E') {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("in parse layout, <%s> Not a valid character in <%s>\n", sdim, str);
HDexit(EXIT_FAILURE);
}
- if ( c=='x' || i==len-1)
- {
- if ( c=='x') {
- sdim[k-1]='\0';
- k=0;
- pack->chunk.chunk_lengths[c_index]=atoi(sdim);
- if (pack->chunk.chunk_lengths[c_index]==0) {
- if (obj_list) HDfree(obj_list);
- error_msg("in parse layout, <%s> conversion to number in <%s>\n",
- sdim,str);
+ if (c == 'x' || i == len - 1) {
+ if (c == 'x') {
+ sdim[k - 1] = '\0';
+ k = 0;
+ pack->chunk.chunk_lengths[c_index] = HDstrtoull(sdim, NULL, 0);
+ if (pack->chunk.chunk_lengths[c_index] == 0) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("in parse layout, <%s> conversion to number in <%s>\n", sdim, str);
HDexit(EXIT_FAILURE);
}
c_index++;
}
- else if (i==len-1) { /*no more parameters */
- sdim[k]='\0';
- k=0;
- if (HDstrcmp(sdim,"NONE")==0)
- {
- pack->chunk.rank=-2;
+ else if (i == len - 1) { /*no more parameters */
+ sdim[k] = '\0';
+ k = 0;
+ if (HDstrcmp(sdim,"NONE") == 0) {
+ pack->chunk.rank = -2;
}
- else
- {
- pack->chunk.chunk_lengths[c_index]=atoi(sdim);
- if (pack->chunk.chunk_lengths[c_index]==0){
- if (obj_list) HDfree(obj_list);
- error_msg("in parse layout, <%s> conversion to number in <%s>\n",
- sdim,str);
+ else {
+ pack->chunk.chunk_lengths[c_index] = HDstrtoull(sdim, NULL, 0);
+ if (pack->chunk.chunk_lengths[c_index] == 0) {
+ if (obj_list)
+ HDfree(obj_list);
+ error_msg("in parse layout, <%s> conversion to number in <%s>\n", sdim, str);
HDexit(EXIT_FAILURE);
}
- pack->chunk.rank=c_index+1;
+ pack->chunk.rank = c_index + 1;
}
} /*if */
} /*if c=='x' || i==len-1 */
} /*i*/
-
-
} /*H5D_CHUNKED*/
-
return obj_list;
}
-
-
-
-
-
-
diff --git a/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst b/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst
new file mode 100644
index 0000000..0993d5b
--- /dev/null
+++ b/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst
@@ -0,0 +1,9 @@
+Objects to modify layout are...
+Objects to apply filter are...
+ User Defined 250
+Making file <out-plugin_zero.h5repack_layout.h5>...
+-----------------------------------------
+ Type Filter (Compression) Name
+-----------------------------------------
+ group /
+h5repack error: <h5repack_layout.h5>: Could not copy data to: out-plugin_zero.h5repack_layout.h5