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_UNALIGNED, PRINT_ALIGNED, PRINT_WRAPPED,
  PRINT_HTML, PRINT_ASCIIDOC, PRINT_LATEX, PRINT_LATEX_LONGTABLE,
  PRINT_TROFF_MS
}
 
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

◆ printTableContent

◆ printTableFooter

◆ printTableOpt

◆ printTextFormat

◆ printTextLineFormat

◆ printTextLineWrap

◆ printTextRule

◆ unicode_linestyle

Enumeration Type Documentation

◆ printFormat

Enumerator
PRINT_NOTHING 
PRINT_UNALIGNED 
PRINT_ALIGNED 
PRINT_WRAPPED 
PRINT_HTML 
PRINT_ASCIIDOC 
PRINT_LATEX 
PRINT_LATEX_LONGTABLE 
PRINT_TROFF_MS 

Definition at line 26 of file print.h.

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

◆ printTextLineWrap

Enumerator
PRINT_LINE_WRAP_NONE 
PRINT_LINE_WRAP_WRAP 
PRINT_LINE_WRAP_NEWLINE 

Definition at line 58 of file print.h.

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

◆ printTextRule

Enumerator
PRINT_RULE_TOP 
PRINT_RULE_MIDDLE 
PRINT_RULE_BOTTOM 
PRINT_RULE_DATA 

Definition at line 49 of file print.h.

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

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 84 of file print.h.

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

Definition at line 2902 of file print.c.

References _, cancel_pressed, and restore_sigpipe_trap().

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

2903 {
2904  if (pagerpipe && pagerpipe != stdout)
2905  {
2906  /*
2907  * If printing was canceled midstream, warn about it.
2908  *
2909  * Some pagers like less use Ctrl-C as part of their command set. Even
2910  * so, we abort our processing and warn the user what we did. If the
2911  * pager quit as a result of the SIGINT, this message won't go
2912  * anywhere ...
2913  */
2914  if (cancel_pressed)
2915  fprintf(pagerpipe, _("Interrupted\n"));
2916 
2917  pclose(pagerpipe);
2919  }
2920 }
volatile bool cancel_pressed
Definition: print.c:46
void restore_sigpipe_trap(void)
Definition: print.c:2824
#define _(x)
Definition: elog.c:84

◆ column_type_alignment()

char column_type_alignment ( Oid  )

Definition at line 3352 of file print.c.

References CASHOID, CIDOID, FLOAT4OID, FLOAT8OID, INT2OID, INT4OID, INT8OID, NUMERICOID, OIDOID, and XIDOID.

Referenced by printCrosstab(), and printQuery().

3353 {
3354  char align;
3355 
3356  switch (ftype)
3357  {
3358  case INT2OID:
3359  case INT4OID:
3360  case INT8OID:
3361  case FLOAT4OID:
3362  case FLOAT8OID:
3363  case NUMERICOID:
3364  case OIDOID:
3365  case XIDOID:
3366  case CIDOID:
3367  case CASHOID:
3368  align = 'r';
3369  break;
3370  default:
3371  align = 'l';
3372  break;
3373  }
3374  return align;
3375 }
#define OIDOID
Definition: pg_type.h:328
#define NUMERICOID
Definition: pg_type.h:554
#define INT4OID
Definition: pg_type.h:316
#define XIDOID
Definition: pg_type.h:336
#define INT2OID
Definition: pg_type.h:308
#define FLOAT4OID
Definition: pg_type.h:416
#define CIDOID
Definition: pg_type.h:340
#define INT8OID
Definition: pg_type.h:304
#define FLOAT8OID
Definition: pg_type.h:419
#define CASHOID
Definition: pg_type.h:439

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 2801 of file print.c.

References pqsignal(), SIG_IGN, and SIGPIPE.

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

2802 {
2803 #ifndef WIN32
2805 #endif
2806 }
#define SIGPIPE
Definition: win32_port.h:168
#define SIG_IGN
Definition: win32_port.h:160
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3414 of file print.c.

References printTableOpt::line_style, and pg_asciiformat.

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

3415 {
3416  /*
3417  * Note: this function mainly exists to preserve the convention that a
3418  * printTableOpt struct can be initialized to zeroes to get default
3419  * behavior.
3420  */
3421  if (opt->line_style != NULL)
3422  return opt->line_style;
3423  else
3424  return &pg_asciiformat;
3425 }
const printTextFormat * line_style
Definition: print.h:112
const printTextFormat pg_asciiformat
Definition: print.c:59

◆ html_escaped_print()

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

Definition at line 1745 of file print.c.

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

1746 {
1747  const char *p;
1748  bool leading_space = true;
1749 
1750  for (p = in; *p; p++)
1751  {
1752  switch (*p)
1753  {
1754  case '&':
1755  fputs("&", fout);
1756  break;
1757  case '<':
1758  fputs("&lt;", fout);
1759  break;
1760  case '>':
1761  fputs("&gt;", fout);
1762  break;
1763  case '\n':
1764  fputs("<br />\n", fout);
1765  break;
1766  case '"':
1767  fputs("&quot;", fout);
1768  break;
1769  case ' ':
1770  /* protect leading space, for EXPLAIN output */
1771  if (leading_space)
1772  fputs("&nbsp;", fout);
1773  else
1774  fputs(" ", fout);
1775  break;
1776  default:
1777  fputc(*p, fout);
1778  }
1779  if (*p != ' ')
1780  leading_space = false;
1781  }
1782 }

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 2851 of file print.c.

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

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

2852 {
2853  /* check whether we need / can / are supposed to use pager */
2854  if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
2855  {
2856 #ifdef TIOCGWINSZ
2857  unsigned short int pager = topt->pager;
2858  int min_lines = topt->pager_min_lines;
2859  int result;
2860  struct winsize screen_size;
2861 
2862  result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
2863 
2864  /* >= accounts for a one-line prompt */
2865  if (result == -1
2866  || (lines >= screen_size.ws_row && lines >= min_lines)
2867  || pager > 1)
2868 #endif
2869  {
2870  const char *pagerprog;
2871  FILE *pagerpipe;
2872 
2873  pagerprog = getenv("PSQL_PAGER");
2874  if (!pagerprog)
2875  pagerprog = getenv("PAGER");
2876  if (!pagerprog)
2877  pagerprog = DEFAULT_PAGER;
2878  else
2879  {
2880  /* if PAGER is empty or all-white-space, don't use pager */
2881  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
2882  return stdout;
2883  }
2885  pagerpipe = popen(pagerprog, "w");
2886  if (pagerpipe)
2887  return pagerpipe;
2888  /* if popen fails, silently proceed without pager */
2890  }
2891  }
2892 
2893  return stdout;
2894 }
void disable_sigpipe_trap(void)
Definition: print.c:2801
void restore_sigpipe_trap(void)
Definition: print.c:2824
unsigned short int pager
Definition: print.h:103
int pager_min_lines
Definition: print.h:105
#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 3287 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(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSDictionaries(), listTSParsers(), listTSTemplates(), listUserMappings(), objectDescription(), permissionsList(), PrintQueryTuples(), and PSQLexecWatch().

3289 {
3290  printTableContent cont;
3291  int i,
3292  r,
3293  c;
3294 
3295  if (cancel_pressed)
3296  return;
3297 
3298  printTableInit(&cont, &opt->topt, opt->title,
3299  PQnfields(result), PQntuples(result));
3300 
3301  /* Assert caller supplied enough translate_columns[] entries */
3302  Assert(opt->translate_columns == NULL ||
3303  opt->n_translate_columns >= cont.ncolumns);
3304 
3305  for (i = 0; i < cont.ncolumns; i++)
3306  {
3307  printTableAddHeader(&cont, PQfname(result, i),
3308  opt->translate_header,
3309  column_type_alignment(PQftype(result, i)));
3310  }
3311 
3312  /* set cells */
3313  for (r = 0; r < cont.nrows; r++)
3314  {
3315  for (c = 0; c < cont.ncolumns; c++)
3316  {
3317  char *cell;
3318  bool mustfree = false;
3319  bool translate;
3320 
3321  if (PQgetisnull(result, r, c))
3322  cell = opt->nullPrint ? opt->nullPrint : "";
3323  else
3324  {
3325  cell = PQgetvalue(result, r, c);
3326  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3327  {
3328  cell = format_numeric_locale(cell);
3329  mustfree = true;
3330  }
3331  }
3332 
3333  translate = (opt->translate_columns && opt->translate_columns[c]);
3334  printTableAddCell(&cont, cell, translate, mustfree);
3335  }
3336  }
3337 
3338  /* set footers */
3339  if (opt->footers)
3340  {
3341  char **footer;
3342 
3343  for (footer = opt->footers; *footer; footer++)
3344  printTableAddFooter(&cont, *footer);
3345  }
3346 
3347  printTable(&cont, fout, is_pager, flog);
3348  printTableCleanup(&cont);
3349 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
char * nullPrint
Definition: print.h:166
void printTableCleanup(printTableContent *const content)
Definition: print.c:3101
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2810
printTableOpt topt
Definition: print.h:165
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
Datum translate(PG_FUNCTION_ARGS)
volatile bool cancel_pressed
Definition: print.c:46
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2970
char * aligns
Definition: print.h:158
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3010
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2962
char * c
bool translate_header
Definition: print.h:169
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3190
char column_type_alignment(Oid ftype)
Definition: print.c:3352
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3058
char * title
Definition: print.h:167
char ** footers
Definition: print.h:168
static char * format_numeric_locale(const char *my_str)
Definition: print.c:247
#define Assert(condition)
Definition: c.h:680
int n_translate_columns
Definition: print.h:172
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2933
bool numericLocale
Definition: print.h:115
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
const bool * translate_columns
Definition: print.h:170

◆ printTable()

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

Definition at line 3190 of file print.c.

References _, cancel_pressed, ClosePager(), EXIT_FAILURE, printTableOpt::expanded, printTableOpt::format, IsPagerNeeded(), printTableContent::opt, PRINT_ALIGNED, print_aligned_text(), print_aligned_vertical(), PRINT_ASCIIDOC, print_asciidoc_text(), print_asciidoc_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().

3192 {
3193  bool is_local_pager = false;
3194 
3195  if (cancel_pressed)
3196  return;
3197 
3198  if (cont->opt->format == PRINT_NOTHING)
3199  return;
3200 
3201  /* print_aligned_*() handle the pager themselves */
3202  if (!is_pager &&
3203  cont->opt->format != PRINT_ALIGNED &&
3204  cont->opt->format != PRINT_WRAPPED)
3205  {
3206  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3207  is_local_pager = is_pager;
3208  }
3209 
3210  /* print the stuff */
3211 
3212  if (flog)
3213  print_aligned_text(cont, flog, false);
3214 
3215  switch (cont->opt->format)
3216  {
3217  case PRINT_UNALIGNED:
3218  if (cont->opt->expanded == 1)
3219  print_unaligned_vertical(cont, fout);
3220  else
3221  print_unaligned_text(cont, fout);
3222  break;
3223  case PRINT_ALIGNED:
3224  case PRINT_WRAPPED:
3225 
3226  /*
3227  * In expanded-auto mode, force vertical if a pager is passed in;
3228  * else we may make different decisions for different hunks of the
3229  * query result.
3230  */
3231  if (cont->opt->expanded == 1 ||
3232  (cont->opt->expanded == 2 && is_pager))
3233  print_aligned_vertical(cont, fout, is_pager);
3234  else
3235  print_aligned_text(cont, fout, is_pager);
3236  break;
3237  case PRINT_HTML:
3238  if (cont->opt->expanded == 1)
3239  print_html_vertical(cont, fout);
3240  else
3241  print_html_text(cont, fout);
3242  break;
3243  case PRINT_ASCIIDOC:
3244  if (cont->opt->expanded == 1)
3245  print_asciidoc_vertical(cont, fout);
3246  else
3247  print_asciidoc_text(cont, fout);
3248  break;
3249  case PRINT_LATEX:
3250  if (cont->opt->expanded == 1)
3251  print_latex_vertical(cont, fout);
3252  else
3253  print_latex_text(cont, fout);
3254  break;
3255  case PRINT_LATEX_LONGTABLE:
3256  if (cont->opt->expanded == 1)
3257  print_latex_vertical(cont, fout);
3258  else
3259  print_latex_longtable_text(cont, fout);
3260  break;
3261  case PRINT_TROFF_MS:
3262  if (cont->opt->expanded == 1)
3263  print_troff_ms_vertical(cont, fout);
3264  else
3265  print_troff_ms_text(cont, fout);
3266  break;
3267  default:
3268  fprintf(stderr, _("invalid output format (internal error): %d"),
3269  cont->opt->format);
3270  exit(EXIT_FAILURE);
3271  }
3272 
3273  if (is_local_pager)
3274  ClosePager(fout);
3275 }
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2681
static void print_unaligned_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:460
void ClosePager(FILE *pagerpipe)
Definition: print.c:2902
static void print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:582
enum printFormat format
Definition: print.h:98
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1230
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2589
const printTableOpt * opt
Definition: print.h:145
volatile bool cancel_pressed
Definition: print.c:46
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3150
unsigned short int expanded
Definition: print.h:99
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1786
static void print_latex_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2221
static void print_unaligned_text(const printTableContent *cont, FILE *fout)
Definition: print.c:369
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2088
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1875
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2323
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1978
static void print_latex_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2479
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84

◆ printTableAddCell()

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

Definition at line 3010 of file print.c.

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

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

3012 {
3013 #ifndef ENABLE_NLS
3014  (void) translate; /* unused parameter */
3015 #endif
3016 
3017  if (content->cellsadded >= content->ncolumns * content->nrows)
3018  {
3019  fprintf(stderr, _("Cannot add cell to table content: "
3020  "total cell count of %d exceeded.\n"),
3021  content->ncolumns * content->nrows);
3022  exit(EXIT_FAILURE);
3023  }
3024 
3025  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3026  content->opt->encoding);
3027 
3028 #ifdef ENABLE_NLS
3029  if (translate)
3030  *content->cell = _(*content->cell);
3031 #endif
3032 
3033  if (mustfree)
3034  {
3035  if (content->cellmustfree == NULL)
3036  content->cellmustfree =
3037  pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
3038 
3039  content->cellmustfree[content->cellsadded] = true;
3040  }
3041  content->cell++;
3042  content->cellsadded++;
3043 }
int encoding
Definition: print.h:118
const printTableOpt * opt
Definition: print.h:145
Datum translate(PG_FUNCTION_ARGS)
const char ** cell
Definition: print.h:153
bool * cellmustfree
Definition: print.h:155
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:154
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84

◆ printTableAddFooter()

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

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

3059 {
3060  printTableFooter *f;
3061 
3062  f = pg_malloc0(sizeof(*f));
3063  f->data = pg_strdup(footer);
3064 
3065  if (content->footers == NULL)
3066  content->footers = f;
3067  else
3068  content->footer->next = f;
3069 
3070  content->footer = f;
3071 }
struct printTableFooter * next
Definition: print.h:136
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:157
printTableFooter * footers
Definition: print.h:156
char * data
Definition: print.h:135

◆ printTableAddHeader()

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

Definition at line 2970 of file print.c.

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

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

2972 {
2973 #ifndef ENABLE_NLS
2974  (void) translate; /* unused parameter */
2975 #endif
2976 
2977  if (content->header >= content->headers + content->ncolumns)
2978  {
2979  fprintf(stderr, _("Cannot add header to table content: "
2980  "column count of %d exceeded.\n"),
2981  content->ncolumns);
2982  exit(EXIT_FAILURE);
2983  }
2984 
2985  *content->header = (char *) mbvalidate((unsigned char *) header,
2986  content->opt->encoding);
2987 #ifdef ENABLE_NLS
2988  if (translate)
2989  *content->header = _(*content->header);
2990 #endif
2991  content->header++;
2992 
2993  *content->align = align;
2994  content->align++;
2995 }
int encoding
Definition: print.h:118
const printTableOpt * opt
Definition: print.h:145
Datum translate(PG_FUNCTION_ARGS)
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
const char ** header
Definition: print.h:150
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:208
#define EXIT_FAILURE
Definition: settings.h:152
char * align
Definition: print.h:160
const char ** headers
Definition: print.h:149
#define _(x)
Definition: elog.c:84

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

Definition at line 3101 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, and printTableContent::title.

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

3102 {
3103  if (content->cellmustfree)
3104  {
3105  int i;
3106 
3107  for (i = 0; i < content->nrows * content->ncolumns; i++)
3108  {
3109  if (content->cellmustfree[i])
3110  free((char *) content->cells[i]);
3111  }
3112  free(content->cellmustfree);
3113  content->cellmustfree = NULL;
3114  }
3115  free(content->headers);
3116  free(content->cells);
3117  free(content->aligns);
3118 
3119  content->opt = NULL;
3120  content->title = NULL;
3121  content->headers = NULL;
3122  content->cells = NULL;
3123  content->aligns = NULL;
3124  content->header = NULL;
3125  content->cell = NULL;
3126  content->align = NULL;
3127 
3128  if (content->footers)
3129  {
3130  for (content->footer = content->footers; content->footer;)
3131  {
3132  printTableFooter *f;
3133 
3134  f = content->footer;
3135  content->footer = f->next;
3136  free(f->data);
3137  free(f);
3138  }
3139  }
3140  content->footers = NULL;
3141  content->footer = NULL;
3142 }
const char * title
Definition: print.h:146
const printTableOpt * opt
Definition: print.h:145
struct printTableFooter * next
Definition: print.h:136
const char ** cell
Definition: print.h:153
bool * cellmustfree
Definition: print.h:155
char * aligns
Definition: print.h:158
const char ** cells
Definition: print.h:151
const char ** header
Definition: print.h:150
printTableFooter * footer
Definition: print.h:157
#define free(a)
Definition: header.h:65
printTableFooter * footers
Definition: print.h:156
int i
char * data
Definition: print.h:135
char * align
Definition: print.h:160
const char ** headers
Definition: print.h:149

◆ printTableInit()

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

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

2935 {
2936  content->opt = opt;
2937  content->title = title;
2938  content->ncolumns = ncolumns;
2939  content->nrows = nrows;
2940 
2941  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
2942 
2943  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
2944 
2945  content->cellmustfree = NULL;
2946  content->footers = NULL;
2947 
2948  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
2949 
2950  content->header = content->headers;
2951  content->cell = content->cells;
2952  content->footer = content->footers;
2953  content->align = content->aligns;
2954  content->cellsadded = 0;
2955 }
const char * title
Definition: print.h:146
const printTableOpt * opt
Definition: print.h:145
const char ** cell
Definition: print.h:153
bool * cellmustfree
Definition: print.h:155
char * aligns
Definition: print.h:158
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
const char ** cells
Definition: print.h:151
long cellsadded
Definition: print.h:154
const char ** header
Definition: print.h:150
printTableFooter * footer
Definition: print.h:157
printTableFooter * footers
Definition: print.h:156
char * align
Definition: print.h:160
const char ** headers
Definition: print.h:149

◆ printTableSetFooter()

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

Definition at line 3083 of file print.c.

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

Referenced by add_tablespace_footer().

3084 {
3085  if (content->footers != NULL)
3086  {
3087  free(content->footer->data);
3088  content->footer->data = pg_strdup(footer);
3089  }
3090  else
3091  printTableAddFooter(content, footer);
3092 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3058
printTableFooter * footer
Definition: print.h:157
#define free(a)
Definition: header.h:65
printTableFooter * footers
Definition: print.h:156
char * data
Definition: print.h:135

◆ refresh_utf8format()

void refresh_utf8format ( const printTableOpt opt)

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

3429 {
3430  printTextFormat *popt = &pg_utf8format;
3431 
3432  const unicodeStyleBorderFormat *border;
3434  const unicodeStyleColumnFormat *column;
3435 
3436  popt->name = "unicode";
3437 
3441 
3442  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3443  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3445  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3446 
3447  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3451 
3452  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3453  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3456 
3457  /* N/A */
3458  popt->lrule[PRINT_RULE_DATA].hrule = "";
3459  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3460  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3461  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3462 
3463  popt->midvrule_nl = column->vertical;
3464  popt->midvrule_wrap = column->vertical;
3465  popt->midvrule_blank = column->vertical;
3466 
3467  /* Same for all unicode today */
3470  popt->nl_left = unicode_style.nl_left;
3475 
3476  return;
3477 }
const char * midvrule
Definition: print.h:45
const char * vertical
Definition: print.c:113
unicodeStyleColumnFormat column_style[2]
Definition: print.c:132
const char * midvrule_wrap
Definition: print.h:72
static const unicodeStyleFormat unicode_style
Definition: print.c:143
const char * header_nl_left
Definition: print.c:134
const char * header_nl_left
Definition: print.h:74
printTextFormat pg_utf8format
Definition: print.c:102
bool wrap_right_border
Definition: print.h:80
const char * wrap_left
Definition: print.c:138
unicode_linestyle unicode_header_linestyle
Definition: print.h:123
printTextLineFormat lrule[4]
Definition: print.h:70
const char * horizontal
Definition: print.c:124
const char * down_and_left
Definition: print.c:125
const char * name
Definition: print.h:69
const char * up_and_right
Definition: print.c:121
const char * midvrule_blank
Definition: print.h:73
unicode_linestyle unicode_border_linestyle
Definition: print.h:121
const char * header_nl_right
Definition: print.c:135
const char * vertical_and_left[2]
Definition: print.c:108
const char * header_nl_right
Definition: print.h:75
unicodeStyleBorderFormat border_style[2]
Definition: print.c:133
const char * down_and_horizontal[2]
Definition: print.c:116
const char * horizontal
Definition: print.c:106
const char * hrule
Definition: print.h:43
const char * vertical_and_horizontal[2]
Definition: print.c:114
unicode_linestyle unicode_column_linestyle
Definition: print.h:122
const char * midvrule_nl
Definition: print.h:71
const char * left_and_right
Definition: print.c:126
const char * wrap_right
Definition: print.c:139
bool wrap_right_border
Definition: print.c:140
const char * nl_left
Definition: print.c:136
const char * leftvrule
Definition: print.h:44
const char * nl_right
Definition: print.c:137
const char * up_and_horizontal[2]
Definition: print.c:115
const char * down_and_right
Definition: print.c:123
const char * nl_right
Definition: print.h:77
const char * vertical
Definition: print.c:122
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:208
const char * vertical_and_right[2]
Definition: print.c:107
const char * nl_left
Definition: print.h:76
const char * rightvrule
Definition: print.h:46
const char * wrap_left
Definition: print.h:78
const char * wrap_right
Definition: print.h:79
unicodeStyleRowFormat row_style[2]
Definition: print.c:131

◆ restore_sigpipe_trap()

void restore_sigpipe_trap ( void  )

Definition at line 2824 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(), and setQFout().

2825 {
2826 #ifndef WIN32
2828 #endif
2829 }
#define SIGPIPE
Definition: win32_port.h:168
#define SIG_IGN
Definition: win32_port.h:160
static bool always_ignore_sigpipe
Definition: print.c:48
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
#define SIG_DFL
Definition: win32_port.h:158

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 2837 of file print.c.

References always_ignore_sigpipe.

Referenced by setQFout().

2838 {
2839  always_ignore_sigpipe = ignore;
2840 }
static bool always_ignore_sigpipe
Definition: print.c:48

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3378 of file print.c.

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

Referenced by main().

3379 {
3380  struct lconv *extlconv;
3381 
3382  extlconv = localeconv();
3383 
3384  /* Don't accept an empty decimal_point string */
3385  if (*extlconv->decimal_point)
3386  decimal_point = pg_strdup(extlconv->decimal_point);
3387  else
3388  decimal_point = "."; /* SQL output standard */
3389 
3390  /*
3391  * Although the Open Group standard allows locales to supply more than one
3392  * group width, we consider only the first one, and we ignore any attempt
3393  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3394  * cash.c, we must apply a range check to avoid being fooled by variant
3395  * CHAR_MAX values.
3396  */
3397  groupdigits = *extlconv->grouping;
3398  if (groupdigits <= 0 || groupdigits > 6)
3399  groupdigits = 3; /* most common */
3400 
3401  /* Don't accept an empty thousands_sep string, either */
3402  /* similar code exists in formatting.c */
3403  if (*extlconv->thousands_sep)
3404  thousands_sep = pg_strdup(extlconv->thousands_sep);
3405  /* Make sure thousands separator doesn't match decimal point symbol. */
3406  else if (strcmp(decimal_point, ",") != 0)
3407  thousands_sep = ",";
3408  else
3409  thousands_sep = ".";
3410 }
static int groupdigits
Definition: print.c:52
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * decimal_point
Definition: print.c:51
static char * thousands_sep
Definition: print.c:53

Variable Documentation

◆ cancel_pressed

◆ pg_asciiformat

const printTextFormat pg_asciiformat

Definition at line 59 of file print.c.

Referenced by do_pset(), and get_line_style().

◆ pg_asciiformat_old

const printTextFormat pg_asciiformat_old

Definition at line 80 of file print.c.

Referenced by do_pset().

◆ pg_utf8format

printTextFormat pg_utf8format

Definition at line 102 of file print.c.

Referenced by do_pset(), and refresh_utf8format().