startup.c 15.1 KB
Newer Older
P
Peter Eisentraut 已提交
1 2 3
/*
 * psql - the PostgreSQL interactive terminal
 *
P
Peter Eisentraut 已提交
4
 * Copyright 2000 by PostgreSQL Global Development Group
P
Peter Eisentraut 已提交
5
 *
6
 * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.51 2001/06/30 17:26:12 petere Exp $
P
Peter Eisentraut 已提交
7
 */
8
#include "postgres_fe.h"
9 10 11

#include <sys/types.h>

12 13
#ifndef WIN32
#include <unistd.h>
14
#else							/* WIN32 */
15
#include <io.h>
B
Hi!  
Bruce Momjian 已提交
16
#include <windows.h>
17
#include <win32.h>
18
#endif	 /* WIN32 */
19 20 21 22 23

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

P
Peter Eisentraut 已提交
24 25 26 27
#ifdef ENABLE_NLS
#include <locale.h>
#endif

28
#include "libpq-fe.h"
29 30 31

#include "command.h"
#include "common.h"
32 33
#include "describe.h"
#include "help.h"
34
#include "input.h"
35
#include "mainloop.h"
36
#include "print.h"
37 38
#include "settings.h"
#include "variables.h"
39

40 41 42 43 44 45 46
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#else
/* XXX Grand unified hard-coded badness; this should go into libpq */
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif

47 48 49
/*
 * Global psql options
 */
50
PsqlSettings pset;
51 52


53 54
/*
 * Structures to pass information between the option parsing routine
55 56
 * and the main function
 */
B
Bruce Momjian 已提交
57 58 59 60 61 62 63
enum _actions
{
	ACT_NOTHING = 0,
	ACT_SINGLE_SLASH,
	ACT_LIST_DB,
	ACT_SINGLE_QUERY,
	ACT_FILE
64 65
};

B
Bruce Momjian 已提交
66 67 68 69 70 71 72 73 74
struct adhoc_opts
{
	char	   *dbname;
	char	   *host;
	char	   *port;
	char	   *username;
	enum _actions action;
	char	   *action_string;
	bool		no_readline;
75
	bool		no_psqlrc;
76 77 78
};

static void
79
			parse_psql_options(int argc, char *argv[], struct adhoc_opts * options);
80

81
static void
82
			process_psqlrc(void);
83 84

static void
85
			showVersion(void);
86

B
Bruce Momjian 已提交
87 88
#ifdef USE_SSL
static void
B
Bruce Momjian 已提交
89 90
			printSSLInfo(void);

B
Bruce Momjian 已提交
91
#endif
92

93 94 95

/*
 *
96
 * main
97 98 99
 *
 */
