Skip to content

Commit fc6603f

Browse files
committed
Advertise --help (rather than '-?') as help option (problems with csh).
Accept --help even if no general long options support exists.
1 parent c25b4db commit fc6603f

File tree

13 files changed

+96
-98
lines changed

13 files changed

+96
-98
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.190 2000/11/25 04:13:17 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.191 2000/11/25 19:05:42 petere Exp $
1515
*
1616
* NOTES
1717
*
@@ -310,6 +310,25 @@ PostmasterMain(int argc, char *argv[])
310310
real_argv = argv;
311311
real_argc = argc;
312312

313+
/*
314+
* Catch standard options before doing much else. This even works
315+
* on systems without getopt_long.
316+
*/
317+
if (argc > 1)
318+
{
319+
if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0)
320+
{
321+
usage(progname);
322+
exit(0);
323+
}
324+
if (strcmp(argv[1], "--version")==0 || strcmp(argv[1], "-V")==0)
325+
{
326+
puts("postmaster (PostgreSQL) " PG_VERSION);
327+
exit(0);
328+
}
329+
}
330+
331+
313332
/*
314333
* for security, no dir or file created can be group or other
315334
* accessible
@@ -358,51 +377,30 @@ PostmasterMain(int argc, char *argv[])
358377
* will occur.
359378
*/
360379
opterr = 1;
361-
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:SsV-:?")) != EOF)
380+
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
362381
{
363382
switch(opt)
364383
{
365384
case 'D':
366385
potential_DataDir = optarg;
367386
break;
368387

369-
case 'V':
370-
puts("postmaster (PostgreSQL) " PG_VERSION);
371-
exit(0);
372-
373-
case '-':
374-
{
375-
char *name, *value;
376-
377-
ParseLongOption(optarg, &name, &value);
378-
if (strcmp(name, "help")==0)
379-
{
380-
usage(progname);
381-
exit(0);
382-
}
383-
else if (strcmp(name, "version")==0)
384-
{
385-
puts("postmaster (PostgreSQL) " PG_VERSION);
386-
exit(0);
387-
}
388-
break;
389-
}
390-
391388
case '?':
392-
if (strcmp(argv[optind - 1], "-?") == 0)
393-
{
394-
usage(progname);
395-
exit(0);
396-
}
397-
else
398-
{
399-
fprintf(stderr, "Try -? for help.\n");
400-
exit(1);
401-
}
402-
break;
389+
fprintf(stderr, "Try '%s --help' for more information.\n", progname);
390+
exit(1);
403391
}
404392
}
405393

394+
/*
395+
* Non-option switch arguments don't exist.
396+
*/
397+
if (optind < argc)
398+
{
399+
fprintf(stderr, "%s: invalid argument -- %s\n", progname, argv[optind]);
400+
fprintf(stderr, "Try '%s --help' for more information.\n", progname);
401+
exit(1);
402+
}
403+
406404
checkDataDir(potential_DataDir); /* issues error messages */
407405
SetDataDir(potential_DataDir);
408406

@@ -414,7 +412,7 @@ PostmasterMain(int argc, char *argv[])
414412
#ifdef HAVE_INT_OPTRESET
415413
optreset = 1;
416414
#endif
417-
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:SsV-:?")) != EOF)
415+
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
418416
{
419417
switch (opt)
420418
{
@@ -546,20 +544,11 @@ PostmasterMain(int argc, char *argv[])
546544

547545
default:
548546
/* shouldn't get here */
549-
fprintf(stderr, "Try -? for help.\n");
547+
fprintf(stderr, "Try '%s --help' for more information.\n", progname);
550548
exit(1);
551549
}
552550
}
553551

554-
/*
555-
* Non-option switch arguments don't exist.
556-
*/
557-
if (optind < argc)
558-
{
559-
fprintf(stderr, "%s: invalid argument -- %s\n", progname, argv[optind]);
560-
exit(1);
561-
}
562-
563552
/*
564553
* Check for invalid combinations of switches
565554
*/

src/backend/tcop/postgres.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.189 2000/11/21 21:16:02 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.190 2000/11/25 19:05:42 petere Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1062,6 +1062,24 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
10621062

10631063
char *potential_DataDir = NULL;
10641064

