Re: [PATCHES] psql latex bugfixes

2004-08-06 Thread Christopher Kings-Lynne
OK, it looks good.  I don't have latex handy to build it, but it looks 
fine to me...

Chris
Bruce Momjian wrote:
If you would like to review it I will apply it.
---
Christopher Kings-Lynne wrote:
Surely this is a really good bug fix and should be in 7.5?
Bruce Momjian wrote:

This has been saved for the 7.6 release:
http:/momjian.postgresql.org/cgi-bin/pgpatches2
---
Roger Leigh wrote:

I have noticed that the latex format in psql has some bugs:
? _ is not escaped, and causes TeX to abort, thinking it's a
subscript outside of maths mode.  Most of my table and field names
use underscores, so this is a really nasty one.
? The column count is calculated using the contents of opt_align.  But
opt_align has one extra element, and so it's always one too many.  I
changed it to count the column headings, like all the other output
formats.  There may be a bug in computing opt_align that this patch
does not address, but I'm not yet familiar enough with the psql
source to fix this as well.
? The line drawing rules for each border setting (0-3) and expanded
mode didn't always match the documented behaviour and what other
formats (e.g. aligned) did.  I made it as conformant as possible,
and also tidied the alignment of the first line of the footer, which
was incorrectly indented.
I've attached some example output with this patch applied.
Regards,
Roger
Index: src/bin/psql/print.c
===
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
retrieving revision 1.48
diff -u -r1.48 print.c
--- src/bin/psql/print.c23 May 2004 22:20:10 -  1.48
+++ src/bin/psql/print.c1 Aug 2004 22:54:22 -
@@ -769,7 +769,7 @@
/*/
-/* LaTeX*/
+/* LaTeX*/
/*/
@@ -790,6 +790,9 @@
case '$':
fputs(\\$, fout);
break;
+   case '_':
+   fputs(\\_, fout);
+   break;
case '{':
fputs(\\{, fout);
break;
@@ -817,7 +820,6 @@
{
unsigned int col_count = 0;
unsigned int i;
-   const char *cp;
const char *const * ptr;
@@ -829,42 +831,39 @@
fputs(\n\\end{center}\n\n, fout);
}
+   /* count columns */
+   for (ptr = headers; *ptr; ptr++)
+   col_count++;
+
/* begin environment and set alignments and borders */
fputs(\\begin{tabular}{, fout);
-   if (opt_border == 0)
-   fputs(opt_align, fout);
-   else if (opt_border == 1)
-   {
-   for (cp = opt_align; *cp; cp++)
-   {
-   if (cp != opt_align)
-   fputc('|', fout);
-   fputc(*cp, fout);
-   }
-   }
-   else if (opt_border == 2)
+
+   if (opt_border == 2)
+ fputs(| , fout);
+for (i = 0; i  col_count; i++)
{
-   for (cp = opt_align; *cp; cp++)
-   {
-   fputc('|', fout);
-   fputc(*cp, fout);
-   }
-   fputc('|', fout);
+ fputc(*(opt_align + i), fout);
+ if (opt_border != 0  i  col_count - 1)
+   fputs ( | , fout);
}
+   if (opt_border == 2)
+ fputs( |, fout);
+
fputs(}\n, fout);
if (!opt_barebones  opt_border == 2)
fputs(\\hline\n, fout);
/* print headers and count columns */
-   for (i = 0, ptr = headers; *ptr; i++, ptr++)
+   for (i = 0, ptr = headers; i  col_count; i++, ptr++)
{
-   col_count++;
if (!opt_barebones)
{
if (i != 0)
fputs(  , fout);
+fputs(\\textit{, fout);
latex_escaped_print(*ptr, fout);
+fputc('}', fout);
}
}
@@ -888,7 +887,7 @@
if (opt_border == 2)
fputs(\\hline\n, fout);
-   fputs(\\end{tabular}\n\n, fout);
+   fputs(\\end{tabular}\n\n\\noindent , fout);
/* print footers */
@@ -951,8 +950,12 @@
if (!opt_barebones)
{
if (opt_border == 2)
+   {
fputs(\\hline\n, fout);
-   fprintf(fout, \\multicolumn{2}{c}{Record %d} \n, 
record++);
+   fprintf(fout, 
\\multicolumn{2}{|c|}{\\textit{Record %d}} \n, record++);
+   

Re: [PATCHES] psql latex bugfixes

2004-08-06 Thread Bruce Momjian

Patch applied for 8.0.  Thanks.

---



Roger Leigh wrote:
 I have noticed that the latex format in psql has some bugs:
 
 ? _ is not escaped, and causes TeX to abort, thinking it's a
   subscript outside of maths mode.  Most of my table and field names
   use underscores, so this is a really nasty one.
 ? The column count is calculated using the contents of opt_align.  But
   opt_align has one extra element, and so it's always one too many.  I
   changed it to count the column headings, like all the other output
   formats.  There may be a bug in computing opt_align that this patch
   does not address, but I'm not yet familiar enough with the psql
   source to fix this as well.
 ? The line drawing rules for each border setting (0-3) and expanded
   mode didn't always match the documented behaviour and what other
   formats (e.g. aligned) did.  I made it as conformant as possible,
   and also tidied the alignment of the first line of the footer, which
   was incorrectly indented.
 
 I've attached some example output with this patch applied.
 
 Regards,
 Roger
 
 
 Index: src/bin/psql/print.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
 retrieving revision 1.48
 diff -u -r1.48 print.c
 --- src/bin/psql/print.c  23 May 2004 22:20:10 -  1.48
 +++ src/bin/psql/print.c  1 Aug 2004 22:54:22 -
 @@ -769,7 +769,7 @@
  
  
  /*/
 -/* LaTeX  */
 +/* LaTeX  */
  /*/
  
  
 @@ -790,6 +790,9 @@
   case '$':
   fputs(\\$, fout);
   break;
 + case '_':
 + fputs(\\_, fout);
 + break;
   case '{':
   fputs(\\{, fout);
   break;
 @@ -817,7 +820,6 @@
  {
   unsigned int col_count = 0;
   unsigned int i;
 - const char *cp;
   const char *const * ptr;
  
  
 @@ -829,42 +831,39 @@
   fputs(\n\\end{center}\n\n, fout);
   }
  
 + /* count columns */
 + for (ptr = headers; *ptr; ptr++)
 + col_count++;
 +
   /* begin environment and set alignments and borders */
   fputs(\\begin{tabular}{, fout);
 - if (opt_border == 0)
 - fputs(opt_align, fout);
 - else if (opt_border == 1)
 - {
 - for (cp = opt_align; *cp; cp++)
 - {
 - if (cp != opt_align)
 - fputc('|', fout);
 - fputc(*cp, fout);
 - }
 - }
 - else if (opt_border == 2)
 +
 + if (opt_border == 2)
 +   fputs(| , fout);
 +for (i = 0; i  col_count; i++)
   {
 - for (cp = opt_align; *cp; cp++)
 - {
 - fputc('|', fout);
 - fputc(*cp, fout);
 - }
 - fputc('|', fout);
 +   fputc(*(opt_align + i), fout);
 +   if (opt_border != 0  i  col_count - 1)
 + fputs ( | , fout);
   }
 + if (opt_border == 2)
 +   fputs( |, fout);
 +
   fputs(}\n, fout);
  
   if (!opt_barebones  opt_border == 2)
   fputs(\\hline\n, fout);
  
   /* print headers and count columns */
 - for (i = 0, ptr = headers; *ptr; i++, ptr++)
 + for (i = 0, ptr = headers; i  col_count; i++, ptr++)
   {
 - col_count++;
   if (!opt_barebones)
   {
   if (i != 0)
   fputs(  , fout);
 +fputs(\\textit{, fout);
   latex_escaped_print(*ptr, fout);
 +fputc('}', fout);
   }
   }
  
 @@ -888,7 +887,7 @@
   if (opt_border == 2)
   fputs(\\hline\n, fout);
  
 - fputs(\\end{tabular}\n\n, fout);
 + fputs(\\end{tabular}\n\n\\noindent , fout);
  
  
   /* print footers */
 @@ -951,8 +950,12 @@
   if (!opt_barebones)
   {
   if (opt_border == 2)
 + {
   fputs(\\hline\n, fout);
 - fprintf(fout, \\multicolumn{2}{c}{Record %d} \n, 
 record++);
 + fprintf(fout, 
 \\multicolumn{2}{|c|}{\\textit{Record %d}} \n, record++);
 + }
 + else
 + fprintf(fout, 
 \\multicolumn{2}{c}{\\textit{Record %d}} \n, record++);
   }
   if (opt_border = 1)
   fputs(\\hline\n, fout);
 @@ -967,7 +970,7 @@
   if (opt_border == 2)
   fputs(\\hline\n, fout);

Re: [PATCHES] psql latex bugfixes

2004-08-03 Thread Tom Lane
Christopher Kings-Lynne [EMAIL PROTECTED] writes:
 Surely this is a really good bug fix and should be in 7.5?

The original patch contained both bug fixes for the LaTeX mode and an
entire new output mode (troff).  At my suggestion, Roger split out the
bug-fix parts as a separate patch.  The new output mode does need to
wait for 7.6^H^H^H8.1, but I think we should accept this patch for
this cycle (pending review of course).

I was thinking Peter would be the most likely candidate to review the
patch, since IIRC he was the last guy to touch this stuff.  But if
he doesn't have time and you do, go for it ...

regards, tom lane

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] psql latex bugfixes

2004-08-02 Thread Bruce Momjian

This has been saved for the 7.6 release:

http:/momjian.postgresql.org/cgi-bin/pgpatches2

---

Roger Leigh wrote:
 I have noticed that the latex format in psql has some bugs:
 
 ? _ is not escaped, and causes TeX to abort, thinking it's a
   subscript outside of maths mode.  Most of my table and field names
   use underscores, so this is a really nasty one.
 ? The column count is calculated using the contents of opt_align.  But
   opt_align has one extra element, and so it's always one too many.  I
   changed it to count the column headings, like all the other output
   formats.  There may be a bug in computing opt_align that this patch
   does not address, but I'm not yet familiar enough with the psql
   source to fix this as well.
 ? The line drawing rules for each border setting (0-3) and expanded
   mode didn't always match the documented behaviour and what other
   formats (e.g. aligned) did.  I made it as conformant as possible,
   and also tidied the alignment of the first line of the footer, which
   was incorrectly indented.
 
 I've attached some example output with this patch applied.
 
 Regards,
 Roger
 
 
 Index: src/bin/psql/print.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
 retrieving revision 1.48
 diff -u -r1.48 print.c
 --- src/bin/psql/print.c  23 May 2004 22:20:10 -  1.48
 +++ src/bin/psql/print.c  1 Aug 2004 22:54:22 -
 @@ -769,7 +769,7 @@
  
  
  /*/
 -/* LaTeX  */
 +/* LaTeX  */
  /*/
  
  
 @@ -790,6 +790,9 @@
   case '$':
   fputs(\\$, fout);
   break;
 + case '_':
 + fputs(\\_, fout);
 + break;
   case '{':
   fputs(\\{, fout);
   break;
 @@ -817,7 +820,6 @@
  {
   unsigned int col_count = 0;
   unsigned int i;
 - const char *cp;
   const char *const * ptr;
  
  
 @@ -829,42 +831,39 @@
   fputs(\n\\end{center}\n\n, fout);
   }
  
 + /* count columns */
 + for (ptr = headers; *ptr; ptr++)
 + col_count++;
 +
   /* begin environment and set alignments and borders */
   fputs(\\begin{tabular}{, fout);
 - if (opt_border == 0)
 - fputs(opt_align, fout);
 - else if (opt_border == 1)
 - {
 - for (cp = opt_align; *cp; cp++)
 - {
 - if (cp != opt_align)
 - fputc('|', fout);
 - fputc(*cp, fout);
 - }
 - }
 - else if (opt_border == 2)
 +
 + if (opt_border == 2)
 +   fputs(| , fout);
 +for (i = 0; i  col_count; i++)
   {
 - for (cp = opt_align; *cp; cp++)
 - {
 - fputc('|', fout);
 - fputc(*cp, fout);
 - }
 - fputc('|', fout);
 +   fputc(*(opt_align + i), fout);
 +   if (opt_border != 0  i  col_count - 1)
 + fputs ( | , fout);
   }
 + if (opt_border == 2)
 +   fputs( |, fout);
 +
   fputs(}\n, fout);
  
   if (!opt_barebones  opt_border == 2)
   fputs(\\hline\n, fout);
  
   /* print headers and count columns */
 - for (i = 0, ptr = headers; *ptr; i++, ptr++)
 + for (i = 0, ptr = headers; i  col_count; i++, ptr++)
   {
 - col_count++;
   if (!opt_barebones)
   {
   if (i != 0)
   fputs(  , fout);
 +fputs(\\textit{, fout);
   latex_escaped_print(*ptr, fout);
 +fputc('}', fout);
   }
   }
  
 @@ -888,7 +887,7 @@
   if (opt_border == 2)
   fputs(\\hline\n, fout);
  
 - fputs(\\end{tabular}\n\n, fout);
 + fputs(\\end{tabular}\n\n\\noindent , fout);
  
  
   /* print footers */
 @@ -951,8 +950,12 @@
   if (!opt_barebones)
   {
   if (opt_border == 2)
 + {
   fputs(\\hline\n, fout);
 - fprintf(fout, \\multicolumn{2}{c}{Record %d} \n, 
 record++);
 + fprintf(fout, 
 \\multicolumn{2}{|c|}{\\textit{Record %d}} \n, record++);
 + }
 + else
 + fprintf(fout, 
 \\multicolumn{2}{c}{\\textit{Record %d}} \n, record++);
   }
   if (opt_border = 1)
   fputs(\\hline\n, fout);
 @@ -967,7 +970,7 @@
   

Re: [PATCHES] psql latex bugfixes

2004-08-02 Thread Christopher Kings-Lynne
Surely this is a really good bug fix and should be in 7.5?
Bruce Momjian wrote:
This has been saved for the 7.6 release:
http:/momjian.postgresql.org/cgi-bin/pgpatches2
---
Roger Leigh wrote:
I have noticed that the latex format in psql has some bugs:
? _ is not escaped, and causes TeX to abort, thinking it's a
 subscript outside of maths mode.  Most of my table and field names
 use underscores, so this is a really nasty one.
? The column count is calculated using the contents of opt_align.  But
 opt_align has one extra element, and so it's always one too many.  I
 changed it to count the column headings, like all the other output
 formats.  There may be a bug in computing opt_align that this patch
 does not address, but I'm not yet familiar enough with the psql
 source to fix this as well.
? The line drawing rules for each border setting (0-3) and expanded
 mode didn't always match the documented behaviour and what other
 formats (e.g. aligned) did.  I made it as conformant as possible,
 and also tidied the alignment of the first line of the footer, which
 was incorrectly indented.
I've attached some example output with this patch applied.
Regards,
Roger
Index: src/bin/psql/print.c
===
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
retrieving revision 1.48
diff -u -r1.48 print.c
--- src/bin/psql/print.c23 May 2004 22:20:10 -  1.48
+++ src/bin/psql/print.c1 Aug 2004 22:54:22 -
@@ -769,7 +769,7 @@
/*/
-/* LaTeX*/
+/* LaTeX*/
/*/
@@ -790,6 +790,9 @@
case '$':
fputs(\\$, fout);
break;
+   case '_':
+   fputs(\\_, fout);
+   break;
case '{':
fputs(\\{, fout);
break;
@@ -817,7 +820,6 @@
{
unsigned int col_count = 0;
unsigned int i;
-   const char *cp;
const char *const * ptr;
@@ -829,42 +831,39 @@
fputs(\n\\end{center}\n\n, fout);
}
+   /* count columns */
+   for (ptr = headers; *ptr; ptr++)
+   col_count++;
+
/* begin environment and set alignments and borders */
fputs(\\begin{tabular}{, fout);
-   if (opt_border == 0)
-   fputs(opt_align, fout);
-   else if (opt_border == 1)
-   {
-   for (cp = opt_align; *cp; cp++)
-   {
-   if (cp != opt_align)
-   fputc('|', fout);
-   fputc(*cp, fout);
-   }
-   }
-   else if (opt_border == 2)
+
+   if (opt_border == 2)
+ fputs(| , fout);
+for (i = 0; i  col_count; i++)
{
-   for (cp = opt_align; *cp; cp++)
-   {
-   fputc('|', fout);
-   fputc(*cp, fout);
-   }
-   fputc('|', fout);
+ fputc(*(opt_align + i), fout);
+ if (opt_border != 0  i  col_count - 1)
+   fputs ( | , fout);
}
+   if (opt_border == 2)
+ fputs( |, fout);
+
fputs(}\n, fout);
if (!opt_barebones  opt_border == 2)
fputs(\\hline\n, fout);
/* print headers and count columns */
-   for (i = 0, ptr = headers; *ptr; i++, ptr++)
+   for (i = 0, ptr = headers; i  col_count; i++, ptr++)
{
-   col_count++;
if (!opt_barebones)
{
if (i != 0)
fputs(  , fout);
+fputs(\\textit{, fout);
latex_escaped_print(*ptr, fout);
+fputc('}', fout);
}
}
@@ -888,7 +887,7 @@
if (opt_border == 2)
fputs(\\hline\n, fout);
-   fputs(\\end{tabular}\n\n, fout);
+   fputs(\\end{tabular}\n\n\\noindent , fout);
/* print footers */
@@ -951,8 +950,12 @@
if (!opt_barebones)
{
if (opt_border == 2)
+   {
fputs(\\hline\n, fout);
-   fprintf(fout, \\multicolumn{2}{c}{Record %d} \n, 
record++);
+   fprintf(fout, 
\\multicolumn{2}{|c|}{\\textit{Record %d}} \n, record++);
+   }
+   else
+   fprintf(fout, \\multicolumn{2}{c}{\\textit{Record 
%d}} \n, record++);
}
if (opt_border = 1)

Re: [PATCHES] psql latex bugfixes

2004-08-02 Thread Bruce Momjian

If you would like to review it I will apply it.

---

Christopher Kings-Lynne wrote:
 Surely this is a really good bug fix and should be in 7.5?
 
 Bruce Momjian wrote:
 
  This has been saved for the 7.6 release:
  
  http:/momjian.postgresql.org/cgi-bin/pgpatches2
  
  ---
  
  Roger Leigh wrote:
  
 I have noticed that the latex format in psql has some bugs:
 
 ? _ is not escaped, and causes TeX to abort, thinking it's a
   subscript outside of maths mode.  Most of my table and field names
   use underscores, so this is a really nasty one.
 ? The column count is calculated using the contents of opt_align.  But
   opt_align has one extra element, and so it's always one too many.  I
   changed it to count the column headings, like all the other output
   formats.  There may be a bug in computing opt_align that this patch
   does not address, but I'm not yet familiar enough with the psql
   source to fix this as well.
 ? The line drawing rules for each border setting (0-3) and expanded
   mode didn't always match the documented behaviour and what other
   formats (e.g. aligned) did.  I made it as conformant as possible,
   and also tidied the alignment of the first line of the footer, which
   was incorrectly indented.
 
 I've attached some example output with this patch applied.
 
 Regards,
 Roger
 
 
 Index: src/bin/psql/print.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
 retrieving revision 1.48
 diff -u -r1.48 print.c
 --- src/bin/psql/print.c23 May 2004 22:20:10 -  1.48
 +++ src/bin/psql/print.c1 Aug 2004 22:54:22 -
 @@ -769,7 +769,7 @@
  
  
  /*/
 -/* LaTeX*/
 +/* LaTeX*/
  /*/
  
  
 @@ -790,6 +790,9 @@
 case '$':
 fputs(\\$, fout);
 break;
 +   case '_':
 +   fputs(\\_, fout);
 +   break;
 case '{':
 fputs(\\{, fout);
 break;
 @@ -817,7 +820,6 @@
  {
 unsigned int col_count = 0;
 unsigned int i;
 -   const char *cp;
 const char *const * ptr;
  
  
 @@ -829,42 +831,39 @@
 fputs(\n\\end{center}\n\n, fout);
 }
  
 +   /* count columns */
 +   for (ptr = headers; *ptr; ptr++)
 +   col_count++;
 +
 /* begin environment and set alignments and borders */
 fputs(\\begin{tabular}{, fout);
 -   if (opt_border == 0)
 -   fputs(opt_align, fout);
 -   else if (opt_border == 1)
 -   {
 -   for (cp = opt_align; *cp; cp++)
 -   {
 -   if (cp != opt_align)
 -   fputc('|', fout);
 -   fputc(*cp, fout);
 -   }
 -   }
 -   else if (opt_border == 2)
 +
 +   if (opt_border == 2)
 + fputs(| , fout);
 +for (i = 0; i  col_count; i++)
 {
 -   for (cp = opt_align; *cp; cp++)
 -   {
 -   fputc('|', fout);
 -   fputc(*cp, fout);
 -   }
 -   fputc('|', fout);
 + fputc(*(opt_align + i), fout);
 + if (opt_border != 0  i  col_count - 1)
 +   fputs ( | , fout);
 }
 +   if (opt_border == 2)
 + fputs( |, fout);
 +
 fputs(}\n, fout);
  
 if (!opt_barebones  opt_border == 2)
 fputs(\\hline\n, fout);
  
 /* print headers and count columns */
 -   for (i = 0, ptr = headers; *ptr; i++, ptr++)
 +   for (i = 0, ptr = headers; i  col_count; i++, ptr++)
 {
 -   col_count++;
 if (!opt_barebones)
 {
 if (i != 0)
 fputs(  , fout);
 +fputs(\\textit{, fout);
 latex_escaped_print(*ptr, fout);
 +fputc('}', fout);
 }
 }
  
 @@ -888,7 +887,7 @@
 if (opt_border == 2)
 fputs(\\hline\n, fout);
  
 -   fputs(\\end{tabular}\n\n, fout);
 +   fputs(\\end{tabular}\n\n\\noindent , fout);
  
  
 /* print footers */
 @@ -951,8 +950,12 @@
 if (!opt_barebones)
 {
 if (opt_border == 2)
 +   {
 fputs(\\hline\n, fout);
 -   fprintf(fout, \\multicolumn{2}{c}{Record %d} \n, 
 record++);
 +   fprintf(fout, 
 \\multicolumn{2}{|c|}{\\textit{Record %d}} \n, record++);
 +   }
 +   else
 +   fprintf(fout, 
 \\multicolumn{2}{c}{\\textit{Record %d}} \n, record++);
 }
 if