int
100
main(int argc, char *argv[])
101
{
B
Bruce Momjian 已提交
102 103
	struct adhoc_opts options;
	int			successResult;
104

B
Bruce Momjian 已提交
105 106 107
	char	   *username = NULL;
	char	   *password = NULL;
	bool		need_pass;
108

P
Peter Eisentraut 已提交
109 110 111 112 113 114
#ifdef ENABLE_NLS
	setlocale(LC_ALL, "");
	bindtextdomain("psql", LOCALEDIR);
	textdomain("psql");
#endif

115
	if (!strrchr(argv[0], '/'))
116 117
		pset.progname = argv[0];
	else
118
		pset.progname = strrchr(argv[0], '/') + 1;
119

120 121
	if (argc > 1)
	{
B
Bruce Momjian 已提交
122
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
123 124 125 126
		{
			usage();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
127
		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
128 129 130 131
		{
			showVersion();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
132
	}
133

134 135
	pset.cur_cmd_source = stdin;
	pset.cur_cmd_interactive = false;
136
	pset.encoding = PQenv2encoding();
137

138
	pset.vars = CreateVariableSpace();
139 140
	if (!pset.vars)
	{
P
Peter Eisentraut 已提交
141
		fprintf(stderr, gettext("%s: out of memory\n"), pset.progname);
142 143
		exit(EXIT_FAILURE);
	}
144 145 146
	pset.popt.topt.format = PRINT_ALIGNED;
	pset.queryFout = stdout;
	pset.popt.topt.border = 1;
P
Peter Eisentraut 已提交
147
	pset.popt.topt.pager = true;
148
	pset.popt.default_footer = true;
149

150
	SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
151

152
	pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
153

154
	/* This is obsolete and should be removed sometime. */
155
#ifdef PSQL_ALWAYS_GET_PASSWORDS
156
	pset.getPassword = true;
157
#else
158
	pset.getPassword = false;
159 160
#endif

161
	parse_psql_options(argc, argv, &options);
162

163 164 165 166
	if (!pset.popt.topt.fieldSep)
		pset.popt.topt.fieldSep = xstrdup(DEFAULT_FIELD_SEP);
	if (!pset.popt.topt.recordSep)
		pset.popt.topt.recordSep = xstrdup(DEFAULT_RECORD_SEP);
167

B
Bruce Momjian 已提交
168 169
	if (options.username)
	{
170 171 172 173 174 175

		/*
		 * The \001 is a hack to support the deprecated -u option which
		 * issues a username prompt. The recommended option is -U followed
		 * by the name on the command line.
		 */
176
		if (strcmp(options.username, "\001") == 0)
177
			username = simple_prompt("User name: ", 100, true);
B
Bruce Momjian 已提交
178 179
		else
			username = strdup(options.username);
180 181
	}

182
	if (pset.getPassword)
B
Bruce Momjian 已提交
183
		password = simple_prompt("Password: ", 100, false);
184

B
Bruce Momjian 已提交
185 186 187 188
	/* loop until we have a password if requested by backend */
	do
	{
		need_pass = false;
189
		pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL,
190 191
			options.action == ACT_LIST_DB ? "template1" : options.dbname,
							   username, password);
B
Bruce Momjian 已提交
192

193
		if (PQstatus(pset.db) == CONNECTION_BAD &&
194 195
			strcmp(PQerrorMessage(pset.db), "fe_sendauth: no password supplied\n") == 0 &&
			!feof(stdin))
B
Bruce Momjian 已提交
196
		{
197
			PQfinish(pset.db);
B
Bruce Momjian 已提交
198 199 200 201 202 203
			need_pass = true;
			free(password);
			password = NULL;
			password = simple_prompt("Password: ", 100, false);
		}
	} while (need_pass);
204

B
Bruce Momjian 已提交
205 206 207
	free(username);
	free(password);

208
	if (PQstatus(pset.db) == CONNECTION_BAD)
B
Bruce Momjian 已提交
209
	{
210
		fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
211
		PQfinish(pset.db);
B
Bruce Momjian 已提交
212 213 214
		exit(EXIT_BADCONN);
	}

215 216 217 218 219 220 221
	PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);

	/*
	 * We need to save the encoding because we want to have it available
	 * even if the database connection goes bad.
	 */
	pset.encoding = PQclientEncoding(pset.db);
P
Peter Eisentraut 已提交
222

B
Bruce Momjian 已提交
223 224
	if (options.action == ACT_LIST_DB)
	{
225
		int			success = listAllDbs(false);
B
Bruce Momjian 已提交
226

227
		PQfinish(pset.db);
228
		exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
B
Bruce Momjian 已提交
229 230
	}

231 232 233 234 235
	SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
	SetVariable(pset.vars, "USER", PQuser(pset.db));
	SetVariable(pset.vars, "HOST", PQhost(pset.db));
	SetVariable(pset.vars, "PORT", PQport(pset.db));
	SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
236

237
	/*
238 239
	 * Now find something to do
	 */
B
Bruce Momjian 已提交
240

241
	/*
242 243
	 * process file given by -f
	 */
244
	if (options.action == ACT_FILE && strcmp(options.action_string, "-")!=0)
245 246 247
	{
		if (!options.no_psqlrc)
			process_psqlrc();
248

249
		successResult = process_file(options.action_string);
250 251
	}

252
	/*
253 254
	 * process slash command if one was given to -c
	 */
B
Bruce Momjian 已提交
255
	else if (options.action == ACT_SINGLE_SLASH)
256 257
	{
		const char *value;
258

259 260
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
261
		successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR
262 263 264
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

265
	/*
266 267
	 * If the query given to -c was a normal one, send it
	 */
B
Bruce Momjian 已提交
268
	else if (options.action == ACT_SINGLE_QUERY)
269 270
	{
		const char *value;
271

272 273
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
274
		successResult = SendQuery(options.action_string)
275 276 277
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

278
	/*
279 280
	 * or otherwise enter interactive main loop
	 */
B
Bruce Momjian 已提交
281
	else
282 283 284 285
	{
		pset.issuper = test_superuser(PQuser(pset.db));
		if (!QUIET() && !pset.notty)
		{
P
Peter Eisentraut 已提交
286 287 288 289 290 291 292
			printf(gettext("Welcome to %s, the PostgreSQL interactive terminal.\n\n"
						   "Type:  \\copyright for distribution terms\n"
						   "       \\h for help with SQL commands\n"
						   "       \\? for help on internal slash commands\n"
						   "       \\g or terminate with semicolon to execute query\n"
						   "       \\q to quit\n\n"),
				   pset.progname);
B
Bruce Momjian 已提交
293
#ifdef USE_SSL
294
			printSSLInfo();
B
Bruce Momjian 已提交
295
#endif
296 297
		}

298 299 300 301 302 303 304
		SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1);
		SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2);
		SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3);
		if (!options.no_psqlrc)
			process_psqlrc();
		if (!pset.notty)
			initializeInput(options.no_readline ? 0 : 1);
305 306
		if (options.action_string) /* -f - was used */
			pset.inputfile = "<stdin>";
P
Peter Eisentraut 已提交
307
		successResult = MainLoop(stdin);
308
	}
