PostgreSQL Source Code  git master
print.h File Reference
#include <signal.h>
#include "libpq-fe.h"
Include dependency graph for print.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  printTextLineFormat
 
struct  printTextFormat
 
struct  separator
 
struct  printTableOpt
 
struct  printTableFooter
 
struct  printTableContent
 
struct  printQueryOpt
 

Macros

#define DEFAULT_PAGER   "more"
 

Typedefs

typedef struct printTextLineFormat printTextLineFormat
 
typedef enum printTextRule printTextRule
 
typedef enum printTextLineWrap printTextLineWrap
 
typedef struct printTextFormat printTextFormat
 
typedef enum unicode_linestyle unicode_linestyle
 
typedef struct printTableOpt printTableOpt
 
typedef struct printTableFooter printTableFooter
 
typedef struct printTableContent printTableContent
 
typedef struct printQueryOpt printQueryOpt
 

Enumerations

enum  printFormat {
  PRINT_NOTHING = 0 , PRINT_ALIGNED , PRINT_ASCIIDOC , PRINT_CSV ,
  PRINT_HTML , PRINT_LATEX , PRINT_LATEX_LONGTABLE , PRINT_TROFF_MS ,
  PRINT_UNALIGNED , PRINT_WRAPPED
}
 
enum  printTextRule { PRINT_RULE_TOP , PRINT_RULE_MIDDLE , PRINT_RULE_BOTTOM , PRINT_RULE_DATA }
 
enum  printTextLineWrap { PRINT_LINE_WRAP_NONE , PRINT_LINE_WRAP_WRAP , PRINT_LINE_WRAP_NEWLINE }
 
enum  unicode_linestyle { UNICODE_LINESTYLE_SINGLE = 0 , UNICODE_LINESTYLE_DOUBLE }
 

Functions

void disable_sigpipe_trap (void)
 
void restore_sigpipe_trap (void)
 
void set_sigpipe_trap_state (bool ignore)
 
FILE * PageOutput (int lines, const printTableOpt *topt)
 
void ClosePager (FILE *pagerpipe)
 
void html_escaped_print (const char *in, FILE *fout)
 
