Attached is a patch that enhances the output of psql's HTML mode.
The output now validates as HTML 4.01 Strict, XHTML 1.0 strict, and XHTML 1.1 (assuming you wrap it in a valid html/body document). It also wraps the output of PGRES_COMMAND_OK if the HTML tag is on, for full compliance: this is why html_escaped_print has to be externalized. Greg Sabino Mullane greg@turnstep.com
This commit is contained in:
parent
e9cda08b2b
commit
ef2ba42717
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.62 2003/03/25 02:44:36 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.63 2003/06/12 07:52:51 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -525,7 +525,18 @@ PrintQueryResults(PGresult *results,
|
|||||||
success = true;
|
success = true;
|
||||||
sprintf(buf, "%u", (unsigned int) PQoidValue(results));
|
sprintf(buf, "%u", (unsigned int) PQoidValue(results));
|
||||||
if (!QUIET())
|
if (!QUIET())
|
||||||
fprintf(pset.queryFout, "%s\n", PQcmdStatus(results));
|
{
|
||||||
|
if (pset.popt.topt.format == PRINT_HTML)
|
||||||
|
{
|
||||||
|
fputs("<p>", pset.queryFout);
|
||||||
|
html_escaped_print(PQcmdStatus(results), pset.queryFout);
|
||||||
|
fputs("</p>\n", pset.queryFout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(pset.queryFout, "%s\n", PQcmdStatus(results));
|
||||||
|
}
|
||||||
|
}
|
||||||
SetVariable(pset.vars, "LASTOID", buf);
|
SetVariable(pset.vars, "LASTOID", buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.37 2003/04/04 15:48:38 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.38 2003/06/12 07:52:51 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -577,7 +577,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
/**********************/
|
/**********************/
|
||||||
|
|
||||||
|
|
||||||
static void
|
void
|
||||||
html_escaped_print(const char *in, FILE *fout)
|
html_escaped_print(const char *in, FILE *fout)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
@ -595,7 +595,13 @@ html_escaped_print(const char *in, FILE *fout)
|
|||||||
fputs(">", fout);
|
fputs(">", fout);
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
fputs("<br>", fout);
|
fputs("<br />\n", fout);
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
fputs(""", fout);
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
fputs("'", fout);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fputc(*p, fout);
|
fputc(*p, fout);
|
||||||
@ -615,7 +621,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
const char *const * ptr;
|
const char *const * ptr;
|
||||||
|
|
||||||
fprintf(fout, "<table border=%d", opt_border);
|
fprintf(fout, "<table border=\"%d\"", opt_border);
|
||||||
if (opt_table_attr)
|
if (opt_table_attr)
|
||||||
fprintf(fout, " %s", opt_table_attr);
|
fprintf(fout, " %s", opt_table_attr);
|
||||||
fputs(">\n", fout);
|
fputs(">\n", fout);
|
||||||
@ -636,7 +642,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
col_count++;
|
col_count++;
|
||||||
if (!opt_barebones)
|
if (!opt_barebones)
|
||||||
{
|
{
|
||||||
fputs(" <th align=center>", fout);
|
fputs(" <th align=\"center\">", fout);
|
||||||
html_escaped_print(*ptr, fout);
|
html_escaped_print(*ptr, fout);
|
||||||
fputs("</th>\n", fout);
|
fputs("</th>\n", fout);
|
||||||
}
|
}
|
||||||
@ -648,12 +654,11 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
for (i = 0, ptr = cells; *ptr; i++, ptr++)
|
for (i = 0, ptr = cells; *ptr; i++, ptr++)
|
||||||
{
|
{
|
||||||
if (i % col_count == 0)
|
if (i % col_count == 0)
|
||||||
fputs(" <tr valign=top>\n", fout);
|
fputs(" <tr valign=\"top\">\n", fout);
|
||||||
|
|
||||||
fprintf(fout, " <td align=%s>", opt_align[(i) % col_count] == 'r' ? "right" : "left");
|
fprintf(fout, " <td align=\"%s\">", opt_align[(i) % col_count] == 'r' ? "right" : "left");
|
||||||
if ((*ptr)[strspn(*ptr, " \t")] == '\0') /* is string only
|
if ((*ptr)[strspn(*ptr, " \t")] == '\0') /* is string only whitespace? */
|
||||||
* whitespace? */
|
fputs(" ", fout);
|
||||||
fputs(" ", fout);
|
|
||||||
else
|
else
|
||||||
html_escaped_print(*ptr, fout);
|
html_escaped_print(*ptr, fout);
|
||||||
fputs("</td>\n", fout);
|
fputs("</td>\n", fout);
|
||||||
@ -666,13 +671,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
|
|
||||||
/* print footers */
|
/* print footers */
|
||||||
|
|
||||||
if (footers && !opt_barebones)
|
if (!opt_barebones && footers && *footers)
|
||||||
|
{
|
||||||
|
fputs("<p>", fout);
|
||||||
for (ptr = footers; *ptr; ptr++)
|
for (ptr = footers; *ptr; ptr++)
|
||||||
{
|
{
|
||||||
html_escaped_print(*ptr, fout);
|
html_escaped_print(*ptr, fout);
|
||||||
fputs("<br>\n", fout);
|
fputs("<br />\n", fout);
|
||||||
}
|
}
|
||||||
|
fputs("</p>", fout);
|
||||||
|
}
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,7 +698,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
unsigned int record = 1;
|
unsigned int record = 1;
|
||||||
const char *const * ptr;
|
const char *const * ptr;
|
||||||
|
|
||||||
fprintf(fout, "<table border=%d", opt_border);
|
fprintf(fout, "<table border=\"%d\"", opt_border);
|
||||||
if (opt_table_attr)
|
if (opt_table_attr)
|
||||||
fprintf(fout, " %s", opt_table_attr);
|
fprintf(fout, " %s", opt_table_attr);
|
||||||
fputs(">\n", fout);
|
fputs(">\n", fout);
|
||||||
@ -713,19 +721,18 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
if (i % col_count == 0)
|
if (i % col_count == 0)
|
||||||
{
|
{
|
||||||
if (!opt_barebones)
|
if (!opt_barebones)
|
||||||
fprintf(fout, "\n <tr><td colspan=2 align=center>Record %d</td></tr>\n", record++);
|
fprintf(fout, "\n <tr><td colspan=\"2\" align=\"center\">Record %d</td></tr>\n", record++);
|
||||||
else
|
else
|
||||||
fputs("\n <tr><td colspan=2> </td></tr>\n", fout);
|
fputs("\n <tr><td colspan=\"2\"> </td></tr>\n", fout);
|
||||||
}
|
}
|
||||||
fputs(" <tr valign=top>\n"
|
fputs(" <tr valign=\"top\">\n"
|
||||||
" <th>", fout);
|
" <th>", fout);
|
||||||
html_escaped_print(headers[i % col_count], fout);
|
html_escaped_print(headers[i % col_count], fout);
|
||||||
fputs("</th>\n", fout);
|
fputs("</th>\n", fout);
|
||||||
|
|
||||||
fprintf(fout, " <td align=%s>", opt_align[i % col_count] == 'r' ? "right" : "left");
|
fprintf(fout, " <td align=\"%s\">", opt_align[i % col_count] == 'r' ? "right" : "left");
|
||||||
if ((*ptr)[strspn(*ptr, " \t")] == '\0') /* is string only
|
if ((*ptr)[strspn(*ptr, " \t")] == '\0') /* is string only whitespace? */
|
||||||
* whitespace? */
|
fputs(" ", fout);
|
||||||
fputs(" ", fout);
|
|
||||||
else
|
else
|
||||||
html_escaped_print(*ptr, fout);
|
html_escaped_print(*ptr, fout);
|
||||||
fputs("</td>\n </tr>\n", fout);
|
fputs("</td>\n </tr>\n", fout);
|
||||||
@ -734,13 +741,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
|||||||
fputs("</table>\n", fout);
|
fputs("</table>\n", fout);
|
||||||
|
|
||||||
/* print footers */
|
/* print footers */
|
||||||
if (footers && !opt_barebones)
|
if (!opt_barebones && footers && *footers)
|
||||||
|
{
|
||||||
|
fputs("<p>", fout);
|
||||||
for (ptr = footers; *ptr; ptr++)
|
for (ptr = footers; *ptr; ptr++)
|
||||||
{
|
{
|
||||||
html_escaped_print(*ptr, fout);
|
html_escaped_print(*ptr, fout);
|
||||||
fputs("<br>\n", fout);
|
fputs("<br />\n", fout);
|
||||||
}
|
}
|
||||||
|
fputs("</p>", fout);
|
||||||
|
}
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1115,6 +1125,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
|
|||||||
char *align;
|
char *align;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
/* extract headers */
|
/* extract headers */
|
||||||
|
|
||||||
nfields = PQnfields(result);
|
nfields = PQnfields(result);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.16 2003/03/18 22:15:44 petere Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.17 2003/06/12 07:52:51 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef PRINT_H
|
#ifndef PRINT_H
|
||||||
#define PRINT_H
|
#define PRINT_H
|
||||||
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
extern FILE *PageOutput(int lines, unsigned short int pager);
|
extern FILE *PageOutput(int lines, unsigned short int pager);
|
||||||
|
|
||||||
|
extern void html_escaped_print(const char *in, FILE *fout);
|
||||||
|
|
||||||
enum printFormat
|
enum printFormat
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user