B
Bruce Momjian 已提交
309 310

	/* clean up */
311 312
	PQfinish(pset.db);
	setQFout(NULL);
B
Bruce Momjian 已提交
313 314

	return successResult;
315 316 317 318 319 320 321 322 323 324
}



/*
 * Parse command line options
 */

#ifdef WIN32
/* getopt is not in the standard includes on Win32 */
B
Bruce Momjian 已提交
325
int			getopt(int, char *const[], const char *);
326

B
Hi!  
Bruce Momjian 已提交
327
/* And it requires progname to be set */
328 329
char	   *__progname = "psql";

330 331 332
#endif

static void
333
parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
334 335
{
#ifdef HAVE_GETOPT_LONG
336
	static struct option long_options[] =
337 338
	{
		{"echo-all", no_argument, NULL, 'a'},
B
Bruce Momjian 已提交
339 340 341
		{"no-align", no_argument, NULL, 'A'},
		{"command", required_argument, NULL, 'c'},
		{"dbname", required_argument, NULL, 'd'},
342
		{"echo-queries", no_argument, NULL, 'e'},
343
		{"echo-hidden", no_argument, NULL, 'E'},
B
Bruce Momjian 已提交
344
		{"file", required_argument, NULL, 'f'},
345
		{"field-separator", required_argument, NULL, 'F'},
B
Bruce Momjian 已提交
346 347 348
		{"host", required_argument, NULL, 'h'},
		{"html", no_argument, NULL, 'H'},
		{"list", no_argument, NULL, 'l'},
349
		{"no-readline", no_argument, NULL, 'n'},
350
		{"output", required_argument, NULL, 'o'},
B
Bruce Momjian 已提交
351 352 353
		{"port", required_argument, NULL, 'p'},
		{"pset", required_argument, NULL, 'P'},
		{"quiet", no_argument, NULL, 'q'},
354
		{"record-separator", required_argument, NULL, 'R'},
B
Bruce Momjian 已提交
355 356 357 358 359 360 361 362 363
		{"single-step", no_argument, NULL, 's'},
		{"single-line", no_argument, NULL, 'S'},
		{"tuples-only", no_argument, NULL, 't'},
		{"table-attr", required_argument, NULL, 'T'},
		{"username", required_argument, NULL, 'U'},
		{"set", required_argument, NULL, 'v'},
		{"variable", required_argument, NULL, 'v'},
		{"version", no_argument, NULL, 'V'},
		{"password", no_argument, NULL, 'W'},
364
		{"expanded", no_argument, NULL, 'x'},
365
		{"no-psqlrc", no_argument, NULL, 'X'},
B
Bruce Momjian 已提交
366 367 368 369
		{"help", no_argument, NULL, '?'},
	};

	int			optindex;
370 371

#endif	 /* HAVE_GETOPT_LONG */
372

B
Bruce Momjian 已提交
373 374 375
	extern char *optarg;
	extern int	optind;
	int			c;
376
	bool		used_old_u_option = false;
377

378
	memset(options, 0, sizeof *options);
379 380

#ifdef HAVE_GETOPT_LONG
381
	while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1)