1065+
/*
1066+
* Catch standard options before doing much else. This even works
1067+
* on systems without getopt_long.
1068+
*/
1069+
if (!IsUnderPostmaster && argc > 1)
1070+
{
1071+
if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0)
1072+
{
1073+
usage(argv[0]);
1074+
exit(0);
1075+
}
1076+
if (strcmp(argv[1], "--version")==0 || strcmp(argv[1], "-V")==0)
1077+
{
1078+
puts("postgres (PostgreSQL) " PG_VERSION);
1079+
exit(0);
1080+
}
1081+
}
1082+
10651083
/*
10661084
* Fire up essential subsystems: error and memory management
10671085
*
@@ -1110,7 +1128,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
11101128

11111129
optind = 1; /* reset after postmaster's usage */
11121130

1113-
while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiLNOPo:p:S:st:v:VW:x:-:?")) != EOF)
1131+
while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiLNOPo:p:S:st:v:W:x:-:")) != EOF)
11141132
switch (flag)
11151133
{
11161134
case 'A':
@@ -1336,10 +1354,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
13361354
FrontendProtocol = (ProtocolVersion) atoi(optarg);
13371355
break;
13381356

1339-
case 'V':
1340-
puts("postgres (PostgreSQL) " PG_VERSION);
1341-
exit(0);
1342-
13431357
case 'W':
13441358
/* ----------------
13451359
* wait N seconds to allow attach from a debugger
@@ -1387,16 +1401,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
13871401
char *name, *value;
13881402

13891403
ParseLongOption(optarg, &name, &value);
1390-
if (strcmp(name, "help")==0)
1391-
{
1392-
usage(argv[0]);
1393-
exit(0);
1394-
}
1395-
else if (strcmp(name, "version")==0)
1396-
{
1397-
puts("postgres (PostgreSQL) " PG_VERSION);
1398-
exit(0);
1399-
}
14001404
if (!value)
14011405
{
14021406
if (flag == '-')
@@ -1412,18 +1416,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
14121416
break;
14131417
}
14141418

1415-
case '?':
1416-
if (strcmp(argv[optind - 1], "-?") == 0)
1417-
{
1418-
usage(argv[0]);
1419-
exit(0);
1420-
}
1421-
else
1422-
errs++;
1423-
break;
1424-
14251419
default:
1426-
/* shouldn't get here */
14271420
errs++;
14281421
break;
14291422
}
@@ -1643,7 +1636,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16431636
if (!IsUnderPostmaster)
16441637
{
16451638
puts("\nPOSTGRES backend interactive interface ");
1646-
puts("$Revision: 1.189 $ $Date: 2000/11/21 21:16:02 $\n");
1639+
puts("$Revision: 1.190 $ $Date: 2000/11/25 19:05:42 $\n");
16471640
}
16481641

16491642
/*

src/bin/initdb/initdb.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
# Copyright (c) 1994, Regents of the University of California
2626
#
27-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.116 2000/11/21 20:55:57 tgl Exp $
27+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.117 2000/11/25 19:05:43 petere Exp $
2828
#
2929
#-------------------------------------------------------------------------
3030

@@ -253,7 +253,7 @@ do
253253
;;
254254
-*)
255255
echo "$CMDNAME: invalid option: $1"
256-
echo "Try '$CMDNAME -?' for help."
256+
echo "Try '$CMDNAME --help' for more information."
257257
exit 1
258258
;;
259259
*)

src/bin/initlocation/initlocation.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.9 2000/11/11 22:59:46 petere Exp $
11+
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.10 2000/11/25 19:05:43 petere Exp $
1212
#
1313
#-------------------------------------------------------------------------
1414

@@ -51,7 +51,7 @@ do
5151

5252
-*)
5353
echo "$CMDNAME: invalid option: $1" 1>&2
54-
echo "Try '$CMDNAME -?' for help." 1>&2
54+
echo "Try '$CMDNAME --help' for more information." 1>&2
5555
exit 1
5656
;;
5757
*)

src/bin/pg_passwd/pg_passwd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ main(int argc, char *argv[])
333333

334334
if (argc != 2)
335335
{
336-
fprintf(stderr, "%s: too %s arguments\nTry '%s -?' for help.\n",
336+
fprintf(stderr, "%s: too %s arguments\nTry '%s --help' for more information.\n",
337337
progname, argc > 2 ? "many" : "few", progname);
338338
exit(1);
339339
}
@@ -350,7 +350,7 @@ main(int argc, char *argv[])
350350
}
351351
if (argv[1][0] == '-')
352352
{
353-
fprintf(stderr, "%s: invalid option: %s\nTry '%s -?' for help.\n",
353+
fprintf(stderr, "%s: invalid option: %s\nTry '%s --help' for more information.\n",
354354
progname, argv[1], progname);
355355
exit(1);
356356
}

src/bin/psql/startup.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.39 2000/11/13 23:37:53 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.40 2000/11/25 19:05:44 petere Exp $
77
*/
88
#include "postgres.h"
99

