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.

Discussion: https://www.postgresql.org/message-id/flat/3efd0fe8-351b-f836-9122-886002602357%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-12-12 14:33:41 +01:00
parent 840ff5f451
commit df8b8968d4
19 changed files with 473 additions and 479 deletions

View 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);

View 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);

View 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;

View 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;

View 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)
{

View 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);
case 1:
xlog_dir = pg_strdup(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++;
break;
case 'P':
showprogress = true;
case 2:
no_slot = true;
break;
case 3:
verify_checksums = false;

View 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;

View 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);

View 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);

View 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)

View 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,6 +6651,50 @@ main(int argc, char **argv)
}
#endif /* HAVE_GETRLIMIT */
break;
case 'C':
benchmarking_option_set = true;
is_connect = true;
break;
case 'd':
pg_logging_increase_verbosity();
break;
case 'D':
{
char *p;
benchmarking_option_set = true;
if ((p = strchr(optarg, '=')) == NULL || p == optarg || *(p + 1) == '\0')
pg_fatal("invalid variable definition: \"%s\"", optarg);
*p++ = '\0';
if (!putVariable(&state[0].variables, "option", optarg, p))
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,
@ -6677,20 +6707,77 @@ main(int argc, char **argv)
pg_fatal("threads are not supported on this platform; use -j1");
#endif /* !ENABLE_THREAD_SAFETY */
break;
case 'C':
case 'l':
benchmarking_option_set = true;
is_connect = 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++)
if (strcmp(optarg, QUERYMODE[querymode]) == 0)
break;
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 */
double throttle_value = atof(optarg);
benchmarking_option_set = true;
if (throttle_value <= 0.0)
pg_fatal("invalid rate limit: \"%s\"", optarg);
/* Invert rate limit into per-transaction delay in usec */
throttle_delay = 1000000.0 / throttle_value;
}
break;
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,
@ -6706,96 +6793,9 @@ main(int argc, char **argv)
case 'U':
username = pg_strdup(optarg);
break;
case 'l':
case 'v':
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;
break;
case 'D':
{
char *p;
benchmarking_option_set = true;
if ((p = strchr(optarg, '=')) == NULL || p == optarg || *(p + 1) == '\0')
pg_fatal("invalid variable definition: \"%s\"", optarg);
*p++ = '\0';
if (!putVariable(&state[0].variables, "option", optarg, p))
exit(1);
}
break;
case 'F':
initialization_option_set = true;
if (!option_parse_int(optarg, "-F/--fillfactor", 10, 100,
&fillfactor))
exit(1);
break;
case 'M':
benchmarking_option_set = true;
for (querymode = 0; querymode < NUM_QUERYMODE; querymode++)
if (strcmp(optarg, QUERYMODE[querymode]) == 0)
break;
if (querymode >= NUM_QUERYMODE)
pg_fatal("invalid query mode (-M): \"%s\"", optarg);
break;
case 'P':
benchmarking_option_set = true;
if (!option_parse_int(optarg, "-P/--progress", 1, INT_MAX,
&progress))
exit(1);
break;
case 'R':
{
/* get a double from the beginning of option value */
double throttle_value = atof(optarg);
benchmarking_option_set = true;
if (throttle_value <= 0.0)
pg_fatal("invalid rate limit: \"%s\"", optarg);
/* Invert rate limit into per-transaction delay in usec */
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);
}
do_vacuum_accounts = true;
break;
case 1: /* unlogged-tables */
initialization_option_set = true;

View 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 'q':
quiet = 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 '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 'v':
verbose = true;
break;
case 2:
maintenance_db = pg_strdup(optarg);
break;

View 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;

View 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;

View 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;

View File

@ -109,45 +109,21 @@ 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);
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 'S':
simple_string_list_append(&schemas, optarg);
case 'a':
alldb = true;
break;
case 'd':
dbname = pg_strdup(optarg);
break;
case 'a':
alldb = true;
case 'e':
echo = true;
break;
case 's':
syscatalog = true;
break;
case 't':
simple_string_list_append(&tables, optarg);
case 'h':
host = pg_strdup(optarg);
break;
case 'i':
simple_string_list_append(&indexes, optarg);
@ -157,9 +133,33 @@ main(int argc, char *argv[])
&concurrentCons))
exit(1);
break;
case 'q':
quiet = true;
break;
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 '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;

View 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 'a':
objfilter |= OBJFILTER_ALL_DBS;
break;
case 'd':
objfilter |= OBJFILTER_DATABASE;
dbname = pg_strdup(optarg);
break;
case 'e':
echo = true;
break;
case 'f':
vacopts.full = true;
break;
case 'F':
vacopts.freeze = true;
break;
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 '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 'e':
echo = true;
break;
case 'q':
quiet = true;
break;
case 'd':
objfilter |= OBJFILTER_DATABASE;
dbname = pg_strdup(optarg);
break;
case 'z':
vacopts.and_analyze = true;
break;
case 'Z':
vacopts.analyze_only = 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;
break;
case 'j':
if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX,
&concurrentCons))
exit(1);
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 2:
maintenance_db = pg_strdup(optarg);
break;

View 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]);

View 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;
}
}