382 383
#else							/* not HAVE_GETOPT_LONG */

B
Bruce Momjian 已提交
384 385 386 387
	/*
	 * Be sure to leave the '-' in here, so we can catch accidental long
	 * options.
	 */
388
	while ((c = getopt(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1)
389
#endif	 /* not HAVE_GETOPT_LONG */
390
	{
B
Bruce Momjian 已提交
391 392
		switch (c)
		{
393 394 395
			case 'a':
				SetVariable(pset.vars, "ECHO", "all");
				break;
B
Bruce Momjian 已提交
396
			case 'A':
397
				pset.popt.topt.format = PRINT_UNALIGNED;
B
Bruce Momjian 已提交
398 399 400 401
				break;
			case 'c':
				options->action_string = optarg;
				if (optarg[0] == '\\')
P
Peter Eisentraut 已提交
402
				{
B
Bruce Momjian 已提交
403
					options->action = ACT_SINGLE_SLASH;
P
Peter Eisentraut 已提交
404 405
					options->action_string++;
				}
B
Bruce Momjian 已提交
406 407 408 409 410 411 412
				else
					options->action = ACT_SINGLE_QUERY;
				break;
			case 'd':
				options->dbname = optarg;
				break;
			case 'e':
413
				SetVariable(pset.vars, "ECHO", "queries");
B
Bruce Momjian 已提交
414 415
				break;
			case 'E':
416
				SetVariableBool(pset.vars, "ECHO_HIDDEN");
B
Bruce Momjian 已提交
417 418 419 420 421 422
				break;
			case 'f':
				options->action = ACT_FILE;
				options->action_string = optarg;
				break;
			case 'F':
423
				pset.popt.topt.fieldSep = xstrdup(optarg);
B
Bruce Momjian 已提交
424 425 426 427 428
				break;
			case 'h':
				options->host = optarg;
				break;
			case 'H':
429
				pset.popt.topt.format = PRINT_HTML;
B
Bruce Momjian 已提交
430 431 432 433 434 435 436 437
				break;
			case 'l':
				options->action = ACT_LIST_DB;
				break;
			case 'n':
				options->no_readline = true;
				break;
			case 'o':
438
				setQFout(optarg);
B
Bruce Momjian 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451
				break;
			case 'p':
				options->port = optarg;
				break;
			case 'P':
				{
					char	   *value;
					char	   *equal_loc;
					bool		result;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
452
						result = do_pset(value, NULL, &pset.popt, true);
B
Bruce Momjian 已提交
453 454 455
					else
					{
						*equal_loc = '\0';
456
						result = do_pset(value, equal_loc + 1, &pset.popt, true);
B
Bruce Momjian 已提交
457 458 459 460
					}

					if (!result)
					{
P
Peter Eisentraut 已提交
461
						fprintf(stderr, gettext("%s: couldn't set printing parameter %s\n"), pset.progname, value);
B
Bruce Momjian 已提交
462 463 464 465 466 467 468
						exit(EXIT_FAILURE);
					}

					free(value);
					break;
				}
			case 'q':
469
				SetVariableBool(pset.vars, "QUIET");
B
Bruce Momjian 已提交
470
				break;
471 472 473
			case 'R':
				pset.popt.topt.recordSep = xstrdup(optarg);
				break;
B
Bruce Momjian 已提交
474
			case 's':
475
				SetVariableBool(pset.vars, "SINGLESTEP");
B
Bruce Momjian 已提交
476 477
				break;
			case 'S':
478
				SetVariableBool(pset.vars, "SINGLELINE");
B
Bruce Momjian 已提交
479 480
				break;
			case 't':
481
				pset.popt.topt.tuples_only = true;
B
Bruce Momjian 已提交
482 483
				break;
			case 'T':
484
				pset.popt.topt.tableAttr = xstrdup(optarg);
B
Bruce Momjian 已提交
485 486
				break;
			case 'u':
487
				pset.getPassword = true;
488 489 490 491
				options->username = "\001";		/* hopefully nobody has
												 * that username */
				/* this option is out */
				used_old_u_option = true;
B
Bruce Momjian 已提交
492 493 494 495 496 497 498 499 500 501 502 503 504
				break;
			case 'U':
				options->username = optarg;
				break;
			case 'v':
				{
					char	   *value;
					char	   *equal_loc;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
					{
505
						if (!DeleteVariable(pset.vars, value))
B
Bruce Momjian 已提交
506
						{
P
Peter Eisentraut 已提交
507
							fprintf(stderr, gettext("%s: could not delete variable %s\n"),
508
									pset.progname, value);
B
Bruce Momjian 已提交
509 510 511 512 513 514
							exit(EXIT_FAILURE);
						}
					}
					else
					{
						*equal_loc = '\0';
515
						if (!SetVariable(pset.vars, value, equal_loc + 1))
B
Bruce Momjian 已提交
516
						{
P
Peter Eisentraut 已提交
517
							fprintf(stderr, gettext("%s: could not set variable %s\n"),
518
									pset.progname, value);
B
Bruce Momjian 已提交
519 520 521 522 523 524 525 526
							exit(EXIT_FAILURE);
						}
					}

					free(value);
					break;
				}
			case 'V':
527 528
				showVersion();
				exit(EXIT_SUCCESS);
B
Bruce Momjian 已提交
529
			case 'W':
530
				pset.getPassword = true;
B
Bruce Momjian 已提交
531
				break;
532 533 534
			case 'x':
				pset.popt.topt.expanded = true;
				break;
535 536 537
			case 'X':
				options->no_psqlrc = true;
				break;
B
Bruce Momjian 已提交
538
			case '?':
539 540 541 542 543 544 545 546 547
				/* Actual help option given */
				if (strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0)
				{
					usage();
					exit(EXIT_SUCCESS);
				}
				/* unknown option reported by getopt */
				else
				{
P
Peter Eisentraut 已提交
548
					fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
549
							pset.progname);
550
					exit(EXIT_FAILURE);
551
				}
B
Bruce Momjian 已提交
552
				break;
553
#ifndef HAVE_GETOPT_LONG
B
Bruce Momjian 已提交
554
			case '-':
P
Peter Eisentraut 已提交
555 556 557 558
				fprintf(stderr,
						gettext("%s was compiled without support for long options.\n"
								"Use --help for help on invocation options.\n"),
						pset.progname);
B
Bruce Momjian 已提交
559 560
				exit(EXIT_FAILURE);
				break;
561
#endif
B
Bruce Momjian 已提交
562
			default:
P
Peter Eisentraut 已提交
563
				fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
564
						pset.progname);
565
				exit(EXIT_FAILURE);
B
Bruce Momjian 已提交
566 567
				break;
		}
568 569
	}

