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

3027 {
3028  if (pagerpipe && pagerpipe != stdout)
3029  {
3030  /*
3031  * If printing was canceled midstream, warn about it.
3032  *
3033  * Some pagers like less use Ctrl-C as part of their command set. Even
3034  * so, we abort our processing and warn the user what we did. If the
3035  * pager quit as a result of the SIGINT, this message won't go
3036  * anywhere ...
3037  */
3038  if (cancel_pressed)
3039  fprintf(pagerpipe, _("Interrupted\n"));
3040 
3041  pclose(pagerpipe);
3043  }
3044 }
#define fprintf
Definition: port.h:220
void restore_sigpipe_trap(void)
Definition: print.c:2948
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
#define _(x)
Definition: elog.c:89

◆ column_type_alignment()

char column_type_alignment ( Oid  )

Definition at line 3485 of file print.c.

Referenced by printCrosstab(), and printQuery().

3486 {
3487  char align;
3488 
3489  switch (ftype)
3490  {
3491  case INT2OID:
3492  case INT4OID:
3493  case INT8OID:
3494  case FLOAT4OID:
3495  case FLOAT8OID:
3496  case NUMERICOID:
3497  case OIDOID:
3498  case XIDOID:
3499  case XID8OID:
3500  case CIDOID:
3501  case MONEYOID:
3502  align = 'r';
3503  break;
3504  default:
3505  align = 'l';
3506  break;
3507  }
3508  return align;
3509 }

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 2925 of file print.c.

References pqsignal(), SIG_IGN, and SIGPIPE.

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

2926 {
2927 #ifndef WIN32
2929 #endif
2930 }
#define SIGPIPE
Definition: win32_port.h:164
#define SIG_IGN
Definition: win32_port.h:156
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3548 of file print.c.

References printTableOpt::line_style, and pg_asciiformat.

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

3549 {
3550  /*
3551  * Note: this function mainly exists to preserve the convention that a
3552  * printTableOpt struct can be initialized to zeroes to get default
3553  * behavior.
3554  */
3555  if (opt->line_style != NULL)
3556  return opt->line_style;
3557  else
3558  return &pg_asciiformat;
3559 }
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 1838 of file print.c.

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

1839 {
1840  const char *p;
1841  bool leading_space = true;
1842 
1843  for (p = in; *p; p++)
1844  {
1845  switch (*p)
1846  {
1847  case '&':
1848  fputs("&amp;", fout);
1849  break;
1850  case '<':
1851  fputs("&lt;", fout);
1852  break;
1853  case '>':
1854  fputs("&gt;", fout);
1855  break;
1856  case '\n':
1857  fputs("<br />\n", fout);
1858  break;
1859  case '"':
1860  fputs("&quot;", fout);
1861  break;
1862  case ' ':
1863  /* protect leading space, for EXPLAIN output */
1864  if (leading_space)
1865  fputs("&nbsp;", fout);
1866  else
1867  fputs(" ", fout);
1868  break;
1869  default:
1870  fputc(*p, fout);
1871  }
1872  if (*p != ' ')
1873  leading_space = false;
1874  }
1875 }

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 2975 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().

2976 {
2977  /* check whether we need / can / are supposed to use pager */
2978  if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
2979  {
2980 #ifdef TIOCGWINSZ
2981  unsigned short int pager = topt->pager;
2982  int min_lines = topt->pager_min_lines;
2983  int result;
2984  struct winsize screen_size;
2985 
2986  result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
2987 
2988  /* >= accounts for a one-line prompt */
2989  if (result == -1
2990  || (lines >= screen_size.ws_row && lines >= min_lines)
2991  || pager > 1)
2992 #endif
2993  {
2994  const char *pagerprog;
2995  FILE *pagerpipe;
2996 
2997  pagerprog = getenv("PSQL_PAGER");
2998  if (!pagerprog)
2999  pagerprog = getenv("PAGER");
3000  if (!pagerprog)
3001  pagerprog = DEFAULT_PAGER;
3002  else
3003  {
3004  /* if PAGER is empty or all-white-space, don't use pager */
3005  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
3006  return stdout;
3007  }
3009  pagerpipe = popen(pagerprog, "w");
3010  if (pagerpipe)
3011  return pagerpipe;
3012  /* if popen fails, silently proceed without pager */
3014  }
3015  }
3016 
3017  return stdout;
3018 }
void disable_sigpipe_trap(void)
Definition: print.c:2925
void restore_sigpipe_trap(void)
Definition: print.c:2948
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 3420 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(), listExtendedStats(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSDictionaries(), listTSParsers(), listTSTemplates(), listUserMappings(), objectDescription(), permissionsList(), PrintQueryTuples(), and PSQLexecWatch().

3422 {
3423  printTableContent cont;
3424  int i,
3425  r,
3426  c;
3427 
3428  if (cancel_pressed)
3429  return;
3430 
3431  printTableInit(&cont, &opt->topt, opt->title,
3432  PQnfields(result), PQntuples(result));
3433 
3434  /* Assert caller supplied enough translate_columns[] entries */
3435  Assert(opt->translate_columns == NULL ||
3436  opt->n_translate_columns >= cont.ncolumns);
3437 
3438  for (i = 0; i < cont.ncolumns; i++)
3439  {
3440  printTableAddHeader(&cont, PQfname(result, i),
3441  opt->translate_header,
3442  column_type_alignment(PQftype(result, i)));
3443  }
3444 
3445  /* set cells */
3446  for (r = 0; r < cont.nrows; r++)
3447  {
3448  for (c = 0; c < cont.ncolumns; c++)
3449  {
3450  char *cell;
3451  bool mustfree = false;
3452  bool translate;
3453 
3454  if (PQgetisnull(result, r, c))
3455  cell = opt->nullPrint ? opt->nullPrint : "";
3456  else
3457  {
3458  cell = PQgetvalue(result, r, c);
3459  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3460  {
3461  cell = format_numeric_locale(cell);
3462  mustfree = true;
3463  }
3464  }
3465 
3466  translate = (opt->translate_columns && opt->translate_columns[c]);
3467  printTableAddCell(&cont, cell, translate, mustfree);
3468  }
3469  }
3470 
3471  /* set footers */
3472  if (opt->footers)
3473  {
3474  char **footer;
3475 
3476  for (footer = opt->footers; *footer; footer++)
3477  printTableAddFooter(&cont, *footer);
3478  }
3479 
3480  printTable(&cont, fout, is_pager, flog);
3481  printTableCleanup(&cont);
3482 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3256
char * nullPrint
Definition: print.h:170
void printTableCleanup(printTableContent *const content)
Definition: print.c:3225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3334
printTableOpt topt
Definition: print.h:169
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
Datum translate(PG_FUNCTION_ARGS)
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3094
char * aligns
Definition: print.h:162
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3134
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3486
char * c
bool translate_header
Definition: print.h:173
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3314
char column_type_alignment(Oid ftype)
Definition: print.c:3485
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3182
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:804
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:3057
bool numericLocale
Definition: print.h:119
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3667
const bool * translate_columns
Definition: print.h:174

◆ printTable()

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

Definition at line 3314 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().

3316 {
3317  bool is_local_pager = false;
3318 
3319  if (cancel_pressed)
3320  return;
3321 
3322  if (cont->opt->format == PRINT_NOTHING)
3323  return;
3324 
3325  /* print_aligned_*() handle the pager themselves */
3326  if (!is_pager &&
3327  cont->opt->format != PRINT_ALIGNED &&
3328  cont->opt->format != PRINT_WRAPPED)
3329  {
3330  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3331  is_local_pager = is_pager;
3332  }
3333 
3334  /* clear any pre-existing error indication on the output stream */
3335  clearerr(fout);
3336 
3337  /* print the stuff */
3338 
3339  if (flog)
3340  print_aligned_text(cont, flog, false);
3341 
3342  switch (cont->opt->format)
3343  {
3344  case PRINT_UNALIGNED:
3345  if (cont->opt->expanded == 1)
3346  print_unaligned_vertical(cont, fout);
3347  else
3348  print_unaligned_text(cont, fout);
3349  break;
3350  case PRINT_ALIGNED:
3351  case PRINT_WRAPPED:
3352 
3353  /*
3354  * In expanded-auto mode, force vertical if a pager is passed in;
3355  * else we may make different decisions for different hunks of the
3356  * query result.
3357  */
3358  if (cont->opt->expanded == 1 ||
3359  (cont->opt->expanded == 2 && is_pager))
3360  print_aligned_vertical(cont, fout, is_pager);
3361  else
3362  print_aligned_text(cont, fout, is_pager);
3363  break;
3364  case PRINT_CSV:
3365  if (cont->opt->expanded == 1)
3366  print_csv_vertical(cont, fout);
3367  else
3368  print_csv_text(cont, fout);
3369  break;
3370  case PRINT_HTML:
3371  if (cont->opt->expanded == 1)
3372  print_html_vertical(cont, fout);
3373  else
3374  print_html_text(cont, fout);
3375  break;
3376  case PRINT_ASCIIDOC:
3377  if (cont->opt->expanded == 1)
3378  print_asciidoc_vertical(cont, fout);
3379  else
3380  print_asciidoc_text(cont, fout);
3381  break;
3382  case PRINT_LATEX:
3383  if (cont->opt->expanded == 1)
3384  print_latex_vertical(cont, fout);
3385  else
3386  print_latex_text(cont, fout);
3387  break;
3388  case PRINT_LATEX_LONGTABLE:
3389  if (cont->opt->expanded == 1)
3390  print_latex_vertical(cont, fout);
3391  else
3392  print_latex_longtable_text(cont, fout);
3393  break;
3394  case PRINT_TROFF_MS:
3395  if (cont->opt->expanded == 1)
3396  print_troff_ms_vertical(cont, fout);
3397  else
3398  print_troff_ms_text(cont, fout);
3399  break;
3400  default:
3401  fprintf(stderr, _("invalid output format (internal error): %d"),
3402  cont->opt->format);
3403  exit(EXIT_FAILURE);
3404  }
3405 
3406  if (is_local_pager)
3407  ClosePager(fout);
3408 }
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2805
static void print_unaligned_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:443
static void print_csv_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1806
void ClosePager(FILE *pagerpipe)
Definition: print.c:3026
static void print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:565
enum printFormat format
Definition: print.h:101
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1211
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2713
static void print_csv_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1766
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:220
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3274
unsigned short int expanded
Definition: print.h:102
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1879
static void print_latex_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2340
static void print_unaligned_text(const printTableContent *cont, FILE *fout)
Definition: print.c:352
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2182
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1968
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2447
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2072
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
static void print_latex_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2603
#define EXIT_FAILURE
Definition: settings.h:162
#define _(x)
Definition: elog.c:89

◆ printTableAddCell()

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

Definition at line 3134 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().

3136 {
3137 #ifndef ENABLE_NLS
3138  (void) translate; /* unused parameter */
3139 #endif
3140 
3141  if (content->cellsadded >= content->ncolumns * content->nrows)
3142  {
3143  fprintf(stderr, _("Cannot add cell to table content: "
3144  "total cell count of %d exceeded.\n"),
3145  content->ncolumns * content->nrows);
3146  exit(EXIT_FAILURE);
3147  }
3148 
3149  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3150  content->opt->encoding);
3151 
3152 #ifdef ENABLE_NLS
3153  if (translate)
3154  *content->cell = _(*content->cell);
3155 #endif
3156 
3157  if (mustfree)
3158  {
3159  if (content->cellmustfree == NULL)
3160  content->cellmustfree =
3161  pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
3162 
3163  content->cellmustfree[content->cellsadded] = true;
3164  }
3165  content->cell++;
3166  content->cellsadded++;
3167 }
int encoding
Definition: print.h:122
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:220
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:162
#define _(x)
Definition: elog.c:89

◆ printTableAddFooter()

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

Definition at line 3182 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().

3183 {
3184  printTableFooter *f;
3185 
3186  f = pg_malloc0(sizeof(*f));
3187  f->data = pg_strdup(footer);
3188 
3189  if (content->footers == NULL)
3190  content->footers = f;
3191  else
3192  content->footer->next = f;
3193 
3194  content->footer = f;
3195 }
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 3094 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().

3096 {
3097 #ifndef ENABLE_NLS
3098  (void) translate; /* unused parameter */
3099 #endif
3100 
3101  if (content->header >= content->headers + content->ncolumns)
3102  {
3103  fprintf(stderr, _("Cannot add header to table content: "
3104  "column count of %d exceeded.\n"),
3105  content->ncolumns);
3106  exit(EXIT_FAILURE);
3107  }
3108 
3109  *content->header = (char *) mbvalidate((unsigned char *) header,
3110  content->opt->encoding);
3111 #ifdef ENABLE_NLS
3112  if (translate)
3113  *content->header = _(*content->header);
3114 #endif
3115  content->header++;
3116 
3117  *content->align = align;
3118  content->align++;
3119 }
int encoding
Definition: print.h:122
const printTableOpt * opt
Definition: print.h:149
#define fprintf
Definition: port.h:220
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:210
#define EXIT_FAILURE
Definition: settings.h:162
char * align
Definition: print.h:164
const char ** headers
Definition: print.h:153
#define _(x)
Definition: elog.c:89

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

Definition at line 3225 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().

3226 {
3227  if (content->cellmustfree)
3228  {
3229  int i;
3230 
3231  for (i = 0; i < content->nrows * content->ncolumns; i++)
3232  {
3233  if (content->cellmustfree[i])
3234  free(unconstify(char *, content->cells[i]));
3235  }
3236  free(content->cellmustfree);
3237  content->cellmustfree = NULL;
3238  }
3239  free(content->headers);
3240  free(content->cells);
3241  free(content->aligns);
3242 
3243  content->opt = NULL;
3244  content->title = NULL;
3245  content->headers = NULL;
3246  content->cells = NULL;
3247  content->aligns = NULL;
3248  content->header = NULL;
3249  content->cell = NULL;
3250  content->align = NULL;
3251 
3252  if (content->footers)
3253  {
3254  for (content->footer = content->footers; content->footer;)
3255  {
3256  printTableFooter *f;
3257 
3258  f = content->footer;
3259  content->footer = f->next;
3260  free(f->data);
3261  free(f);
3262  }
3263  }
3264  content->footers = NULL;
3265  content->footer = NULL;
3266 }
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:1243
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 3057 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().

3059 {
3060  content->opt = opt;
3061  content->title = title;
3062  content->ncolumns = ncolumns;
3063  content->nrows = nrows;
3064 
3065  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
3066 
3067  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
3068 
3069  content->cellmustfree = NULL;
3070  content->footers = NULL;
3071 
3072  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
3073 
3074  content->header = content->headers;
3075  content->cell = content->cells;
3076  content->footer = content->footers;
3077  content->align = content->aligns;
3078  content->cellsadded = 0;
3079 }
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 3207 of file print.c.

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

Referenced by add_tablespace_footer().

3208 {
3209  if (content->footers != NULL)
3210  {
3211  free(content->footer->data);
3212  content->footer->data = pg_strdup(footer);
3213  }
3214  else
3215  printTableAddFooter(content, footer);
3216 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3182
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 3562 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().

3563 {
3564  printTextFormat *popt = &pg_utf8format;
3565 
3566  const unicodeStyleBorderFormat *border;
3568  const unicodeStyleColumnFormat *column;
3569 
3570  popt->name = "unicode";
3571 
3575 
3576  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3577  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3579  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3580 
3581  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3585 
3586  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3587  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3590 
3591  /* N/A */
3592  popt->lrule[PRINT_RULE_DATA].hrule = "";
3593  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3594  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3595  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3596 
3597  popt->midvrule_nl = column->vertical;
3598  popt->midvrule_wrap = column->vertical;
3599  popt->midvrule_blank = column->vertical;
3600 
3601  /* Same for all unicode today */
3604  popt->nl_left = unicode_style.nl_left;
3609 }
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:210
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 2948 of file print.c.

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

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

2949 {
2950 #ifndef WIN32
2952 #endif
2953 }
#define SIGPIPE
Definition: win32_port.h:164
#define SIG_IGN
Definition: win32_port.h:156
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:154

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 2961 of file print.c.

References always_ignore_sigpipe.

Referenced by setQFout().

2962 {
2963  always_ignore_sigpipe = ignore;
2964 }
static bool always_ignore_sigpipe
Definition: print.c:45

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3512 of file print.c.

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

Referenced by main().

3513 {
3514  struct lconv *extlconv;
3515 
3516  extlconv = localeconv();
3517 
3518  /* Don't accept an empty decimal_point string */
3519  if (*extlconv->decimal_point)
3520  decimal_point = pg_strdup(extlconv->decimal_point);
3521  else
3522  decimal_point = "."; /* SQL output standard */
3523 
3524  /*
3525  * Although the Open Group standard allows locales to supply more than one
3526  * group width, we consider only the first one, and we ignore any attempt
3527  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3528  * cash.c, we must apply a range check to avoid being fooled by variant
3529  * CHAR_MAX values.
3530  */
3531  groupdigits = *extlconv->grouping;
3532  if (groupdigits <= 0 || groupdigits > 6)
3533  groupdigits = 3; /* most common */
3534 
3535  /* Don't accept an empty thousands_sep string, either */
3536  /* similar code exists in formatting.c */
3537  if (*extlconv->thousands_sep)
3538  thousands_sep = pg_strdup(extlconv->thousands_sep);
3539  /* Make sure thousands separator doesn't match decimal point symbol. */
3540  else if (strcmp(decimal_point, ",") != 0)
3541  thousands_sep = ",";
3542  else
3543  thousands_sep = ".";
3544 }
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().