From 5df5ee8956c9613793908169676de0fb47582c71 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Thu, 5 Oct 2006 09:35:40 -0500 Subject: [svn-r12720] added output of error messages using the tools library function error_msg, that prints the program name and error on the message tested: kagiso --- tools/h5repack/h5repack.c | 20 +++++++------ tools/h5repack/h5repack_copy.c | 17 ++++++----- tools/h5repack/h5repack_list.c | 5 ++-- tools/h5repack/h5repack_main.c | 12 +++++++- tools/h5repack/h5repack_opttable.c | 13 +++++---- tools/h5repack/h5repack_parse.c | 59 +++++++++++++++++++------------------- tools/h5repack/h5repack_refs.c | 20 +++++++------ tools/h5repack/h5repack_verify.c | 8 ++++-- 8 files changed, 88 insertions(+), 66 deletions(-) diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index 4b0bb7e..cc39201 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -14,8 +14,12 @@ #include #include +#include "h5tools_utils.h" #include "h5repack.h" +extern char *progname; + + /*------------------------------------------------------------------------- * File: h5repack.c * Purpose: Public API functions @@ -137,7 +141,7 @@ int h5repack_addfilter(const char* str, int n_objs; /*number of objects in the current -f or -c option entry */ if (options->all_filter==1){ - printf("Error: Invalid compression input: all option is present \ + error_msg(progname, "invalid compression input: 'all' option is present \ with other objects <%s>\n",str); return -1; } @@ -187,7 +191,7 @@ int h5repack_addlayout(const char* str, init_packobject(&pack); if (options->all_layout==1){ - printf("Error: Invalid layout input: all option \ + error_msg(progname, "invalid layout input: 'all' option \ is present with other objects <%s>\n",str); return -1; } @@ -304,7 +308,7 @@ static int check_options(pack_opt_t *options) } if (options->all_layout==1 && has_ck){ - printf("Error: Invalid chunking input: all option\ + error_msg(progname, "invalid chunking input: 'all' option\ is present with other objects\n"); return -1; } @@ -359,7 +363,7 @@ static int check_options(pack_opt_t *options) } /* i */ if (options->all_filter==1 && has_cp){ - printf("Error: Invalid compression input: all option\ + error_msg(progname, "invalid compression input: 'all' option\ is present with other objects\n"); return -1; } @@ -403,7 +407,7 @@ void read_info(const char *filename, if ((fp = fopen(data_file, "r")) == (FILE *)NULL) { - printf( "Cannot open options file %s", filename); + error_msg(progname, "cannot open options file %s", filename); exit(1); } @@ -440,7 +444,7 @@ void read_info(const char *filename, comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addfilter(comp_info,options)==-1){ - printf( "Could not add compression option. Exiting\n"); + error_msg(progname, "could not add compression option\n"); exit(1); } } @@ -470,7 +474,7 @@ void read_info(const char *filename, comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addlayout(comp_info,options)==-1){ - printf( "Could not add chunck option. Exiting\n"); + error_msg(progname, "could not add chunck option\n"); exit(1); } } @@ -479,7 +483,7 @@ void read_info(const char *filename, *------------------------------------------------------------------------- */ else { - printf( "Bad file format for %s", filename); + error_msg(progname, "bad file format for %s", filename); exit(1); } } diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index c62407f..b2c375c 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -12,13 +12,16 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - #include #include #include #include "H5private.h" +#include "h5tools_utils.h" #include "h5repack.h" +extern char *progname; + + #define PER(A,B) { per = 0; \ if (A!=0) \ per = (float)fabs(1-( (float)B / (float)A )); \ @@ -178,11 +181,11 @@ int copy_objects(const char* fnamein, *------------------------------------------------------------------------- */ if ((fidin=h5tools_fopen(fnamein, NULL, NULL, 0))<0 ){ - printf("<%s>: %s\n", fnamein, H5FOPENERROR ); + error_msg(progname, "<%s>: %s\n", fnamein, H5FOPENERROR ); goto out; } if ((fidout=H5Fcreate(fnameout,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0 ){ - printf("<%s>: Could not create file\n", fnameout ); + error_msg(progname, "<%s>: Could not create file\n", fnameout ); goto out; } @@ -201,7 +204,7 @@ int copy_objects(const char* fnamein, *------------------------------------------------------------------------- */ if(do_copy_objects(fidin,fidout,travt,options)<0) { - printf("<%s>: Could not copy data to: %s\n", fnamein, fnameout); + error_msg(progname, "<%s>: Could not copy data to: %s\n", fnamein, fnameout); goto out; } @@ -211,7 +214,7 @@ int copy_objects(const char* fnamein, *------------------------------------------------------------------------- */ if(do_copy_refobjs(fidin,fidout,travt,options)<0) { - printf("<%s>: Could not copy data to: %s\n", fnamein, fnameout); + error_msg(progname, "<%s>: Could not copy data to: %s\n", fnamein, fnameout); goto out; } @@ -409,7 +412,7 @@ int do_copy_objects(hid_t fidin, { buf=(void *) HDmalloc((unsigned)(nelmts*msize)); if ( buf==NULL){ - printf( "cannot read into memory\n" ); + error_msg(progname, "cannot read into memory\n" ); goto error; } if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0) @@ -735,7 +738,7 @@ int copy_attr(hid_t loc_in, buf=(void *) HDmalloc((unsigned)(nelmts*msize)); if ( buf==NULL){ - printf( "cannot read into memory\n" ); + error_msg(progname, "cannot read into memory\n" ); goto error; } if (H5Aread(attr_id,mtype_id,buf)<0) diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c index b414398..32cbc24 100644 --- a/tools/h5repack/h5repack_list.c +++ b/tools/h5repack/h5repack_list.c @@ -12,13 +12,14 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - #include #include #include #include "H5private.h" +#include "h5tools_utils.h" #include "h5repack.h" +extern char *progname; /*------------------------------------------------------------------------- * Function: check_objects @@ -83,7 +84,7 @@ int check_objects(const char* fname, /* the input object names are present in the file and are valid */ if (h5trav_getindext(name,travt)<0) { - printf("%sError: Could not find <%s> in file <%s>. Exiting...\n", + error_msg(progname, "%s Could not find <%s> in file <%s>. Exiting...\n", (options->verbose?"\n":""),name,fname); goto out; } diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 333a49a..92433f9 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -14,8 +14,10 @@ #include #include +#include "h5tools_utils.h" #include "h5repack.h" +/* module-scoped variables */ const char *progname = "h5repack"; int d_status = EXIT_SUCCESS; static void usage(void); @@ -69,7 +71,10 @@ int main(int argc, char **argv) /* add the -f filter option */ if (h5repack_addfilter(argv[i+1],&options)<0) + { + error_msg(progname, "in parsing filter\n"); exit(1); + } /* jump to next */ ++i; @@ -78,7 +83,10 @@ int main(int argc, char **argv) /* parse the -l layout option */ if (h5repack_addlayout(argv[i+1],&options)<0) + { + error_msg(progname, "in parsing layout\n"); exit(1); + } /* jump to next */ ++i; @@ -87,7 +95,7 @@ int main(int argc, char **argv) else if (strcmp(argv[i], "-m") == 0) { options.threshold = parse_number(argv[i+1]); if ((int)options.threshold==-1) { - printf("Error: Invalid treshold size <%s>\n",argv[i+1]); + error_msg(progname, "invalid treshold size <%s>\n",argv[i+1]); exit(1); } ++i; @@ -98,6 +106,7 @@ int main(int argc, char **argv) } else if (argv[i][0] == '-') { + error_msg(progname, " - is not a valid argument\n"); usage(); exit(1); } @@ -105,6 +114,7 @@ int main(int argc, char **argv) if (infile == NULL || outfile == NULL) { + error_msg(progname, "file names missing\n"); usage(); exit(1); } diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index 17e8f2c..a0b1698 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -12,11 +12,12 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - #include #include +#include "h5tools_utils.h" #include "h5repack.h" +extern char *progname; /*------------------------------------------------------------------------- * Function: init_packobject @@ -67,7 +68,7 @@ static void aux_tblinsert_filter(pack_opttbl_t *table, } else { - printf("Cannot insert the filter in this object.\ + error_msg(progname, "cannot insert the filter in this object.\ Maximum capacity exceeded\n"); } } @@ -126,7 +127,7 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) table->size += n_objs; table->objs = (pack_info_t*)realloc(table->objs, table->size * sizeof(pack_info_t)); if (table->objs==NULL) { - printf("Error: not enough memory for options table\n"); + error_msg(progname, "not enough memory for options table\n"); return -1; } for (i = table->nelems; i < table->size; i++) @@ -151,7 +152,7 @@ int options_table_init( pack_opttbl_t **tbl ) int i; pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); if (table==NULL) { - printf("Error: not enough memory for options table\n"); + error_msg(progname, "not enough memory for options table\n"); return -1; } @@ -159,7 +160,7 @@ int options_table_init( pack_opttbl_t **tbl ) table->nelems = 0; table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t)); if (table->objs==NULL) { - printf("Error: not enough memory for options table\n"); + error_msg(progname, "not enough memory for options table\n"); return -1; } @@ -229,7 +230,7 @@ int options_add_layout( obj_list_t *obj_list, /* already chunk info inserted for this one; exit */ if (table->objs[i].chunk.rank>0) { - printf("Input Error: chunk information already inserted for <%s>\n",obj_list[j].obj); + error_msg(progname, "chunk information already inserted for <%s>\n",obj_list[j].obj); exit(1); } /* insert the layout info */ diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c index 9243b72..7b173cc 100644 --- a/tools/h5repack/h5repack_parse.c +++ b/tools/h5repack/h5repack_parse.c @@ -16,11 +16,10 @@ #include #include #include +#include "h5tools_utils.h" #include "h5repack.h" -#if 0 -#define PARSE_DEBUG -#endif +extern char *progname; /*------------------------------------------------------------------------- * Function: parse_filter @@ -96,7 +95,7 @@ obj_list_t* parse_filter(const char *str, obj_list=malloc(n*sizeof(obj_list_t)); if (obj_list==NULL) { - printf("Could not alloc object list\n"); + error_msg(progname, "could not allocate object list\n"); return NULL; } *n_objs=n; @@ -119,7 +118,7 @@ obj_list_t* parse_filter(const char *str, if (end_obj+1==(int)len) { if (obj_list) free(obj_list); - printf("Input Error: Invalid compression type in <%s>\n",str); + error_msg(progname, "input Error: Invalid compression type in <%s>\n",str); exit(1); } @@ -156,7 +155,7 @@ obj_list_t* parse_filter(const char *str, c = str[u]; if (!isdigit(c) && l==-1){ if (obj_list) free(obj_list); - printf("Input Error: Compression parameter not digit in <%s>\n",str); + error_msg(progname, "compression parameter not digit in <%s>\n",str); exit(1); } if (l==-1) @@ -176,7 +175,7 @@ obj_list_t* parse_filter(const char *str, filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK; else { - printf("Input Error: szip mask must be 'NN' or 'EC' \n"); + error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); exit(1); } @@ -215,7 +214,7 @@ obj_list_t* parse_filter(const char *str, c = str[u]; if (!isdigit(c) && l==-1){ if (obj_list) free(obj_list); - printf("Input Error: Compression parameter not digit in <%s>\n",str); + error_msg(progname, "compression parameter is not a digit in <%s>\n",str); exit(1); } if (l==-1) @@ -235,7 +234,7 @@ obj_list_t* parse_filter(const char *str, filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE; else { - printf("Input Error: scale type must be 'IN' or 'DS' \n"); + error_msg(progname, "scale type must be 'IN' or 'DS' \n"); exit(1); } @@ -259,7 +258,7 @@ obj_list_t* parse_filter(const char *str, c = str[u]; if (!isdigit(c)){ if (obj_list) free(obj_list); - printf("Input Error: Compression parameter not digit in <%s>\n",str); + error_msg(progname, "compression parameter is not a digit in <%s>\n",str); exit(1); } stype[m]=c; @@ -294,7 +293,7 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_DEFLATE; if (no_param) { /*no more parameters, GZIP must have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Missing compression parameter in <%s>\n",str); + error_msg(progname, "missing compression parameter in <%s>\n",str); exit(1); } } @@ -308,7 +307,7 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_SZIP; if (no_param) { /*no more parameters, SZIP must have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Missing compression parameter in <%s>\n",str); + error_msg(progname, "missing compression parameter in <%s>\n",str); exit(1); } } @@ -322,7 +321,7 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_SHUFFLE; if (m>0){ /*shuffle does not have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Extra parameter in SHUF <%s>\n",str); + error_msg(progname, "extra parameter in SHUF <%s>\n",str); exit(1); } } @@ -335,7 +334,7 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_FLETCHER32; if (m>0){ /*shuffle does not have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Extra parameter in FLET <%s>\n",str); + error_msg(progname, "extra parameter in FLET <%s>\n",str); exit(1); } } @@ -348,7 +347,7 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_NBIT; if (m>0){ /*nbit does not have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Extra parameter in NBIT <%s>\n",str); + error_msg(progname, "extra parameter in NBIT <%s>\n",str); exit(1); } } @@ -361,13 +360,13 @@ obj_list_t* parse_filter(const char *str, filt->filtn=H5Z_FILTER_SCALEOFFSET; if (no_param) { /*no more parameters, SOFF must have parameter */ if (obj_list) free(obj_list); - printf("Input Error: Missing compression parameter in <%s>\n",str); + error_msg(progname, "missing compression parameter in <%s>\n",str); exit(1); } } else { if (obj_list) free(obj_list); - printf("Input Error: Invalid filter type in <%s>\n",str); + error_msg(progname, "invalid filter type in <%s>\n",str); exit(1); } } @@ -384,7 +383,7 @@ obj_list_t* parse_filter(const char *str, case H5Z_FILTER_DEFLATE: if (filt->cd_values[0]<0 || filt->cd_values[0]>9 ){ if (obj_list) free(obj_list); - printf("Input Error: Invalid compression parameter in <%s>\n",str); + error_msg(progname, "invalid compression parameter in <%s>\n",str); exit(1); } break; @@ -394,24 +393,24 @@ obj_list_t* parse_filter(const char *str, pixels_per_block=filt->cd_values[0]; if ((pixels_per_block%2)==1) { if (obj_list) free(obj_list); - printf("Input Error: pixels_per_block is not even in <%s>\n",str); + error_msg(progname, "pixels_per_block is not even in <%s>\n",str); exit(1); } if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK) { if (obj_list) free(obj_list); - printf("Input Error: pixels_per_block is too large in <%s>\n",str); + error_msg(progname, "pixels_per_block is too large in <%s>\n",str); exit(1); } if ( (strcmp(smask,"NN")!=0) && (strcmp(smask,"EC")!=0) ) { if (obj_list) free(obj_list); - printf("Input Error: szip mask must be 'NN' or 'EC' \n"); + error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); exit(1); } break; case H5Z_FILTER_SCALEOFFSET: if (filt->cd_values[0]<0 ){ if (obj_list) free(obj_list); - printf("Input Error: Invalid compression parameter in <%s>\n",str); + error_msg(progname, "invalid compression parameter in <%s>\n",str); exit(1); } break; @@ -448,7 +447,7 @@ const char* get_sfilter(H5Z_filter_t filtn) else if (filtn==H5Z_FILTER_SCALEOFFSET) return "SOFF"; else { - printf("Input error in filter type\n"); + error_msg(progname, "input error in filter type\n"); exit(1); } return NULL; @@ -517,7 +516,7 @@ obj_list_t* parse_layout(const char *str, obj_list=malloc(n*sizeof(obj_list_t)); if (obj_list==NULL) { - printf("Could not alloc object list\n"); + error_msg(progname, "could not allocate object list\n"); return NULL; } *n_objs=n; @@ -541,7 +540,7 @@ obj_list_t* parse_layout(const char *str, if (end_obj+1==(int)len) { if (obj_list) free(obj_list); - printf("Parse layout error: No characters after : in <%s>\n",str); + error_msg(progname, "in parse layout, no characters after : in <%s>\n",str); exit(1); } @@ -558,7 +557,7 @@ obj_list_t* parse_layout(const char *str, else if (strcmp(slayout,"CHUNK")==0) pack->layout=H5D_CHUNKED; else { - printf("Parse layout error: Not a valid layout in <%s>\n",str); + error_msg(progname, "in parse layout, not a valid layout in <%s>\n",str); exit(1); } } @@ -582,7 +581,7 @@ obj_list_t* parse_layout(const char *str, if (j>(int)len) { if (obj_list) free(obj_list); - printf("Parse layout error: <%s> Chunk dimensions missing\n",str); + error_msg(progname, "in parse layout, <%s> Chunk dimensions missing\n",str); exit(1); } @@ -596,7 +595,7 @@ obj_list_t* parse_layout(const char *str, && c!='N' && c!='O' && c!='N' && c!='E' ){ if (obj_list) free(obj_list); - printf("Parse layout error: <%s> Not a valid character in <%s>\n", + error_msg(progname, "in parse layout, <%s> Not a valid character in <%s>\n", sdim,str); exit(1); } @@ -609,7 +608,7 @@ obj_list_t* parse_layout(const char *str, pack->chunk.chunk_lengths[c_index]=atoi(sdim); if (pack->chunk.chunk_lengths[c_index]==0) { if (obj_list) free(obj_list); - printf("Parse layout error: <%s> Conversion to number in <%s>\n", + error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", sdim,str); exit(1); } @@ -627,7 +626,7 @@ obj_list_t* parse_layout(const char *str, pack->chunk.chunk_lengths[c_index]=atoi(sdim); if (pack->chunk.chunk_lengths[c_index]==0){ if (obj_list) free(obj_list); - printf("Parse layout error: <%s> Conversion to number in <%s>\n", + error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", sdim,str); exit(1); } diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c index 73fb2fc..1f7c2e9 100644 --- a/tools/h5repack/h5repack_refs.c +++ b/tools/h5repack/h5repack_refs.c @@ -12,13 +12,15 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - #include #include #include #include "H5private.h" +#include "h5tools_utils.h" #include "h5repack.h" +extern char *progname; + static const char* MapIdToName(hid_t refobj_id, trav_table_t *travt); @@ -173,7 +175,7 @@ int do_copy_refobjs(hid_t fidin, { buf=(void *) HDmalloc((unsigned)(nelmts*msize)); if ( buf==NULL){ - printf( "cannot read into memory\n" ); + error_msg(progname, "cannot read into memory\n" ); goto error; } if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0) @@ -183,7 +185,7 @@ int do_copy_refobjs(hid_t fidin, goto error; refbuf=HDmalloc((unsigned)nelmts*msize); if ( refbuf==NULL){ - printf( "cannot allocate memory\n" ); + error_msg(progname, "cannot allocate memory\n" ); goto error; } for ( u=0; u: %s\n", fname1, H5FOPENERROR ); + error_msg(progname, "<%s>: %s\n", fname1, H5FOPENERROR ); return -1; } if ((fid2=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ) { - printf("<%s>: %s\n", fname2, H5FOPENERROR ); + error_msg(progname, "<%s>: %s\n", fname2, H5FOPENERROR ); H5Fclose(fid1); return -1; } @@ -429,7 +431,7 @@ int h5repack_cmpdcpl(const char *fname1, if (ret==0) { - printf("Property lists for <%s> are different\n",travt1->objs[i].name); + error_msg(progname, "property lists for <%s> are different\n",travt1->objs[i].name); goto error; } -- cgit v0.12