B
Bruce Momjian 已提交
570 571 572 573 574 575 576 577 578 579
	/*
	 * if we still have arguments, use it as the database name and
	 * username
	 */
	while (argc - optind >= 1)
	{
		if (!options->dbname)
			options->dbname = argv[optind];
		else if (!options->username)
			options->username = argv[optind];
580
		else if (!QUIET())
P
Peter Eisentraut 已提交
581
			fprintf(stderr, gettext("%s: warning: extra option %s ignored\n"),
582
					pset.progname, argv[optind]);
B
Bruce Momjian 已提交
583 584 585

		optind++;
	}
586

587
	if (used_old_u_option && !QUIET())
P
Peter Eisentraut 已提交
588
		fprintf(stderr, gettext("%s: Warning: The -u option is deprecated. Use -U.\n"), pset.progname);
589

590 591 592 593 594
}



/*
P
Peter Eisentraut 已提交
595
 * Load .psqlrc file, if found.
596 597
 */
static void
598
process_psqlrc(void)
599
{
B
Bruce Momjian 已提交
600 601
	char	   *psqlrc;
	char	   *home;
602 603 604 605 606

#ifdef WIN32
#define R_OK 0
#endif

B
Bruce Momjian 已提交
607 608
	/* Look for one in the home dir */
	home = getenv("HOME");
609

B
Bruce Momjian 已提交
610 611
	if (home)
	{
612
		psqlrc = malloc(strlen(home) + 20);
B
Bruce Momjian 已提交
613 614
		if (!psqlrc)
		{
P
Peter Eisentraut 已提交
615
			fprintf(stderr, gettext("%s: out of memory\n"), pset.progname);
B
Bruce Momjian 已提交
616 617
			exit(EXIT_FAILURE);
		}
618

619
		sprintf(psqlrc, "%s/.psqlrc-" PG_VERSION, home);
B
Bruce Momjian 已提交
620
		if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
621
			process_file(psqlrc);
B
Bruce Momjian 已提交
622 623 624 625
		else
		{
			sprintf(psqlrc, "%s/.psqlrc", home);
			if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
626
				process_file(psqlrc);
B
Bruce Momjian 已提交
627 628
		}
		free(psqlrc);
629 630 631 632 633 634 635
	}
}



