diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2016-09-18 13:46:32 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2016-09-18 14:00:10 +0300 |
commit | b31f335bfe65321f1d23d312d3fd69c00334f5da (patch) | |
tree | 05304b0abece682fc31d90c74b411272df726f9e /src | |
parent | 0db3c5552a16c0e73e0c24a36a3bacc77820bf02 (diff) |
Fix ecpg -? option on Windows, add -V alias for --version.
This makes the -? and -V options work consistently with other binaries.
--help and --version are now only recognized as the first option, i.e.
"ecpg --foobar --help" no longer prints the help, but that's consistent
with most of our other binaries, too.
Backpatch to all supported versions.
Haribabu Kommi
Discussion: <CAJrrPGfnRXvmCzxq6Dy=stAWebfNHxiL+Y_z7uqksZUCkW_waQ@mail.gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/ecpg/preproc/ecpg.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 7b2634d1478..55ae30c534c 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -54,7 +54,7 @@ help(const char *progname) " \"no_indicator\", \"prepare\", \"questionmarks\"\n")); printf(_(" --regression run in regression testing mode\n")); printf(_(" -t turn on autocommit of transactions\n")); - printf(_(" --version output version information, then exit\n")); + printf(_(" -V, --version output version information, then exit\n")); printf(_(" -?, --help show this help, then exit\n")); printf(_("\nIf no output file is specified, the name is formed by adding .c to the\n" "input file name, after stripping off .pgc if present.\n")); @@ -111,15 +111,11 @@ add_preprocessor_define(char *define) defines->next = pd; } -#define ECPG_GETOPT_LONG_HELP 1 -#define ECPG_GETOPT_LONG_VERSION 2 -#define ECPG_GETOPT_LONG_REGRESSION 3 +#define ECPG_GETOPT_LONG_REGRESSION 1 int main(int argc, char *const argv[]) { static struct option ecpg_options[] = { - {"help", no_argument, NULL, ECPG_GETOPT_LONG_HELP}, - {"version", no_argument, NULL, ECPG_GETOPT_LONG_VERSION}, {"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION}, {NULL, 0, NULL, 0} }; @@ -140,33 +136,26 @@ main(int argc, char *const argv[]) find_my_exec(argv[0], my_exec_path); + if (argc > 1) + { + if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) + { + help(progname); + exit(0); + } + if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) + { + printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION, + MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); + exit(0); + } + } + output_filename = NULL; - while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h?", ecpg_options, NULL)) != -1) + while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h", ecpg_options, NULL)) != -1) { switch (c) { - case ECPG_GETOPT_LONG_VERSION: - printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION, - MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); - exit(0); - case ECPG_GETOPT_LONG_HELP: - help(progname); - exit(0); - - /* - * -? is an alternative spelling of --help. However it is also - * returned by getopt_long for unknown options. We can - * distinguish both cases by means of the optopt variable - * which is set to 0 if it was really -? and not an unknown - * option character. - */ - case '?': - if (optopt == 0) - { - help(progname); - exit(0); - } - break; case ECPG_GETOPT_LONG_REGRESSION: regression_mode = true; break; |