Обсуждение: Tiny patch on print.c of psql
Hi all,
This is my 1st patch ever in C :-)... I was just borried by a bad psql
\H html output of an EXPLAIN
because it didnt respected spaces sent from backend like:
-> Sort
-> Sort
I just remarked in this print.c the case of a white space wasnt handled
in the function escaping special caracters to HTML codes, so I added it
replacing a space by special html " " (& n b s p).
So we'll have now:
-> Sort
-> Sort
... in the html generated
(see example at http://www.pack-solutions.net/~jpargudo/explain.html)
Then, every single space in the html source is replaced by this. The
source looks ugly, yes, I will look to *only replacing starting spaces*
of each row of the EXPLAIN, thats will be my 1st patch ever, version 2 :)
So I post this patch only FYI.. I had much fun playing with C a bit :-)
(yes, I dont code C, just a bit of Perl and Python).
Cheers! Thanks again for such a powerfull release.
--
Jean-Paul Argudo
www.PostgreSQLFr.org
--- postgresql-8.0.0/src/bin/psql/print.c 2005-01-01 06:43:08.000000000 +0100
+++ postgresql-8.0.0-patch/src/bin/psql/print.c 2005-01-20 21:54:56.000000000 +0100
@@ -617,6 +617,9 @@
case '\'':
fputs("'", fout);
break;
+ case ' ':
+ fputs(" ", fout);
+ break;
default:
fputc(*p, fout);
}
This has been saved for the 8.1 release:
http://momjian.postgresql.org/cgi-bin/pgpatches2
---------------------------------------------------------------------------
Jean-Paul Argudo wrote:
> Hi all,
>
> This is my 1st patch ever in C :-)... I was just borried by a bad psql
> \H html output of an EXPLAIN
>
> because it didnt respected spaces sent from backend like:
>
> -> Sort
> -> Sort
>
> I just remarked in this print.c the case of a white space wasnt handled
> in the function escaping special caracters to HTML codes, so I added it
> replacing a space by special html " " (& n b s p).
>
> So we'll have now:
>
> -> Sort
> -> Sort
>
> ... in the html generated
>
> (see example at http://www.pack-solutions.net/~jpargudo/explain.html)
>
> Then, every single space in the html source is replaced by this. The
> source looks ugly, yes, I will look to *only replacing starting spaces*
> of each row of the EXPLAIN, thats will be my 1st patch ever, version 2 :)
>
> So I post this patch only FYI.. I had much fun playing with C a bit :-)
> (yes, I dont code C, just a bit of Perl and Python).
>
> Cheers! Thanks again for such a powerfull release.
>
> --
> Jean-Paul Argudo
> www.PostgreSQLFr.org
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
I have applied your patch, and added the optimization that only leading spaces are converted to ' ', as you suggested. --------------------------------------------------------------------------- Jean-Paul Argudo wrote: > Hi all, > > This is my 1st patch ever in C :-)... I was just borried by a bad psql > \H html output of an EXPLAIN > > because it didnt respected spaces sent from backend like: > > -> Sort > -> Sort > > I just remarked in this print.c the case of a white space wasnt handled > in the function escaping special caracters to HTML codes, so I added it > replacing a space by special html " " (& n b s p). > > So we'll have now: > > -> Sort > -> Sort > > ... in the html generated > > (see example at http://www.pack-solutions.net/~jpargudo/explain.html) > > Then, every single space in the html source is replaced by this. The > source looks ugly, yes, I will look to *only replacing starting spaces* > of each row of the EXPLAIN, thats will be my 1st patch ever, version 2 :) > > So I post this patch only FYI.. I had much fun playing with C a bit :-) > (yes, I dont code C, just a bit of Perl and Python). > > Cheers! Thanks again for such a powerfull release. > > -- > Jean-Paul Argudo > www.PostgreSQLFr.org > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 Index: src/bin/psql/print.c =================================================================== RCS file: /cvsroot/pgsql/src/bin/psql/print.c,v retrieving revision 1.59 diff -c -c -r1.59 print.c *** src/bin/psql/print.c 14 Jun 2005 02:57:41 -0000 1.59 --- src/bin/psql/print.c 14 Jun 2005 22:14:20 -0000 *************** *** 595,602 **** html_escaped_print(const char *in, FILE *fout) { const char *p; ! for (p = in; *p; p++) switch (*p) { case '&': --- 595,604 ---- html_escaped_print(const char *in, FILE *fout) { const char *p; ! bool leading_space = true; ! for (p = in; *p; p++) + { switch (*p) { case '&': *************** *** 617,625 **** --- 619,637 ---- case '\'': fputs("'", fout); break; + case ' ': + /* protect leading space, for EXPLAIN output */ + if (leading_space) + fputs(" ", fout); + else + fputs(" ", fout); + break; default: fputc(*p, fout); } + if (*p != ' ') + leading_space = false; + } }