startup.c 15.2 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.52 2001/10/25 05:49:54 momjian 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
enum _actions
{
59 60 61 62 63
				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
			printSSLInfo(void);
B
Bruce Momjian 已提交
90
#endif
91

92 93 94

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

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

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

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

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

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

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

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

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

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

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

162 163 164 165
	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);
166

B
Bruce Momjian 已提交
167 168
	if (options.username)
	{
169 170 171 172 173
		/*
		 * 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.
		 */
174
		if (strcmp(options.username, "\001") == 0)
175
			username = simple_prompt("User name: ", 100, true);
B
Bruce Momjian 已提交
176 177
		else
			username = strdup(options.username);
178 179
	}

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

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

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

B
Bruce Momjian 已提交
203 204 205
	free(username);
	free(password);

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

213 214 215 216 217 218 219
	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 已提交
220

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

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

229 230 231 232 233
	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));
234

235
	/*
236 237
	 * Now find something to do
	 */
B
Bruce Momjian 已提交
238

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

247
		successResult = process_file(options.action_string);
248 249
	}

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

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

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

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

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

296 297 298 299 300 301 302
		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);
303
		if (options.action_string)		/* -f - was used */
304
			pset.inputfile = "<stdin>";
P
Peter Eisentraut 已提交
305
		successResult = MainLoop(stdin);
306
	}
B
Bruce Momjian 已提交
307 308

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

	return successResult;
313 314 315 316 317 318 319 320 321 322
}



/*
 * Parse command line options
 */

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

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

static void
330
parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
331 332
{
#ifdef HAVE_GETOPT_LONG
333
	static struct option long_options[] =
334 335
	{
		{"echo-all", no_argument, NULL, 'a'},
B
Bruce Momjian 已提交
336 337 338
		{"no-align", no_argument, NULL, 'A'},
		{"command", required_argument, NULL, 'c'},
		{"dbname", required_argument, NULL, 'd'},
339
		{"echo-queries", no_argument, NULL, 'e'},
340
		{"echo-hidden", no_argument, NULL, 'E'},
B
Bruce Momjian 已提交
341
		{"file", required_argument, NULL, 'f'},
342
		{"field-separator", required_argument, NULL, 'F'},
B
Bruce Momjian 已提交
343 344 345
		{"host", required_argument, NULL, 'h'},
		{"html", no_argument, NULL, 'H'},
		{"list", no_argument, NULL, 'l'},
346
		{"no-readline", no_argument, NULL, 'n'},
347
		{"output", required_argument, NULL, 'o'},
B
Bruce Momjian 已提交
348 349 350
		{"port", required_argument, NULL, 'p'},
		{"pset", required_argument, NULL, 'P'},
		{"quiet", no_argument, NULL, 'q'},
351
		{"record-separator", required_argument, NULL, 'R'},
B
Bruce Momjian 已提交
352 353 354 355 356 357 358 359 360
		{"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'},
361
		{"expanded", no_argument, NULL, 'x'},
362
		{"no-psqlrc", no_argument, NULL, 'X'},
B
Bruce Momjian 已提交
363 364 365 366
		{"help", no_argument, NULL, '?'},
	};

	int			optindex;
367
#endif	 /* HAVE_GETOPT_LONG */
368

B
Bruce Momjian 已提交
369 370 371
	extern char *optarg;
	extern int	optind;
	int			c;
372
	bool		used_old_u_option = false;
373

374
	memset(options, 0, sizeof *options);
375 376

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

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

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

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

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

					free(value);
					break;
				}
			case 'V':
523 524
				showVersion();
				exit(EXIT_SUCCESS);
B
Bruce Momjian 已提交
525
			case 'W':
526
				pset.getPassword = true;
B
Bruce Momjian 已提交
527
				break;
528 529 530
			case 'x':
				pset.popt.topt.expanded = true;
				break;
531 532 533
			case 'X':
				options->no_psqlrc = true;
				break;
B
Bruce Momjian 已提交
534
			case '?':
535 536 537 538 539 540 541 542 543
				/* 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 已提交
544
					fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
545
							pset.progname);
546
					exit(EXIT_FAILURE);
547
				}
B
Bruce Momjian 已提交
548
				break;
549
#ifndef HAVE_GETOPT_LONG
B
Bruce Momjian 已提交
550
			case '-':
P
Peter Eisentraut 已提交
551 552
				fprintf(stderr,
						gettext("%s was compiled without support for long options.\n"
553
						 "Use --help for help on invocation options.\n"),
P
Peter Eisentraut 已提交
554
						pset.progname);
B
Bruce Momjian 已提交
555 556
				exit(EXIT_FAILURE);
				break;
557
#endif
B
Bruce Momjian 已提交
558
			default:
P
Peter Eisentraut 已提交
559
				fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
560
						pset.progname);
561
				exit(EXIT_FAILURE);
B
Bruce Momjian 已提交
562 563
				break;
		}
564 565
	}

B
Bruce Momjian 已提交
566 567 568 569 570 571 572 573 574 575
	/*
	 * 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];
576
		else if (!QUIET())
P
Peter Eisentraut 已提交
577
			fprintf(stderr, gettext("%s: warning: extra option %s ignored\n"),
578
					pset.progname, argv[optind]);
B
Bruce Momjian 已提交
579 580 581

		optind++;
	}
582

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

586 587 588 589 590
}



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

#ifdef WIN32
#define R_OK 0
#endif

B
Bruce Momjian 已提交
603 604
	/* Look for one in the home dir */
	home = getenv("HOME");
605

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

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



/* showVersion
 *
632
 * This output format is intended to match GNU standards.
633 634
 */
static void
635
showVersion(void)
636
{
637
	puts("psql (PostgreSQL) " PG_VERSION);
638

639
#if defined(USE_READLINE) || defined (USE_HISTORY) || defined(MULTIBYTE)
P
Peter Eisentraut 已提交
640
	fputs(gettext("contains support for: "), stdout);
641 642

#ifdef USE_READLINE
P
Peter Eisentraut 已提交
643
	fputs(gettext("readline"), stdout);
644
#define _Feature
645
#endif
646

647
#ifdef USE_HISTORY
648
#ifdef _Feature
649
	fputs(", ", stdout);
650 651
#else
#define _Feature
652
#endif
P
Peter Eisentraut 已提交
653
	fputs(gettext("history"), stdout);
654
#endif
655 656 657

#ifdef MULTIBYTE
#ifdef _Feature
658
	fputs(", ", stdout);
659 660
#else
#define _Feature
661
#endif
P
Peter Eisentraut 已提交
662
	fputs(gettext("multibyte"), stdout);
663
#endif
664

665
#undef _Feature
666

P
Peter Eisentraut 已提交
667
	puts("");
668
#endif
669

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



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

	ssl = PQgetssl(pset.db);
	if (!ssl)
B
Bruce Momjian 已提交
692
		return;					/* no SSL */
B
Bruce Momjian 已提交
693 694

	SSL_get_cipher_bits(ssl, &sslbits);
P
Peter Eisentraut 已提交
695
	printf(gettext("SSL connection (cipher: %s, bits: %i)\n\n"),
B
Bruce Momjian 已提交
696
		   SSL_get_cipher(ssl), sslbits);
B
Bruce Momjian 已提交
697 698
}
#endif