Order getopt arguments
authorPeter Eisentraut <[email protected]>
Mon, 12 Dec 2022 13:33:41 +0000 (14:33 +0100)
committerPeter Eisentraut <[email protected]>
Mon, 12 Dec 2022 14:20:00 +0000 (15:20 +0100)
Order the letters in the arguments of getopt() and getopt_long(), as
well as in the subsequent switch statements.  In most cases, I used
alphabetical with lower case first.  In a few cases, existing
different orders (e.g., upper case first) was kept to reduce the diff
size.

Discussion: https://www.postgresql.org/message-id/flat/3efd0fe8-351b-f836-9122-886002602357%40enterprisedb.com

19 files changed:
src/backend/bootstrap/bootstrap.c
src/backend/postmaster/postmaster.c
src/backend/tcop/postgres.c
src/bin/pg_amcheck/pg_amcheck.c
src/bin/pg_archivecleanup/pg_archivecleanup.c
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_receivewal.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_upgrade/option.c
src/bin/pgbench/pgbench.c
src/bin/scripts/clusterdb.c
src/bin/scripts/createdb.c
src/bin/scripts/dropdb.c
src/bin/scripts/dropuser.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c
src/interfaces/ecpg/preproc/ecpg.c
src/test/modules/libpq_pipeline/libpq_pipeline.c

index 661ebacb0c2014229cccd788fc8384c7f1572b94..d623ad9d50d04d75edf70c51ed9478901da4fb0a 100644 (file)
@@ -228,6 +228,32 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
                        case 'B':
                                SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                                break;
+                       case 'c':
+                       case '-':
+                               {
+                                       char       *name,
+                                                          *value;
+
+                                       ParseLongOption(optarg, &name, &value);
+                                       if (!value)
+                                       {
+                                               if (flag == '-')
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("--%s requires a value",
+                                                                                       optarg)));
+                                               else
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("-c %s requires a value",
+                                                                                       optarg)));
+                                       }
+
+                                       SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
+                                       pfree(name);
+                                       pfree(value);
+                                       break;
+                               }
                        case 'D':
                                userDoption = pstrdup(optarg);
                                break;
@@ -265,32 +291,6 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
                                                                        PGC_S_DYNAMIC_DEFAULT);
                                }
                                break;
-                       case 'c':
-                       case '-':
-                               {
-                                       char       *name,
-                                                          *value;
-
-                                       ParseLongOption(optarg, &name, &value);
-                                       if (!value)
-                                       {
-                                               if (flag == '-')
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("--%s requires a value",
-                                                                                       optarg)));
-                                               else
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("-c %s requires a value",
-                                                                                       optarg)));
-                                       }
-
-                                       SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
-                                       pfree(name);
-                                       pfree(value);
-                                       break;
-                               }
                        default:
                                write_stderr("Try \"%s --help\" for more information.\n",
                                                         progname);
index a8a246921f2377a8caa718f96e676bd8b075b336..f459dab360923260063fc2df730e3357bebb2b4e 100644 (file)
@@ -690,7 +690,7 @@ PostmasterMain(int argc, char *argv[])
         * tcop/postgres.c (the option sets should not conflict) and with the
         * common help() function in main/main.c.
         */
-       while ((opt = getopt(argc, argv, "B:bc:C:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:")) != -1)
+       while ((opt = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:")) != -1)
        {
                switch (opt)
                {
@@ -707,6 +707,33 @@ PostmasterMain(int argc, char *argv[])
                                output_config_variable = strdup(optarg);
                                break;
 
+                       case 'c':
+                       case '-':
+                               {
+                                       char       *name,
+                                                          *value;
+
+                                       ParseLongOption(optarg, &name, &value);
+                                       if (!value)
+                                       {
+                                               if (opt == '-')
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("--%s requires a value",
+                                                                                       optarg)));
+                                               else
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("-c %s requires a value",
+                                                                                       optarg)));
+                                       }
+
+                                       SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
+                                       pfree(name);
+                                       pfree(value);
+                                       break;
+                               }
+
                        case 'D':
                                userDoption = strdup(optarg);
                                break;
@@ -814,33 +841,6 @@ PostmasterMain(int argc, char *argv[])
                                SetConfigOption("post_auth_delay", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                                break;
 
-                       case 'c':
-                       case '-':
-                               {
-                                       char       *name,
-                                                          *value;
-
-                                       ParseLongOption(optarg, &name, &value);
-                                       if (!value)
-                                       {
-                                               if (opt == '-')
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("--%s requires a value",
-                                                                                       optarg)));
-                                               else
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("-c %s requires a value",
-                                                                                       optarg)));
-                                       }
-
-                                       SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
-                                       pfree(name);
-                                       pfree(value);
-                                       break;
-                               }
-
                        default:
                                write_stderr("Try \"%s --help\" for more information.\n",
                                                         progname);
index 3082093d1eabdb8c7aeb61f1a505e0acb2618a7c..f8808d2191fc4826f884da9cf617a744a0916758 100644 (file)
@@ -3718,7 +3718,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
         * postmaster/postmaster.c (the option sets should not conflict) and with
         * the common help() function in main/main.c.
         */
-       while ((flag = getopt(argc, argv, "B:bc:C:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)
+       while ((flag = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:v:W:-:")) != -1)
        {
                switch (flag)
                {
@@ -3736,6 +3736,32 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
                                /* ignored for consistency with the postmaster */
                                break;
 
+                       case 'c':
+                       case '-':
+                               {
+                                       char       *name,
+                                                          *value;
+
+                                       ParseLongOption(optarg, &name, &value);
+                                       if (!value)
+                                       {
+                                               if (flag == '-')
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("--%s requires a value",
+                                                                                       optarg)));
+                                               else
+                                                       ereport(ERROR,
+                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                        errmsg("-c %s requires a value",
+                                                                                       optarg)));
+                                       }
+                                       SetConfigOption(name, value, ctx, gucsource);
+                                       pfree(name);
+                                       pfree(value);
+                                       break;
+                               }
+
                        case 'D':
                                if (secure)
                                        userDoption = strdup(optarg);
@@ -3850,32 +3876,6 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
                                SetConfigOption("post_auth_delay", optarg, ctx, gucsource);
                                break;
 
-                       case 'c':
-                       case '-':
-                               {
-                                       char       *name,
-                                                          *value;
-
-                                       ParseLongOption(optarg, &name, &value);
-                                       if (!value)
-                                       {
-                                               if (flag == '-')
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("--%s requires a value",
-                                                                                       optarg)));
-                                               else
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("-c %s requires a value",
-                                                                                       optarg)));
-                                       }
-                                       SetConfigOption(name, value, ctx, gucsource);
-                                       pfree(name);
-                                       pfree(value);
-                                       break;
-                               }
-
                        default:
                                errs++;
                                break;
index 9ce4b11f1e9a64b9bd0643eb7bbc939aacd24996..aa4b12e707e2c2cc375d51891ac3287344a181bf 100644 (file)
@@ -291,7 +291,7 @@ main(int argc, char *argv[])
        handle_help_version_opts(argc, argv, progname, help);
 
        /* process command-line options */