/* showVersion
 *
636
 * This output format is intended to match GNU standards.
637 638
 */
static void
639
showVersion(void)
640
{
641
	puts("psql (PostgreSQL) " PG_VERSION);
642

643
#if defined(USE_READLINE) || defined (USE_HISTORY) || defined(MULTIBYTE)
P
Peter Eisentraut 已提交
644
	fputs(gettext("contains support for: "), stdout);
645 646

#ifdef USE_READLINE
P
Peter Eisentraut 已提交
647
	fputs(gettext("readline"), stdout);
648
#define _Feature
649
#endif
650

651
#ifdef USE_HISTORY
652
#ifdef _Feature
653
	fputs(", ", stdout);
654 655
#else
#define _Feature
656
#endif
P
Peter Eisentraut 已提交
657
	fputs(gettext("history"), stdout);
658
#endif
659 660 661

#ifdef MULTIBYTE
#ifdef _Feature
662
	fputs(", ", stdout);
663 664
#else
#define _Feature
665
#endif
P
Peter Eisentraut 已提交
666
	fputs(gettext("multibyte"), stdout);
667
#endif
668

669
#undef _Feature
670

P
Peter Eisentraut 已提交
671
	puts("");
672
#endif
673

P
Peter Eisentraut 已提交
674 675 676 677
	puts(gettext("Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group\n"
				 "Portions Copyright (c) 1996, Regents of the University of California\n"
				 "Read the file COPYRIGHT or use the command \\copyright to see the\n"
				 "usage and distribution terms."));
678
}
B
Bruce Momjian 已提交
679 680 681 682 683 684 685 686 687



/*
 * printSSLInfo
 *
 * Prints information about the current SSL connection, if SSL is in use
 */
#ifdef USE_SSL
B
Bruce Momjian 已提交
688
static void
B
Bruce Momjian 已提交
689 690
printSSLInfo(void)
{
B
Bruce Momjian 已提交
691 692
	int			sslbits = -1;
	SSL		   *ssl;
B
Bruce Momjian 已提交
693 694 695

	ssl = PQgetssl(pset.db);
	if (!ssl)
B
Bruce Momjian 已提交
696
		return;					/* no SSL */
B
Bruce Momjian 已提交
697 698

	SSL_get_cipher_bits(ssl, &sslbits);
P
Peter Eisentraut 已提交
699
	printf(gettext("SSL connection (cipher: %s, bits: %i)\n\n"),
B
Bruce Momjian 已提交
700
		   SSL_get_cipher(ssl), sslbits);
B
Bruce Momjian 已提交
701
}
B
Bruce Momjian 已提交
702

B
Bruce Momjian 已提交
703
#endif