@@ -107,6 +107,20 @@ main(int argc, char *argv[])
107107
else
108108
pset.progname = strrchr(argv[0], SEP_CHAR) + 1;
109109

110+
if (argc > 1)
111+
{
112+
if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0)
113+
{
114+
usage();
115+
exit(EXIT_SUCCESS);
116+
}
117+
if (strcmp(argv[1], "--version")==0 || strcmp(argv[1], "-V")==0)
118+
{
119+
showVersion();
120+
exit(EXIT_SUCCESS);
121+
}
122+
}
123+
110124
pset.cur_cmd_source = stdin;
111125
pset.cur_cmd_interactive = false;
112126
pset.encoding = PQenv2encoding();
@@ -520,19 +534,21 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
520534
/* unknown option reported by getopt */
521535
else
522536
{
523-
fputs("Try -? for help.\n", stderr);
537+
fprintf(stderr, "Try '%s --help' for more information.\n",
538+
pset.progname);
524539
exit(EXIT_FAILURE);
525540
}
526541
break;
527542
#ifndef HAVE_GETOPT_LONG
528543
case '-':
529544
fprintf(stderr, "%s was compiled without support for long options.\n"
530-
"Use -? for help on invocation options.\n", pset.progname);
545+
"Use --help for help on invocation options.\n", pset.progname);
531546
exit(EXIT_FAILURE);
532547
break;
533548
#endif
534549
default:
535-
fputs("Try -? for help.\n", stderr);
550+
fprintf(stderr, "Try '%s --help' for more information.\n",
551+
pset.progname);
536552
exit(EXIT_FAILURE);
537553
break;
538554
}

src/bin/scripts/createdb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
#
1313
# IDENTIFICATION
14-
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.11 2000/11/13 23:37:53 momjian Exp $
14+
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.12 2000/11/25 19:05:44 petere Exp $
1515
#
1616
#-------------------------------------------------------------------------
1717

@@ -89,7 +89,7 @@ do
8989
;;
9090
-*)
9191
echo "$CMDNAME: invalid option: $1" 1>&2
92-
echo "Try '$CMDNAME -?' for help." 1>&2
92+
echo "Try '$CMDNAME --help' for more information." 1>&2
9393
exit 1
9494
;;
9595
*)

src/bin/scripts/createlang.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.20 2000/11/20 20:36:50 tgl Exp $
11+
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.21 2000/11/25 19:05:44 petere Exp $
1212
#
1313
#-------------------------------------------------------------------------
1414

@@ -99,7 +99,7 @@ do
9999

100100
-*)
101101
echo "$CMDNAME: invalid option: $1" 1>&2
102-
echo "Try '$CMDNAME -?' for help." 1>&2
102+
echo "Try '$CMDNAME --help' for more information." 1>&2
103103
exit 1
104104
;;
105105
*)

src/bin/scripts/createuser

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.14 2000/11/13 23:37:53 momjian Exp $
11+
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.15 2000/11/25 19:05:44 petere Exp $
1212
#
1313
# Note - this should NOT be setuid.
1414
#
@@ -110,7 +110,7 @@ do
110110
;;
111111
-*)
112112
echo "$CMDNAME: invalid option: $1" 1>&2
113-
echo "Try '$CMDNAME -?' for help." 1>&2
113+
echo "Try '$CMDNAME --help' for more information." 1>&2
114114
exit 1
115115
;;
116116
*)

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