void printTableInit (printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
 
void printTableAddHeader (printTableContent *const content, char *header, const bool translate, const char align)
 
void printTableAddCell (printTableContent *const content, char *cell, const bool translate, const bool mustfree)
 
void printTableAddFooter (printTableContent *const content, const char *footer)
 
void printTableSetFooter (printTableContent *const content, const char *footer)
 
void printTableCleanup (printTableContent *const content)
 
void printTable (const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
 
void printQuery (const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
 
char column_type_alignment (Oid)
 
void setDecimalLocale (void)
 
const printTextFormatget_line_style (const printTableOpt *opt)
 
void refresh_utf8format (const printTableOpt *opt)
 

Variables

PGDLLIMPORT volatile sig_atomic_t cancel_pressed
 
PGDLLIMPORT const printTextFormat pg_asciiformat
 
PGDLLIMPORT const printTextFormat pg_asciiformat_old
 
PGDLLIMPORT printTextFormat pg_utf8format
 

Macro Definition Documentation

◆ DEFAULT_PAGER

#define DEFAULT_PAGER   "more"

Definition at line 23 of file print.h.

Typedef Documentation

◆ printQueryOpt

typedef struct printQueryOpt printQueryOpt

◆ printTableContent

◆ printTableFooter

◆ printTableOpt

typedef struct printTableOpt printTableOpt

◆ printTextFormat

◆ printTextLineFormat

◆ printTextLineWrap

◆ printTextRule

◆ unicode_linestyle

Enumeration Type Documentation

◆ printFormat

Enumerator
PRINT_NOTHING 
PRINT_ALIGNED 
PRINT_ASCIIDOC 
PRINT_CSV 
PRINT_HTML 
PRINT_LATEX 
PRINT_LATEX_LONGTABLE 
PRINT_TROFF_MS 
PRINT_UNALIGNED 
PRINT_WRAPPED 

Definition at line 28 of file print.h.

29 {
30  PRINT_NOTHING = 0, /* to make sure someone initializes this */
33  PRINT_CSV,
34  PRINT_HTML,
40  /* add your favourite output format here ... */
41 };
@ PRINT_LATEX_LONGTABLE
Definition: print.h:36
@ PRINT_CSV
Definition: print.h:33
@ PRINT_UNALIGNED
Definition: print.h:38
@ PRINT_ALIGNED
Definition: print.h:31
@ PRINT_TROFF_MS
Definition: print.h:37
@ PRINT_ASCIIDOC
Definition: print.h:32
@ PRINT_NOTHING
Definition: print.h:30
@ PRINT_LATEX
Definition: print.h:35
@ PRINT_HTML
Definition: print.h:34
@ PRINT_WRAPPED
Definition: print.h:39

◆ printTextLineWrap

Enumerator
PRINT_LINE_WRAP_NONE 
PRINT_LINE_WRAP_WRAP 
PRINT_LINE_WRAP_NEWLINE 

Definition at line 61 of file print.h.

62 {
63  /* Line wrapping conditions */
64  PRINT_LINE_WRAP_NONE, /* No wrapping */
65  PRINT_LINE_WRAP_WRAP, /* Wraparound due to overlength line */
66  PRINT_LINE_WRAP_NEWLINE /* Newline in data */
printTextLineWrap
Definition: print.h:62
@ PRINT_LINE_WRAP_WRAP
Definition: print.h:65
@ PRINT_LINE_WRAP_NEWLINE
Definition: print.h:66
@ PRINT_LINE_WRAP_NONE
Definition: print.h:64

◆ printTextRule

Enumerator
PRINT_RULE_TOP 
PRINT_RULE_MIDDLE 
PRINT_RULE_BOTTOM 
PRINT_RULE_DATA 

Definition at line 52 of file print.h.

53 {
54  /* Additional context for selecting line drawing characters */
55  PRINT_RULE_TOP, /* top horizontal line */
56  PRINT_RULE_MIDDLE, /* intra-data horizontal line */
57  PRINT_RULE_BOTTOM, /* bottom horizontal line */
58  PRINT_RULE_DATA /* data line (hrule is unused here) */
printTextRule
Definition: print.h:53
@ PRINT_RULE_MIDDLE
Definition: print.h:56
@ PRINT_RULE_BOTTOM
Definition: print.h:57
@ PRINT_RULE_DATA
Definition: print.h:58
@ PRINT_RULE_TOP
Definition: print.h:55

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 87 of file print.h.

88 {
unicode_linestyle
Definition: print.h:88
@ UNICODE_LINESTYLE_SINGLE
Definition: print.h:89
@ UNICODE_LINESTYLE_DOUBLE
Definition: print.h:90

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

Definition at line 3096 of file print.c.

3097 {
3098  if (pagerpipe && pagerpipe != stdout)
3099  {
3100  /*
3101  * If printing was canceled midstream, warn about it.
3102  *
3103  * Some pagers like less use Ctrl-C as part of their command set. Even
3104  * so, we abort our processing and warn the user what we did. If the
3105  * pager quit as a result of the SIGINT, this message won't go
3106  * anywhere ...
3107  */
3108  if (cancel_pressed)
3109  fprintf(pagerpipe, _("Interrupted\n"));
3110 
3111  pclose(pagerpipe);
3113  }
3114 }
#define _(x)
Definition: elog.c:89
void restore_sigpipe_trap(void)
Definition: print.c:3018
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
#define fprintf
Definition: port.h:229

References _, cancel_pressed, fprintf, restore_sigpipe_trap(), and generate_unaccent_rules::stdout.

Referenced by exec_command_sf_sv(), ExecQueryUsingCursor(), helpSQL(), helpVariables(), print_aligned_text(), print_aligned_vertical(), printHistory(), printTable(), slashUsage(), and usage().

◆ column_type_alignment()

char column_type_alignment ( Oid  ftype)

Definition at line 3555 of file print.c.

3556 {
3557  char align;
3558 
3559  switch (ftype)
3560  {
3561  case INT2OID:
3562  case INT4OID:
3563  case INT8OID:
3564  case FLOAT4OID:
3565  case FLOAT8OID:
3566  case NUMERICOID:
3567  case OIDOID:
3568  case XIDOID:
3569  case XID8OID:
3570  case CIDOID:
3571  case MONEYOID:
3572  align = 'r';
3573  break;
3574  default:
3575  align = 'l';
3576  break;
3577  }
3578  return align;
3579 }

Referenced by printCrosstab(), and printQuery().

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 2995 of file print.c.

2996 {
2997 #ifndef WIN32
2999 #endif
3000 }
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:180
#define SIGPIPE
Definition: win32_port.h:172
#define SIG_IGN
Definition: win32_port.h:164

References pqsignal(), SIG_IGN, and SIGPIPE.

Referenced by do_copy(), do_watch(), exec_command_write(), ExecQueryUsingCursor(), HandleCopyResult(), PageOutput(), and PrintQueryTuples().

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3618 of file print.c.

3619 {
3620  /*
3621  * Note: this function mainly exists to preserve the convention that a
3622  * printTableOpt struct can be initialized to zeroes to get default
3623  * behavior.
3624  */
3625  if (opt->line_style != NULL)
3626  return opt->line_style;
3627  else
3628  return &pg_asciiformat;
3629 }
const printTextFormat pg_asciiformat
Definition: print.c:56
const printTextFormat * line_style
Definition: print.h:115

References printTableOpt::line_style, and pg_asciiformat.

Referenced by print_aligned_text(), print_aligned_vertical(), printPsetInfo(), and pset_value_string().

◆ html_escaped_print()

void html_escaped_print ( const char *  in,
FILE *  fout 
)

Definition at line 1908 of file print.c.

1909 {
1910  const char *p;
1911  bool leading_space = true;
1912 
1913  for (p = in; *p; p++)
1914  {
1915  switch (*p)
1916  {
1917  case '&':
1918  fputs("&amp;", fout);
1919  break;
1920  case '<':
1921  fputs("&lt;", fout);
1922  break;
1923  case '>':
1924  fputs("&gt;", fout);
1925  break;
1926  case '\n':
1927  fputs("<br />\n", fout);
1928  break;
1929  case '"':
1930  fputs("&quot;", fout);
1931  break;
1932  case ' ':
1933  /* protect leading space, for EXPLAIN output */
1934  if (leading_space)
1935  fputs("&nbsp;", fout);
1936  else
1937  fputs(" ", fout);
1938  break;
1939  default:
1940  fputc(*p, fout);
1941  }
1942  if (*p != ' ')
1943  leading_space = false;
1944  }
1945 }

Referenced by print_html_text(), print_html_vertical(), and PrintQueryStatus().

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 3045 of file print.c.

3046 {
3047  /* check whether we need / can / are supposed to use pager */
3048  if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
3049  {
3050 #ifdef TIOCGWINSZ
3051  unsigned short int pager = topt->pager;
3052  int min_lines = topt->pager_min_lines;
3053  int result;
3054  struct winsize screen_size;
3055 
3056  result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
3057 
3058  /* >= accounts for a one-line prompt */
3059  if (result == -1
3060  || (lines >= screen_size.ws_row && lines >= min_lines)
3061  || pager > 1)
3062 #endif
3063  {
3064  const char *pagerprog;
3065  FILE *pagerpipe;
3066 
3067  pagerprog = getenv("PSQL_PAGER");
3068  if (!pagerprog)
3069  pagerprog = getenv("PAGER");
3070  if (!pagerprog)
3071  pagerprog = DEFAULT_PAGER;
3072  else
3073  {
3074  /* if PAGER is empty or all-white-space, don't use pager */
3075  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
3076  return stdout;
3077  }
3079  pagerpipe = popen(pagerprog, "w");
3080  if (pagerpipe)
3081  return pagerpipe;
3082  /* if popen fails, silently proceed without pager */
3084  }
3085  }
3086 
3087  return stdout;
3088 }
void disable_sigpipe_trap(void)
Definition: print.c:2995
#define DEFAULT_PAGER
Definition: print.h:23
int pager_min_lines
Definition: print.h:108
unsigned short int pager
Definition: print.h:106

References DEFAULT_PAGER, disable_sigpipe_trap(), printTableOpt::pager, printTableOpt::pager_min_lines, restore_sigpipe_trap(), and generate_unaccent_rules::stdout.

Referenced by exec_command_sf_sv(), ExecQueryUsingCursor(), helpSQL(), helpVariables(), IsPagerNeeded(), print_aligned_text(), printHistory(), slashUsage(), and usage().

◆ printQuery()

void printQuery ( const PGresult result,
const printQueryOpt opt,
FILE *  fout,
bool  is_pager,
FILE *  flog 
)

Definition at line 3490 of file print.c.

3492 {
3493  printTableContent cont;
3494  int i,
3495  r,
3496  c;
3497 
3498  if (cancel_pressed)
3499  return;
3500 
3501  printTableInit(&cont, &opt->topt, opt->title,
3502  PQnfields(result), PQntuples(result));
3503 
3504  /* Assert caller supplied enough translate_columns[] entries */
3505  Assert(opt->translate_columns == NULL ||
3506  opt->n_translate_columns >= cont.ncolumns);
3507 
3508  for (i = 0; i < cont.ncolumns; i++)
3509  {
3510  printTableAddHeader(&cont, PQfname(result, i),
3511  opt->translate_header,
3512  column_type_alignment(PQftype(result, i)));
3513  }
3514 
3515  /* set cells */
3516  for (r = 0; r < cont.nrows; r++)
3517  {
3518  for (c = 0; c < cont.ncolumns; c++)
3519  {
3520  char *cell;
3521  bool mustfree = false;
3522  bool translate;
3523 
3524  if (PQgetisnull(result, r, c))
3525  cell = opt->nullPrint ? opt->nullPrint : "";
3526  else
3527  {
3528  cell = PQgetvalue(result, r, c);
3529  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3530  {
3531  cell = format_numeric_locale(cell);
3532  mustfree = true;
3533  }
3534  }
3535 
3536  translate = (opt->translate_columns && opt->translate_columns[c]);
3537  printTableAddCell(&cont, cell, translate, mustfree);
3538  }
3539  }
3540 
3541  /* set footers */
3542  if (opt->footers)
3543  {
3544  char **footer;
3545 
3546  for (footer = opt->footers; *footer; footer++)
3547  printTableAddFooter(&cont, *footer);
3548  }
3549 
3550  printTable(&cont, fout, is_pager, flog);
3551  printTableCleanup(&cont);
3552 }
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3578
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3340
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3426
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3735
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3760
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3348
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3127
void printTableCleanup(printTableContent *const content)
Definition: print.c:3295
char column_type_alignment(Oid ftype)
Definition: print.c:3555
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3204
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3384
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3252
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3164
static char * format_numeric_locale(const char *my_str)
Definition: print.c:314
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
Datum translate(PG_FUNCTION_ARGS)
char * c
const bool * translate_columns
Definition: print.h:174
printTableOpt topt
Definition: print.h:169
char * nullPrint
Definition: print.h:170
char * title
Definition: print.h:171
char ** footers
Definition: print.h:172
bool translate_header
Definition: print.h:173
int n_translate_columns
Definition: print.h:176
char * aligns
Definition: print.h:162
bool numericLocale
Definition: print.h:119

References printTableContent::aligns, Assert(), cancel_pressed, column_type_alignment(), printQueryOpt::footers, format_numeric_locale(), i, printQueryOpt::n_translate_columns, printTableContent::ncolumns, printTableContent::nrows, printQueryOpt::nullPrint, printTableOpt::numericLocale, PQfname(), PQftype(), PQgetisnull(), PQgetvalue(), PQnfields(), PQntuples(), printTable(), printTableAddCell(), printTableAddFooter(), printTableAddHeader(), printTableCleanup(), printTableInit(), printQueryOpt::title, printQueryOpt::topt, translate(), printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describeSubscriptions(), describeTablespaces(), describeTypes(), ExecQueryUsingCursor(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSDictionaries(), listTSParsers(), listTSTemplates(), listUserMappings(), objectDescription(), permissionsList(), and PrintQueryTuples().

◆ printTable()

void printTable ( const printTableContent cont,
FILE *  fout,
bool  is_pager,
FILE *  flog 
)

Definition at line 3384 of file print.c.

3386 {
3387  bool is_local_pager = false;
3388 
3389  if (cancel_pressed)
3390  return;
3391 
3392  if (cont->opt->format == PRINT_NOTHING)
3393  return;
3394 
3395  /* print_aligned_*() handle the pager themselves */
3396  if (!is_pager &&
3397  cont->opt->format != PRINT_ALIGNED &&
3398  cont->opt->format != PRINT_WRAPPED)
3399  {
3400  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3401  is_local_pager = is_pager;
3402  }
3403 
3404  /* clear any pre-existing error indication on the output stream */
3405  clearerr(fout);
3406 
3407  /* print the stuff */
3408 
3409  if (flog)
3410  print_aligned_text(cont, flog, false);
3411 
3412  switch (cont->opt->format)
3413  {
3414  case PRINT_UNALIGNED:
3415  if (cont->opt->expanded == 1)
3416  print_unaligned_vertical(cont, fout);
3417  else
3418  print_unaligned_text(cont, fout);
3419  break;
3420  case PRINT_ALIGNED:
3421  case PRINT_WRAPPED:
3422 
3423  /*
3424  * In expanded-auto mode, force vertical if a pager is passed in;
3425  * else we may make different decisions for different hunks of the
3426  * query result.
3427  */
3428  if (cont->opt->expanded == 1 ||
3429  (cont->opt->expanded == 2 && is_pager))
3430  print_aligned_vertical(cont, fout, is_pager);
3431  else
3432  print_aligned_text(cont, fout, is_pager);
3433  break;
3434  case PRINT_CSV:
3435  if (cont->opt->expanded == 1)
3436  print_csv_vertical(cont, fout);
3437  else
3438  print_csv_text(cont, fout);
3439  break;
3440  case PRINT_HTML:
3441  if (cont->opt->expanded == 1)
3442  print_html_vertical(cont, fout);
3443  else
3444  print_html_text(cont, fout);
3445  break;
3446  case PRINT_ASCIIDOC:
3447  if (cont->opt->expanded == 1)
3448  print_asciidoc_vertical(cont, fout);
3449  else
3450  print_asciidoc_text(cont, fout);
3451  break;
3452  case PRINT_LATEX:
3453  if (cont->opt->expanded == 1)
3454  print_latex_vertical(cont, fout);
3455  else
3456  print_latex_text(cont, fout);
3457  break;
3458  case PRINT_LATEX_LONGTABLE:
3459  if (cont->opt->expanded == 1)
3460  print_latex_vertical(cont, fout);
3461  else
3462  print_latex_longtable_text(cont, fout);
3463  break;
3464  case PRINT_TROFF_MS:
3465  if (cont->opt->expanded == 1)
3466  print_troff_ms_vertical(cont, fout);
3467  else
3468  print_troff_ms_text(cont, fout);
3469  break;
3470  default:
3471  fprintf(stderr, _("invalid output format (internal error): %d"),
3472  cont->opt->format);
3473  exit(EXIT_FAILURE);
3474  }
3475 
3476  if (is_local_pager)
3477  ClosePager(fout);
3478 }
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2142
static void print_unaligned_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:513
static void print_latex_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2410
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2783
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1949
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2875
void ClosePager(FILE *pagerpipe)
Definition: print.c:3096
static void print_csv_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1836
static void print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:635
static void print_csv_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1876
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2038
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2252
static void print_unaligned_text(const printTableContent *cont, FILE *fout)
Definition: print.c:422
static void print_latex_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2673
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3344
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2517
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1281
exit(1)
#define EXIT_FAILURE
Definition: settings.h:163
const printTableOpt * opt
Definition: print.h:149
unsigned short int expanded
Definition: print.h:102
enum printFormat format
Definition: print.h:101

References _, cancel_pressed, ClosePager(), exit(), EXIT_FAILURE, printTableOpt::expanded, printTableOpt::format, fprintf, IsPagerNeeded(), printTableContent::opt, PRINT_ALIGNED, print_aligned_text(), print_aligned_vertical(), PRINT_ASCIIDOC, print_asciidoc_text(), print_asciidoc_vertical(), PRINT_CSV, print_csv_text(), print_csv_vertical(), PRINT_HTML, print_html_text(), print_html_vertical(), PRINT_LATEX, PRINT_LATEX_LONGTABLE, print_latex_longtable_text(), print_latex_text(), print_latex_vertical(), PRINT_NOTHING, PRINT_TROFF_MS, print_troff_ms_text(), print_troff_ms_vertical(), PRINT_UNALIGNED, print_unaligned_text(), print_unaligned_vertical(), and PRINT_WRAPPED.

Referenced by describeOneTableDetails(), describePublications(), describeRoles(), printCrosstab(), and printQuery().

◆ printTableAddCell()

void printTableAddCell ( printTableContent *const  content,
char *  cell,
const bool  translate,
const bool  mustfree 
)

Definition at line 3204 of file print.c.

3206 {
3207 #ifndef ENABLE_NLS
3208  (void) translate; /* unused parameter */
3209 #endif
3210 
3211  if (content->cellsadded >= content->ncolumns * content->nrows)
3212  {
3213  fprintf(stderr, _("Cannot add cell to table content: "
3214  "total cell count of %d exceeded.\n"),
3215  content->ncolumns * content->nrows);
3216  exit(EXIT_FAILURE);
3217  }
3218 
3219  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3220  content->opt->encoding);
3221 
3222 #ifdef ENABLE_NLS
3223  if (translate)
3224  *content->cell = _(*content->cell);
3225 #endif
3226 
3227  if (mustfree)
3228  {
3229  if (content->cellmustfree == NULL)
3230  content->cellmustfree =
3231  pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
3232 
3233  content->cellmustfree[content->cellsadded] = true;
3234  }
3235  content->cell++;
3236  content->cellsadded++;
3237 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
bool * cellmustfree
Definition: print.h:159
const char ** cell
Definition: print.h:157
long cellsadded
Definition: print.h:158
int encoding
Definition: print.h:122

References _, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cellsadded, printTableOpt::encoding, exit(), EXIT_FAILURE, fprintf, mbvalidate(), printTableContent::ncolumns, printTableContent::nrows, printTableContent::opt, pg_malloc0(), and translate().

Referenced by describeOneTableDetails(), describePublications(), describeRoles(), and printQuery().

◆ printTableAddFooter()

void printTableAddFooter ( printTableContent *const  content,
const char *  footer 
)

Definition at line 3252 of file print.c.

3253 {
3254  printTableFooter *f;
3255 
3256  f = pg_malloc0(sizeof(*f));
3257  f->data = pg_strdup(footer);
3258 
3259  if (content->footers == NULL)
3260  content->footers = f;
3261  else
3262  content->footer->next = f;
3263 
3264  content->footer = f;
3265 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
printTableFooter * footers
Definition: print.h:160
printTableFooter * footer
Definition: print.h:161
char * data
Definition: print.h:139
struct printTableFooter * next
Definition: print.h:140

References printTableFooter::data, printTableContent::footer, printTableContent::footers, printTableFooter::next, pg_malloc0(), and pg_strdup().

Referenced by add_tablespace_footer(), addFooterToPublicationDesc(), describeOneTableDetails(), printQuery(), and printTableSetFooter().

◆ printTableAddHeader()

void printTableAddHeader ( printTableContent *const  content,
char *  header,
const bool  translate,
const char  align 
)

Definition at line 3164 of file print.c.

3166 {
3167 #ifndef ENABLE_NLS
3168  (void) translate; /* unused parameter */
3169 #endif
3170 
3171  if (content->header >= content->headers + content->ncolumns)
3172  {
3173  fprintf(stderr, _("Cannot add header to table content: "
3174  "column count of %d exceeded.\n"),
3175  content->ncolumns);
3176  exit(EXIT_FAILURE);
3177  }
3178 
3179  *content->header = (char *) mbvalidate((unsigned char *) header,
3180  content->opt->encoding);
3181 #ifdef ENABLE_NLS
3182  if (translate)
3183  *content->header = _(*content->header);
3184 #endif
3185  content->header++;
3186 
3187  *content->align = align;
3188  content->align++;
3189 }
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212
char * align
Definition: print.h:164
const char ** header
Definition: print.h:154
const char ** headers
Definition: print.h:153

References _, printTableContent::align, printTableOpt::encoding, exit(), EXIT_FAILURE, fprintf, printTableContent::header, header(), printTableContent::headers, mbvalidate(), printTableContent::ncolumns, printTableContent::opt, and translate().

Referenced by describeOneTableDetails(), describePublications(), describeRoles(), printCrosstab(), and printQuery().

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

Definition at line 3295 of file print.c.

3296 {
3297  if (content->cellmustfree)
3298  {
3299  int i;
3300 
3301  for (i = 0; i < content->nrows * content->ncolumns; i++)
3302  {
3303  if (content->cellmustfree[i])
3304  free(unconstify(char *, content->cells[i]));
3305  }
3306  free(content->cellmustfree);
3307  content->cellmustfree = NULL;
3308  }
3309  free(content->headers);
3310  free(content->cells);
3311  free(content->aligns);
3312 
3313  content->opt = NULL;
3314  content->title = NULL;
3315  content->headers = NULL;
3316  content->cells = NULL;
3317  content->aligns = NULL;
3318  content->header = NULL;
3319  content->cell = NULL;
3320  content->align = NULL;
3321 
3322  if (content->footers)
3323  {
3324  for (content->footer = content->footers; content->footer;)
3325  {
3326  printTableFooter *f;
3327 
3328  f = content->footer;
3329  content->footer = f->next;
3330  free(f->data);
3331  free(f);
3332  }
3333  }
3334  content->footers = NULL;
3335  content->footer = NULL;
3336 }
#define unconstify(underlying_type, expr)
Definition: c.h:1240
#define free(a)
Definition: header.h:65
const char * title
Definition: print.h:150
const char ** cells
Definition: print.h:155

References printTableContent::align, printTableContent::aligns, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cells, printTableFooter::data, printTableContent::footer, printTableContent::footers, free, printTableContent::header, printTableContent::headers, i, printTableContent::ncolumns, printTableFooter::next, printTableContent::nrows, printTableContent::opt, printTableContent::title, and unconstify.

Referenced by describeOneTableDetails(), describePublications(), describeRoles(), printCrosstab(), and printQuery().

◆ printTableInit()

void printTableInit ( printTableContent *const  content,
const printTableOpt opt,
const char *  title,
const int  ncolumns,
const int  nrows 
)

Definition at line 3127 of file print.c.

3129 {
3130  content->opt = opt;
3131  content->title = title;
3132  content->ncolumns = ncolumns;
3133  content->nrows = nrows;
3134 
3135  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
3136 
3137  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
3138 
3139  content->cellmustfree = NULL;
3140  content->footers = NULL;
3141 
3142  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
3143 
3144  content->header = content->headers;
3145  content->cell = content->cells;
3146  content->footer = content->footers;
3147  content->align = content->aligns;
3148  content->cellsadded = 0;
3149 }

References printTableContent::align, printTableContent::aligns, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cells, printTableContent::cellsadded, printTableContent::footer, printTableContent::footers, printTableContent::header, printTableContent::headers, printTableContent::ncolumns, printTableContent::nrows, printTableContent::opt, pg_malloc0(), and printTableContent::title.

Referenced by describeOneTableDetails(), describePublications(), describeRoles(), printCrosstab(), and printQuery().

◆ printTableSetFooter()

void printTableSetFooter ( printTableContent *const  content,
const char *  footer 
)

Definition at line 3277 of file print.c.

3278 {
3279  if (content->footers != NULL)
3280  {
3281  free(content->footer->data);
3282  content->footer->data = pg_strdup(footer);
3283  }
3284  else
3285  printTableAddFooter(content, footer);
3286 }

References printTableFooter::data, printTableContent::footer, printTableContent::footers, free, pg_strdup(), and printTableAddFooter().

Referenced by add_tablespace_footer().

◆ refresh_utf8format()

void refresh_utf8format ( const printTableOpt opt)

Definition at line 3632 of file print.c.

3633 {
3634  printTextFormat *popt = &pg_utf8format;
3635 
3636  const unicodeStyleBorderFormat *border;
3638  const unicodeStyleColumnFormat *column;
3639 
3640  popt->name = "unicode";
3641 
3645 
3646  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3647  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3649  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3650 
3651  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3652  popt->lrule[PRINT_RULE_MIDDLE].leftvrule = header->vertical_and_right[opt->unicode_border_linestyle];
3654  popt->lrule[PRINT_RULE_MIDDLE].rightvrule = header->vertical_and_left[opt->unicode_border_linestyle];
3655 
3656  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3657  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3660 
3661  /* N/A */
3662  popt->lrule[PRINT_RULE_DATA].hrule = "";
3663  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3664  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3665  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3666 
3667  popt->midvrule_nl = column->vertical;
3668  popt->midvrule_wrap = column->vertical;
3669  popt->midvrule_blank = column->vertical;
3670 
3671  /* Same for all unicode today */
3674  popt->nl_left = unicode_style.nl_left;
3679 }
static const unicodeStyleFormat unicode_style
Definition: print.c:140
printTextFormat pg_utf8format
Definition: print.c:99
unicode_linestyle unicode_border_linestyle
Definition: print.h:125
unicode_linestyle unicode_header_linestyle
Definition: print.h:127
unicode_linestyle unicode_column_linestyle
Definition: print.h:126
bool wrap_right_border
Definition: print.h:83
const char * nl_right
Definition: print.h:80
const char * wrap_left
Definition: print.h:81
const char * midvrule_blank
Definition: print.h:76
const char * header_nl_left
Definition: print.h:77
const char * nl_left
Definition: print.h:79
const char * midvrule_nl
Definition: print.h:74
printTextLineFormat lrule[4]
Definition: print.h:73
const char * wrap_right
Definition: print.h:82
const char * midvrule_wrap
Definition: print.h:75
const char * name
Definition: print.h:72
const char * header_nl_right
Definition: print.h:78
const char * hrule
Definition: print.h:46
const char * rightvrule
Definition: print.h:49
const char * midvrule
Definition: print.h:48
const char * leftvrule
Definition: print.h:47
const char * up_and_right
Definition: print.c:118
const char * left_and_right
Definition: print.c:123
const char * vertical
Definition: print.c:119
const char * down_and_left
Definition: print.c:122
const char * horizontal
Definition: print.c:121
const char * down_and_right
Definition: print.c:120
const char * vertical_and_horizontal[2]
Definition: print.c:111
const char * up_and_horizontal[2]
Definition: print.c:112
const char * vertical
Definition: print.c:110
const char * down_and_horizontal[2]
Definition: print.c:113
unicodeStyleRowFormat row_style[2]
Definition: print.c:128
unicodeStyleColumnFormat column_style[2]
Definition: print.c:129
const char * nl_right
Definition: print.c:134
const char * wrap_right
Definition: print.c:136
const char * header_nl_left
Definition: print.c:131
const char * header_nl_right
Definition: print.c:132
unicodeStyleBorderFormat border_style[2]
Definition: print.c:130
const char * nl_left
Definition: print.c:133
const char * wrap_left
Definition: print.c:135
bool wrap_right_border
Definition: print.c:137

References unicodeStyleFormat::border_style, unicodeStyleFormat::column_style, unicodeStyleColumnFormat::down_and_horizontal, unicodeStyleBorderFormat::down_and_left, unicodeStyleBorderFormat::down_and_right, header(), unicodeStyleFormat::header_nl_left, printTextFormat::header_nl_left, unicodeStyleFormat::header_nl_right, printTextFormat::header_nl_right, unicodeStyleBorderFormat::horizontal, printTextLineFormat::hrule, unicodeStyleBorderFormat::left_and_right, printTextLineFormat::leftvrule, printTextFormat::lrule, printTextLineFormat::midvrule, printTextFormat::midvrule_blank, printTextFormat::midvrule_nl, printTextFormat::midvrule_wrap, printTextFormat::name, unicodeStyleFormat::nl_left, printTextFormat::nl_left, unicodeStyleFormat::nl_right, printTextFormat::nl_right, pg_utf8format, PRINT_RULE_BOTTOM, PRINT_RULE_DATA, PRINT_RULE_MIDDLE, PRINT_RULE_TOP, printTextLineFormat::rightvrule, unicodeStyleFormat::row_style, printTableOpt::unicode_border_linestyle, printTableOpt::unicode_column_linestyle, printTableOpt::unicode_header_linestyle, unicode_style, unicodeStyleColumnFormat::up_and_horizontal, unicodeStyleBorderFormat::up_and_right, unicodeStyleColumnFormat::vertical, unicodeStyleBorderFormat::vertical, unicodeStyleColumnFormat::vertical_and_horizontal, unicodeStyleFormat::wrap_left, printTextFormat::wrap_left, unicodeStyleFormat::wrap_right, printTextFormat::wrap_right, unicodeStyleFormat::wrap_right_border, and printTextFormat::wrap_right_border.

Referenced by do_pset(), and main().

◆ restore_sigpipe_trap()

void restore_sigpipe_trap ( void  )

Definition at line 3018 of file print.c.

3019 {
3020 #ifndef WIN32
3022 #endif
3023 }
static bool always_ignore_sigpipe
Definition: print.c:45
#define SIG_DFL
Definition: win32_port.h:162

References always_ignore_sigpipe, pqsignal(), SIG_DFL, SIG_IGN, and SIGPIPE.

Referenced by ClosePager(), do_copy(), do_watch(), exec_command_write(), ExecQueryUsingCursor(), HandleCopyResult(), PageOutput(), PrintQueryTuples(), and setQFout().

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 3031 of file print.c.

3032 {
3033  always_ignore_sigpipe = ignore;
3034 }

References always_ignore_sigpipe.

Referenced by setQFout().

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3582 of file print.c.

3583 {
3584  struct lconv *extlconv;
3585 
3586  extlconv = localeconv();
3587 
3588  /* Don't accept an empty decimal_point string */
3589  if (*extlconv->decimal_point)
3590  decimal_point = pg_strdup(extlconv->decimal_point);
3591  else
3592  decimal_point = "."; /* SQL output standard */
3593 
3594  /*
3595  * Although the Open Group standard allows locales to supply more than one
3596  * group width, we consider only the first one, and we ignore any attempt
3597  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3598  * cash.c, we must apply a range check to avoid being fooled by variant
3599  * CHAR_MAX values.
3600  */
3601  groupdigits = *extlconv->grouping;
3602  if (groupdigits <= 0 || groupdigits > 6)
3603  groupdigits = 3; /* most common */
3604 
3605  /* Don't accept an empty thousands_sep string, either */
3606  /* similar code exists in formatting.c */
3607  if (*extlconv->thousands_sep)
3608  thousands_sep = pg_strdup(extlconv->thousands_sep);
3609  /* Make sure thousands separator doesn't match decimal point symbol. */
3610  else if (strcmp(decimal_point, ",") != 0)
3611  thousands_sep = ",";
3612  else
3613  thousands_sep = ".";
3614 }
static char * thousands_sep
Definition: print.c:50
static char * decimal_point
Definition: print.c:48
static int groupdigits
Definition: print.c:49

References decimal_point, groupdigits, pg_strdup(), and thousands_sep.

Referenced by main().

Variable Documentation

◆ cancel_pressed

◆ pg_asciiformat

PGDLLIMPORT const printTextFormat pg_asciiformat
extern

Definition at line 56 of file print.c.

Referenced by do_pset(), and get_line_style().

◆ pg_asciiformat_old

PGDLLIMPORT const printTextFormat pg_asciiformat_old
extern

Definition at line 77 of file print.c.

Referenced by do_pset(), and print_aligned_vertical().

◆ pg_utf8format

PGDLLIMPORT printTextFormat pg_utf8format
extern

Definition at line 99 of file print.c.

Referenced by do_pset(), and refresh_utf8format().