[PATCH 5/6] psql: print_aligned_text uses table formatting

From: Roger Leigh <rleigh(at)debian(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Roger Leigh <rleigh(at)debian(dot)org>
Subject: [PATCH 5/6] psql: print_aligned_text uses table formatting
Date: 2009-08-22 15:59:49
Message-ID: 1250956790-18404-6-git-send-email-rleigh@debian.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Convert print_aligned_text, and its helper function, to use
table formatting in place of hardcoded ASCII characters.

Signed-off-by: Roger Leigh <rleigh(at)debian(dot)org>
---
src/bin/psql/print.c | 50 +++++++++++++++++++++++++++++++++++++-------------
1 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 641fd63..84f6bdc 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -394,29 +394,41 @@ _print_horizontal_line(const unsigned int ncolumns, const unsigned int *widths,
unsigned int i,
j;

+ const printTextLineFormat *lformat = &format->lrule[pos];
+
if (border == 1)
- fputc('-', fout);
+ fputs(format->hrule, fout);
else if (border == 2)
- fputs("+-", fout);
+ {
+ fputs(lformat->leftvrule, fout);
+ fputs(format->hrule, fout);
+ }

for (i = 0; i < ncolumns; i++)
{
for (j = 0; j < widths[i]; j++)
- fputc('-', fout);
+ fputs(format->hrule, fout);

if (i < ncolumns - 1)
{
if (border == 0)
fputc(' ', fout);
else
- fputs("-+-", fout);
+ {
+ fputs(format->hrule, fout);
+ fputs(lformat->midvrule, fout);
+ fputs(format->hrule, fout);
+ }
}
}

if (border == 2)
- fputs("-+", fout);
+ {
+ fputs(format->hrule, fout);
+ fputs(lformat->rightvrule, fout);
+ }
else if (border == 1)
- fputc('-', fout);
+ fputs(format->hrule, fout);

fputc('\n', fout);
}
@@ -752,7 +764,7 @@ print_aligned_text(const printTableContent *cont, const printTextFormat *format,
while (more_col_wrapping)
{
if (opt_border == 2)
- fprintf(fout, "|%c", curr_nl_line ? '+' : ' ');
+ fprintf(fout, "%s%c", format->vrule, curr_nl_line ? '+' : ' ');
else if (opt_border == 1)
fputc(curr_nl_line ? '+' : ' ', fout);

@@ -783,13 +795,16 @@ print_aligned_text(const printTableContent *cont, const printTextFormat *format,
if (opt_border == 0)
fputc(curr_nl_line ? '+' : ' ', fout);
else
- fprintf(fout, " |%c", curr_nl_line ? '+' : ' ');
+ fprintf(fout, " %s%c", format->vrule, curr_nl_line ? '+' : ' ');
}
}
curr_nl_line++;

if (opt_border == 2)
- fputs(" |", fout);
+ {
+ fputc(' ', fout);
+ fputs(format->vrule, fout);
+ }
else if (opt_border == 1)
fputc(' ', fout);
fputc('\n', fout);
@@ -841,7 +856,10 @@ print_aligned_text(const printTableContent *cont, const printTextFormat *format,

/* left border */
if (opt_border == 2)
- fputs("| ", fout);
+ {
+ fputs(format->vrule, fout);
+ fputc(' ', fout);
+ }
else if (opt_border == 1)
fputc(' ', fout);

@@ -922,14 +940,20 @@ print_aligned_text(const printTableContent *cont, const printTextFormat *format,
else if (curr_nl_line[j + 1] != 0)
fputs(" : ", fout);
else
+ {
/* Ordinary line */
- fputs(" | ", fout);
+ fputc(' ', fout);
+ fputs(format->vrule, fout);
+ fputc(' ', fout);
+ }
}
}

/* end-of-row border */
- if (opt_border == 2)
- fputs(" |", fout);
+ if (opt_border == 2) {
+ fputc(' ', fout);
+ fputs(format->vrule, fout);
+ }
fputc('\n', fout);

} while (more_lines);
--
1.6.3.3

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Roger Leigh 2009-08-22 15:59:50 [PATCH 6/6] psql: print_aligned_vertical uses table formatting
Previous Message Roger Leigh 2009-08-22 15:59:48 [PATCH 4/6] psql: Pass table formatting object to text output functions