diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-11-14 15:37:19 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-11-14 15:37:19 (GMT) |
commit | e43e3e0cb1da0ee07597872941db235e006c99ca (patch) | |
tree | f6b00a9fcf67fc75220e2cc1afbe4a32410f2217 | |
parent | 338645cf3d62e6551eb9ec89f3b738e80dc84b33 (diff) | |
download | hdf5-e43e3e0cb1da0ee07597872941db235e006c99ca.zip hdf5-e43e3e0cb1da0ee07597872941db235e006c99ca.tar.gz hdf5-e43e3e0cb1da0ee07597872941db235e006c99ca.tar.bz2 |
[svn-r16076] introduced a wildcard "*" option in tools parsing (optionally to additional argument ":")
when "*" is present after a letter switch, that letter can have or not the extra argument
used in -b for h5dump to make the default NATIVE when no extra argument is present
tested: windows, linux
-rw-r--r-- | tools/h5dump/h5dump.c | 67 | ||||
-rw-r--r-- | tools/h5dump/testh5dump.sh.in | 21 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 27 |
3 files changed, 76 insertions, 39 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index eaca6f8..b1f58a2 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -59,6 +59,8 @@ static char *prefix; static const char *driver = NULL; /* The driver to open the file with. */ static const h5dump_header_t *dump_header_format; static const char *fp_format = NULL; +static const char *outfname=NULL; + /* things to display or which are set via command line parameters */ static int display_all = TRUE; @@ -350,7 +352,7 @@ struct handler_t { * parameters. The long-named ones can be partially spelled. When * adding more, make sure that they don't clash with each other. */ -static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b:F:s:S:Am:"; +static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*:F:s:S:Am:"; static struct long_options l_opts[] = { { "help", no_arg, 'h' }, { "hel", no_arg, 'h' }, @@ -458,7 +460,7 @@ static struct long_options l_opts[] = { { "onlyattr", no_arg, 'A' }, { "escape", no_arg, 'e' }, { "noindex", no_arg, 'y' }, - { "binary", require_arg, 'b' }, + { "binary", optional_arg, 'b' }, { "form", require_arg, 'F' }, { "format", require_arg, 'm' }, { NULL, 0, '\0' } @@ -2830,8 +2832,11 @@ set_binary_form(const char *form) { int bform=-1; - if (strcmp(form,"MEMORY")==0) /* native form */ + if (strcmp(form,"NATIVE")==0 || + strcmp(form,"MEMORY")==0) + {/* native form */ bform = 0; + } else if (strcmp(form,"FILE")==0) /* file type form */ bform = 1; else if (strcmp(form,"LE")==0) /* convert to little endian */ @@ -3320,11 +3325,6 @@ parse_command_line(int argc, const char *argv[]) struct handler_t *hand, *last_dset = NULL; int i, opt, last_was_dset = FALSE; - /* some logic to handle both -o and -b order */ - const char *outfname=NULL; - bin_form = -1; - - /* no arguments */ if (argc == 1) { usage(progname); @@ -3448,7 +3448,7 @@ parse_start: case 'o': - if (bin_form > 0 ) + if ( bin_output ) { if (set_output_file(opt_arg, 1) < 0){ usage(progname); @@ -3462,7 +3462,7 @@ parse_start: leave(EXIT_FAILURE); } } - + usingdasho = TRUE; last_was_dset = FALSE; outfname = opt_arg; @@ -3470,24 +3470,29 @@ parse_start: case 'b': - if ( ( bin_form = set_binary_form(opt_arg)) < 0){ - /* failed to set binary form */ - usage(progname); - leave(EXIT_FAILURE); - } - bin_output = TRUE; - if (outfname!=NULL) { - if (set_output_file(outfname, 1) < 0){ - /* failed to set output file */ - usage(progname); - leave(EXIT_FAILURE); - } - - - last_was_dset = FALSE; - } - - break; + if ( opt_arg != NULL) + { + if ( ( bin_form = set_binary_form(opt_arg)) < 0) + { + /* failed to set binary form */ + usage(progname); + leave(EXIT_FAILURE); + } + } + bin_output = TRUE; + if (outfname!=NULL) + { + if (set_output_file(outfname, 1) < 0) + { + /* failed to set output file */ + usage(progname); + leave(EXIT_FAILURE); + } + + last_was_dset = FALSE; + } + + break; /** begin XML parameters **/ case 'x': @@ -3701,6 +3706,12 @@ main(int argc, const char *argv[]) h5tools_init(); hand = parse_command_line(argc, argv); + if ( bin_output && outfname == NULL ) + { + error_msg(progname, "binary output requires a file name, use -o <filename>\n"); + leave(EXIT_FAILURE); + } + /* Check for conflicting options */ if (doxml) { if (!display_all) { diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in index 05816b3..9c3e48f 100644 --- a/tools/h5dump/testh5dump.sh.in +++ b/tools/h5dump/testh5dump.sh.in @@ -437,23 +437,26 @@ TOOLTEST thyperslab.ddl thyperslab.h5 #TOOLTEST tldouble.ddl tldouble.h5 # test for binary output -TOOLTEST1 tbin1.ddl -d integer -o $TESTDIR/out1.bin -b LE tbinary.h5 -TOOLTEST1 tbin2.ddl -d float -o $TESTDIR/out2.bin -b BE tbinary.h5 +TOOLTEST1 tbin1.ddl -d integer -o $TESTDIR/out1.bin -b LE tbinary.h5 -# the MEMORY test can be validated with h5import/h5diff -TOOLTEST1 tbin3.ddl -d integer -o $TESTDIR/out3.bin -b MEMORY tbinary.h5 -IMPORTTEST $TESTDIR/out3.bin -c out3.h5import -o $TESTDIR/out3.h5 -DIFFTEST tbinary.h5 $TESTDIR/out3.h5 /integer /integer +# NATIVE default. the NATIVE test can be validated with h5import/h5diff +TOOLTEST1 tbin1.ddl -d integer -o $TESTDIR/out1.bin -b tbinary.h5 +IMPORTTEST $TESTDIR/out1.bin -c out3.h5import -o $TESTDIR/out1.h5 +DIFFTEST tbinary.h5 $TESTDIR/out1.h5 /integer /integer -TOOLTEST1 tbin4.ddl -d double -o $TESTDIR/out4.bin -b FILE tbinary.h5 +TOOLTEST1 tbin2.ddl -b BE -d float -o $TESTDIR/out2.bin tbinary.h5 -# tests for floating point user defined printf format -TOOLTEST tfpformat.ddl -m %.7f tfpformat.h5 +# the NATIVE test can be validated with h5import/h5diff +TOOLTEST1 tbin3.ddl -d integer -o $TESTDIR/out3.bin -b NATIVE tbinary.h5 +IMPORTTEST $TESTDIR/out3.bin -c out3.h5import -o $TESTDIR/out3.h5 +DIFFTEST tbinary.h5 $TESTDIR/out3.h5 /integer /integer +TOOLTEST1 tbin4.ddl -d double -b FILE -o $TESTDIR/out4.bin tbinary.h5 # Clean up binary output files if test -z "$HDF5_NOCLEANUP"; then rm -f $TESTDIR/out[1-4].bin + rm -f $TESTDIR/out1.h5 rm -f $TESTDIR/out3.h5 fi diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index e2cd298..c412948 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -126,7 +126,9 @@ warn_msg(const char *progname, const char *fmt, ...) * Programmer: Bill Wendling * Friday, 5. January 2001 * - * Modifications: + * Modifications: Pedro Vicente + * October, 27 2008 + * Wilcard "*" argument type * *------------------------------------------------------------------------- */ @@ -236,12 +238,33 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti } sp = 1; - } else { + } + + /* wildcard argument */ + else if (*cp == '*') + { + /* check the next argument */ + opt_ind++; + /* we do have an extra argument, check if not last */ + if ( argv[opt_ind][0] != '-' && (opt_ind+1) < argc ) + { + opt_arg = argv[opt_ind++]; + } + else + { + opt_arg = NULL; + } + } + + else + { /* set up to look at next char in token, next time */ if (argv[opt_ind][++sp] == '\0') { /* no more in current token, so setup next token */ opt_ind++; sp = 1; + + } opt_arg = NULL; |