8000 Fix ecpg -? option on Windows, add -V alias for --version. · intobs/postgres@ed29d2d · GitHub
[go: up one dir, main page]

Skip to content

Commit ed29d2d

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 3ed7f54 commit ed29d2d

File tree

1 file changed

+17
-28
lines changed
  • src/interfaces/ecpg/preproc

1 file changed

+17
-28
lines changed

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
@@ -140,33 +136,26 @@ main(int argc, char *const argv[])
140136

141137
find_my_exec(argv[0], my_exec_path);
142138

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

0 commit comments

Comments
 (0)
0