From 022b6f7665e7f38fd773f7d44c892344b714f795 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 5 Dec 2022 09:15:53 +0100 Subject: [PATCH] Order getopt arguments 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. --- src/backend/bootstrap/bootstrap.c | 52 ++--- src/backend/postmaster/postmaster.c | 56 ++--- src/backend/tcop/postgres.c | 54 ++--- src/bin/pg_amcheck/pg_amcheck.c | 10 +- src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 +- src/bin/pg_basebackup/pg_basebackup.c | 108 ++++----- src/bin/pg_basebackup/pg_receivewal.c | 41 ++-- src/bin/pg_basebackup/pg_recvlogical.c | 8 +- src/bin/pg_checksums/pg_checksums.c | 14 +- src/bin/pg_upgrade/option.c | 2 +- src/bin/pgbench/pgbench.c | 206 +++++++++--------- src/bin/scripts/clusterdb.c | 38 ++-- src/bin/scripts/createdb.c | 44 ++-- src/bin/scripts/dropdb.c | 20 +- src/bin/scripts/dropuser.c | 14 +- src/bin/scripts/reindexdb.c | 56 ++--- src/bin/scripts/vacuumdb.c | 98 ++++----- src/interfaces/ecpg/preproc/ecpg.c | 91 ++++---- .../modules/libpq_pipeline/libpq_pipeline.c | 8 +- 19 files changed, 458 insertions(+), 464 deletions(-) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 661ebacb0c..d623ad9d50 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -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); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index a8a246921f..f459dab360 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -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); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 3082093d1e..f8808d2191 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -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; diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c index 9ce4b11f1e..aa4b12e707 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -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; diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c index 064cbb222f..7726d05149 100644 --- a/src/bin/pg_archivecleanup/pg_archivecleanup.c +++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c @@ -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) { diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 920569e447..931e2013b8 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -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; diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index c7a46b8a2a..c8e21f51bc 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -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; diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 5f2e6af445..1ce803cce8 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -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); diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index 324ccf7783..7f3d5fc040 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -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); diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index f441668c61..2939f584b4 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -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) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index ee1a33c9ee..3182a73ad7 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -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; diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index df1766679b..0bda941580 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -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; diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index a1482df3d9..fa1713a3a0 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -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; diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index afc00dac78..3ca5b82ddc 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -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; diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index 82c1f35ab2..d8c77cc8ff 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -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; diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 0e93a4eeff..1fbf924ab3 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -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; diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 0482aa9e88..272e37d290 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -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; diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 6fff9e78ed..1790a5844f 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -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]); diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index a37e4e2500..f5642ffaa2 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -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; } } -- 2.38.1