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

volatile sig_atomic_t cancel_pressed
 
const printTextFormat pg_asciiformat
 
const printTextFormat pg_asciiformat_old
 
printTextFormat pg_utf8format
 

Macro Definition Documentation

◆ DEFAULT_PAGER

#define DEFAULT_PAGER   "more"

Definition at line 23 of file print.h.

Referenced by PageOutput().

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 };

◆ 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:61

◆ 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:52

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 87 of file print.h.

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

Definition at line 3042 of file print.c.

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().

3043 {
3044  if (pagerpipe && pagerpipe != stdout)
3045  {
3046  /*
3047  * If printing was canceled midstream, warn about it.
3048  *
3049  * Some pagers like less use Ctrl-C as part of their command set. Even
3050  * so, we abort our processing and warn the user what we did. If the
3051  * pager quit as a result of the SIGINT, this message won't go
3052  * anywhere ...
3053  */
3054  if (cancel_pressed)
3055  fprintf(pagerpipe, _("Interrupted\n"));
3056 
3057  pclose(pagerpipe);
3059  }
3060 }
#define fprintf
Definition: port.h:196
void restore_sigpipe_trap(void)
Definition: print.c:2964
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
#define _(x)
Definition: elog.c:87

◆ column_type_alignment()

char column_type_alignment ( Oid  )

Definition at line 3498 of file print.c.

Referenced by printCrosstab(), and printQuery().

3499 {
3500  char align;
3501 
3502  switch (ftype)
3503  {
3504  case INT2OID:
3505  case INT4OID:
3506  case INT8OID:
3507  case FLOAT4OID:
3508  case FLOAT8OID:
3509  case NUMERICOID:
3510  case OIDOID:
3511  case XIDOID:
3512  case CIDOID:
3513  case CASHOID:
3514  align = 'r';
3515  break;
3516  default:
3517  align = 'l';
3518  break;
3519  }
3520  return align;
3521 }

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 2941 of file print.c.

References pqsignal(), SIG_IGN, and SIGPIPE.

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

2942 {
2943 #ifndef WIN32
2945 #endif
2946 }
#define SIGPIPE
Definition: win32_port.h:159
#define SIG_IGN
Definition: win32_port.h:151
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3560 of file print.c.

References printTableOpt::line_style, and pg_asciiformat.

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

3561 {
3562  /*
3563  * Note: this function mainly exists to preserve the convention that a
3564  * printTableOpt struct can be initialized to zeroes to get default
3565  * behavior.
3566  */
3567  if (opt->line_style != NULL)
3568  return opt->line_style;
3569  else
3570  return &pg_asciiformat;
3571 }
const printTextFormat * line_style
Definition: print.h:115
const printTextFormat pg_asciiformat
Definition: print.c:56

◆ html_escaped_print()

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

Definition at line 1854 of file print.c.

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

1855 {
1856  const char *p;
1857  bool leading_space = true;
1858 
1859  for (p = in; *p; p++)
1860  {
1861  switch (*p)
1862  {
1863  case '&':
1864  fputs("&amp;", fout);
1865  break;
1866  case '<':
1867  fputs("&lt;", fout);
1868  break;
1869  case '>':
1870  fputs("&gt;", fout);
1871  break;
1872  case '\n':
1873  fputs("<br />\n", fout);
1874  break;
1875  case '"':
1876  fputs("&quot;", fout);
1877  break;
1878  case ' ':
1879  /* protect leading space, for EXPLAIN output */
1880  if (leading_space)
1881  fputs("&nbsp;", fout);
1882  else
1883  fputs(" ", fout);
1884  break;
1885  default:
1886  fputc(*p, fout);
1887  }
1888  if (*p != ' ')
1889  leading_space = false;
1890  }
1891 }

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 2991 of file print.c.

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().

