Skip to content

Commit e2eed71

Browse files
committed
Code cleanup: remove PGUT_NO_PROMPT macro
1 parent 5372a1e commit e2eed71

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

pgut/pgut.c

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ char *password = NULL;
3636
bool verbose = false;
3737
bool quiet = false;
3838

39-
#ifndef PGUT_NO_PROMPT
40-
YesNo prompt_password = DEFAULT;
41-
#endif
39+
bool prompt_password = false;
4240

4341
/* Database connections */
4442
static PGcancel *volatile cancel_conn = NULL;
@@ -76,10 +74,8 @@ static pgut_option default_options[] =
7674
{ 'b', 'q', "quiet" , &quiet, SOURCE_CMDLINE },
7775
{ 's', 'U', "username" , &username, SOURCE_CMDLINE },
7876
{ 'b', 'v', "verbose" , &verbose, SOURCE_CMDLINE },
79-
#ifndef PGUT_NO_PROMPT
80-
{ 'Y', 'w', "no-password" , &prompt_password, SOURCE_CMDLINE },
81-
{ 'y', 'W', "password" , &prompt_password, SOURCE_CMDLINE },
82-
#endif
77+
{ 'B', 'w', "no-password" , &prompt_password, SOURCE_CMDLINE },
78+
{ 'b', 'W', "password" , &prompt_password, SOURCE_CMDLINE },
8379
{ 0 }
8480
};
8581

@@ -98,8 +94,6 @@ option_has_arg(char type)
9894
{
9995
case 'b':
10096
case 'B':
101-
case 'y':
102-
case 'Y':
10397
return no_argument;
10498
default:
10599
return required_argument;
@@ -225,24 +219,6 @@ assign_option(pgut_option *opt, const char *optarg, pgut_optsrc src)
225219
return;
226220
message = "a time";
227221
break;
228-
case 'y':
229-
case 'Y':
230-
if (optarg == NULL)
231-
{
232-
*(YesNo *) opt->var = (opt->type == 'y' ? YES : NO);
233-
return;
234-
}
235-
else
236-
{
237-
bool value;
238-
if (parse_bool(optarg, &value))
239-
{
240-
*(YesNo *) opt->var = (value ? YES : NO);
241-
return;
242-
}
243-
}
244-
message = "a boolean";
245-
break;
246222
default:
247223
elog(ERROR, "invalid option type: %c", opt->type);
248224
return; /* keep compiler quiet */
@@ -867,7 +843,6 @@ parse_pair(const char buffer[], char key[], char value[])
867843
return true;
868844
}
869845

870-
#ifndef PGUT_NO_PROMPT
871846
/*
872847
* Ask the user for a password; 'username' is the username the
873848
* password is for, if one has been explicitly specified.
@@ -902,7 +877,6 @@ prompt_for_password(const char *username)
902877
}
903878
#endif
904879
}
905-
#endif
906880

907881
PGconn *
908882
pgut_connect(const char *dbname)
@@ -912,10 +886,8 @@ pgut_connect(const char *dbname)
912886
if (interrupted && !in_cleanup)
913887
elog(ERROR, "interrupted");
914888

915-
#ifndef PGUT_NO_PROMPT
916-
if (prompt_password == YES)
889+
if (prompt_password)
917890
prompt_for_password(username);
918-
#endif
919891

920892
/* Start the connection. Loop until we have a password if requested by backend. */
921893
for (;;)
@@ -925,14 +897,12 @@ pgut_connect(const char *dbname)
925897
if (PQstatus(conn) == CONNECTION_OK)
926898
return conn;
927899

928-
#ifndef PGUT_NO_PROMPT
929-
if (conn && PQconnectionNeedsPassword(conn) && prompt_password != NO)
900+
if (conn && PQconnectionNeedsPassword(conn) && prompt_password)
930901
{
931902
PQfinish(conn);
932903
prompt_for_password(username);
933904
continue;
934905
}
935-
#endif
936906
elog(ERROR, "could not connect to database %s: %s",
937907
dbname, PQerrorMessage(conn));
938908

@@ -1384,10 +1354,8 @@ help(bool details)
13841354
printf(" -h, --host=HOSTNAME database server host or socket directory\n");
13851355
printf(" -p, --port=PORT database server port\n");
13861356
printf(" -U, --username=USERNAME user name to connect as\n");
1387-
#ifndef PGUT_NO_PROMPT
13881357
printf(" -w, --no-password never prompt for password\n");
13891358
printf(" -W, --password force password prompt\n");
1390-
#endif
13911359
}
13921360

13931361
printf("\nGeneric options:\n");

pgut/pgut.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ typedef char bool;
3030

3131
#define INFINITE_STR "INFINITE"
3232

33-
typedef enum YesNo
34-
{
35-
DEFAULT,
36-
NO,
37-
YES
38-
} YesNo;
39-
4033
typedef enum pgut_optsrc
4134
{
4235
SOURCE_DEFAULT,
@@ -58,8 +51,6 @@ typedef enum pgut_optsrc
5851
* U: 64bit unsigned integer
5952
* s: string
6053
* t: time_t
61-
* y: YesNo (YES)
62-
* Y: YesNo (NO)
6354
*/
6455
typedef struct pgut_option
6556
{
@@ -95,9 +86,7 @@ extern char *password;
9586
extern bool verbose;
9687
extern bool quiet;
9788

98-
#ifndef PGUT_NO_PROMPT
99-
extern YesNo prompt_password;
100-
#endif
89+
extern bool prompt_password;
10190

10291
extern bool interrupted;
10392

0 commit comments

Comments
 (0)