33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.37 2003/04/04 15:48:38 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.38 2003/06/12 07:52:51 momjian Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -577,7 +577,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
577577/**********************/
578578
579579
580- static void
580+ void
581581html_escaped_print (const char * in ,FILE * fout )
582582{
583583const char * p ;
@@ -595,7 +595,13 @@ html_escaped_print(const char *in, FILE *fout)
595595fputs (">" ,fout );
596596break ;
597597case '\n' :
598- fputs ("<br>" ,fout );
598+ fputs ("<br />\n" ,fout );
599+ break ;
600+ case '"' :
601+ fputs (""" ,fout );
602+ break ;
603+ case '\'' :
604+ fputs ("'" ,fout );
599605break ;
600606default :
601607fputc (* p ,fout );
@@ -615,7 +621,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
615621unsignedint i ;
616622const char * const * ptr ;
617623
618- fprintf (fout ,"<table border=%d " ,opt_border );
624+ fprintf (fout ,"<table border=\"%d\" " ,opt_border );
619625if (opt_table_attr )
620626fprintf (fout ," %s" ,opt_table_attr );
621627fputs (">\n" ,fout );
@@ -636,7 +642,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
636642col_count ++ ;
637643if (!opt_barebones )
638644{
639- fputs (" <th align=center>" ,fout );
645+ fputs (" <th align=\" center\" >" ,fout );
640646html_escaped_print (* ptr ,fout );
641647fputs ("</th>\n" ,fout );
642648}
@@ -648,12 +654,11 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
648654for (i = 0 ,ptr = cells ;* ptr ;i ++ ,ptr ++ )
649655{
650656if (i %col_count == 0 )
651- fputs (" <tr valign=top>\n" ,fout );
657+ fputs (" <tr valign=\" top\" >\n" ,fout );
652658
653- fprintf (fout ," <td align=%s>" ,opt_align [(i ) %col_count ]== 'r' ?"right" :"left" );
654- if ((* ptr )[strspn (* ptr ," \t" )]== '\0' )/* is string only
655- * whitespace? */
656- fputs (" " ,fout );
659+ fprintf (fout ," <td align=\"%s\">" ,opt_align [(i ) %col_count ]== 'r' ?"right" :"left" );
660+ if ((* ptr )[strspn (* ptr ," \t" )]== '\0' )/* is string only whitespace? */
661+ fputs (" " ,fout );
657662else
658663html_escaped_print (* ptr ,fout );
659664fputs ("</td>\n" ,fout );
@@ -666,13 +671,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
666671
667672/* print footers */
668673
669- if (footers && !opt_barebones )
674+ if (!opt_barebones && footers && * footers )
675+ {
676+ fputs ("<p>" ,fout );
670677for (ptr = footers ;* ptr ;ptr ++ )
671678{
672679html_escaped_print (* ptr ,fout );
673- fputs ("<br>\n" ,fout );
680+ fputs ("<br / >\n" ,fout );
674681}
675-
682+ fputs ("</p>" ,fout );
683+ }
676684fputc ('\n' ,fout );
677685}
678686
@@ -690,7 +698,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
690698unsignedint record = 1 ;
691699const char * const * ptr ;
692700
693- fprintf (fout ,"<table border=%d " ,opt_border );
701+ fprintf (fout ,"<table border=\"%d\" " ,opt_border );
694702if (opt_table_attr )
695703fprintf (fout ," %s" ,opt_table_attr );
696704fputs (">\n" ,fout );
@@ -713,19 +721,18 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
713721if (i %col_count == 0 )
714722{
715723if (!opt_barebones )
716- fprintf (fout ,"\n <tr><td colspan=2 align=center>Record %d</td></tr>\n" ,record ++ );
724+ fprintf (fout ,"\n <tr><td colspan=\"2\" align=\" center\" >Record %d</td></tr>\n" ,record ++ );
717725else
718- fputs ("\n <tr><td colspan=2 > </td></tr>\n" ,fout );
726+ fputs ("\n <tr><td colspan=\"2\" > </td></tr>\n" ,fout );
719727}
720- fputs (" <tr valign=top>\n"
728+ fputs (" <tr valign=\" top\" >\n"
721729" <th>" ,fout );
722730html_escaped_print (headers [i %col_count ],fout );
723731fputs ("</th>\n" ,fout );
724732
725- fprintf (fout ," <td align=%s>" ,opt_align [i %col_count ]== 'r' ?"right" :"left" );
726- if ((* ptr )[strspn (* ptr ," \t" )]== '\0' )/* is string only
727- * whitespace? */
728- fputs (" " ,fout );
733+ fprintf (fout ," <td align=\"%s\">" ,opt_align [i %col_count ]== 'r' ?"right" :"left" );
734+ if ((* ptr )[strspn (* ptr ," \t" )]== '\0' )/* is string only whitespace? */
735+ fputs (" " ,fout );
729736else
730737html_escaped_print (* ptr ,fout );
731738fputs ("</td>\n </tr>\n" ,fout );
@@ -734,13 +741,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
734741fputs ("</table>\n" ,fout );
735742
736743/* print footers */
737- if (footers && !opt_barebones )
744+ if (!opt_barebones && footers && * footers )
745+ {
746+ fputs ("<p>" ,fout );
738747for (ptr = footers ;* ptr ;ptr ++ )
739748{
740749html_escaped_print (* ptr ,fout );
741- fputs ("<br>\n" ,fout );
750+ fputs ("<br / >\n" ,fout );
742751}
743-
752+ fputs ("</p>" ,fout );
753+ }
744754fputc ('\n' ,fout );
745755}
746756
@@ -1115,6 +1125,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11151125char * align ;
11161126int i ;
11171127
1128+
11181129/* extract headers */
11191130
11201131nfields = PQnfields (result );