2992 {
2993  /* check whether we need / can / are supposed to use pager */
2994  if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
2995  {
2996 #ifdef TIOCGWINSZ
2997  unsigned short int pager = topt->pager;
2998  int min_lines = topt->pager_min_lines;
2999  int result;
3000  struct winsize screen_size;
3001 
3002  result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
3003 
3004  /* >= accounts for a one-line prompt */
3005  if (result == -1
3006  || (lines >= screen_size.ws_row && lines >= min_lines)
3007  || pager > 1)
3008 #endif
3009  {
3010  const char *pagerprog;
3011  FILE *pagerpipe;
3012 
3013  pagerprog = getenv("PSQL_PAGER");
3014  if (!pagerprog)
3015  pagerprog = getenv("PAGER");
3016  if (!pagerprog)
3017  pagerprog = DEFAULT_PAGER;
3018  else
3019  {
3020  /* if PAGER is empty or all-white-space, don't use pager */
3021  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
3022  return stdout;
3023  }
3025  pagerpipe = popen(pagerprog, "w");
3026  if (pagerpipe)
3027  return pagerpipe;
3028  /* if popen fails, silently proceed without pager */
3030  }
3031  }
3032 
3033  return stdout;
3034 }
void disable_sigpipe_trap(void)
Definition: print.c:2941
void restore_sigpipe_trap(void)
Definition: print.c:2964
unsigned short int pager
Definition: print.h:106
int pager_min_lines
Definition: print.h:108
#define DEFAULT_PAGER
Definition: print.h:23

◆ printQuery()

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

