diff --git a/mfhdf/dumper/hdp.c b/mfhdf/dumper/hdp.c index 23b3e23df6..13d8fd519c 100644 --- a/mfhdf/dumper/hdp.c +++ b/mfhdf/dumper/hdp.c @@ -11,11 +11,34 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#define HDP_MASTER #define VSET_INTERFACE #include "hdp.h" #include "local_nc.h" /* to use some definitions */ +/********************/ +/* Global Variables */ +/********************/ + +/* indicates Vsets have been initialized for the current file */ +intn vinit_done = FALSE; + +/********************************/ +/* Local variables and typedefs */ +/********************************/ + +/* hdp commands (stored as (value, name) pairs to keep them in sync) */ +typedef enum { HELP, LIST, DUMPSDS, DUMPRIG, DUMPVG, DUMPVD, DUMPGR, BAD_COMMAND } command_value_t; + +typedef struct command_t { + const command_value_t value; + const char *name; +} command_t; + +static const command_t commands[] = {{HELP, "help"}, {LIST, "list"}, + {DUMPSDS, "dumpsds"}, {DUMPRIG, "dumprig"}, + {DUMPVG, "dumpvg"}, {DUMPVD, "dumpvd"}, + {DUMPGR, "dumpgr"}, {BAD_COMMAND, "BADNESS - not a valid command"}}; + /* Print the usage message about this utility */ static void usage(intn argc, char *argv[]) @@ -87,58 +110,56 @@ init_dump_opts(dump_info_t *dump_opts) int main(int argc, char *argv[]) { - command_t cmd; /* command to perform */ - intn curr_arg; /* current cmd line argument */ - dump_opt_t glob_opts; /* global options for all commands */ - intn j; /* local counting variables */ + command_value_t cmd = BAD_COMMAND; /* command to perform */ + intn curr_arg; /* current cmd line argument */ + dump_opt_t glob_opts; /* global options for all commands */ + intn j; /* local counting variables */ memset(&glob_opts, 0, sizeof(dump_opt_t)); if (argc < 2) { usage(argc, argv); - exit(1); - } /* end if */ + exit(EXIT_FAILURE); + } curr_arg = 1; - /* printf("Argument 0: %s\n",argv[0]); - printf("Argument 1: %s\n",argv[1]); - */ while (curr_arg < argc && (argv[curr_arg][0] == '-')) { - /* while(curr_arg>> Please make a note that dumprig is no longer available.\n"); fprintf( stderr, " The command dumpgr is and should be used in its place.\n" ); if (FAIL == do_dumpgr(curr_arg, argc, argv, glob_opts.help)) */ - exit(1); + exit(EXIT_FAILURE); break; case DUMPVG: if (FAIL == do_dumpvg(curr_arg, argc, argv, glob_opts.help)) - exit(1); + exit(EXIT_FAILURE); break; case DUMPVD: if (FAIL == do_dumpvd(curr_arg, argc, argv, glob_opts.help)) - exit(1); + exit(EXIT_FAILURE); break; case DUMPGR: if (FAIL == do_dumpgr(curr_arg, argc, argv, glob_opts.help)) - exit(1); + exit(EXIT_FAILURE); break; case HELP: - case NONE: usage(argc, argv); break; + /* Should not get here - invalid commands are handled earlier */ + case BAD_COMMAND: default: - printf("Invalid command!, cmd=%d\n", (int)cmd); - exit(1); + printf("Invalid command!\n"); + exit(EXIT_FAILURE); break; - } /* end switch */ + } - return (0); + return EXIT_SUCCESS; } /* ----------------------------------------------------------------- diff --git a/mfhdf/dumper/hdp.h b/mfhdf/dumper/hdp.h index 81a609e49e..a203fdbc8c 100644 --- a/mfhdf/dumper/hdp.h +++ b/mfhdf/dumper/hdp.h @@ -18,20 +18,15 @@ #include "hfile.h" /* Global Variables */ -#ifndef HDP_MASTER -extern -#endif /* !HDP_MASTER */ - intn vinit_done -#ifdef HDP_MASTER - = FALSE /* indicates Vsets have been init'ed for the current file */ -#endif /* HDP_MASTER */ - ; +extern intn vinit_done; /* Global Definitions */ #define MAXCHOICES 50 + #ifndef MAXNAMELEN #define MAXNAMELEN 100 -#endif /* !MAXNAMELEN */ +#endif + #define MAXCLASSLEN 100 #define MAXPERLINE 65 /* max # of chars per line in the output */ #define MAXRANK 100 @@ -283,18 +278,6 @@ extern } \ } -/* Add enum and string for new commands to both of the variables below. */ -/* Preserve the correct/corresponding ordering */ -typedef enum { HELP, LIST, DUMPSDS, DUMPRIG, DUMPVG, DUMPVD, DUMPGR, NONE } command_t; -#ifndef HDP_MASTER -extern -#endif /* !HDP_MASTER */ - const char *commands[] -#ifdef HDP_MASTER - = {"help", "list", "dumpsds", "dumprig", "dumpvg", "dumpvd", "dumpgr"} -#endif /* HDP_MASTER */ -; - /* Global options structure */ typedef struct { intn help; /* Print help on this command */