From 5969ee4df7e98cbb8cc0d1ec04027567ab932a50 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Wed, 18 Apr 2012 10:58:01 -0400 Subject: [PATCH] Revert recent commit re positional arguments. --- src/bin/initdb/initdb.c | 7 ++----- src/bin/scripts/clusterdb.c | 26 +++++++++++--------------- src/bin/scripts/createlang.c | 14 ++------------ src/bin/scripts/droplang.c | 14 ++------------ src/bin/scripts/reindexdb.c | 25 ++++++++++--------------- src/bin/scripts/vacuumdb.c | 27 +++++++++++---------------- 6 files changed, 38 insertions(+), 75 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index bbc7997930..7ca4c93431 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -2563,11 +2563,8 @@ main(int argc, char *argv[]) } - /* - * Non-option argument specifies data directory - * as long as it wasn't already specified with -D / --pgdata - */ - if (optind < argc && strlen(pg_data) == 0) + /* Non-option argument specifies data directory */ + if (optind < argc) { pg_data = xstrdup(argv[optind]); optind++; diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 8fe494a752..c2b2020af7 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -106,22 +106,18 @@ main(int argc, char *argv[]) } } - /* - * Non-option argument specifies database name - * as long as it wasn't already specified with -d / --dbname - */ - if (optind < argc && dbname == NULL) + switch (argc - optind) { - dbname = argv[optind]; - optind++; - } - - if (optind < argc) - { - fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), - progname, argv[optind + 1]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); - exit(1); + case 0: + break; + case 1: + dbname = argv[optind]; + break; + default: + fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), + progname, argv[optind + 1]); + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + exit(1); } setup_cancel_handler(); diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c index ff86ec5949..a36b39bdee 100644 --- a/src/bin/scripts/createlang.c +++ b/src/bin/scripts/createlang.c @@ -91,24 +91,14 @@ main(int argc, char *argv[]) } } - /* - * We set dbname from positional arguments if it is not - * already set by option arguments -d. If not doing - * listlangs, positional dbname must follow positional - * langname. - */ - if (argc - optind > 0) { if (listlangs) - { - if (dbname == NULL) - dbname = argv[optind++]; - } + dbname = argv[optind++]; else { langname = argv[optind++]; - if (argc - optind > 0 && dbname == NULL) + if (argc - optind > 0) dbname = argv[optind++]; } } diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c index a7a9f3f283..b634506f0f 100644 --- a/src/bin/scripts/droplang.c +++ b/src/bin/scripts/droplang.c @@ -102,24 +102,14 @@ main(int argc, char *argv[]) } } - /* - * We set dbname from positional arguments if it is not - * already set by option arguments -d. If not doing - * listlangs, positional dbname must follow positional - * langname. - */ - if (argc - optind > 0) { if (listlangs) - { - if (dbname == NULL) - dbname = argv[optind++]; - } + dbname = argv[optind++]; else { langname = argv[optind++]; - if (argc - optind > 0 && dbname == NULL) + if (argc - optind > 0) dbname = argv[optind++]; } } diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 47fbcde125..9781b3eb08 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -116,22 +116,17 @@ main(int argc, char *argv[]) } } - /* - * Non-option argument specifies database name - * as long as it wasn't already specified with -d / --dbname - */ - if (optind < argc && dbname == NULL) + switch (argc - optind) { - dbname = argv[optind]; - optind++; - } - - if (optind < argc) - { - fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), - progname, argv[optind + 1]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); - exit(1); + case 0: + break; + case 1: + dbname = argv[optind]; + break; + default: + fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind + 1]); + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + exit(1); } setup_cancel_handler(); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index ccf4b3153e..0bac34954d 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -129,23 +129,18 @@ main(int argc, char *argv[]) } } - - /* - * Non-option argument specifies database name - * as long as it wasn't already specified with -d / --dbname - */ - if (optind < argc && dbname == NULL) + switch (argc - optind) { - dbname = argv[optind]; - optind++; - } - - if (optind < argc) - { - fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), - progname, argv[optind + 1]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); - exit(1); + case 0: + break; + case 1: + dbname = argv[optind]; + break; + default: + fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), + progname, argv[optind + 1]); + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + exit(1); } if (analyze_only) -- 2.40.0