Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8447148

Browse files
committed
psql: Add PAGER for \h and \?,\C fix, indices spell fix.
1 parent4d8a5ef commit8447148

File tree

1 file changed

+78
-49
lines changed

1 file changed

+78
-49
lines changed

‎src/bin/psql/psql.c

Lines changed: 78 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.77 1997/07/14 22:08:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.78 1997/07/24 20:01:33 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -153,40 +153,52 @@ on(bool f)
153153
staticvoid
154154
slashUsage(PsqlSettings*ps)
155155
{
156-
intch;
157-
158-
fprintf(stderr," \\? -- help\n");
159-
fprintf(stderr," \\a -- toggle field-alignment (currenty %s)\n",on(ps->opt.align));
160-
fprintf(stderr," \\C [<captn>] -- set html3 caption (currently '%s')\n",ps->opt.caption ?ps->opt.caption :"");
161-
fprintf(stderr," \\connect <dbname|-> <user> -- connect to new database (currently '%s')\n",PQdb(ps->db));
162-
fprintf(stderr," \\copy table {from | to} <fname>\n");
163-
fprintf(stderr," \\d [<table>] -- list tables and indicies in database or columns in <table>, * for all\n");
164-
fprintf(stderr," \\di -- list only indicies in database\n");
165-
fprintf(stderr," \\ds -- list only sequences in database\n");
166-
fprintf(stderr," \\dt -- list only tables in database\n");
167-
fprintf(stderr," \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
168-
fprintf(stderr," \\f [<sep>] -- change field separater (currently '%s')\n",ps->opt.fieldSep);
169-
fprintf(stderr," \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n");
170-
fprintf(stderr," \\h [<cmd>] -- help on syntax of sql commands, * for all commands\n");
171-
fprintf(stderr," \\H -- toggle html3 output (currently %s)\n",on(ps->opt.html3));
172-
fprintf(stderr," \\i <fname> -- read and execute queries from filename\n");
173-
fprintf(stderr," \\l -- list all databases\n");
174-
fprintf(stderr," \\m -- toggle monitor-like table display (currently %s)\n",on(ps->opt.standard));
175-
fprintf(stderr," \\o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe\n");
176-
fprintf(stderr," \\p -- print the current query buffer\n");
177-
178-
fprintf(stderr,"Press ENTER to continue");
179-
/* eat up any extra characters typed before ENTER */
180-
while ((ch=fgetc(stdin))!='\r'&&ch!='\n')
181-
;
182-
fprintf(stderr," \\q -- quit\n");
183-
fprintf(stderr," \\r -- reset(clear) the query buffer\n");
184-
fprintf(stderr," \\s [<fname>] -- print history or save it in <fname>\n");
185-
fprintf(stderr," \\t -- toggle table headings and row count (currently %s)\n",on(ps->opt.header));
186-
fprintf(stderr," \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n",ps->opt.tableOpt ?ps->opt.tableOpt :"");
187-
fprintf(stderr," \\x -- toggle expanded output (currently %s)\n",on(ps->opt.expanded));
188-
fprintf(stderr," \\z -- list current grant/revoke permissions\n");
189-
fprintf(stderr," \\! [<cmd>] -- shell escape or command\n");
156+
intusePipe=0;
157+
char*pagerenv;
158+
FILE*fout;
159+
160+
if ((pagerenv=getenv("PAGER"))&& (pagerenv[0]!='\0')&& \
161+
(fout=popen(pagerenv,"w")))
162+
{
163+
usePipe=1;
164+
pqsignal(SIGPIPE,SIG_IGN);
165+
}
166+
else
167+
fout=stderr;
168+
169+
fprintf(fout," \\? -- help\n");
170+
fprintf(fout," \\a -- toggle field-alignment (currenty %s)\n",on(ps->opt.align));
171+
fprintf(fout," \\C [<captn>] -- set html3 caption (currently '%s')\n",ps->opt.caption ?ps->opt.caption :"");
172+
fprintf(fout," \\connect <dbname|-> <user> -- connect to new database (currently '%s')\n",PQdb(ps->db));
173+
fprintf(fout," \\copy table {from | to} <fname>\n");
174+
fprintf(fout," \\d [<table>] -- list tables and indices in database or columns in <table>, * for all\n");
175+
fprintf(fout," \\di -- list only indices in database\n");
176+
fprintf(fout," \\ds -- list only sequences in database\n");
177+
fprintf(fout," \\dt -- list only tables in database\n");
178+
fprintf(fout," \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
179+
fprintf(fout," \\f [<sep>] -- change field separater (currently '%s')\n",ps->opt.fieldSep);
180+
fprintf(fout," \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n");
181+
fprintf(fout," \\h [<cmd>] -- help on syntax of sql commands, * for all commands\n");
182+
fprintf(fout," \\H -- toggle html3 output (currently %s)\n",on(ps->opt.html3));
183+
fprintf(fout," \\i <fname> -- read and execute queries from filename\n");
184+
fprintf(fout," \\l -- list all databases\n");
185+
fprintf(fout," \\m -- toggle monitor-like table display (currently %s)\n",on(ps->opt.standard));
186+
fprintf(fout," \\o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe\n");
187+
fprintf(fout," \\p -- print the current query buffer\n");
188+
fprintf(fout," \\q -- quit\n");
189+
fprintf(fout," \\r -- reset(clear) the query buffer\n");
190+
fprintf(fout," \\s [<fname>] -- print history or save it in <fname>\n");
191+
fprintf(fout," \\t -- toggle table headings and row count (currently %s)\n",on(ps->opt.header));
192+
fprintf(fout," \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n",ps->opt.tableOpt ?ps->opt.tableOpt :"");
193+
fprintf(fout," \\x -- toggle expanded output (currently %s)\n",on(ps->opt.expanded));
194+
fprintf(fout," \\z -- list current grant/revoke permissions\n");
195+
fprintf(fout," \\! [<cmd>] -- shell escape or command\n");
196+
197+
if (usePipe)
198+
{
199+
pclose(fout);
200+
pqsignal(SIGPIPE,SIG_DFL);
201+
}
190202
}
191203

192204
staticPGresult*
@@ -326,12 +338,12 @@ tableList(PsqlSettings * ps, bool deep_tablelist, char info_type)
326338
switch (info_type) {
327339
case't':fprintf(stderr,"Couldn't find any tables!\n");
328340
break;
329-
case'i':fprintf(stderr,"Couldn't find anyindicies!\n");
341+
case'i':fprintf(stderr,"Couldn't find anyindices!\n");
330342
break;
331343
case'S':fprintf(stderr,"Couldn't find any sequences!\n");
332344
break;
333345
case'b':
334-
default:fprintf(stderr,"Couldn't find any tables, sequences orindicies!\n");
346+
default:fprintf(stderr,"Couldn't find any tables, sequences orindices!\n");
335347
break;
336348
}
337349
return (-1);
@@ -1030,18 +1042,38 @@ do_help(const char *topic)
10301042
inti;/* Index into QL_HELP[] */
10311043
boolhelp_found;/* We found the help he asked for */
10321044

1045+
intusePipe=0;
1046+
char*pagerenv;
1047+
FILE*fout;
1048+
1049+
if ((pagerenv=getenv("PAGER"))&& (pagerenv[0]!='\0')&& \
1050+
(fout=popen(pagerenv,"w")))
1051+
{
1052+
usePipe=1;
1053+
pqsignal(SIGPIPE,SIG_IGN);
1054+
}
1055+
else
1056+
fout=stderr;
1057+
10331058
help_found= false;/* Haven't found it yet */
10341059
for (i=0;QL_HELP[i].cmd;i++) {
10351060
if (strcmp(QL_HELP[i].cmd,topic)==0||
10361061
strcmp(topic,"*")==0) {
10371062
help_found= true;
1038-
printf("Command: %s\n",QL_HELP[i].cmd);
1039-
printf("Description: %s\n",QL_HELP[i].help);
1040-
printf("Syntax:\n");
1041-
printf("%s\n",QL_HELP[i].syntax);
1042-
printf("\n");
1063+
fprintf(fout,"Command: %s\n",QL_HELP[i].cmd);
1064+
fprintf(fout,"Description: %s\n",QL_HELP[i].help);
1065+
fprintf(fout,"Syntax:\n");
1066+
fprintf(fout,"%s\n",QL_HELP[i].syntax);
1067+
fprintf(fout,"\n");
10431068
}
10441069
}
1070+
1071+
if (usePipe)
1072+
{
1073+
pclose(fout);
1074+
pqsignal(SIGPIPE,SIG_DFL);
1075+
}
1076+
10451077
if (!help_found)
10461078
printf("command not found, "
10471079
"try \\h with no arguments to see available help\n");
@@ -1145,14 +1177,11 @@ HandleSlashCmds(PsqlSettings * settings,
11451177
break;
11461178
case'C':/* define new caption */
11471179
if (settings->opt.caption)
1148-
free(settings->opt.caption);
1149-
if (!optarg)
11501180
{
1151-
if (settings->opt.caption)
1152-
free(settings->opt.caption);
1181+
free(settings->opt.caption);
11531182
settings->opt.caption=NULL;
11541183
}
1155-
elseif (!(settings->opt.caption=strdup(optarg))) {
1184+
if (optarg&&!(settings->opt.caption=strdup(optarg))) {
11561185
perror("malloc");
11571186
exit(1);
11581187
}
@@ -1198,11 +1227,11 @@ HandleSlashCmds(PsqlSettings * settings,
11981227
case'd':/* \d describe tables or columns in a table */
11991228
if (strncmp(cmd,"dt",2)==0) {/* only tables */
12001229
tableList(settings,0,'t');
1201-
}elseif (strncmp(cmd,"di",2)==0) {/* onlyindicies */
1230+
}elseif (strncmp(cmd,"di",2)==0) {/* onlyindices */
12021231
tableList(settings,0,'i');
12031232
}elseif (strncmp(cmd,"ds",2)==0) {/* only sequences */
12041233
tableList(settings,0,'S');
1205-
}elseif (!optarg) {/* show tables, sequences andindicies */
1234+
}elseif (!optarg) {/* show tables, sequences andindices */
12061235
tableList(settings,0,'b');
12071236
}elseif (strcmp(optarg,"*")==0) {/* show everything */
12081237
tableList(settings,0,'b');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp