PostgreSQL Source Code  git master
print.h File Reference
#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 bool 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 21 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 26 of file print.h.

27 {
28  PRINT_NOTHING = 0, /* to make sure someone initializes this */
31  PRINT_CSV,
32  PRINT_HTML,
38  /* add your favourite output format here ... */
39 };

◆ printTextLineWrap

Enumerator
PRINT_LINE_WRAP_NONE 
PRINT_LINE_WRAP_WRAP 
PRINT_LINE_WRAP_NEWLINE 

Definition at line 59 of file print.h.

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

◆ printTextRule

Enumerator
PRINT_RULE_TOP 
PRINT_RULE_MIDDLE 
PRINT_RULE_BOTTOM 
PRINT_RULE_DATA 

Definition at line 50 of file print.h.

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

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 85 of file print.h.

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

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

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

◆ column_type_alignment()

char column_type_alignment ( Oid  )

Definition at line 3499 of file print.c.

Referenced by printCrosstab(), and printQuery().

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

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 2942 of file print.c.

References pqsignal(), SIG_IGN, and SIGPIPE.

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

2943 {
2944 #ifndef WIN32
2946 #endif
2947 }
#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 3561 of file print.c.

References printTableOpt::line_style, and pg_asciiformat.

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

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

◆ html_escaped_print()

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

Definition at line 1855 of file print.c.

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

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

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

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

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

◆ printQuery()

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

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

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

◆ printTable()

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

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

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

◆ printTableAddCell()

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

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

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

◆ printTableAddFooter()

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

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

3200 {
3201  printTableFooter *f;
3202 
3203  f = pg_malloc0(sizeof(*f));
3204  f->data = pg_strdup(footer);
3205 
3206  if (content->footers == NULL)
3207  content->footers = f;
3208  else
3209  content->footer->next = f;
3210 
3211  content->footer = f;
3212 }
struct printTableFooter * next
Definition: print.h:138
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:159
printTableFooter * footers
Definition: print.h:158
char * data
Definition: print.h:137

◆ printTableAddHeader()

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

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

3113 {
3114 #ifndef ENABLE_NLS
3115  (void) translate; /* unused parameter */
3116 #endif
3117 
3118  if (content->header >= content->headers + content->ncolumns)
3119  {
3120  fprintf(stderr, _("Cannot add header to table content: "
3121  "column count of %d exceeded.\n"),
3122  content->ncolumns);
3123  exit(EXIT_FAILURE);
3124  }
3125 
3126  *content->header = (char *) mbvalidate((unsigned char *) header,
3127  content->opt->encoding);
3128 #ifdef ENABLE_NLS
3129  if (translate)
3130  *content->header = _(*content->header);
3131 #endif
3132  content->header++;
3133 
3134  *content->align = align;
3135  content->align++;
3136 }
int encoding
Definition: print.h:120
const printTableOpt * opt
Definition: print.h:147
#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:152
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:209
#define EXIT_FAILURE
Definition: settings.h:154
char * align
Definition: print.h:162
const char ** headers
Definition: print.h:151
#define _(x)
Definition: elog.c:87

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

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

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

◆ printTableInit()

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

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

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

◆ printTableSetFooter()

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

Definition at line 3224 of file print.c.

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

Referenced by add_tablespace_footer().

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

◆ refresh_utf8format()

void refresh_utf8format ( const printTableOpt opt)

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

3576 {
3577  printTextFormat *popt = &pg_utf8format;
3578 
3579  const unicodeStyleBorderFormat *border;
3581  const unicodeStyleColumnFormat *column;
3582 
3583  popt->name = "unicode";
3584 
3588 
3589  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3590  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3592  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3593 
3594  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3598 
3599  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3600  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3603 
3604  /* N/A */
3605  popt->lrule[PRINT_RULE_DATA].hrule = "";
3606  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3607  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3608  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3609 
3610  popt->midvrule_nl = column->vertical;
3611  popt->midvrule_wrap = column->vertical;
3612  popt->midvrule_blank = column->vertical;
3613 
3614  /* Same for all unicode today */
3617  popt->nl_left = unicode_style.nl_left;
3622 
3623  return;
3624 }
const char * midvrule
Definition: print.h:46
const char * vertical
Definition: print.c:111
unicodeStyleColumnFormat column_style[2]
Definition: print.c:130
const char * midvrule_wrap
Definition: print.h:73
static const unicodeStyleFormat unicode_style
Definition: print.c:141
const char * header_nl_left
Definition: print.c:132
const char * header_nl_left
Definition: print.h:75
printTextFormat pg_utf8format
Definition: print.c:100
bool wrap_right_border
Definition: print.h:81
const char * wrap_left
Definition: print.c:136
unicode_linestyle unicode_header_linestyle
Definition: print.h:125
printTextLineFormat lrule[4]
Definition: print.h:71
const char * horizontal
Definition: print.c:122
const char * down_and_left
Definition: print.c:123
const char * name
Definition: print.h:70
const char * up_and_right
Definition: print.c:119
const char * midvrule_blank
Definition: print.h:74
unicode_linestyle unicode_border_linestyle
Definition: print.h:123
const char * header_nl_right
Definition: print.c:133
const char * vertical_and_left[2]
Definition: print.c:106
const char * header_nl_right
Definition: print.h:76
unicodeStyleBorderFormat border_style[2]
Definition: print.c:131
const char * down_and_horizontal[2]
Definition: print.c:114
const char * horizontal
Definition: print.c:104
const char * hrule
Definition: print.h:44
const char * vertical_and_horizontal[2]
Definition: print.c:112
unicode_linestyle unicode_column_linestyle
Definition: print.h:124
const char * midvrule_nl
Definition: print.h:72
const char * left_and_right
Definition: print.c:124
const char * wrap_right
Definition: print.c:137
bool wrap_right_border
Definition: print.c:138
const char * nl_left
Definition: print.c:134
const char * leftvrule
Definition: print.h:45
const char * nl_right
Definition: print.c:135
const char * up_and_horizontal[2]
Definition: print.c:113
const char * down_and_right
Definition: print.c:121
const char * nl_right
Definition: print.h:78
const char * vertical
Definition: print.c:120
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:209
const char * vertical_and_right[2]
Definition: print.c:105
const char * nl_left
Definition: print.h:77
const char * rightvrule
Definition: print.h:47
const char * wrap_left
Definition: print.h:79
const char * wrap_right
Definition: print.h:80
unicodeStyleRowFormat row_style[2]
Definition: print.c:129

◆ restore_sigpipe_trap()

void restore_sigpipe_trap ( void  )

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

2966 {
2967 #ifndef WIN32
2969 #endif
2970 }
#define SIGPIPE
Definition: win32_port.h:159
#define SIG_IGN
Definition: win32_port.h:151
static bool always_ignore_sigpipe
Definition: print.c:46
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 2978 of file print.c.

References always_ignore_sigpipe.

Referenced by setQFout().

2979 {
2980  always_ignore_sigpipe = ignore;
2981 }
static bool always_ignore_sigpipe
Definition: print.c:46

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3525 of file print.c.

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

Referenced by main().

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

Variable Documentation

◆ cancel_pressed

◆ pg_asciiformat

const printTextFormat pg_asciiformat

Definition at line 57 of file print.c.

Referenced by do_pset(), and get_line_style().

◆ pg_asciiformat_old

const printTextFormat pg_asciiformat_old

Definition at line 78 of file print.c.

Referenced by do_pset().

◆ pg_utf8format

printTextFormat pg_utf8format

Definition at line 100 of file print.c.

Referenced by do_pset(), and refresh_utf8format().