Definition at line 3433 of file print.c.

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(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describeSubscriptions(), describeTablespaces(), describeTypes(), do_lo_list(), ExecQueryUsingCursor(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSDictionaries(), listTSParsers(), listTSTemplates(), listUserMappings(), objectDescription(), permissionsList(), PrintQueryTuples(), and PSQLexecWatch().

3435 {
3436  printTableContent cont;
3437  int i,
3438  r,
3439  c;
3440 
3441  if (cancel_pressed)
3442  return;
3443 
3444  printTableInit(&cont, &opt->topt, opt->title,
3445  PQnfields(result), PQntuples(result));
3446 
3447  /* Assert caller supplied enough translate_columns[] entries */
3448  Assert(opt->translate_columns == NULL ||
3449  opt->n_translate_columns >= cont.ncolumns);
3450 
3451  for (i = 0; i < cont.ncolumns; i++)
3452  {
3453  printTableAddHeader(&cont, PQfname(result, i),
3454  opt->translate_header,
3455  column_type_alignment(PQftype(result, i)));
3456  }
3457 
3458  /* set cells */
3459  for (r = 0; r < cont.nrows; r++)
3460  {
3461  for (c = 0; c < cont.ncolumns; c++)
3462  {
3463  char *cell;
3464  bool mustfree = false;
3465  bool translate;
3466 
3467  if (PQgetisnull(result, r, c))
3468  cell = opt->nullPrint ? opt->nullPrint : "";
3469  else
3470  {
3471  cell = PQgetvalue(result, r, c);
3472  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3473  {
3474  cell = format_numeric_locale(cell);
3475  mustfree = true;
3476  }
3477  }
3478 
3479  translate = (opt->translate_columns && opt->translate_columns[c]);
3480  printTableAddCell(&cont, cell, translate, mustfree);
3481  }
3482  }
3483 
3484  /* set footers */
3485  if (opt->footers)
3486  {
3487  char **footer;
3488 
3489  for (footer = opt->footers; *footer; footer++)
3490  printTableAddFooter(&cont, *footer);
3491  }
3492 
3493  printTable(&cont, fout, is_pager, flog);
3494  printTableCleanup(&cont);
3495 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
char * nullPrint
Definition: print.h:170
void printTableCleanup(printTableContent *const content)
Definition: print.c:3241
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2855
printTableOpt topt
Definition: print.h:169
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
Datum translate(PG_FUNCTION_ARGS)
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3110
char * aligns
Definition: print.h:162
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3150
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3007
char * c
bool translate_header
Definition: print.h:173
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3330
char column_type_alignment(Oid ftype)
Definition: print.c:3498
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3198
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
char * title
Definition: print.h:171
char ** footers
Definition: print.h:172
static char * format_numeric_locale(const char *my_str)
Definition: print.c:244
#define Assert(condition)
Definition: c.h:739
int n_translate_columns
Definition: print.h:176
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3073
bool numericLocale
Definition: print.h:119
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
const bool * translate_columns
Definition: print.h:174

◆ printTable()

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

Definition at line 3330 of file print.c.

References _, cancel_pressed, ClosePager(), 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().

3332 {
3333  bool is_local_pager = false;
3334 
3335  if (cancel_pressed)
3336  return;
3337 
3338  if (cont->opt->format == PRINT_NOTHING)
3339  return;
3340 
3341  /* print_aligned_*() handle the pager themselves */
3342  if (!is_pager &&
3343  cont->opt->format != PRINT_ALIGNED &&
3344  cont->opt->format != PRINT_WRAPPED)
3345  {
3346  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3347  is_local_pager = is_pager;
3348  }
3349 
3350  /* print the stuff */
3351 
3352  if (flog)
3353  print_aligned_text(cont, flog, false);
3354 
3355  switch (cont->opt->format)
3356  {
3357  case PRINT_UNALIGNED:
3358  if (cont->opt->expanded == 1)
3359  print_unaligned_vertical(cont, fout);
3360  else
3361  print_unaligned_text(cont, fout);
3362  break;
3363  case PRINT_ALIGNED:
3364  case PRINT_WRAPPED:
3365 
3366  /*
3367  * In expanded-auto mode, force vertical if a pager is passed in;
3368  * else we may make different decisions for different hunks of the
3369  * query result.
3370  */
3371  if (cont->opt->expanded == 1 ||
3372  (cont->opt->expanded == 2 && is_pager))
3373  print_aligned_vertical(cont, fout, is_pager);
3374  else
3375  print_aligned_text(cont, fout, is_pager);
3376  break;
3377  case PRINT_CSV:
3378  if (cont->opt->expanded == 1)
3379  print_csv_vertical(cont, fout);
3380  else
3381  print_csv_text(cont, fout);
3382  break;
3383  case PRINT_HTML:
3384  if (cont->opt->expanded == 1)
3385  print_html_vertical(cont, fout);
3386  else
3387  print_html_text(cont, fout);
3388  break;
3389  case PRINT_ASCIIDOC:
3390  if (cont->opt->expanded == 1)
3391  print_asciidoc_vertical(cont, fout);
3392  else
3393  print_asciidoc_text(cont, fout);
3394  break;
3395  case PRINT_LATEX:
3396  if (cont->opt->expanded == 1)
3397  print_latex_vertical(cont, fout);
3398  else
3399  print_latex_text(cont, fout);
3400  break;
3401  case PRINT_LATEX_LONGTABLE:
3402  if (cont->opt->expanded == 1)
3403  print_latex_vertical(cont, fout);
3404  else
3405  print_latex_longtable_text(cont, fout);
3406  break;
3407  case PRINT_TROFF_MS:
3408  if (cont->opt->expanded == 1)
3409  print_troff_ms_vertical(cont, fout);
3410  else
3411  print_troff_ms_text(cont, fout);
3412  break;
3413  default:
3414  fprintf(stderr, _("invalid output format (internal error): %d"),
3415  cont->opt->format);
3416  exit(EXIT_FAILURE);
3417  }
3418 
3419  if (is_local_pager)
3420  ClosePager(fout);
3421 }
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2821
static void print_unaligned_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:457
static void print_csv_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1822
void ClosePager(FILE *pagerpipe)
Definition: print.c:3042
static void print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:579
enum printFormat format
Definition: print.h:101
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1227
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2729
static void print_csv_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1782
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:196
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3290
unsigned short int expanded
Definition: print.h:102
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1895
static void print_latex_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2356
static void print_unaligned_text(const printTableContent *cont, FILE *fout)
Definition: print.c:366
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2198
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1984
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2463
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2088
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
static void print_latex_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2619
#define EXIT_FAILURE
Definition: settings.h:153
#define _(x)
Definition: elog.c:87

◆ printTableAddCell()

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

Definition at line 3150 of file print.c.

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

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

3152 {
3153 #ifndef ENABLE_NLS
3154  (void) translate; /* unused parameter */
3155 #endif
3156 
3157  if (content->cellsadded >= content->ncolumns * content->nrows)
3158  {
3159  fprintf(stderr, _("Cannot add cell to table content: "
3160  "total cell count of %d exceeded.\n"),
3161  content->ncolumns * content->nrows);
3162  exit(EXIT_FAILURE);
3163  }
3164 
3165  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3166  content->opt->encoding);
3167 
3168 #ifdef ENABLE_NLS
3169  if (translate)
3170  *content->cell = _(*content->cell);
3171 #endif
3172 
3173  if (mustfree)
3174  {
3175  if (content->cellmustfree == NULL)
3176  content->cellmustfree =
3177  pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
3178 
3179  content->cellmustfree[content->cellsadded] = true;
3180  }
3181  content->cell++;
3182  content->cellsadded++;
3183 }
int encoding
Definition: print.h:122
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:196
Datum translate(PG_FUNCTION_ARGS)
const char ** cell
Definition: print.h:157
bool * cellmustfree
Definition: print.h:159
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
long cellsadded
Definition: print.h:158
#define EXIT_FAILURE
Definition: settings.h:153
#define _(x)
Definition: elog.c:87

◆ printTableAddFooter()

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

Definition at line 3198 of file print.c.

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

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

3199 {
3200  printTableFooter *f;
3201 
3202  f = pg_malloc0(sizeof(*f));
3203  f->data = pg_strdup(footer);
3204 
3205  if (content->footers == NULL)
3206  content->footers = f;
3207  else
3208  content->footer->next = f;
3209 
3210  content->footer = f;
3211 }
struct printTableFooter * next
Definition: print.h:140
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
printTableFooter * footer
Definition: print.h:161
printTableFooter * footers
Definition: print.h:160
char * data
Definition: print.h:139

◆ printTableAddHeader()

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

Definition at line 3110 of file print.c.

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

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

3112 {
3113 #ifndef ENABLE_NLS
3114  (void) translate; /* unused parameter */
3115 #endif
3116 
3117  if (content->header >= content->headers + content->ncolumns)
3118  {
3119  fprintf(stderr, _("Cannot add header to table content: "
3120  "column count of %d exceeded.\n"),
3121  content->ncolumns);
3122  exit(EXIT_FAILURE);
3123  }
3124 
3125  *content->header = (char *) mbvalidate((unsigned char *) header,
3126  content->opt->encoding);
3127 #ifdef ENABLE_NLS
3128  if (translate)
3129  *content->header = _(*content->header);
3130 #endif
3131  content->header++;
3132 
3133  *content->align = align;
3134  content->align++;
3135 }
int encoding
Definition: print.h:122
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:196
Datum translate(PG_FUNCTION_ARGS)
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
const char ** header
Definition: print.h:154
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:209
#define EXIT_FAILURE
Definition: settings.h:153
char * align
Definition: print.h:164
const char ** headers
Definition: print.h:153
#define _(x)
Definition: elog.c:87

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

Definition at line 3241 of file print.c.

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().

3242 {
3243  if (content->cellmustfree)
3244  {
3245  int i;
3246 
3247  for (i = 0; i < content->nrows * content->ncolumns; i++)
3248  {
3249  if (content->cellmustfree[i])
3250  free(unconstify(char *, content->cells[i]));
3251  }
3252  free(content->cellmustfree);
3253  content->cellmustfree = NULL;
3254  }
3255  free(content->headers);
3256  free(content->cells);
3257  free(content->aligns);
3258 
3259  content->opt = NULL;
3260  content->title = NULL;
3261  content->headers = NULL;
3262  content->cells = NULL;
3263  content->aligns = NULL;
3264  content->header = NULL;
3265  content->cell = NULL;
3266  content->align = NULL;
3267 
3268  if (content->footers)
3269  {
3270  for (content->footer = content->footers; content->footer;)
3271  {
3272  printTableFooter *f;
3273 
3274  f = content->footer;
3275  content->footer = f->next;
3276  free(f->data);
3277  free(f);
3278  }
3279  }
3280  content->footers = NULL;
3281  content->footer = NULL;
3282 }
const char * title
Definition: print.h:150
const printTableOpt * opt
Definition: print.h:149
struct printTableFooter * next
Definition: print.h:140
const char ** cell
Definition: print.h:157
bool * cellmustfree
Definition: print.h:159
char * aligns
Definition: print.h:162
const char ** cells
Definition: print.h:155
const char ** header
Definition: print.h:154
#define unconstify(underlying_type, expr)
Definition: c.h:1193
printTableFooter * footer
Definition: print.h:161
#define free(a)
Definition: header.h:65
printTableFooter * footers
Definition: print.h:160
int i
char * data
Definition: print.h:139
char * align
Definition: print.h:164
const char ** headers
Definition: print.h:153

◆ printTableInit()

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

Definition at line 3073 of file print.c.

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().

3075 {
3076  content->opt = opt;
3077  content->title = title;
3078  content->ncolumns = ncolumns;
3079  content->nrows = nrows;
3080 
3081  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
3082 
3083  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
3084 
3085  content->cellmustfree = NULL;
3086  content->footers = NULL;
3087 
3088  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
3089 
3090  content->header = content->headers;
3091  content->cell = content->cells;
3092  content->footer = content->footers;
3093  content->align = content->aligns;
3094  content->cellsadded = 0;
3095 }
const char * title
Definition: print.h:150
const printTableOpt * opt
Definition: print.h:149
const char ** cell
Definition: print.h:157
bool * cellmustfree
Definition: print.h:159
char * aligns
Definition: print.h:162
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
const char ** cells
Definition: print.h:155
long cellsadded
Definition: print.h:158
const char ** header
Definition: print.h:154
printTableFooter * footer
Definition: print.h:161
printTableFooter * footers
Definition: print.h:160
char * align
Definition: print.h:164
const char ** headers
Definition: print.h:153

◆ printTableSetFooter()

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

Definition at line 3223 of file print.c.

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

Referenced by add_tablespace_footer().

3224 {
3225  if (content->footers != NULL)
3226  {
3227  free(content->footer->data);
3228  content->footer->data = pg_strdup(footer);
3229  }
3230  else
3231  printTableAddFooter(content, footer);
3232 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3198
printTableFooter * footer
Definition: print.h:161
#define free(a)
Definition: header.h:65
printTableFooter * footers
Definition: print.h:160
char * data
Definition: print.h:139

◆ refresh_utf8format()

void refresh_utf8format ( const printTableOpt opt)

Definition at line 3574 of file print.c.

References unicodeStyleFormat::border_style, unicodeStyleFormat::column_style, unicodeStyleColumnFormat::down_and_horizontal, unicodeStyleBorderFormat::down_and_left, unicodeStyleBorderFormat::down_and_right, header(), printTextFormat::header_nl_left, unicodeStyleFormat::header_nl_left, printTextFormat::header_nl_right, unicodeStyleFormat::header_nl_right, unicodeStyleRowFormat::horizontal, 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, printTextFormat::nl_left, unicodeStyleFormat::nl_left, printTextFormat::nl_right, unicodeStyleFormat::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, unicodeStyleColumnFormat::up_and_horizontal, unicodeStyleBorderFormat::up_and_right, unicodeStyleColumnFormat::vertical, unicodeStyleBorderFormat::vertical, unicodeStyleColumnFormat::vertical_and_horizontal, unicodeStyleRowFormat::vertical_and_left, unicodeStyleRowFormat::vertical_and_right, printTextFormat::wrap_left, unicodeStyleFormat::wrap_left, printTextFormat::wrap_right, unicodeStyleFormat::wrap_right, printTextFormat::wrap_right_border, and unicodeStyleFormat::wrap_right_border.

Referenced by do_pset(), and main().

3575 {
3576  printTextFormat *popt = &pg_utf8format;
3577 
3578  const unicodeStyleBorderFormat *border;
3580  const unicodeStyleColumnFormat *column;
3581 
3582  popt->name = "unicode";
3583 
3587 
3588  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3589  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3591  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3592 
3593  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3597 
3598  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3599  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3602 
3603  /* N/A */
3604  popt->lrule[PRINT_RULE_DATA].hrule = "";
3605  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3606  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3607  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3608 
3609  popt->midvrule_nl = column->vertical;
3610  popt->midvrule_wrap = column->vertical;
3611  popt->midvrule_blank = column->vertical;
3612 
3613  /* Same for all unicode today */
3616  popt->nl_left = unicode_style.nl_left;
3621 }
const char * midvrule
Definition: print.h:48
const char * vertical
Definition: print.c:110
unicodeStyleColumnFormat column_style[2]
Definition: print.c:129
const char * midvrule_wrap
Definition: print.h:75
static const unicodeStyleFormat unicode_style
Definition: print.c:140
const char * header_nl_left
Definition: print.c:131
const char * header_nl_left
Definition: print.h:77
printTextFormat pg_utf8format
Definition: print.c:99
bool wrap_right_border
Definition: print.h:83
const char * wrap_left
Definition: print.c:135
unicode_linestyle unicode_header_linestyle
Definition: print.h:127
printTextLineFormat lrule[4]
Definition: print.h:73
const char * horizontal
Definition: print.c:121
const char * down_and_left
Definition: print.c:122
const char * name
Definition: print.h:72
const char * up_and_right
Definition: print.c:118
const char * midvrule_blank
Definition: print.h:76
unicode_linestyle unicode_border_linestyle
Definition: print.h:125
const char * header_nl_right
Definition: print.c:132
const char * vertical_and_left[2]
Definition: print.c:105
const char * header_nl_right
Definition: print.h:78
unicodeStyleBorderFormat border_style[2]
Definition: print.c:130
const char * down_and_horizontal[2]
Definition: print.c:113
const char * horizontal
Definition: print.c:103
const char * hrule
Definition: print.h:46
const char * vertical_and_horizontal[2]
Definition: print.c:111
unicode_linestyle unicode_column_linestyle
Definition: print.h:126
const char * midvrule_nl
Definition: print.h:74
const char * left_and_right
Definition: print.c:123
const char * wrap_right
Definition: print.c:136
bool wrap_right_border
Definition: print.c:137
const char * nl_left
Definition: print.c:133
const char * leftvrule
Definition: print.h:47
const char * nl_right
Definition: print.c:134
const char * up_and_horizontal[2]
Definition: print.c:112
const char * down_and_right
Definition: print.c:120
const char * nl_right
Definition: print.h:80
const char * vertical
Definition: print.c:119
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:209
const char * vertical_and_right[2]
Definition: print.c:104
const char * nl_left
Definition: print.h:79
const char * rightvrule
Definition: print.h:49
const char * wrap_left
Definition: print.h:81
const char * wrap_right
Definition: print.h:82
unicodeStyleRowFormat row_style[2]
Definition: print.c:128

◆ restore_sigpipe_trap()

void restore_sigpipe_trap ( void  )

Definition at line 2964 of file print.c.

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

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

2965 {
2966 #ifndef WIN32
2968 #endif
2969 }
#define SIGPIPE
Definition: win32_port.h:159
#define SIG_IGN
Definition: win32_port.h:151
static bool always_ignore_sigpipe
Definition: print.c:45
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:149

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 2977 of file print.c.

References always_ignore_sigpipe.

Referenced by setQFout().

2978 {
2979  always_ignore_sigpipe = ignore;
2980 }
static bool always_ignore_sigpipe
Definition: print.c:45

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3524 of file print.c.

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

Referenced by main().

3525 {
3526  struct lconv *extlconv;
3527 
3528  extlconv = localeconv();
3529 
3530  /* Don't accept an empty decimal_point string */
3531  if (*extlconv->decimal_point)
3532  decimal_point = pg_strdup(extlconv->decimal_point);
3533  else
3534  decimal_point = "."; /* SQL output standard */
3535 
3536  /*
3537  * Although the Open Group standard allows locales to supply more than one
3538  * group width, we consider only the first one, and we ignore any attempt
3539  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3540  * cash.c, we must apply a range check to avoid being fooled by variant
3541  * CHAR_MAX values.
3542  */
3543  groupdigits = *extlconv->grouping;
3544  if (groupdigits <= 0 || groupdigits > 6)
3545  groupdigits = 3; /* most common */
3546 
3547  /* Don't accept an empty thousands_sep string, either */
3548  /* similar code exists in formatting.c */
3549  if (*extlconv->thousands_sep)
3550  thousands_sep = pg_strdup(extlconv->thousands_sep);
3551  /* Make sure thousands separator doesn't match decimal point symbol. */
3552  else if (strcmp(decimal_point, ",") != 0)
3553  thousands_sep = ",";
3554  else
3555  thousands_sep = ".";
3556 }
static int groupdigits
Definition: print.c:49
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * decimal_point
Definition: print.c:48
static char * thousands_sep
Definition: print.c:50

Variable Documentation

◆ cancel_pressed

◆ pg_asciiformat

const printTextFormat pg_asciiformat

Definition at line 56 of file print.c.

Referenced by do_pset(), and get_line_style().

◆ pg_asciiformat_old

const printTextFormat pg_asciiformat_old

Definition at line 77 of file print.c.

Referenced by do_pset().

◆ pg_utf8format

printTextFormat pg_utf8format

Definition at line 99 of file print.c.

Referenced by do_pset(), and refresh_utf8format().