-       while ((c = getopt_long(argc, argv, "ad:D:eh:Hi:I:j:p:Pr:R:s:S:t:T:U:wWv",
+       while ((c = getopt_long(argc, argv, "ad:D:eh:Hi:I:j:p:Pr:R:s:S:t:T:U:vwW",
                                                        long_options, &optindex)) != -1)
        {
                char       *endptr;
@@ -363,16 +363,16 @@ main(int argc, char *argv[])
                        case 'U':
                                username = pg_strdup(optarg);
                                break;
+                       case 'v':
+                               opts.verbose = true;
+                               pg_logging_increase_verbosity();
+                               break;
                        case 'w':
                                prompt_password = TRI_NO;
                                break;
                        case 'W':
                                prompt_password = TRI_YES;
                                break;
-                       case 'v':
-                               opts.verbose = true;
-                               pg_logging_increase_verbosity();
-                               break;
                        case 1:
                                maintenance_db = pg_strdup(optarg);
                                break;
index 064cbb222f257bef54aa83f356a14f311cad3c35..7726d051499b7c9d14819938cb3d8ccb59a1977f 100644 (file)
@@ -294,7 +294,7 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt(argc, argv, "x:dn")) != -1)
+       while ((c = getopt(argc, argv, "dnx:")) != -1)
        {
                switch (c)
                {
index 920569e447495e863fd8d056193437e40405e939..931e2013b89672b560b283b3e78e948b88aa30f2 100644 (file)
@@ -2295,14 +2295,26 @@ main(int argc, char **argv)
 
        atexit(cleanup_directories_atexit);
 
-       while ((c = getopt_long(argc, argv, "CD:F:r:RS:t:T:X:l:nNzZ:d:c:h:p:U:s:wWvP",
+       while ((c = getopt_long(argc, argv, "c:Cd:D:F:h:l:nNp:Pr:Rs:S:t:T:U:vwWX:zZ:",
                                                        long_options, &option_index)) != -1)
        {
                switch (c)
                {
+                       case 'c':
+                               if (pg_strcasecmp(optarg, "fast") == 0)
+                                       fastcheckpoint = true;
+                               else if (pg_strcasecmp(optarg, "spread") == 0)
+                                       fastcheckpoint = false;
+                               else
+                                       pg_fatal("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
+                                                        optarg);
+                               break;
                        case 'C':
                                create_slot = true;
                                break;
+                       case 'd':
+                               connection_string = pg_strdup(optarg);
+                               break;
                        case 'D':
                                basedir = pg_strdup(optarg);
                                break;
@@ -2315,12 +2327,37 @@ main(int argc, char **argv)
                                        pg_fatal("invalid output format \"%s\", must be \"plain\" or \"tar\"",
                                                         optarg);
                                break;
+                       case 'h':
+                               dbhost = pg_strdup(optarg);
+                               break;
+                       case 'l':
+                               label = pg_strdup(optarg);
+                               break;
+                       case 'n':
+                               noclean = true;
+                               break;
+                       case 'N':
+                               do_sync = false;
+                               break;
+                       case 'p':
+                               dbport = pg_strdup(optarg);
+                               break;
+                       case 'P':
+                               showprogress = true;
+                               break;
                        case 'r':
                                maxrate = parse_max_rate(optarg);
                                break;
                        case 'R':
                                writerecoveryconf = true;
                                break;
+                       case 's':
+                               if (!option_parse_int(optarg, "-s/--status-interval", 0,
+                                                                         INT_MAX / 1000,
+                                                                         &standby_message_timeout))
+                                       exit(1);
+                               standby_message_timeout *= 1000;
+                               break;
                        case 'S':
 
                                /*
@@ -2330,15 +2367,24 @@ main(int argc, char **argv)
                                replication_slot = pg_strdup(optarg);
                                temp_replication_slot = false;
                                break;
-                       case 2:
-                               no_slot = true;
-                               break;
                        case 't':
                                backup_target = pg_strdup(optarg);
                                break;
                        case 'T':
                                tablespace_list_append(optarg);
                                break;
+                       case 'U':
+                               dbuser = pg_strdup(optarg);
+                               break;
+                       case 'v':
+                               verbose++;
+                               break;
+                       case 'w':
+                               dbgetpassword = -1;
+                               break;
+                       case 'W':
+                               dbgetpassword = 1;
+                               break;
                        case 'X':
                                if (strcmp(optarg, "n") == 0 ||
                                        strcmp(optarg, "none") == 0)
@@ -2359,18 +2405,6 @@ main(int argc, char **argv)
                                        pg_fatal("invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"",
                                                         optarg);
                                break;
-                       case 1:
-                               xlog_dir = pg_strdup(optarg);
-                               break;
-                       case 'l':
-                               label = pg_strdup(optarg);
-                               break;
-                       case 'n':
-                               noclean = true;
-                               break;
-                       case 'N':
-                               do_sync = false;
-                               break;
                        case 'z':
                                compression_algorithm = "gzip";
                                compression_detail = NULL;
@@ -2380,45 +2414,11 @@ main(int argc, char **argv)
                                backup_parse_compress_options(optarg, &compression_algorithm,
                                                                                          &compression_detail, &compressloc);
                                break;
-                       case 'c':
-                               if (pg_strcasecmp(optarg, "fast") == 0)
-                                       fastcheckpoint = true;
-                               else if (pg_strcasecmp(optarg, "spread") == 0)
-                                       fastcheckpoint = false;
-                               else
-                                       pg_fatal("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
-                                                        optarg);
-                               break;
-                       case 'd':
-                               connection_string = pg_strdup(optarg);
-                               break;
-                       case 'h':
-                               dbhost = pg_strdup(optarg);
-                               break;
-                       case 'p':
-                               dbport = pg_strdup(optarg);
-                               break;
-                       case 'U':
-                               dbuser = pg_strdup(optarg);
-                               break;
-                       case 'w':
-                               dbgetpassword = -1;
-                               break;
-                       case 'W':
-                               dbgetpassword = 1;
-                               break;
-                       case 's':
-                               if (!option_parse_int(optarg, "-s/--status-interval", 0,
-                                                                         INT_MAX / 1000,
-                                                                         &standby_message_timeout))
-                                       exit(1);
-                               standby_message_timeout *= 1000;
-                               break;
-                       case 'v':
-                               verbose++;
+                       case 1:
+                               xlog_dir = pg_strdup(optarg);
                                break;
-                       case 'P':
-                               showprogress = true;
+                       case 2:
+                               no_slot = true;
                                break;
                        case 3:
                                verify_checksums = false;
index c7a46b8a2abca4972f74aeea2a21732743300f81..c8e21f51bced545c7eb715d803379d2d0c5a1dca 100644 (file)
@@ -43,7 +43,7 @@
 static char *basedir = NULL;
 static int     verbose = 0;
 static int     compresslevel = 0;
-static int     noloop = 0;
+static bool    noloop = false;
 static int     standby_message_timeout = 10 * 1000;    /* 10 sec = default */
 static volatile sig_atomic_t time_to_stop = false;
 static bool do_create_slot = false;
@@ -677,32 +677,31 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt_long(argc, argv, "D:d:E:h:p:U:s:S:nwWvZ:",
+       while ((c = getopt_long(argc, argv, "d:D:E:h:np:s:S:U:vwWZ:",
                                                        long_options, &option_index)) != -1)
        {
                switch (c)
                {
+                       case 'd':
+                               connection_string = pg_strdup(optarg);
+                               break;
                        case 'D':
                                basedir = pg_strdup(optarg);
                                break;
-                       case 'd':
-                               connection_string = pg_strdup(optarg);
+                       case 'E':
+                               if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
+                                       pg_fatal("could not parse end position \"%s\"", optarg);
+                               endpos = ((uint64) hi) << 32 | lo;
                                break;
                        case 'h':
                                dbhost = pg_strdup(optarg);
                                break;
+                       case 'n':
+                               noloop = true;
+                               break;
                        case 'p':
                                dbport = pg_strdup(optarg);
                                break;
-                       case 'U':
-                               dbuser = pg_strdup(optarg);
-                               break;
-                       case 'w':
-                               dbgetpassword = -1;
-                               break;
-                       case 'W':
-                               dbgetpassword = 1;
-                               break;
                        case 's':
                                if (!option_parse_int(optarg, "-s/--status-interval", 0,
                                                                          INT_MAX / 1000,
@@ -713,22 +712,22 @@ main(int argc, char **argv)
                        case 'S':
                                replication_slot = pg_strdup(optarg);
                                break;
-                       case 'E':
-                               if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
-                                       pg_fatal("could not parse end position \"%s\"", optarg);
-                               endpos = ((uint64) hi) << 32 | lo;
-                               break;
-                       case 'n':
-                               noloop = 1;
+                       case 'U':
+                               dbuser = pg_strdup(optarg);
                                break;
                        case 'v':
                                verbose++;
                                break;
+                       case 'w':
+                               dbgetpassword = -1;
+                               break;
+                       case 'W':
+                               dbgetpassword = 1;
+                               break;
                        case 'Z':
                                parse_compress_options(optarg, &compression_algorithm_str,
                                                                           &compression_detail);
                                break;
-/* action */
                        case 1:
                                do_create_slot = true;
                                break;
index 5f2e6af44577176feb06835cd170b7e71a663554..1ce803cce8564262d3e7f51e2fb5940b5d33a3da 100644 (file)
@@ -728,7 +728,7 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt_long(argc, argv, "E:f:F:nvtd:h:p:U:wWI:o:P:s:S:",
+       while ((c = getopt_long(argc, argv, "E:f:F:ntvd:h:p:U:wWI:o:P:s:S:",
                                                        long_options, &option_index)) != -1)
        {
                switch (c)
@@ -747,12 +747,12 @@ main(int argc, char **argv)
                        case 'n':
                                noloop = 1;
                                break;
-                       case 'v':
-                               verbose++;
-                               break;
                        case 't':
                                two_phase = true;
                                break;
+                       case 'v':
+                               verbose++;
+                               break;
 /* connection options */
                        case 'd':
                                dbname = pg_strdup(optarg);
index 324ccf77834e12da1c8676130df78f3cc7df7efd..7f3d5fc040ff8514f5ba3560107b23d54badca75 100644 (file)
@@ -471,7 +471,7 @@ main(int argc, char *argv[])
                }
        }
 
-       while ((c = getopt_long(argc, argv, "cD:deNPf:v", long_options, &option_index)) != -1)
+       while ((c = getopt_long(argc, argv, "cdD:ef:NPv", long_options, &option_index)) != -1)
        {
                switch (c)
                {
@@ -481,6 +481,9 @@ main(int argc, char *argv[])
                        case 'd':
                                mode = PG_MODE_DISABLE;
                                break;
+                       case 'D':
+                               DataDir = optarg;
+                               break;
                        case 'e':
                                mode = PG_MODE_ENABLE;
                                break;
@@ -494,15 +497,12 @@ main(int argc, char *argv[])
                        case 'N':
                                do_sync = false;
                                break;
-                       case 'v':
-                               verbose = true;
-                               break;
-                       case 'D':
-                               DataDir = optarg;
-                               break;
                        case 'P':
                                showprogress = true;
                                break;
+                       case 'v':
+                               verbose = true;
+                               break;
                        default:
                                /* getopt_long already emitted a complaint */
                                pg_log_error_hint("Try \"%s --help\" for more information.", progname);
index f441668c612afc120e2e068820275cf05e92859c..2939f584b4c0c562acc442930f72090f92b8141a 100644 (file)
@@ -99,7 +99,7 @@ parseCommandLine(int argc, char *argv[])
        if (os_user_effective_id == 0)
                pg_fatal("%s: cannot be run as root", os_info.progname);
 
-       while ((option = getopt_long(argc, argv, "d:D:b:B:cj:kNo:O:p:P:rs:U:v",
+       while ((option = getopt_long(argc, argv, "b:B:cd:D:j:kNo:O:p:P:rs:U:v",
                                                                 long_options, &optindex)) != -1)
        {
                switch (option)
index ee1a33c9ee88230c9b8dff46538895e0f9c764ab..3182a73ad7246cdbf8531eba9e90980ba24486b5 100644 (file)
@@ -6615,36 +6615,22 @@ main(int argc, char **argv)
        if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED")))
                pg_fatal("error while setting random seed from PGBENCH_RANDOM_SEED environment variable");
 
-       while ((c = getopt_long(argc, argv, "iI:h:nvp:dqb:SNc:j:Crs:t:T:U:lf:D:F:M:P:R:L:", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "b:c:CdD:f:F:h:iI:j:lL:M:nNp:P:qrR:s:St:T:U:v", long_options, &optindex)) != -1)
        {
                char       *script;
 
                switch (c)
                {
-                       case 'i':
-                               is_init_mode = true;
-                               break;
-                       case 'I':
-                               pg_free(initialize_steps);
-                               initialize_steps = pg_strdup(optarg);
-                               checkInitSteps(initialize_steps);
-                               initialization_option_set = true;
-                               break;
-                       case 'h':
-                               pghost = pg_strdup(optarg);
-                               break;
-                       case 'n':
-                               is_no_vacuum = true;
-                               break;
-                       case 'v':
+                       case 'b':
+                               if (strcmp(optarg, "list") == 0)
+                               {
+                                       listAvailableScripts();
+                                       exit(0);
+                               }
+                               weight = parseScriptWeight(optarg, &script);
+                               process_builtin(findBuiltin(script), weight);
                                benchmarking_option_set = true;
-                               do_vacuum_accounts = true;
-                               break;
-                       case 'p':
-                               pgport = pg_strdup(optarg);
-                               break;
-                       case 'd':
-                               pg_logging_increase_verbosity();
+                               internal_script_used = true;
                                break;
                        case 'c':
                                benchmarking_option_set = true;
@@ -6665,80 +6651,12 @@ main(int argc, char **argv)
                                }
 #endif                                                 /* HAVE_GETRLIMIT */
                                break;
-                       case 'j':                       /* jobs */
-                               benchmarking_option_set = true;
-                               if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
-                                                                         &nthreads))
-                               {
-                                       exit(1);
-                               }
-#ifndef ENABLE_THREAD_SAFETY
-                               if (nthreads != 1)
-                                       pg_fatal("threads are not supported on this platform; use -j1");
-#endif                                                 /* !ENABLE_THREAD_SAFETY */
-                               break;
                        case 'C':
                                benchmarking_option_set = true;
                                is_connect = true;
                                break;
-                       case 'r':
-                               benchmarking_option_set = true;
-                               report_per_command = true;
-                               break;
-                       case 's':
-                               scale_given = true;
-                               if (!option_parse_int(optarg, "-s/--scale", 1, INT_MAX,
-                                                                         &scale))
-                                       exit(1);
-                               break;
-                       case 't':
-                               benchmarking_option_set = true;
-                               if (!option_parse_int(optarg, "-t/--transactions", 1, INT_MAX,
-                                                                         &nxacts))
-                                       exit(1);
-                               break;
-                       case 'T':
-                               benchmarking_option_set = true;
-                               if (!option_parse_int(optarg, "-T/--time", 1, INT_MAX,
-                                                                         &duration))
-                                       exit(1);
-                               break;
-                       case 'U':
-                               username = pg_strdup(optarg);
-                               break;
-                       case 'l':
-                               benchmarking_option_set = true;
-                               use_log = true;
-                               break;
-                       case 'q':
-                               initialization_option_set = true;
-                               use_quiet = true;
-                               break;
-                       case 'b':
-                               if (strcmp(optarg, "list") == 0)
-                               {
-                                       listAvailableScripts();
-                                       exit(0);
-                               }
-                               weight = parseScriptWeight(optarg, &script);
-                               process_builtin(findBuiltin(script), weight);
-                               benchmarking_option_set = true;
-                               internal_script_used = true;
-                               break;
-                       case 'S':
-                               process_builtin(findBuiltin("select-only"), 1);
-                               benchmarking_option_set = true;
-                               internal_script_used = true;
-                               break;
-                       case 'N':
-                               process_builtin(findBuiltin("simple-update"), 1);
-                               benchmarking_option_set = true;
-                               internal_script_used = true;
-                               break;
-                       case 'f':
-                               weight = parseScriptWeight(optarg, &script);
-                               process_file(script, weight);
-                               benchmarking_option_set = true;
+                       case 'd':
+                               pg_logging_increase_verbosity();
                                break;
                        case 'D':
                                {
@@ -6754,12 +6672,55 @@ main(int argc, char **argv)
                                                exit(1);
                                }
                                break;
+                       case 'f':
+                               weight = parseScriptWeight(optarg, &script);
+                               process_file(script, weight);
+                               benchmarking_option_set = true;
+                               break;
                        case 'F':
                                initialization_option_set = true;
                                if (!option_parse_int(optarg, "-F/--fillfactor", 10, 100,
                                                                          &fillfactor))
                                        exit(1);
                                break;
+                       case 'h':
+                               pghost = pg_strdup(optarg);
+                               break;
+                       case 'i':
+                               is_init_mode = true;
+                               break;
+                       case 'I':
+                               pg_free(initialize_steps);
+                               initialize_steps = pg_strdup(optarg);
+                               checkInitSteps(initialize_steps);
+                               initialization_option_set = true;
+                               break;
+                       case 'j':                       /* jobs */
+                               benchmarking_option_set = true;
+                               if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
+                                                                         &nthreads))
+                               {
+                                       exit(1);
+                               }
+#ifndef ENABLE_THREAD_SAFETY
+                               if (nthreads != 1)
+                                       pg_fatal("threads are not supported on this platform; use -j1");
+#endif                                                 /* !ENABLE_THREAD_SAFETY */
+                               break;
+                       case 'l':
+                               benchmarking_option_set = true;
+                               use_log = true;
+                               break;
+                       case 'L':
+                               {
+                                       double          limit_ms = atof(optarg);
+
+                                       if (limit_ms <= 0.0)
+                                               pg_fatal("invalid latency limit: \"%s\"", optarg);
+                                       benchmarking_option_set = true;
+                                       latency_limit = (int64) (limit_ms * 1000);
+                               }
+                               break;
                        case 'M':
                                benchmarking_option_set = true;
                                for (querymode = 0; querymode < NUM_QUERYMODE; querymode++)
@@ -6768,12 +6729,31 @@ main(int argc, char **argv)
                                if (querymode >= NUM_QUERYMODE)
                                        pg_fatal("invalid query mode (-M): \"%s\"", optarg);
                                break;
+                       case 'n':
+                               is_no_vacuum = true;
+                               break;
+                       case 'N':
+                               process_builtin(findBuiltin("simple-update"), 1);
+                               benchmarking_option_set = true;
+                               internal_script_used = true;
+                               break;
+                       case 'p':
+                               pgport = pg_strdup(optarg);
+                               break;
                        case 'P':
                                benchmarking_option_set = true;
                                if (!option_parse_int(optarg, "-P/--progress", 1, INT_MAX,
                                                                          &progress))
                                        exit(1);
                                break;
+                       case 'q':
+                               initialization_option_set = true;
+                               use_quiet = true;
+                               break;
+                       case 'r':
+                               benchmarking_option_set = true;
+                               report_per_command = true;
+                               break;
                        case 'R':
                                {
                                        /* get a double from the beginning of option value */
@@ -6787,15 +6767,35 @@ main(int argc, char **argv)
                                        throttle_delay = 1000000.0 / throttle_value;
                                }
                                break;
-                       case 'L':
-                               {
-                                       double          limit_ms = atof(optarg);
-
-                                       if (limit_ms <= 0.0)
-                                               pg_fatal("invalid latency limit: \"%s\"", optarg);
-                                       benchmarking_option_set = true;
-                                       latency_limit = (int64) (limit_ms * 1000);
-                               }
+                       case 's':
+                               scale_given = true;
+                               if (!option_parse_int(optarg, "-s/--scale", 1, INT_MAX,
+                                                                         &scale))
+                                       exit(1);
+                               break;
+                       case 'S':
+                               process_builtin(findBuiltin("select-only"), 1);
+                               benchmarking_option_set = true;
+                               internal_script_used = true;
+                               break;
+                       case 't':
+                               benchmarking_option_set = true;
+                               if (!option_parse_int(optarg, "-t/--transactions", 1, INT_MAX,
+                                                                         &nxacts))
+                                       exit(1);
+                               break;
+                       case 'T':
+                               benchmarking_option_set = true;
+                               if (!option_parse_int(optarg, "-T/--time", 1, INT_MAX,
+                                                                         &duration))
+                                       exit(1);
+                               break;
+                       case 'U':
+                               username = pg_strdup(optarg);
+                               break;
+                       case 'v':
+                               benchmarking_option_set = true;
+                               do_vacuum_accounts = true;
                                break;
                        case 1:                         /* unlogged-tables */
                                initialization_option_set = true;
index df1766679b5d0d614280bec718d25fdeaaef3a0c..0bda94158034f0f2f5793ddcad1122926338ce32 100644 (file)
@@ -68,43 +68,43 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "clusterdb", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:at:v", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "ad:eh:p:qt:U:vwW", long_options, &optindex)) != -1)
        {
                switch (c)
                {
+                       case 'a':
+                               alldb = true;
+                               break;
+                       case 'd':
+                               dbname = pg_strdup(optarg);
+                               break;
+                       case 'e':
+                               echo = true;
+                               break;
                        case 'h':
                                host = pg_strdup(optarg);
                                break;
                        case 'p':
                                port = pg_strdup(optarg);
                                break;
-                       case 'U':
-                               username = pg_strdup(optarg);
-                               break;
-                       case 'w':
-                               prompt_password = TRI_NO;
-                               break;
-                       case 'W':
-                               prompt_password = TRI_YES;
-                               break;
-                       case 'e':
-                               echo = true;
-                               break;
                        case 'q':
                                quiet = true;
                                break;
-                       case 'd':
-                               dbname = pg_strdup(optarg);
-                               break;
-                       case 'a':
-                               alldb = true;
-                               break;
                        case 't':
                                simple_string_list_append(&tables, optarg);
                                break;
+                       case 'U':
+                               username = pg_strdup(optarg);
+                               break;
                        case 'v':
                                verbose = true;
                                break;
+                       case 'w':
+                               prompt_password = TRI_NO;
+                               break;
+                       case 'W':
+                               prompt_password = TRI_YES;
+                               break;
                        case 2:
                                maintenance_db = pg_strdup(optarg);
                                break;
index a1482df3d981a680dd3322052e7c03ddacc8dc26..fa1713a3a0c4d4429a21c29893761844cbc044be 100644 (file)
@@ -79,16 +79,37 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "createdb", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWeO:D:T:E:l:S:", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "D:eE:h:l:O:p:S:T:U:wW", long_options, &optindex)) != -1)
        {
                switch (c)
                {
+                       case 'D':
+                               tablespace = pg_strdup(optarg);
+                               break;
+                       case 'e':
+                               echo = true;
+                               break;
+                       case 'E':
+                               encoding = pg_strdup(optarg);
+                               break;
                        case 'h':
                                host = pg_strdup(optarg);
                                break;
+                       case 'l':
+                               locale = pg_strdup(optarg);
+                               break;
+                       case 'O':
+                               owner = pg_strdup(optarg);
+                               break;
                        case 'p':
                                port = pg_strdup(optarg);
                                break;
+                       case 'S':
+                               strategy = pg_strdup(optarg);
+                               break;
+                       case 'T':
+                               template = pg_strdup(optarg);
+                               break;
                        case 'U':
                                username = pg_strdup(optarg);
                                break;
@@ -98,33 +119,12 @@ main(int argc, char *argv[])
                        case 'W':
                                prompt_password = TRI_YES;
                                break;
-                       case 'e':
-                               echo = true;
-                               break;
-                       case 'O':
-                               owner = pg_strdup(optarg);
-                               break;
-                       case 'D':
-                               tablespace = pg_strdup(optarg);
-                               break;
-                       case 'T':
-                               template = pg_strdup(optarg);
-                               break;
-                       case 'E':
-                               encoding = pg_strdup(optarg);
-                               break;
-                       case 'S':
-                               strategy = pg_strdup(optarg);
-                               break;
                        case 1:
                                lc_collate = pg_strdup(optarg);
                                break;
                        case 2:
                                lc_ctype = pg_strdup(optarg);
                                break;
-                       case 'l':
-                               locale = pg_strdup(optarg);
-                               break;
                        case 3:
                                maintenance_db = pg_strdup(optarg);
                                break;
index afc00dac7841b7bf0d1b3affd543fe033ea6452d..3ca5b82ddcef01e22873e411b09432b2c576b6ed 100644 (file)
@@ -65,13 +65,22 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "dropdb", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWeif", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "efh:ip:U:wW", long_options, &optindex)) != -1)
        {
                switch (c)
                {
+                       case 'e':
+                               echo = true;
+                               break;
+                       case 'f':
+                               force = true;
+                               break;
                        case 'h':
                                host = pg_strdup(optarg);
                                break;
+                       case 'i':
+                               interactive = true;
+                               break;
                        case 'p':
                                port = pg_strdup(optarg);
                                break;
@@ -84,15 +93,6 @@ main(int argc, char *argv[])
                        case 'W':
                                prompt_password = TRI_YES;
                                break;
-                       case 'e':
-                               echo = true;
-                               break;
-                       case 'i':
-                               interactive = true;
-                               break;
-                       case 'f':
-                               force = true;
-                               break;
                        case 0:
                                /* this covers the long options */
                                break;
index 82c1f35ab23fef2c8c440751087aee32540a587f..d8c77cc8ffe9a267a0c07db8a2a629247f2b94d4 100644 (file)
@@ -62,13 +62,19 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "dropuser", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWei", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "eh:ip:U:wW", long_options, &optindex)) != -1)
        {
                switch (c)
                {
+                       case 'e':
+                               echo = true;
+                               break;
                        case 'h':
                                host = pg_strdup(optarg);
                                break;
+                       case 'i':
+                               interactive = true;
+                               break;
                        case 'p':
                                port = pg_strdup(optarg);
                                break;
@@ -81,12 +87,6 @@ main(int argc, char *argv[])
                        case 'W':
                                prompt_password = TRI_YES;
                                break;
-                       case 'e':
-                               echo = true;
-                               break;
-                       case 'i':
-                               interactive = true;
-                               break;
                        case 0:
                                /* this covers the long options */
                                break;
index 0e93a4eeff0d7a191e619b1c6e3466cd3a3c6c7d..1fbf924ab3a96d6e515706107f90b913a2841c28 100644 (file)
@@ -109,57 +109,57 @@ main(int argc, char *argv[])
        handle_help_version_opts(argc, argv, "reindexdb", help);
 
        /* process command-line options */
-       while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:j:v", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "ad:eh:i:j:qp:sS:t:U:vwW", long_options, &optindex)) != -1)
        {
                switch (c)
                {
-                       case 'h':
-                               host = pg_strdup(optarg);
+                       case 'a':
+                               alldb = true;
                                break;
-                       case 'p':
-                               port = pg_strdup(optarg);
+                       case 'd':
+                               dbname = pg_strdup(optarg);
                                break;
-                       case 'U':
-                               username = pg_strdup(optarg);
+                       case 'e':
+                               echo = true;
                                break;
-                       case 'w':
-                               prompt_password = TRI_NO;
+                       case 'h':
+                               host = pg_strdup(optarg);
                                break;
-                       case 'W':
-                               prompt_password = TRI_YES;
+                       case 'i':
+                               simple_string_list_append(&indexes, optarg);
                                break;
-                       case 'e':
-                               echo = true;
+                       case 'j':
+                               if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
+                                                                         &concurrentCons))
+                                       exit(1);
                                break;
                        case 'q':
                                quiet = true;
                                break;
-                       case 'S':
-                               simple_string_list_append(&schemas, optarg);
-                               break;
-                       case 'd':
-                               dbname = pg_strdup(optarg);
-                               break;
-                       case 'a':
-                               alldb = true;
+                       case 'p':
+                               port = pg_strdup(optarg);
                                break;
                        case 's':
                                syscatalog = true;
                                break;
+                       case 'S':
+                               simple_string_list_append(&schemas, optarg);
+                               break;
                        case 't':
                                simple_string_list_append(&tables, optarg);
                                break;
-                       case 'i':
-                               simple_string_list_append(&indexes, optarg);
-                               break;
-                       case 'j':
-                               if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
-                                                                         &concurrentCons))
-                                       exit(1);
+                       case 'U':
+                               username = pg_strdup(optarg);
                                break;
                        case 'v':
                                verbose = true;
                                break;
+                       case 'w':
+                               prompt_password = TRI_NO;
+                               break;
+                       case 'W':
+                               prompt_password = TRI_YES;
+                               break;
                        case 1:
                                concurrently = true;
                                break;
index 0482aa9e88569df641b4be1b90058bec0c543f95..272e37d290cff3f21ff85ed72183a94963032181 100644 (file)
@@ -155,82 +155,76 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "vacuumdb", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:P:n:N:", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "ad:efFh:j:n:N:p:P:qt:U:vwWzZ", long_options, &optindex)) != -1)
        {
                switch (c)
                {
-                       case 'h':
-                               host = pg_strdup(optarg);
-                               break;
-                       case 'p':
-                               port = pg_strdup(optarg);
-                               break;
-                       case 'U':
-                               username = pg_strdup(optarg);
-                               break;
-                       case 'w':
-                               prompt_password = TRI_NO;
-                               break;
-                       case 'W':
-                               prompt_password = TRI_YES;
-                               break;
-                       case 'e':
-                               echo = true;
-                               break;
-                       case 'q':
-                               quiet = true;
+                       case 'a':
+                               objfilter |= OBJFILTER_ALL_DBS;
                                break;
                        case 'd':
                                objfilter |= OBJFILTER_DATABASE;
                                dbname = pg_strdup(optarg);
                                break;
-                       case 'z':
-                               vacopts.and_analyze = true;
+                       case 'e':
+                               echo = true;
                                break;
-                       case 'Z':
-                               vacopts.analyze_only = true;
+                       case 'f':
+                               vacopts.full = true;
                                break;
                        case 'F':
                                vacopts.freeze = true;
                                break;
-                       case 'a':
-                               objfilter |= OBJFILTER_ALL_DBS;
-                               break;
-                       case 't':
-                               {
-                                       objfilter |= OBJFILTER_TABLE;
-                                       simple_string_list_append(&objects, optarg);
-                                       tbl_count++;
-                                       break;
-                               }
-                       case 'f':
-                               vacopts.full = true;
-                               break;
-                       case 'v':
-                               vacopts.verbose = true;
+                       case 'h':
+                               host = pg_strdup(optarg);
                                break;
                        case 'j':
                                if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
                                                                          &concurrentCons))
                                        exit(1);
                                break;
+                       case 'n':
+                               objfilter |= OBJFILTER_SCHEMA;
+                               simple_string_list_append(&objects, optarg);
+                               break;
+                       case 'N':
+                               objfilter |= OBJFILTER_SCHEMA_EXCLUDE;
+                               simple_string_list_append(&objects, optarg);
+                               break;
+                       case 'p':
+                               port = pg_strdup(optarg);
+                               break;
                        case 'P':
                                if (!option_parse_int(optarg, "-P/--parallel", 0, INT_MAX,
                                                                          &vacopts.parallel_workers))
                                        exit(1);
                                break;
-                       case 'n':
-                               {
-                                       objfilter |= OBJFILTER_SCHEMA;
-                                       simple_string_list_append(&objects, optarg);
-                                       break;
-                               }
-                       case 'N':
-                               {
-                                       objfilter |= OBJFILTER_SCHEMA_EXCLUDE;
-                                       simple_string_list_append(&objects, optarg);
-                                       break;
-                               }
+                       case 'q':
+                               quiet = true;
+                               break;
+                       case 't':
+                               objfilter |= OBJFILTER_TABLE;
+                               simple_string_list_append(&objects, optarg);
+                               tbl_count++;
+                               break;
+                       case 'U':
+                               username = pg_strdup(optarg);
+                               break;
+                       case 'v':
+                               vacopts.verbose = true;
+                               break;
+                       case 'w':
+                               prompt_password = TRI_NO;
+                               break;
+                       case 'W':
+                               prompt_password = TRI_YES;
+                               break;
+                       case 'z':
+                               vacopts.and_analyze = true;
+                               break;
+                       case 'Z':
+                               vacopts.analyze_only = true;
+                               break;
                        case 2:
                                maintenance_db = pg_strdup(optarg);
                                break;
index 6fff9e78ede33a0f290bf07a00b052da2dd5b4cc..1790a5844fad474baa00fc9b780da939792fa5ce 100644 (file)
@@ -157,48 +157,13 @@ main(int argc, char *const argv[])
        }
 
        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, "cC:dD:hiI:o:r:tv", ecpg_options, NULL)) != -1)
        {
                switch (c)
                {
-                       case ECPG_GETOPT_LONG_REGRESSION:
-                               regression_mode = true;
-                               break;
-                       case 'o':
-                               output_filename = mm_strdup(optarg);
-                               if (strcmp(output_filename, "-") == 0)
-                                       base_yyout = stdout;
-                               else
-                                       base_yyout = fopen(output_filename, PG_BINARY_W);
-
-                               if (base_yyout == NULL)
-                               {
-                                       fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
-                                                       progname, output_filename, strerror(errno));
-                                       output_filename = NULL;
-                               }
-                               else
-                                       out_option = 1;
-                               break;
-                       case 'I':
-                               add_include_path(optarg);
-                               break;
-                       case 't':
-                               autocommit = true;
-                               break;
-                       case 'v':
-                               verbose = true;
-                               break;
-                       case 'h':
-                               header_mode = true;
-                               /* this must include "-c" to make sense, so fall through */
-                               /* FALLTHROUGH */
                        case 'c':
                                auto_create_c = true;
                                break;
-                       case 'i':
-                               system_includes = true;
-                               break;
                        case 'C':
                                if (pg_strcasecmp(optarg, "INFORMIX") == 0 || pg_strcasecmp(optarg, "INFORMIX_SE") == 0)
                                {
@@ -220,6 +185,44 @@ main(int argc, char *const argv[])
                                        return ILLEGAL_OPTION;
                                }
                                break;
+                       case 'd':
+#ifdef YYDEBUG
+                               base_yydebug = 1;
+#else
+                               fprintf(stderr, _("%s: parser debug support (-d) not available\n"),
+                                               progname);
+#endif
+                               break;
+                       case 'D':
+                               add_preprocessor_define(optarg);
+                               break;
+                       case 'h':
+                               header_mode = true;
+                               /* this must include "-c" to make sense: */
+                               auto_create_c = true;
+                               break;
+                       case 'i':
+                               system_includes = true;
+                               break;
+                       case 'I':
+                               add_include_path(optarg);
+                               break;
+                       case 'o':
+                               output_filename = mm_strdup(optarg);
+                               if (strcmp(output_filename, "-") == 0)
+                                       base_yyout = stdout;
+                               else
+                                       base_yyout = fopen(output_filename, PG_BINARY_W);
+
+                               if (base_yyout == NULL)
+                               {
+                                       fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
+                                                       progname, output_filename, strerror(errno));
+                                       output_filename = NULL;
+                               }
+                               else
+                                       out_option = 1;
+                               break;
                        case 'r':
                                if (pg_strcasecmp(optarg, "no_indicator") == 0)
                                        force_indicator = false;
@@ -233,16 +236,14 @@ main(int argc, char *const argv[])
                                        return ILLEGAL_OPTION;
                                }
                                break;
-                       case 'D':
-                               add_preprocessor_define(optarg);
+                       case 't':
+                               autocommit = true;
                                break;
-                       case 'd':
-#ifdef YYDEBUG
-                               base_yydebug = 1;
-#else
-                               fprintf(stderr, _("%s: parser debug support (-d) not available\n"),
-                                               progname);
-#endif
+                       case 'v':
+                               verbose = true;
+                               break;
+                       case ECPG_GETOPT_LONG_REGRESSION:
+                               regression_mode = true;
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
index a37e4e250080b03bee44a7fcd11aec800e9865d9..f5642ffaa2da6f6faaa23610b3462205ee667b65 100644 (file)
@@ -1705,13 +1705,10 @@ main(int argc, char **argv)
        PGresult   *res;
        int                     c;
 
-       while ((c = getopt(argc, argv, "t:r:")) != -1)
+       while ((c = getopt(argc, argv, "r:t:")) != -1)
        {
                switch (c)
                {
-                       case 't':                       /* trace file */
-                               tracefile = pg_strdup(optarg);
-                               break;
                        case 'r':                       /* numrows */
                                errno = 0;
                                numrows = strtol(optarg, NULL, 10);
@@ -1722,6 +1719,9 @@ main(int argc, char **argv)
                                        exit(1);
                                }
                                break;
+                       case 't':                       /* trace file */
+                               tracefile = pg_strdup(optarg);
+                               break;
                }
        }