Skip to content

Commit e06728d

Browse files
committed
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>
1 parent 9895818 commit e06728d

File tree

1 file changed

+18
-29
lines changed
  • src/interfaces/ecpg/preproc

1 file changed

+18
-29
lines changed

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ help(const char *progname)
5454
" \"no_indicator\", \"prepare\", \"questionmarks\"\n"));
5555
printf(_(" --regression run in regression testing mode\n"));
5656
printf(_(" -t turn on autocommit of transactions\n"));
57-
printf(_(" --version output version information, then exit\n"));
57+
printf(_(" -V, --version output version information, then exit\n"));
5858
printf(_(" -?, --help show this help, then exit\n"));
5959
printf(_("\nIf no output file is specified, the name is formed by adding .c to the\n"
6060
"input file name, after stripping off .pgc if present.\n"));
@@ -111,15 +111,11 @@ add_preprocessor_define(char *define)
111111
defines->next = pd;
112112
}
113113

114-
#define ECPG_GETOPT_LONG_HELP 1
115-
#define ECPG_GETOPT_LONG_VERSION 2
116-
#define ECPG_GETOPT_LONG_REGRESSION 3
114+
#define ECPG_GETOPT_LONG_REGRESSION 1
117115
int
118116
main(int argc, char *const argv[])
119117
{
120118
static struct option ecpg_options[] = {
121-
{"help", no_argument, NULL, ECPG_GETOPT_LONG_HELP},
122-
{"version", no_argument, NULL, ECPG_GETOPT_LONG_VERSION},
123119
{"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION},
124120
{NULL, 0, NULL, 0}
125121
};
@@ -144,33 +140,26 @@ main(int argc, char *const argv[])
144140
return (ILLEGAL_OPTION);
145141
}
146142

143+
if (argc > 1)
144+
{
145+
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
146+
{
147+
help(progname);
148+
exit(0);
149+
}
150+
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
151+
{
152+
printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION,
153+
MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
154+
exit(0);
155+
}
156+
}
157+
147158
output_filename = NULL;
148-
while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h?", ecpg_options, NULL)) != -1)
159+
while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h", ecpg_options, NULL)) != -1)
149160
{
150161
switch (c)
151162
{
152-
case ECPG_GETOPT_LONG_VERSION:
153-
printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION,
154-
MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
155-
exit(0);
156-
case ECPG_GETOPT_LONG_HELP:
157-
help(progname);
158-
exit(0);
159-
160-
/*
161-
* -? is an alternative spelling of --help. However it is also
162-
* returned by getopt_long for unknown options. We can
163-
* distinguish both cases by means of the optopt variable
164-
* which is set to 0 if it was really -? and not an unknown
165-
* option character.
166-
*/
167-
case '?':
168-
if (optopt == 0)
169-
{
170-
help(progname);
171-
exit(0);
172-
}
173-
break;
174163
case ECPG_GETOPT_LONG_REGRESSION:
175164
regression_mode = true;
176165
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy