77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.14 1996/07/29 20:58:42 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.15 1996/07/31 02:11:23 scrappy Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -109,7 +109,7 @@ usage(char *progname)
109109fprintf (stderr ,"\t -q run quietly (no messages, no prompts)\n" );
110110fprintf (stderr ,"\t -s single step mode (prompts for each query)\n" );
111111fprintf (stderr ,"\t -S single line mode (i.e. query terminated by newline)\n" );
112- fprintf (stderr ,"\t -t turn off printing ofattribute headers \n" );
112+ fprintf (stderr ,"\t -t turn off printing ofheadings and row count \n" );
113113fprintf (stderr ,"\t -T html set html3.0 table command options (cf. -H)\n" );
114114fprintf (stderr ,"\t -x turn on expanded output (field names on left)\n" );
115115exit (1 );
@@ -128,33 +128,30 @@ char *on(bool f)
128128static void
129129slashUsage (PsqlSettings * ps )
130130{
131+ fprintf (stderr ,"\t \\? -- help\n" );
131132fprintf (stderr ,"\t \\a -- toggle field-alignment (currenty %s)\n" ,on (ps -> opt .align ));
132133fprintf (stderr ,"\t \\C [<captn>] -- set html3 caption (currently '%s')\n" ,ps -> opt .caption ?ps -> opt .caption :"" );
133134fprintf (stderr ,"\t \\c <dbname> -- connect to new database (currently '%s')\n" ,PQdb (ps -> db ));
134- fprintf (stderr ,"\t \\d [<table>] -- list tables in database or columns in <table>\n" );
135- fprintf (stderr ,"\t \\d * -- list tables in database and columns in all tables\n" );
136- fprintf (stderr ,"\t \\e [<fname>] -- edit the current query buffer or <fname>\n" );
135+ fprintf (stderr ,"\t \\d [<table>] -- list tables in database or columns in <table>,* for all\n" );
136+ fprintf (stderr ,"\t \\e [<fname>] -- edit the current query buffer or <fname>, \E execute too\n" );
137137fprintf (stderr ,"\t \\f [<sep>] -- change field separater (currently '%s')\n" ,ps -> opt .fieldSep );
138138fprintf (stderr ,"\t \\g [<fname>] -- send query to backend [and place results in <fname>]\n" );
139139fprintf (stderr ,"\t \\g |<cmd> -- send query to backend and pipe results into <cmd>\n" );
140- fprintf (stderr ,"\t \\h [<cmd>] -- help on syntax of sql commands\n" );
141- fprintf (stderr ,"\t \\h * -- complete description of all sql commands\n" );
140+ fprintf (stderr ,"\t \\h [<cmd>] -- help on syntax of sql commands, * for all commands\n" );
142141fprintf (stderr ,"\t \\H -- toggle html3 output (currently %s)\n" ,on (ps -> opt .html3 ));
143142fprintf (stderr ,"\t \\i <fname> -- read and execute queries from filename\n" );
144143fprintf (stderr ,"\t \\l -- list all databases\n" );
145- fprintf (stderr ,"\t \\m -- toggle monitor-liketype-setting (currently %s)\n" ,on (ps -> opt .standard ));
144+ fprintf (stderr ,"\t \\m -- toggle monitor-liketable display (currently %s)\n" ,on (ps -> opt .standard ));
146145fprintf (stderr ,"\t \\o [<fname>] -- send all query results to <fname> or stdout\n" );
147146fprintf (stderr ,"\t \\o |<cmd> -- pipe all query results through <cmd>\n" );
148147fprintf (stderr ,"\t \\p -- print the current query buffer\n" );
149148fprintf (stderr ,"\t \\q -- quit\n" );
150- fprintf (stderr ,"\t \\r[<fname>] -- edit <fname> then execute on save \n" );
149+ fprintf (stderr ,"\t \\r -- reset(clear) the query buffer \n" );
151150fprintf (stderr ,"\t \\s [<fname>] -- print history or save it in <fname>\n" );
152- fprintf (stderr ,"\t \\t -- toggle tableoutput header (currently %s)\n" ,on (ps -> opt .header ));
151+ fprintf (stderr ,"\t \\t -- toggle tableheadings and row count (currently %s)\n" ,on (ps -> opt .header ));
153152fprintf (stderr ,"\t \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n" ,ps -> opt .tableOpt ?ps -> opt .tableOpt :"" );
154153fprintf (stderr ,"\t \\x -- toggle expanded output (currently %s)\n" ,on (ps -> opt .expanded ));
155- fprintf (stderr ,"\t \\z -- zorch current query buffer (i.e clear it)\n" );
156154fprintf (stderr ,"\t \\! [<cmd>] -- shell escape or command\n" );
157- fprintf (stderr ,"\t \\? -- help\n" );
158155}
159156
160157PGresult *
@@ -624,7 +621,7 @@ HandleSlashCmds(PsqlSettings *settings,
624621decode (optarg );
625622 }
626623switch (line [1 ])
627- {
624+ {
628625case 'a' :/* toggles to align fields on output */
629626toggle (settings ,& settings -> opt .align ,"field alignment" );
630627break ;
@@ -641,7 +638,7 @@ HandleSlashCmds(PsqlSettings *settings,
641638}
642639break ;
643640case 'c' :/* \c means connect to new database */
644- {
641+ {
645642char * dbname = PQdb (settings -> db );
646643if (!optarg ) {
647644fprintf (stderr ,"\\c must be followed by a database name\n" );
@@ -687,7 +684,7 @@ HandleSlashCmds(PsqlSettings *settings,
687684 }
688685break ;
689686case 'e' :
690- {
687+ {
691688int fd ;
692689char tmp [64 ];
693690char * fname ;
@@ -743,7 +740,46 @@ HandleSlashCmds(PsqlSettings *settings,
743740if (query [strlen (query )- 1 ]== ';' )
744741return 0 ;
745742break ;
746- }
743+ }
744+ case 'E' :
745+ {
746+ FILE * fd ;
747+ static char * lastfile ;
748+ struct stat st ,st2 ;
749+ if (optarg )
750+ {
751+ if (lastfile )
752+ free (lastfile );
753+ lastfile = malloc (strlen (optarg + 1 ));
754+ if (!lastfile )
755+ {
756+ perror ("malloc" );
757+ exit (1 );
758+ }
759+ strcpy (lastfile ,optarg );
760+ }else if (!lastfile )
761+ {
762+ fprintf (stderr ,"\\r must be followed by a file name initially\n" );
763+ break ;
764+ }
765+ stat (lastfile ,& st );
766+ editFile (lastfile );
767+ if ((stat (lastfile ,& st2 )== -1 )|| ((fd = fopen (lastfile ,"r" ))== NULL ))
768+ {
769+ perror (lastfile );
770+ break ;
771+ }
772+ if (st2 .st_mtime == st .st_mtime )
773+ {
774+ if (!settings -> quiet )
775+ fprintf (stderr ,"warning: %s not modified. query not executed\n" ,lastfile );
776+ fclose (fd );
777+ break ;
778+ }
779+ MainLoop (settings ,fd );
780+ fclose (fd );
781+ break ;
782+ }
747783case 'f' :
748784 {
749785char * fs = DEFAULT_FIELD_SEP ;
@@ -760,12 +796,12 @@ HandleSlashCmds(PsqlSettings *settings,
760796fprintf (stderr ,"field separater changed to '%s'\n" ,settings -> opt .fieldSep );
761797break ;
762798 }
763- case 'g' :/* \g means send query */
799+ case 'g' :/* \g means send query */
764800settings -> gfname = optarg ;
765801status = 0 ;
766802break ;
767803case 'h' :
768- {
804+ {
769805char * cmd ;
770806int i ,numCmds ;
771807int all_help = 0 ;
@@ -811,7 +847,7 @@ HandleSlashCmds(PsqlSettings *settings,
811847printf ("command not found, try \\h with no arguments to see available help\n" );
812848}
813849break ;
814- }
850+ }
815851case 'i' :/* \i is include file */
816852 {
817853FILE * fd ;
@@ -829,7 +865,7 @@ HandleSlashCmds(PsqlSettings *settings,
829865MainLoop (settings ,fd );
830866fclose (fd );
831867break ;
832- }
868+ }
833869case 'l' :/* \l is list database */
834870listAllDbs (settings );
835871break ;
@@ -850,45 +886,11 @@ HandleSlashCmds(PsqlSettings *settings,
850886case 'q' :/* \q is quit */
851887status = 2 ;
852888break ;
853- case 'r' :
854- {
855- FILE * fd ;
856- static char * lastfile ;
857- struct stat st ,st2 ;
858- if (optarg )
859- {
860- if (lastfile )
861- free (lastfile );
862- lastfile = malloc (strlen (optarg + 1 ));
863- if (!lastfile )
864- {
865- perror ("malloc" );
866- exit (1 );
867- }
868- strcpy (lastfile ,optarg );
869- }else if (!lastfile )
870- {
871- fprintf (stderr ,"\\r must be followed by a file name initially\n" );
872- break ;
873- }
874- stat (lastfile ,& st );
875- editFile (lastfile );
876- if ((stat (lastfile ,& st2 )== -1 )|| ((fd = fopen (lastfile ,"r" ))== NULL ))
877- {
878- perror (lastfile );
879- break ;
880- }
881- if (st2 .st_mtime == st .st_mtime )
882- {
883- if (!settings -> quiet )
884- fprintf (stderr ,"warning: %s not modified. query not executed\n" ,lastfile );
885- fclose (fd );
886- break ;
887- }
888- MainLoop (settings ,fd );
889- fclose (fd );
890- break ;
891- }
889+ case 'r' :/* reset(clear) the buffer */
890+ query [0 ]= '\0' ;
891+ if (!settings -> quiet )
892+ fprintf (stderr ,"buffer reset(cleared)\n" );
893+ break ;
892894case 's' :/* \s is save history to a file */
893895if (!optarg )
894896optarg = "/dev/tty" ;
@@ -913,7 +915,7 @@ HandleSlashCmds(PsqlSettings *settings,
913915 }
914916break ;
915917case 't' :/* toggle headers */
916- toggle (settings ,& settings -> opt .header ,"outputheaders " );
918+ toggle (settings ,& settings -> opt .header ,"outputheadings and row count " );
917919break ;
918920case 'T' :/* define html <table ...> option */
919921if (settings -> opt .tableOpt )
@@ -930,11 +932,6 @@ HandleSlashCmds(PsqlSettings *settings,
930932case 'x' :
931933toggle (settings ,& settings -> opt .expanded ,"expanded table representation" );
932934break ;
933- case 'z' :/* zorch buffer */
934- query [0 ]= '\0' ;
935- if (!settings -> quiet )
936- fprintf (stderr ,"zorched current query buffer\n" );
937- break ;
938935case '!' :
939936if (!optarg ) {
940937char * sys ;