|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * 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 $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -153,40 +153,52 @@ on(bool f)
|
153 | 153 | static void
|
154 | 154 | slashUsage(PsqlSettings * ps)
|
155 | 155 | {
|
156 |
| - int ch; |
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 | + int usePipe = 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 | + } |
190 | 202 | }
|
191 | 203 |
|
192 | 204 | static PGresult *
|
@@ -326,12 +338,12 @@ tableList(PsqlSettings * ps, bool deep_tablelist, char info_type)
|
326 | 338 | switch (info_type) {
|
327 | 339 | case 't': fprintf(stderr, "Couldn't find any tables!\n");
|
328 | 340 | break;
|
329 |
| - case 'i': fprintf(stderr, "Couldn't find any indicies!\n"); |
| 341 | + case 'i': fprintf(stderr, "Couldn't find any indices!\n"); |
330 | 342 | break;
|
331 | 343 | case 'S': fprintf(stderr, "Couldn't find any sequences!\n");
|
332 | 344 | break;
|
333 | 345 | case 'b':
|
334 |
| - default: fprintf(stderr, "Couldn't find any tables, sequences or indicies!\n"); |
| 346 | + default: fprintf(stderr, "Couldn't find any tables, sequences or indices!\n"); |
335 | 347 | break;
|
336 | 348 | }
|
337 | 349 | return (-1);
|
@@ -1030,18 +1042,38 @@ do_help(const char *topic)
|
1030 | 1042 | int i; /* Index into QL_HELP[] */
|
1031 | 1043 | bool help_found; /* We found the help he asked for */
|
1032 | 1044 |
|
| 1045 | + int usePipe = 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 | + |
1033 | 1058 | help_found = false; /* Haven't found it yet */
|
1034 | 1059 | for (i = 0; QL_HELP[i].cmd; i++) {
|
1035 | 1060 | if (strcmp(QL_HELP[i].cmd, topic) == 0 ||
|
1036 | 1061 | strcmp(topic, "*") == 0) {
|
1037 | 1062 | 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"); |
1043 | 1068 | }
|
1044 | 1069 | }
|
| 1070 | + |
| 1071 | + if (usePipe) |
| 1072 | + { |
| 1073 | + pclose(fout); |
| 1074 | + pqsignal(SIGPIPE, SIG_DFL); |
| 1075 | + } |
| 1076 | + |
1045 | 1077 | if (!help_found)
|
1046 | 1078 | printf("command not found, "
|
1047 | 1079 | "try \\h with no arguments to see available help\n");
|
@@ -1145,14 +1177,11 @@ HandleSlashCmds(PsqlSettings * settings,
|
1145 | 1177 | break;
|
1146 | 1178 | case 'C': /* define new caption */
|
1147 | 1179 | if (settings->opt.caption)
|
1148 |
| - free(settings->opt.caption); |
1149 |
| - if (!optarg) |
1150 | 1180 | {
|
1151 |
| - if (settings->opt.caption) |
1152 |
| - free(settings->opt.caption); |
| 1181 | + free(settings->opt.caption); |
1153 | 1182 | settings->opt.caption = NULL;
|
1154 | 1183 | }
|
1155 |
| - else if (!(settings->opt.caption = strdup(optarg))) { |
| 1184 | + if (optarg && !(settings->opt.caption = strdup(optarg))) { |
1156 | 1185 | perror("malloc");
|
1157 | 1186 | exit(1);
|
1158 | 1187 | }
|
@@ -1198,11 +1227,11 @@ HandleSlashCmds(PsqlSettings * settings,
|
1198 | 1227 | case 'd': /* \d describe tables or columns in a table */
|
1199 | 1228 | if (strncmp(cmd, "dt", 2) == 0) { /* only tables */
|
1200 | 1229 | tableList(settings, 0, 't');
|
1201 |
| - } else if (strncmp(cmd, "di", 2) == 0) { /* only indicies */ |
| 1230 | + } else if (strncmp(cmd, "di", 2) == 0) { /* only indices */ |
1202 | 1231 | tableList(settings, 0, 'i');
|
1203 | 1232 | } else if (strncmp(cmd, "ds", 2) == 0) { /* only sequences */
|
1204 | 1233 | tableList(settings, 0, 'S');
|
1205 |
| - } else if (!optarg) { /* show tables, sequences and indicies */ |
| 1234 | + } else if (!optarg) { /* show tables, sequences and indices */ |
1206 | 1235 | tableList(settings, 0, 'b');
|
1207 | 1236 | } else if (strcmp(optarg, "*") == 0) { /* show everything */
|
1208 | 1237 | tableList(settings, 0, 'b');
|
|
0 commit comments