7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.152 1998/08/06 05:12:55 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.153 1998/08/10 20:31:38 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -254,6 +254,7 @@ slashUsage(PsqlSettings *pset)
254
254
fprintf (fout , " \\t -- toggle table headings and row count (currently %s)\n" , on (pset -> opt .header ));
255
255
fprintf (fout , " \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n" , pset -> opt .tableOpt ? pset -> opt .tableOpt : "" );
256
256
fprintf (fout , " \\x -- toggle expanded output (currently %s)\n" , on (pset -> opt .expanded ));
257
+ fprintf (fout , " \\w <fname> -- output current buffer to a file\n" );
257
258
fprintf (fout , " \\z -- list current grant/revoke permissions\n" );
258
259
fprintf (fout , " \\! [<cmd>] -- shell escape or command\n" );
259
260
@@ -2135,13 +2136,34 @@ HandleSlashCmds(PsqlSettings *pset,
2135
2136
break ;
2136
2137
}
2137
2138
2139
+ case 'H' :
2140
+ if (toggle (pset , & pset -> opt .html3 , "HTML3.0 tabular output" ))
2141
+ pset -> opt .standard = 0 ;
2142
+ break ;
2143
+
2138
2144
case 'l' : /* \l is list database */
2139
2145
listAllDbs (pset );
2140
2146
break ;
2141
2147
2142
- case 'H' :
2143
- if (toggle (pset , & pset -> opt .html3 , "HTML3.0 tabular output" ))
2144
- pset -> opt .standard = 0 ;
2148
+ case 'm' : /* monitor like type-setting */
2149
+ if (toggle (pset , & pset -> opt .standard , "standard SQL separaters and padding" ))
2150
+ {
2151
+ pset -> opt .html3 = pset -> opt .expanded = 0 ;
2152
+ pset -> opt .align = pset -> opt .header = 1 ;
2153
+ if (pset -> opt .fieldSep )
2154
+ free (pset -> opt .fieldSep );
2155
+ pset -> opt .fieldSep = strdup ("|" );
2156
+ if (!pset -> quiet )
2157
+ printf ("field separator changed to '%s'\n" , pset -> opt .fieldSep );
2158
+ }
2159
+ else
2160
+ {
2161
+ if (pset -> opt .fieldSep )
2162
+ free (pset -> opt .fieldSep );
2163
+ pset -> opt .fieldSep = strdup (DEFAULT_FIELD_SEP );
2164
+ if (!pset -> quiet )
2165
+ printf ("field separator changed to '%s'\n" , pset -> opt .fieldSep );
2166
+ }
2145
2167
break ;
2146
2168
2147
2169
case 'o' :
@@ -2175,31 +2197,6 @@ HandleSlashCmds(PsqlSettings *pset,
2175
2197
#endif
2176
2198
break ;
2177
2199
2178
- case 'm' : /* monitor like type-setting */
2179
- if (toggle (pset , & pset -> opt .standard , "standard SQL separaters and padding" ))
2180
- {
2181
- pset -> opt .html3 = pset -> opt .expanded = 0 ;
2182
- pset -> opt .align = pset -> opt .header = 1 ;
2183
- if (pset -> opt .fieldSep )
2184
- free (pset -> opt .fieldSep );
2185
- pset -> opt .fieldSep = strdup ("|" );
2186
- if (!pset -> quiet )
2187
- printf ("field separator changed to '%s'\n" , pset -> opt .fieldSep );
2188
- }
2189
- else
2190
- {
2191
- if (pset -> opt .fieldSep )
2192
- free (pset -> opt .fieldSep );
2193
- pset -> opt .fieldSep = strdup (DEFAULT_FIELD_SEP );
2194
- if (!pset -> quiet )
2195
- printf ("field separator changed to '%s'\n" , pset -> opt .fieldSep );
2196
- }
2197
- break ;
2198
-
2199
- case 'z' : /* list table rights (grant/revoke) */
2200
- rightsList (pset );
2201
- break ;
2202
-
2203
2200
case 't' : /* toggle headers */
2204
2201
toggle (pset , & pset -> opt .header , "output headings and row count" );
2205
2202
break ;
@@ -2216,10 +2213,34 @@ HandleSlashCmds(PsqlSettings *pset,
2216
2213
}
2217
2214
break ;
2218
2215
2216
+ case 'w' :
2217
+ {
2218
+ FILE * fd ;
2219
+
2220
+ if (!optarg )
2221
+ {
2222
+ fprintf (stderr , "\\w must be followed by a file name\n" );
2223
+ break ;
2224
+ }
2225
+ if ((fd = fopen (optarg , "w" )) == NULL )
2226
+ {
2227
+ fprintf (stderr , "file named %s could not be opened\n" , optarg );
2228
+ break ;
2229
+ }
2230
+ fputs (query , fd );
2231
+ fputs ("\n" , fd );
2232
+ fclose (fd );
2233
+ break ;
2234
+ }
2235
+
2219
2236
case 'x' :
2220
2237
toggle (pset , & pset -> opt .expanded , "expanded table representation" );
2221
2238
break ;
2222
2239
2240
+ case 'z' : /* list table rights (grant/revoke) */
2241
+ rightsList (pset );
2242
+ break ;
2243
+
2223
2244
case '!' :
2224
2245
do_shell (optarg );
2225
2246
break ;
@@ -2252,13 +2273,17 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
2252
2273
int successResult = 1 ;
2253
2274
int slashCmdStatus = CMD_SEND ;
2254
2275
2255
- /*
2256
- * slashCmdStatus can be: CMD_UNKNOWN - send currently constructed
2257
- * query to backend (i.e. we got a \g) CMD_SEND - send
2258
- * currently constructed query to backend (i.e. we got a \g)
2259
- * CMD_SKIP_LINE - skip processing of this line, continue building
2260
- * up query CMD_TERMINATE - terminate processing of this query
2261
- * entirely CMD_NEWEDIT - new query supplied by edit
2276
+ /*--------------------------------------------------------------
2277
+ * slashCmdStatus can be:
2278
+ * CMD_UNKNOWN - send currently constructed query to backend
2279
+ * (i.e. we got a \g)
2280
+ * CMD_SEND - send currently constructed query to backend
2281
+ * (i.e. we got a \g)
2282
+ * CMD_SKIP_LINE - skip processing of this line, continue building
2283
+ * up query
2284
+ * CMD_TERMINATE - terminate processing of this query entirely
2285
+ * CMD_NEWEDIT - new query supplied by edit
2286
+ *---------------------------------------------------------------
2262
2287
*/
2263
2288
2264
2289
bool querySent = false;
@@ -2358,7 +2383,6 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
2358
2383
* query - pointer to current command query_start - placeholder
2359
2384
* for next command
2360
2385
*/
2361
-
2362
2386
if (line == NULL || (!interactive && * line == '\0' ))
2363
2387
{ /* No more input. Time to quit, or \i
2364
2388
* done */
0 commit comments