I've created a patch which adds support for troff "-ms" output to
psql. i.e. "\pset format troff-ms". The patch also corrects some problems with the "latex" format, notably defining an extra column in the output table, and correcting some alignment issues; it also changes the output to match the border setting as documented in the manual page and as shown with the "aligned" format. The troff-ms output is mostly identical to the latex output allowing for the differences between the two typesetters. The output should be saved in a file and piped as follows: cat file | tbl | troff -T ps -ms > file.ps or tbl file | troff -T ps -ms > file.ps Because it contains tabs, you'll need to redirect psql output or use "script", rather than pasting from a terminal window, due to the tabs which can be replaced with spaces. Roger Leigh
This commit is contained in:
parent
a31ad27fc5
commit
4a5cda7bba
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.138 2005/06/02 01:23:48 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.139 2005/06/09 15:27:26 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -1386,9 +1386,10 @@ lo_import 152801
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Sets the output format to one of <literal>unaligned</literal>,
|
Sets the output format to one of <literal>unaligned</literal>,
|
||||||
<literal>aligned</literal>, <literal>html</literal>, or
|
<literal>aligned</literal>, <literal>html</literal>,
|
||||||
<literal>latex</literal>. Unique abbreviations are allowed.
|
<literal>latex</literal>, or <literal>troff-ms</literal>.
|
||||||
(That would mean one letter is enough.)
|
Unique abbreviations are allowed. (That would mean one letter
|
||||||
|
is enough.)
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.143 2005/04/29 13:42:20 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.144 2005/06/09 15:27:26 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
@ -1357,6 +1357,9 @@ _align2string(enum printFormat in)
|
||||||
case PRINT_LATEX:
|
case PRINT_LATEX:
|
||||||
return "latex";
|
return "latex";
|
||||||
break;
|
break;
|
||||||
|
case PRINT_TROFF_MS:
|
||||||
|
return "troff-ms";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
@ -1385,9 +1388,11 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
|
||||||
popt->topt.format = PRINT_HTML;
|
popt->topt.format = PRINT_HTML;
|
||||||
else if (pg_strncasecmp("latex", value, vallen) == 0)
|
else if (pg_strncasecmp("latex", value, vallen) == 0)
|
||||||
popt->topt.format = PRINT_LATEX;
|
popt->topt.format = PRINT_LATEX;
|
||||||
|
else if (pg_strncasecmp("troff-ms", value, vallen) == 0)
|
||||||
|
popt->topt.format = PRINT_TROFF_MS;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
psql_error("\\pset: allowed formats are unaligned, aligned, html, latex\n");
|
psql_error("\\pset: allowed formats are unaligned, aligned, html, latex, troff-ms\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.55 2005/02/22 04:40:57 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.56 2005/06/09 15:27:27 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
@ -992,6 +992,213 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*************************/
|
||||||
|
/* Troff -ms */
|
||||||
|
/*************************/
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
troff_ms_escaped_print(const char *in, FILE *fout)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
for (p = in; *p; p++)
|
||||||
|
switch (*p)
|
||||||
|
{
|
||||||
|
case '\\':
|
||||||
|
fputs("\(rs", fout);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fputc(*p, fout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_troff_ms_text(const char *title, const char *const * headers,
|
||||||
|
const char *const * cells, const char *const * footers,
|
||||||
|
const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
||||||
|
FILE *fout)
|
||||||
|
{
|
||||||
|
unsigned int col_count = 0;
|
||||||
|
unsigned int i;
|
||||||
|
const char *const * ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* print title */
|
||||||
|
if (!opt_barebones && title)
|
||||||
|
{
|
||||||
|
fputs(".LP\n.DS C\n", fout);
|
||||||
|
troff_ms_escaped_print(title, fout);
|
||||||
|
fputs("\n.DE\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count columns */
|
||||||
|
for (ptr = headers; *ptr; ptr++)
|
||||||
|
col_count++;
|
||||||
|
|
||||||
|
/* begin environment and set alignments and borders */
|
||||||
|
fputs(".LP\n.TS\n", fout);
|
||||||
|
if (opt_border == 2)
|
||||||
|
fputs("center box;\n", fout);
|
||||||
|
else
|
||||||
|
fputs("center;\n", fout);
|
||||||
|
|
||||||
|
for (i = 0; i < col_count; i++)
|
||||||
|
{
|
||||||
|
fputc(*(opt_align + i), fout);
|
||||||
|
if (opt_border > 0 && i < col_count - 1)
|
||||||
|
fputs(" | ", fout);
|
||||||
|
}
|
||||||
|
fputs(".\n", fout);
|
||||||
|
|
||||||
|
/* print headers and count columns */
|
||||||
|
for (i = 0, ptr = headers; i < col_count; i++, ptr++)
|
||||||
|
{
|
||||||
|
if (!opt_barebones)
|
||||||
|
{
|
||||||
|
if (i != 0)
|
||||||
|
fputc('\t', fout);
|
||||||
|
fputs("\\fI", fout);
|
||||||
|
troff_ms_escaped_print(*ptr, fout);
|
||||||
|
fputs("\\fP", fout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opt_barebones)
|
||||||
|
{
|
||||||
|
fputs("\n_\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* print cells */
|
||||||
|
for (i = 0, ptr = cells; *ptr; i++, ptr++)
|
||||||
|
{
|
||||||
|
troff_ms_escaped_print(*ptr, fout);
|
||||||
|
|
||||||
|
if ((i + 1) % col_count == 0)
|
||||||
|
fputc('\n', fout);
|
||||||
|
else
|
||||||
|
fputc('\t', fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs(".TE\n.DS L\n", fout);
|
||||||
|
|
||||||
|
|
||||||
|
/* print footers */
|
||||||
|
|
||||||
|
if (footers && !opt_barebones)
|
||||||
|
for (ptr = footers; *ptr; ptr++)
|
||||||
|
{
|
||||||
|
troff_ms_escaped_print(*ptr, fout);
|
||||||
|
fputc('\n', fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs(".DE\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_troff_ms_vertical(const char *title, const char *const * headers,
|
||||||
|
const char *const * cells, const char *const * footers,
|
||||||
|
const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
||||||
|
FILE *fout)
|
||||||
|
{
|
||||||
|
unsigned int col_count = 0;
|
||||||
|
unsigned int i;
|
||||||
|
const char *const * ptr;
|
||||||
|
unsigned int record = 1;
|
||||||
|
unsigned short current_format = 0; /* 0=none, 1=header, 2=body */
|
||||||
|
|
||||||
|
(void) opt_align; /* currently unused parameter */
|
||||||
|
|
||||||
|
/* print title */
|
||||||
|
if (!opt_barebones && title)
|
||||||
|
{
|
||||||
|
fputs(".LP\n.DS C\n", fout);
|
||||||
|
troff_ms_escaped_print(title, fout);
|
||||||
|
fputs("\n.DE\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* begin environment and set alignments and borders */
|
||||||
|
fputs(".LP\n.TS\n", fout);
|
||||||
|
if (opt_border == 2)
|
||||||
|
fputs("center box;\n", fout);
|
||||||
|
else
|
||||||
|
fputs("center;\n", fout);
|
||||||
|
|
||||||
|
/* basic format */
|
||||||
|
if (opt_barebones)
|
||||||
|
fputs("c l;\n", fout);
|
||||||
|
|
||||||
|
|
||||||
|
/* count columns */
|
||||||
|
for (ptr = headers; *ptr; ptr++)
|
||||||
|
col_count++;
|
||||||
|
|
||||||
|
|
||||||
|
/* print records */
|
||||||
|
for (i = 0, ptr = cells; *ptr; i++, ptr++)
|
||||||
|
{
|
||||||
|
/* new record */
|
||||||
|
if (i % col_count == 0)
|
||||||
|
{
|
||||||
|
if (!opt_barebones)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (current_format != 1)
|
||||||
|
{
|
||||||
|
if (opt_border == 2 && i > 0)
|
||||||
|
fputs("_\n", fout);
|
||||||
|
if (current_format != 0)
|
||||||
|
fputs(".T&\n", fout);
|
||||||
|
fputs("c s.\n", fout);
|
||||||
|
current_format = 1;
|
||||||
|
}
|
||||||
|
fprintf(fout, "\\fIRecord %d\\fP\n", record++);
|
||||||
|
}
|
||||||
|
if (opt_border >= 1)
|
||||||
|
fputs("_\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opt_barebones)
|
||||||
|
{
|
||||||
|
if (current_format != 2)
|
||||||
|
{
|
||||||
|
if (current_format != 0)
|
||||||
|
fputs(".T&\n", fout);
|
||||||
|
if (opt_border != 1)
|
||||||
|
fputs("c l.\n", fout);
|
||||||
|
else
|
||||||
|
fputs("c | l.\n", fout);
|
||||||
|
current_format = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
troff_ms_escaped_print(headers[i % col_count], fout);
|
||||||
|
fputc('\t', fout);
|
||||||
|
troff_ms_escaped_print(*ptr, fout);
|
||||||
|
fputc('\n', fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs(".TE\n.DS L\n", fout);
|
||||||
|
|
||||||
|
|
||||||
|
/* print footers */
|
||||||
|
|
||||||
|
if (footers && !opt_barebones)
|
||||||
|
for (ptr = footers; *ptr; ptr++)
|
||||||
|
{
|
||||||
|
troff_ms_escaped_print(*ptr, fout);
|
||||||
|
fputc('\n', fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs(".DE\n", fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********************************/
|
/********************************/
|
||||||
/* Public functions */
|
/* Public functions */
|
||||||
/********************************/
|
/********************************/
|
||||||
|
@ -1121,6 +1328,12 @@ printTable(const char *title,
|
||||||
else
|
else
|
||||||
print_latex_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
|
print_latex_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
|
||||||
break;
|
break;
|
||||||
|
case PRINT_TROFF_MS:
|
||||||
|
if (opt->expanded)
|
||||||
|
print_troff_ms_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output);
|
||||||
|
else
|
||||||
|
print_troff_ms_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "+ Oops, you shouldn't see this!\n");
|
fprintf(stderr, "+ Oops, you shouldn't see this!\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.22 2005/01/01 05:43:08 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.23 2005/06/09 15:27:27 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef PRINT_H
|
#ifndef PRINT_H
|
||||||
#define PRINT_H
|
#define PRINT_H
|
||||||
|
@ -21,7 +21,8 @@ enum printFormat
|
||||||
PRINT_UNALIGNED,
|
PRINT_UNALIGNED,
|
||||||
PRINT_ALIGNED,
|
PRINT_ALIGNED,
|
||||||
PRINT_HTML,
|
PRINT_HTML,
|
||||||
PRINT_LATEX
|
PRINT_LATEX,
|
||||||
|
PRINT_TROFF_MS
|
||||||
/* add your favourite output format here ... */
|
/* add your favourite output format here ... */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue