PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 enum printXheaderWidthType printXheaderWidthType
 
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  printXheaderWidthType { PRINT_XHEADER_FULL , PRINT_XHEADER_COLUMN , PRINT_XHEADER_PAGE , PRINT_XHEADER_EXACT_WIDTH }
 
enum  unicode_linestyle { UNICODE_LINESTYLE_SINGLE = 0 , UNICODE_LINESTYLE_DOUBLE }
 

Functions

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

Variables

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

Macro Definition Documentation

◆ DEFAULT_PAGER

#define DEFAULT_PAGER   "more"

Definition at line 23 of file print.h.

Typedef Documentation

◆ printQueryOpt

typedef struct printQueryOpt printQueryOpt

◆ printTableContent

◆ printTableFooter

◆ printTableOpt

typedef struct printTableOpt printTableOpt

◆ printTextFormat

◆ printTextLineFormat

◆ printTextLineWrap

◆ printTextRule

◆ printXheaderWidthType

◆ unicode_linestyle

Enumeration Type Documentation

◆ printFormat

Enumerator
PRINT_NOTHING 
PRINT_ALIGNED 
PRINT_ASCIIDOC 
PRINT_CSV 
PRINT_HTML 
PRINT_LATEX 
PRINT_LATEX_LONGTABLE 
PRINT_TROFF_MS 
PRINT_UNALIGNED 
PRINT_WRAPPED 

Definition at line 28 of file print.h.

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

◆ printTextLineWrap

Enumerator
PRINT_LINE_WRAP_NONE 
PRINT_LINE_WRAP_WRAP 
PRINT_LINE_WRAP_NEWLINE 

Definition at line 61 of file print.h.

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

◆ printTextRule

Enumerator
PRINT_RULE_TOP 
PRINT_RULE_MIDDLE 
PRINT_RULE_BOTTOM 
PRINT_RULE_DATA 

Definition at line 52 of file print.h.

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

◆ printXheaderWidthType

Enumerator
PRINT_XHEADER_FULL 
PRINT_XHEADER_COLUMN 
PRINT_XHEADER_PAGE 
PRINT_XHEADER_EXACT_WIDTH 

Definition at line 69 of file print.h.

70 {
71  /* Expanded header line width variants */
72  PRINT_XHEADER_FULL, /* do not truncate header line (this is the
73  * default) */
74  PRINT_XHEADER_COLUMN, /* only print header line above the first
75  * column */
76  PRINT_XHEADER_PAGE, /* header line must not be longer than
77  * terminal width */
78  PRINT_XHEADER_EXACT_WIDTH, /* explicitly specified width */
printXheaderWidthType
Definition: print.h:70
@ PRINT_XHEADER_EXACT_WIDTH
Definition: print.h:78
@ PRINT_XHEADER_PAGE
Definition: print.h:76
@ PRINT_XHEADER_COLUMN
Definition: print.h:74
@ PRINT_XHEADER_FULL
Definition: print.h:72

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 99 of file print.h.

100 {
unicode_linestyle
Definition: print.h:100
@ UNICODE_LINESTYLE_SINGLE
Definition: print.h:101
@ UNICODE_LINESTYLE_DOUBLE
Definition: print.h:102

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

Definition at line 3141 of file print.c.

3142 {
3143  if (pagerpipe && pagerpipe != stdout)
3144  {
3145  /*
3146  * If printing was canceled midstream, warn about it.
3147  *
3148  * Some pagers like less use Ctrl-C as part of their command set. Even
3149  * so, we abort our processing and warn the user what we did. If the
3150  * pager quit as a result of the SIGINT, this message won't go
3151  * anywhere ...
3152  */
3153  if (cancel_pressed)
3154  fprintf(pagerpipe, _("Interrupted\n"));
3155 
3156  pclose(pagerpipe);
3158  }
3159 }
#define _(x)
Definition: elog.c:90
void restore_sigpipe_trap(void)
Definition: print.c:3062
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
#define fprintf
Definition: port.h:242

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

Referenced by exec_command_sf_sv(), ExecQueryAndProcessResults(), print_aligned_text(), print_aligned_vertical(), printHistory(), printTable(), slashUsage(), and usage().

◆ column_type_alignment()

char column_type_alignment ( Oid  ftype)

Definition at line 3614 of file print.c.

3615 {
3616  char align;
3617 
3618  switch (ftype)
3619  {
3620  case INT2OID:
3621  case INT4OID:
3622  case INT8OID:
3623  case FLOAT4OID:
3624  case FLOAT8OID:
3625  case NUMERICOID:
3626  case OIDOID:
3627  case XIDOID:
3628  case XID8OID:
3629  case CIDOID:
3630  case MONEYOID:
3631  align = 'r';
3632  break;
3633  default:
3634  align = 'l';
3635  break;
3636  }
3637  return align;
3638 }

Referenced by printCrosstab(), and printQuery().

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 3039 of file print.c.

3040 {
3041 #ifndef WIN32
3043 #endif
3044 }
pqsigfunc pqsignal(int signo, pqsigfunc func)
#define SIGPIPE
Definition: win32_port.h:173
#define SIG_IGN
Definition: win32_port.h:165

References pqsignal(), SIG_IGN, and SIGPIPE.

Referenced by do_copy(), do_watch(), exec_command_write(), PageOutput(), and SetupGOutput().

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3677 of file print.c.

3678 {
3679  /*
3680  * Note: this function mainly exists to preserve the convention that a
3681  * printTableOpt struct can be initialized to zeroes to get default
3682  * behavior.
3683  */
3684  if (opt->line_style != NULL)
3685  return opt->line_style;
3686  else
3687  return &pg_asciiformat;
3688 }
const printTextFormat pg_asciiformat
Definition: print.c:56
const printTextFormat * line_style
Definition: print.h:131

References printTableOpt::line_style, and pg_asciiformat.

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

◆ html_escaped_print()

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

Definition at line 1952 of file print.c.

1953 {
1954  const char *p;
1955  bool leading_space = true;
1956 
1957  for (p = in; *p; p++)
1958  {
1959  switch (*p)
1960  {
1961  case '&':
1962  fputs("&amp;", fout);
1963  break;
1964  case '<':
1965  fputs("&lt;", fout);
1966  break;
1967  case '>':
1968  fputs("&gt;", fout);
1969  break;
1970  case '\n':
1971  fputs("<br />\n", fout);
1972  break;
1973  case '"':
1974  fputs("&quot;", fout);
1975  break;
1976  case ' ':
1977  /* protect leading space, for EXPLAIN output */
1978  if (leading_space)
1979  fputs("&nbsp;", fout);
1980  else
1981  fputs(" ", fout);
1982  break;
1983  default:
1984  fputc(*p, fout);
1985  }
1986  if (*p != ' ')
1987  leading_space = false;
1988  }
1989 }

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

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 3089 of file print.c.

3090 {
3091  /* check whether we need / can / are supposed to use pager */
3092  if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
3093  {
3094 #ifdef TIOCGWINSZ
3095  unsigned short int pager = topt->pager;
3096  int min_lines = topt->pager_min_lines;
3097  int result;
3098  struct winsize screen_size;
3099 
3100  result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
3101 
3102  /* >= accounts for a one-line prompt */
3103  if (result == -1
3104  || (lines >= screen_size.ws_row && lines >= min_lines)
3105  || pager > 1)
3106 #endif
3107  {
3108  const char *pagerprog;
3109  FILE *pagerpipe;
3110 
3111  pagerprog = getenv("PSQL_PAGER");
3112  if (!pagerprog)
3113  pagerprog = getenv("PAGER");
3114  if (!pagerprog)
3115  pagerprog = DEFAULT_PAGER;
3116  else
3117  {
3118  /* if PAGER is empty or all-white-space, don't use pager */
3119  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
3120  return stdout;
3121  }
3122  fflush(NULL);
3124  pagerpipe = popen(pagerprog, "w");
3125  if (pagerpipe)
3126  return pagerpipe;
3127  /* if popen fails, silently proceed without pager */
3129  }
3130  }
3131 
3132  return stdout;
3133 }
void disable_sigpipe_trap(void)
Definition: print.c:3039
#define DEFAULT_PAGER
Definition: print.h:23
static void const char fflush(stdout)
int pager_min_lines
Definition: print.h:124
unsigned short int pager
Definition: print.h:122

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

Referenced by exec_command_sf_sv(), ExecQueryAndProcessResults(), IsPagerNeeded(), print_aligned_text(), printHistory(), slashUsage(), and usage().

◆ printQuery()

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

Definition at line 3549 of file print.c.

3551 {
3552  printTableContent cont;
3553  int i,
3554  r,
3555  c;
3556 
3557  if (cancel_pressed)
3558  return;
3559 
3560  printTableInit(&cont, &opt->topt, opt->title,
3561  PQnfields(result), PQntuples(result));
3562 
3563  /* Assert caller supplied enough translate_columns[] entries */
3564  Assert(opt->translate_columns == NULL ||
3565  opt->n_translate_columns >= cont.ncolumns);
3566 
3567  for (i = 0; i < cont.ncolumns; i++)
3568  {
3569  printTableAddHeader(&cont, PQfname(result, i),
3570  opt->translate_header,
3571  column_type_alignment(PQftype(result, i)));
3572  }
3573 
3574  /* set cells */
3575  for (r = 0; r < cont.nrows; r++)
3576  {
3577  for (c = 0; c < cont.ncolumns; c++)
3578  {
3579  char *cell;
3580  bool mustfree = false;
3581  bool translate;
3582 
3583  if (PQgetisnull(result, r, c))
3584  cell = opt->nullPrint ? opt->nullPrint : "";
3585  else
3586  {
3587  cell = PQgetvalue(result, r, c);
3588  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3589  {
3590  cell = format_numeric_locale(cell);
3591  mustfree = true;
3592  }
3593  }
3594 
3595  translate = (opt->translate_columns && opt->translate_columns[c]);
3596  printTableAddCell(&cont, cell, translate, mustfree);
3597  }
3598  }
3599 
3600  /* set footers */
3601  if (opt->footers)
3602  {
3603  char **footer;
3604 
3605  for (footer = opt->footers; *footer; footer++)
3606  printTableAddFooter(&cont, *footer);
3607  }
3608 
3609  printTable(&cont, fout, is_pager, flog);
3610  printTableCleanup(&cont);
3611 }
#define Assert(condition)
Definition: c.h:863
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3719
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3567
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3489
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3172
void printTableCleanup(printTableContent *const content)
Definition: print.c:3353
char column_type_alignment(Oid ftype)
Definition: print.c:3614
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3260
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3443
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3310
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3220
static char * format_numeric_locale(const char *my_str)
Definition: print.c:314
int i
Definition: isn.c:72
Datum translate(PG_FUNCTION_ARGS)
char * c
const bool * translate_columns
Definition: print.h:190
printTableOpt topt
Definition: print.h:185
char * nullPrint
Definition: print.h:186
char * title
Definition: print.h:187
char ** footers
Definition: print.h:188
bool translate_header
Definition: print.h:189
int n_translate_columns
Definition: print.h:192
char * aligns
Definition: print.h:178
bool numericLocale
Definition: print.h:135

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

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

◆ printTable()

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

Definition at line 3443 of file print.c.

3445 {
3446  bool is_local_pager = false;
3447 
3448  if (cancel_pressed)
3449  return;
3450 
3451  if (cont->opt->format == PRINT_NOTHING)
3452  return;
3453 
3454  /* print_aligned_*() handle the pager themselves */
3455  if (!is_pager &&
3456  cont->opt->format != PRINT_ALIGNED &&
3457  cont->opt->format != PRINT_WRAPPED)
3458  {
3459  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3460  is_local_pager = is_pager;
3461  }
3462 
3463  /* clear any pre-existing error indication on the output stream */
3464  clearerr(fout);
3465 
3466  /* print the stuff */
3467 
3468  if (flog)
3469  print_aligned_text(cont, flog, false);
3470 
3471  switch (cont->opt->format)
3472  {
3473  case PRINT_UNALIGNED:
3474  if (cont->opt->expanded == 1)
3475  print_unaligned_vertical(cont, fout);
3476  else
3477  print_unaligned_text(cont, fout);
3478  break;
3479  case PRINT_ALIGNED:
3480  case PRINT_WRAPPED:
3481 
3482  /*
3483  * In expanded-auto mode, force vertical if a pager is passed in;
3484  * else we may make different decisions for different hunks of the
3485  * query result.
3486  */
3487  if (cont->opt->expanded == 1 ||
3488  (cont->opt->expanded == 2 && is_pager))
3489  print_aligned_vertical(cont, fout, is_pager);
3490  else
3491  print_aligned_text(cont, fout, is_pager);
3492  break;
3493  case PRINT_CSV:
3494  if (cont->opt->expanded == 1)
3495  print_csv_vertical(cont, fout);
3496  else
3497  print_csv_text(cont, fout);
3498  break;
3499  case PRINT_HTML:
3500  if (cont->opt->expanded == 1)
3501  print_html_vertical(cont, fout);
3502  else
3503  print_html_text(cont, fout);
3504  break;
3505  case PRINT_ASCIIDOC:
3506  if (cont->opt->expanded == 1)
3507  print_asciidoc_vertical(cont, fout);
3508  else
3509  print_asciidoc_text(cont, fout);
3510  break;
3511  case PRINT_LATEX:
3512  if (cont->opt->expanded == 1)
3513  print_latex_vertical(cont, fout);
3514  else
3515  print_latex_text(cont, fout);
3516  break;
3517  case PRINT_LATEX_LONGTABLE:
3518  if (cont->opt->expanded == 1)
3519  print_latex_vertical(cont, fout);
3520  else
3521  print_latex_longtable_text(cont, fout);
3522  break;
3523  case PRINT_TROFF_MS:
3524  if (cont->opt->expanded == 1)
3525  print_troff_ms_vertical(cont, fout);
3526  else
3527  print_troff_ms_text(cont, fout);
3528  break;
3529  default:
3530  fprintf(stderr, _("invalid output format (internal error): %d"),
3531  cont->opt->format);
3532  exit(EXIT_FAILURE);
3533  }
3534 
3535  if (is_local_pager)
3536  ClosePager(fout);
3537 }
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2186
static void print_unaligned_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:513
static void print_latex_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2454
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2827
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1993
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2919
void ClosePager(FILE *pagerpipe)
Definition: print.c:3141
static void print_csv_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1880
static void print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:635
static void print_csv_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:1920
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2082
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2296
static void print_unaligned_text(const printTableContent *cont, FILE *fout)
Definition: print.c:422
static void print_latex_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2717
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3403
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2561
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1324
exit(1)
#define EXIT_FAILURE
Definition: settings.h:178
const printTableOpt * opt
Definition: print.h:165
unsigned short int expanded
Definition: print.h:114
enum printFormat format
Definition: print.h:113

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

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

◆ printTableAddCell()

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

Definition at line 3260 of file print.c.

3262 {
3263  uint64 total_cells;
3264 
3265 #ifndef ENABLE_NLS
3266  (void) translate; /* unused parameter */
3267 #endif
3268 
3269  total_cells = (uint64) content->ncolumns * content->nrows;
3270  if (content->cellsadded >= total_cells)
3271  {
3272  fprintf(stderr, _("Cannot add cell to table content: total cell count of %lld exceeded.\n"),
3273  (long long int) total_cells);
3274  exit(EXIT_FAILURE);
3275  }
3276 
3277  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3278  content->opt->encoding);
3279 
3280 #ifdef ENABLE_NLS
3281  if (translate)
3282  *content->cell = _(*content->cell);
3283 #endif
3284 
3285  if (mustfree)
3286  {
3287  if (content->cellmustfree == NULL)
3288  content->cellmustfree =
3289  pg_malloc0((total_cells + 1) * sizeof(bool));
3290 
3291  content->cellmustfree[content->cellsadded] = true;
3292  }
3293  content->cell++;
3294  content->cellsadded++;
3295 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
uint64 cellsadded
Definition: print.h:174
bool * cellmustfree
Definition: print.h:175
const char ** cell
Definition: print.h:173
int encoding
Definition: print.h:138

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

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

◆ printTableAddFooter()

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

Definition at line 3310 of file print.c.

3311 {
3312  printTableFooter *f;
3313 
3314  f = pg_malloc0(sizeof(*f));
3315  f->data = pg_strdup(footer);
3316 
3317  if (content->footers == NULL)
3318  content->footers = f;
3319  else
3320  content->footer->next = f;
3321 
3322  content->footer = f;
3323 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
printTableFooter * footers
Definition: print.h:176
printTableFooter * footer
Definition: print.h:177
char * data
Definition: print.h:155
struct printTableFooter * next
Definition: print.h:156

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

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

◆ printTableAddHeader()

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

Definition at line 3220 of file print.c.

3222 {
3223 #ifndef ENABLE_NLS
3224  (void) translate; /* unused parameter */
3225 #endif
3226 
3227  if (content->header >= content->headers + content->ncolumns)
3228  {
3229  fprintf(stderr, _("Cannot add header to table content: "
3230  "column count of %d exceeded.\n"),
3231  content->ncolumns);
3232  exit(EXIT_FAILURE);
3233  }
3234 
3235  *content->header = (char *) mbvalidate((unsigned char *) header,
3236  content->opt->encoding);
3237 #ifdef ENABLE_NLS
3238  if (translate)
3239  *content->header = _(*content->header);
3240 #endif
3241  content->header++;
3242 
3243  *content->align = align;
3244  content->align++;
3245 }
char * align
Definition: print.h:180
const char ** header
Definition: print.h:170
const char ** headers
Definition: print.h:169

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

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

◆ printTableCleanup()

void printTableCleanup ( printTableContent *const  content)

Definition at line 3353 of file print.c.

3354 {
3355  if (content->cellmustfree)
3356  {
3357  uint64 total_cells;
3358 
3359  total_cells = (uint64) content->ncolumns * content->nrows;
3360  for (uint64 i = 0; i < total_cells; i++)
3361  {
3362  if (content->cellmustfree[i])
3363  free(unconstify(char *, content->cells[i]));
3364  }
3365  free(content->cellmustfree);
3366  content->cellmustfree = NULL;
3367  }
3368  free(content->headers);
3369  free(content->cells);
3370  free(content->aligns);
3371 
3372  content->opt = NULL;
3373  content->title = NULL;
3374  content->headers = NULL;
3375  content->cells = NULL;
3376  content->aligns = NULL;
3377  content->header = NULL;
3378  content->cell = NULL;
3379  content->align = NULL;
3380 
3381  if (content->footers)
3382  {
3383  for (content->footer = content->footers; content->footer;)
3384  {
3385  printTableFooter *f;
3386 
3387  f = content->footer;
3388  content->footer = f->next;
3389  free(f->data);
3390  free(f);
3391  }
3392  }
3393  content->footers = NULL;
3394  content->footer = NULL;
3395 }
#define unconstify(underlying_type, expr)
Definition: c.h:1250
for(;;)
#define free(a)
Definition: header.h:65
const char * title
Definition: print.h:166
const char ** cells
Definition: print.h:171

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

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

◆ printTableInit()

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

Definition at line 3172 of file print.c.

3174 {
3175  uint64 total_cells;
3176 
3177  content->opt = opt;
3178  content->title = title;
3179  content->ncolumns = ncolumns;
3180  content->nrows = nrows;
3181 
3182  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
3183 
3184  total_cells = (uint64) ncolumns * nrows;
3185  /* Catch possible overflow. Using >= here allows adding 1 below */
3186  if (total_cells >= SIZE_MAX / sizeof(*content->cells))
3187  {
3188  fprintf(stderr, _("Cannot print table contents: number of cells %lld is equal to or exceeds maximum %lld.\n"),
3189  (long long int) total_cells,
3190  (long long int) (SIZE_MAX / sizeof(*content->cells)));
3191  exit(EXIT_FAILURE);
3192  }
3193  content->cells = pg_malloc0((total_cells + 1) * sizeof(*content->cells));
3194 
3195  content->cellmustfree = NULL;
3196  content->footers = NULL;
3197 
3198  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
3199 
3200  content->header = content->headers;
3201  content->cell = content->cells;
3202  content->footer = content->footers;
3203  content->align = content->aligns;
3204  content->cellsadded = 0;
3205 }

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

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

◆ printTableSetFooter()

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

Definition at line 3335 of file print.c.

3336 {
3337  if (content->footers != NULL)
3338  {
3339  free(content->footer->data);
3340  content->footer->data = pg_strdup(footer);
3341  }
3342  else
3343  printTableAddFooter(content, footer);
3344 }

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

Referenced by add_tablespace_footer().

◆ refresh_utf8format()

void refresh_utf8format ( const printTableOpt opt)

Definition at line 3691 of file print.c.

3692 {
3693  printTextFormat *popt = &pg_utf8format;
3694 
3695  const unicodeStyleBorderFormat *border;
3696  const unicodeStyleRowFormat *header;
3697  const unicodeStyleColumnFormat *column;
3698 
3699  popt->name = "unicode";
3700 
3704 
3705  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3706  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3708  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3709 
3710  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3714 
3715  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3716  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3719 
3720  /* N/A */
3721  popt->lrule[PRINT_RULE_DATA].hrule = "";
3722  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3723  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3724  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3725 
3726  popt->midvrule_nl = column->vertical;
3727  popt->midvrule_wrap = column->vertical;
3728  popt->midvrule_blank = column->vertical;
3729 
3730  /* Same for all unicode today */
3733  popt->nl_left = unicode_style.nl_left;
3738 }
static const unicodeStyleFormat unicode_style
Definition: print.c:140
printTextFormat pg_utf8format
Definition: print.c:99
unicode_linestyle unicode_border_linestyle
Definition: print.h:141
unicode_linestyle unicode_header_linestyle
Definition: print.h:143
unicode_linestyle unicode_column_linestyle
Definition: print.h:142
bool wrap_right_border
Definition: print.h:95
const char * nl_right
Definition: print.h:92
const char * wrap_left
Definition: print.h:93
const char * midvrule_blank
Definition: print.h:88
const char * header_nl_left
Definition: print.h:89
const char * nl_left
Definition: print.h:91
const char * midvrule_nl
Definition: print.h:86
printTextLineFormat lrule[4]
Definition: print.h:85
const char * wrap_right
Definition: print.h:94
const char * midvrule_wrap
Definition: print.h:87
const char * name
Definition: print.h:84
const char * header_nl_right
Definition: print.h:90
const char * hrule
Definition: print.h:46
const char * rightvrule
Definition: print.h:49
const char * midvrule
Definition: print.h:48
const char * leftvrule
Definition: print.h:47
const char * up_and_right
Definition: print.c:118
const char * left_and_right
Definition: print.c:123
const char * vertical
Definition: print.c:119
const char * down_and_left
Definition: print.c:122
const char * horizontal
Definition: print.c:121
const char * down_and_right
Definition: print.c:120
const char * vertical_and_horizontal[2]
Definition: print.c:111
const char * up_and_horizontal[2]
Definition: print.c:112
const char * vertical
Definition: print.c:110
const char * down_and_horizontal[2]
Definition: print.c:113
unicodeStyleRowFormat row_style[2]
Definition: print.c:128
unicodeStyleColumnFormat column_style[2]
Definition: print.c:129
const char * nl_right
Definition: print.c:134
const char * wrap_right
Definition: print.c:136
const char * header_nl_left
Definition: print.c:131
const char * header_nl_right
Definition: print.c:132
unicodeStyleBorderFormat border_style[2]
Definition: print.c:130
const char * nl_left
Definition: print.c:133
const char * wrap_left
Definition: print.c:135
bool wrap_right_border
Definition: print.c:137
const char * vertical_and_right[2]
Definition: print.c:104
const char * vertical_and_left[2]
Definition: print.c:105
const char * horizontal
Definition: print.c:103

References unicodeStyleFormat::border_style, unicodeStyleFormat::column_style, unicodeStyleColumnFormat::down_and_horizontal, unicodeStyleBorderFormat::down_and_left, unicodeStyleBorderFormat::down_and_right, unicodeStyleFormat::header_nl_left, printTextFormat::header_nl_left, unicodeStyleFormat::header_nl_right, printTextFormat::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, unicodeStyleFormat::nl_left, printTextFormat::nl_left, unicodeStyleFormat::nl_right, printTextFormat::nl_right, pg_utf8format, PRINT_RULE_BOTTOM, PRINT_RULE_DATA, PRINT_RULE_MIDDLE, PRINT_RULE_TOP, printTextLineFormat::rightvrule, unicodeStyleFormat::row_style, printTableOpt::unicode_border_linestyle, printTableOpt::unicode_column_linestyle, printTableOpt::unicode_header_linestyle, unicode_style, unicodeStyleColumnFormat::up_and_horizontal, unicodeStyleBorderFormat::up_and_right, unicodeStyleColumnFormat::vertical, unicodeStyleBorderFormat::vertical, unicodeStyleColumnFormat::vertical_and_horizontal, unicodeStyleRowFormat::vertical_and_left, unicodeStyleRowFormat::vertical_and_right, unicodeStyleFormat::wrap_left, printTextFormat::wrap_left, unicodeStyleFormat::wrap_right, printTextFormat::wrap_right, unicodeStyleFormat::wrap_right_border, and printTextFormat::wrap_right_border.

Referenced by do_pset(), and main().

◆ restore_sigpipe_trap()

void restore_sigpipe_trap ( void  )

Definition at line 3062 of file print.c.

3063 {
3064 #ifndef WIN32
3066 #endif
3067 }
static bool always_ignore_sigpipe
Definition: print.c:45
#define SIG_DFL
Definition: win32_port.h:163

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

Referenced by CloseGOutput(), ClosePager(), do_copy(), do_watch(), exec_command_write(), PageOutput(), and setQFout().

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 3075 of file print.c.

3076 {
3077  always_ignore_sigpipe = ignore;
3078 }

References always_ignore_sigpipe.

Referenced by setQFout().

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3641 of file print.c.

3642 {
3643  struct lconv *extlconv;
3644 
3645  extlconv = localeconv();
3646 
3647  /* Don't accept an empty decimal_point string */
3648  if (*extlconv->decimal_point)
3649  decimal_point = pg_strdup(extlconv->decimal_point);
3650  else
3651  decimal_point = "."; /* SQL output standard */
3652 
3653  /*
3654  * Although the Open Group standard allows locales to supply more than one
3655  * group width, we consider only the first one, and we ignore any attempt
3656  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3657  * cash.c, we must apply a range check to avoid being fooled by variant
3658  * CHAR_MAX values.
3659  */
3660  groupdigits = *extlconv->grouping;
3661  if (groupdigits <= 0 || groupdigits > 6)
3662  groupdigits = 3; /* most common */
3663 
3664  /* Don't accept an empty thousands_sep string, either */
3665  /* similar code exists in formatting.c */
3666  if (*extlconv->thousands_sep)
3667  thousands_sep = pg_strdup(extlconv->thousands_sep);
3668  /* Make sure thousands separator doesn't match decimal point symbol. */
3669  else if (strcmp(decimal_point, ",") != 0)
3670  thousands_sep = ",";
3671  else
3672  thousands_sep = ".";
3673 }
static char * thousands_sep
Definition: print.c:50
static char * decimal_point
Definition: print.c:48
static int groupdigits
Definition: print.c:49

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

Referenced by main().

Variable Documentation

◆ cancel_pressed

◆ pg_asciiformat

PGDLLIMPORT const printTextFormat pg_asciiformat
extern

Definition at line 56 of file print.c.

Referenced by do_pset(), and get_line_style().

◆ pg_asciiformat_old

PGDLLIMPORT const printTextFormat pg_asciiformat_old
extern

Definition at line 77 of file print.c.

Referenced by do_pset(), and print_aligned_vertical().

◆ pg_utf8format

PGDLLIMPORT printTextFormat pg_utf8format
extern

Definition at line 99 of file print.c.

Referenced by do_pset(), and refresh_utf8format().