PostgreSQL Source Code  git master
print.h File Reference
#include <signal.h>
#include "libpq-fe.h"
Include dependency graph for print.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  printTextLineFormat
 
struct  printTextFormat
 
struct  separator
 
struct  printTableOpt
 
struct  printTableFooter
 
struct  printTableContent
 
struct  printQueryOpt
 

Macros

#define DEFAULT_PAGER   "more"
 

Typedefs

typedef struct printTextLineFormat printTextLineFormat
 
typedef enum printTextRule printTextRule
 
typedef enum printTextLineWrap printTextLineWrap
 
typedef 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 default) */
73  PRINT_XHEADER_COLUMN, /* only print header line above the first column */
74  PRINT_XHEADER_PAGE, /* header line must not be longer than terminal width */
75  PRINT_XHEADER_EXACT_WIDTH, /* explicitly specified width */
printXheaderWidthType
Definition: print.h:70
@ PRINT_XHEADER_EXACT_WIDTH
Definition: print.h:75
@ PRINT_XHEADER_PAGE
Definition: print.h:74
@ PRINT_XHEADER_COLUMN
Definition: print.h:73
@ PRINT_XHEADER_FULL
Definition: print.h:72

◆ unicode_linestyle

Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 96 of file print.h.

97 {
unicode_linestyle
Definition: print.h:97
@ UNICODE_LINESTYLE_SINGLE
Definition: print.h:98
@ UNICODE_LINESTYLE_DOUBLE
Definition: print.h:99

Function Documentation

◆ ClosePager()

void ClosePager ( FILE *  pagerpipe)

Definition at line 3140 of file print.c.

3141 {
3142  if (pagerpipe && pagerpipe != stdout)
3143  {
3144  /*
3145  * If printing was canceled midstream, warn about it.
3146  *
3147  * Some pagers like less use Ctrl-C as part of their command set. Even
3148  * so, we abort our processing and warn the user what we did. If the
3149  * pager quit as a result of the SIGINT, this message won't go
3150  * anywhere ...
3151  */
3152  if (cancel_pressed)
3153  fprintf(pagerpipe, _("Interrupted\n"));
3154 
3155  pclose(pagerpipe);
3157  }
3158 }
#define _(x)
Definition: elog.c:91
void restore_sigpipe_trap(void)
Definition: print.c:3061
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(), ExecQueryUsingCursor(), helpSQL(), helpVariables(), print_aligned_text(), print_aligned_vertical(), printHistory(), printTable(), slashUsage(), and usage().

◆ column_type_alignment()

char column_type_alignment ( Oid  ftype)

Definition at line 3599 of file print.c.

3600 {
3601  char align;
3602 
3603  switch (ftype)
3604  {
3605  case INT2OID:
3606  case INT4OID:
3607  case INT8OID:
3608  case FLOAT4OID:
3609  case FLOAT8OID:
3610  case NUMERICOID:
3611  case OIDOID:
3612  case XIDOID:
3613  case XID8OID:
3614  case CIDOID:
3615  case MONEYOID:
3616  align = 'r';
3617  break;
3618  default:
3619  align = 'l';
3620  break;
3621  }
3622  return align;
3623 }

Referenced by printCrosstab(), and printQuery().

◆ disable_sigpipe_trap()

void disable_sigpipe_trap ( void  )

Definition at line 3038 of file print.c.

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

References pqsignal(), SIG_IGN, and SIGPIPE.

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

◆ get_line_style()

const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3662 of file print.c.

3663 {
3664  /*
3665  * Note: this function mainly exists to preserve the convention that a
3666  * printTableOpt struct can be initialized to zeroes to get default
3667  * behavior.
3668  */
3669  if (opt->line_style != NULL)
3670  return opt->line_style;
3671  else
3672  return &pg_asciiformat;
3673 }
const printTextFormat pg_asciiformat
Definition: print.c:56
const printTextFormat * line_style
Definition: print.h:126

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 1951 of file print.c.

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

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

◆ PageOutput()

FILE* PageOutput ( int  lines,
const printTableOpt topt 
)

Definition at line 3088 of file print.c.

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

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(), ExecQueryUsingCursor(), helpSQL(), helpVariables(), 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 3534 of file print.c.

3536 {
3537  printTableContent cont;
3538  int i,
3539  r,
3540  c;
3541 
3542  if (cancel_pressed)
3543  return;
3544 
3545  printTableInit(&cont, &opt->topt, opt->title,
3546  PQnfields(result), PQntuples(result));
3547 
3548  /* Assert caller supplied enough translate_columns[] entries */
3549  Assert(opt->translate_columns == NULL ||
3550  opt->n_translate_columns >= cont.ncolumns);
3551 
3552  for (i = 0; i < cont.ncolumns; i++)
3553  {
3554  printTableAddHeader(&cont, PQfname(result, i),
3555  opt->translate_header,
3556  column_type_alignment(PQftype(result, i)));
3557  }
3558 
3559  /* set cells */
3560  for (r = 0; r < cont.nrows; r++)
3561  {
3562  for (c = 0; c < cont.ncolumns; c++)
3563  {
3564  char *cell;
3565  bool mustfree = false;
3566  bool translate;
3567 
3568  if (PQgetisnull(result, r, c))
3569  cell = opt->nullPrint ? opt->nullPrint : "";
3570  else
3571  {
3572  cell = PQgetvalue(result, r, c);
3573  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3574  {
3575  cell = format_numeric_locale(cell);
3576  mustfree = true;
3577  }
3578  }
3579 
3580  translate = (opt->translate_columns && opt->translate_columns[c]);
3581  printTableAddCell(&cont, cell, translate, mustfree);
3582  }
3583  }
3584 
3585  /* set footers */
3586  if (opt->footers)
3587  {
3588  char **footer;
3589 
3590  for (footer = opt->footers; *footer; footer++)
3591  printTableAddFooter(&cont, *footer);
3592  }
3593 
3594  printTable(&cont, fout, is_pager, flog);
3595  printTableCleanup(&cont);
3596 }
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3548
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3310
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3396
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3705
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3730
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3318
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3171
void printTableCleanup(printTableContent *const content)
Definition: print.c:3339
char column_type_alignment(Oid ftype)
Definition: print.c:3599
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3248
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3428
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3296
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3208
static char * format_numeric_locale(const char *my_str)
Definition: print.c:314
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
Datum translate(PG_FUNCTION_ARGS)
char * c
const bool * translate_columns
Definition: print.h:185
printTableOpt topt
Definition: print.h:180
char * nullPrint
Definition: print.h:181
char * title
Definition: print.h:182
char ** footers
Definition: print.h:183
bool translate_header
Definition: print.h:184
int n_translate_columns
Definition: print.h:187
char * aligns
Definition: print.h:173
bool numericLocale
Definition: print.h:130

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(), describeSubscriptions(), describeTablespaces(), describeTypes(), ExecQueryUsingCursor(), 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 3428 of file print.c.

3430 {
3431  bool is_local_pager = false;
3432 
3433  if (cancel_pressed)
3434  return;
3435 
3436  if (cont->opt->format == PRINT_NOTHING)
3437  return;
3438 
3439  /* print_aligned_*() handle the pager themselves */
3440  if (!is_pager &&
3441  cont->opt->format != PRINT_ALIGNED &&
3442  cont->opt->format != PRINT_WRAPPED)
3443  {
3444  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3445  is_local_pager = is_pager;
3446  }
3447 
3448  /* clear any pre-existing error indication on the output stream */
3449  clearerr(fout);
3450 
3451  /* print the stuff */
3452 
3453  if (flog)
3454  print_aligned_text(cont, flog, false);
3455 
3456  switch (cont->opt->format)
3457  {
3458  case PRINT_UNALIGNED:
3459  if (cont->opt->expanded == 1)
3460  print_unaligned_vertical(cont, fout);
3461  else
3462  print_unaligned_text(cont, fout);
3463  break;
3464  case PRINT_ALIGNED:
3465  case PRINT_WRAPPED:
3466 
3467  /*
3468  * In expanded-auto mode, force vertical if a pager is passed in;
3469  * else we may make different decisions for different hunks of the
3470  * query result.
3471  */
3472  if (cont->opt->expanded == 1 ||
3473  (cont->opt->expanded == 2 && is_pager))
3474  print_aligned_vertical(cont, fout, is_pager);
3475  else
3476  print_aligned_text(cont, fout, is_pager);
3477  break;
3478  case PRINT_CSV:
3479  if (cont->opt->expanded == 1)
3480  print_csv_vertical(cont, fout);
3481  else
3482  print_csv_text(cont, fout);
3483  break;
3484  case PRINT_HTML:
3485  if (cont->opt->expanded == 1)
3486  print_html_vertical(cont, fout);
3487  else
3488  print_html_text(cont, fout);
3489  break;
3490  case PRINT_ASCIIDOC:
3491  if (cont->opt->expanded == 1)
3492  print_asciidoc_vertical(cont, fout);
3493  else
3494  print_asciidoc_text(cont, fout);
3495  break;
3496  case PRINT_LATEX:
3497  if (cont->opt->expanded == 1)
3498  print_latex_vertical(cont, fout);
3499  else
3500  print_latex_text(cont, fout);
3501  break;
3502  case PRINT_LATEX_LONGTABLE:
3503  if (cont->opt->expanded == 1)
3504  print_latex_vertical(cont, fout);
3505  else
3506  print_latex_longtable_text(cont, fout);
3507  break;
3508  case PRINT_TROFF_MS:
3509  if (cont->opt->expanded == 1)
3510  print_troff_ms_vertical(cont, fout);
3511  else
3512  print_troff_ms_text(cont, fout);
3513  break;
3514  default:
3515  fprintf(stderr, _("invalid output format (internal error): %d"),
3516  cont->opt->format);
3517  exit(EXIT_FAILURE);
3518  }
3519 
3520  if (is_local_pager)
3521  ClosePager(fout);
3522 }
static void print_asciidoc_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2185
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:2453
static void print_troff_ms_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2826
static void print_html_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1992
static void print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2918
void ClosePager(FILE *pagerpipe)
Definition: print.c:3140
static void print_csv_text(const printTableContent *cont, FILE *fout)
Definition: print.c:1879
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:1919
static void print_html_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2081
static void print_asciidoc_vertical(const printTableContent *cont, FILE *fout)
Definition: print.c:2295
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:2716
static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, FILE **fout, bool *is_pager)
Definition: print.c:3388
static void print_latex_longtable_text(const printTableContent *cont, FILE *fout)
Definition: print.c:2560
static void print_aligned_vertical(const printTableContent *cont, FILE *fout, bool is_pager)
Definition: print.c:1323
exit(1)
#define EXIT_FAILURE
Definition: settings.h:166
const printTableOpt * opt
Definition: print.h:160
unsigned short int expanded
Definition: print.h:111
enum printFormat format
Definition: print.h:110

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 3248 of file print.c.

3250 {
3251 #ifndef ENABLE_NLS
3252  (void) translate; /* unused parameter */
3253 #endif
3254 
3255  if (content->cellsadded >= content->ncolumns * content->nrows)
3256  {
3257  fprintf(stderr, _("Cannot add cell to table content: "
3258  "total cell count of %d exceeded.\n"),
3259  content->ncolumns * content->nrows);
3260  exit(EXIT_FAILURE);
3261  }
3262 
3263  *content->cell = (char *) mbvalidate((unsigned char *) cell,
3264  content->opt->encoding);
3265 
3266 #ifdef ENABLE_NLS
3267  if (translate)
3268  *content->cell = _(*content->cell);
3269 #endif
3270 
3271  if (mustfree)
3272  {
3273  if (content->cellmustfree == NULL)
3274  content->cellmustfree =
3275  pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
3276 
3277  content->cellmustfree[content->cellsadded] = true;
3278  }
3279  content->cell++;
3280  content->cellsadded++;
3281 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
Definition: mbprint.c:392
bool * cellmustfree
Definition: print.h:170
const char ** cell
Definition: print.h:168
long cellsadded
Definition: print.h:169
int encoding
Definition: print.h:133

References _, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cellsadded, printTableOpt::encoding, exit(), EXIT_FAILURE, fprintf, 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 3296 of file print.c.

3297 {
3298  printTableFooter *f;
3299 
3300  f = pg_malloc0(sizeof(*f));
3301  f->data = pg_strdup(footer);
3302 
3303  if (content->footers == NULL)
3304  content->footers = f;
3305  else
3306  content->footer->next = f;
3307 
3308  content->footer = f;
3309 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
printTableFooter * footers
Definition: print.h:171
printTableFooter * footer
Definition: print.h:172
char * data
Definition: print.h:150
struct printTableFooter * next
Definition: print.h:151

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 3208 of file print.c.

3210 {
3211 #ifndef ENABLE_NLS
3212  (void) translate; /* unused parameter */
3213 #endif
3214 
3215  if (content->header >= content->headers + content->ncolumns)
3216  {
3217  fprintf(stderr, _("Cannot add header to table content: "
3218  "column count of %d exceeded.\n"),
3219  content->ncolumns);
3220  exit(EXIT_FAILURE);
3221  }
3222 
3223  *content->header = (char *) mbvalidate((unsigned char *) header,
3224  content->opt->encoding);
3225 #ifdef ENABLE_NLS
3226  if (translate)
3227  *content->header = _(*content->header);
3228 #endif
3229  content->header++;
3230 
3231  *content->align = align;
3232  content->align++;
3233 }
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
char * align
Definition: print.h:175
const char ** header
Definition: print.h:165
const char ** headers
Definition: print.h:164

References _, printTableContent::align, printTableOpt::encoding, exit(), EXIT_FAILURE, fprintf, printTableContent::header, 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 3339 of file print.c.

3340 {
3341  if (content->cellmustfree)
3342  {
3343  int i;
3344 
3345  for (i = 0; i < content->nrows * content->ncolumns; i++)
3346  {
3347  if (content->cellmustfree[i])
3348  free(unconstify(char *, content->cells[i]));
3349  }
3350  free(content->cellmustfree);
3351  content->cellmustfree = NULL;
3352  }
3353  free(content->headers);
3354  free(content->cells);
3355  free(content->aligns);
3356 
3357  content->opt = NULL;
3358  content->title = NULL;
3359  content->headers = NULL;
3360  content->cells = NULL;
3361  content->aligns = NULL;
3362  content->header = NULL;
3363  content->cell = NULL;
3364  content->align = NULL;
3365 
3366  if (content->footers)
3367  {
3368  for (content->footer = content->footers; content->footer;)
3369  {
3370  printTableFooter *f;
3371 
3372  f = content->footer;
3373  content->footer = f->next;
3374  free(f->data);
3375  free(f);
3376  }
3377  }
3378  content->footers = NULL;
3379  content->footer = NULL;
3380 }
#define unconstify(underlying_type, expr)
Definition: c.h:1232
#define free(a)
Definition: header.h:65
const char * title
Definition: print.h:161
const char ** cells
Definition: print.h:166

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

◆ printTableInit()

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

Definition at line 3171 of file print.c.

3173 {
3174  content->opt = opt;
3175  content->title = title;
3176  content->ncolumns = ncolumns;
3177  content->nrows = nrows;
3178 
3179  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
3180 
3181  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
3182 
3183  content->cellmustfree = NULL;
3184  content->footers = NULL;
3185 
3186  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
3187 
3188  content->header = content->headers;
3189  content->cell = content->cells;
3190  content->footer = content->footers;
3191  content->align = content->aligns;
3192  content->cellsadded = 0;
3193 }

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

◆ printTableSetFooter()

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

Definition at line 3321 of file print.c.

3322 {
3323  if (content->footers != NULL)
3324  {
3325  free(content->footer->data);
3326  content->footer->data = pg_strdup(footer);
3327  }
3328  else
3329  printTableAddFooter(content, footer);
3330 }

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 3676 of file print.c.

3677 {
3678  printTextFormat *popt = &pg_utf8format;
3679 
3680  const unicodeStyleBorderFormat *border;
3682  const unicodeStyleColumnFormat *column;
3683 
3684  popt->name = "unicode";
3685 
3689 
3690  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3691  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3693  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3694 
3695  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3696  popt->lrule[PRINT_RULE_MIDDLE].leftvrule = header->vertical_and_right[opt->unicode_border_linestyle];
3698  popt->lrule[PRINT_RULE_MIDDLE].rightvrule = header->vertical_and_left[opt->unicode_border_linestyle];
3699 
3700  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3701  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3704 
3705  /* N/A */
3706  popt->lrule[PRINT_RULE_DATA].hrule = "";
3707  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3708  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3709  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3710 
3711  popt->midvrule_nl = column->vertical;
3712  popt->midvrule_wrap = column->vertical;
3713  popt->midvrule_blank = column->vertical;
3714 
3715  /* Same for all unicode today */
3718  popt->nl_left = unicode_style.nl_left;
3723 }
static const unicodeStyleFormat unicode_style
Definition: print.c:140
printTextFormat pg_utf8format
Definition: print.c:99
unicode_linestyle unicode_border_linestyle
Definition: print.h:136
unicode_linestyle unicode_header_linestyle
Definition: print.h:138
unicode_linestyle unicode_column_linestyle
Definition: print.h:137
bool wrap_right_border
Definition: print.h:92
const char * nl_right
Definition: print.h:89
const char * wrap_left
Definition: print.h:90
const char * midvrule_blank
Definition: print.h:85
const char * header_nl_left
Definition: print.h:86
const char * nl_left
Definition: print.h:88
const char * midvrule_nl
Definition: print.h:83
printTextLineFormat lrule[4]
Definition: print.h:82
const char * wrap_right
Definition: print.h:91
const char * midvrule_wrap
Definition: print.h:84
const char * name
Definition: print.h:81
const char * header_nl_right
Definition: print.h:87
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

References unicodeStyleFormat::border_style, unicodeStyleFormat::column_style, unicodeStyleColumnFormat::down_and_horizontal, unicodeStyleBorderFormat::down_and_left, unicodeStyleBorderFormat::down_and_right, header(), unicodeStyleFormat::header_nl_left, printTextFormat::header_nl_left, unicodeStyleFormat::header_nl_right, printTextFormat::header_nl_right, 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, 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 3061 of file print.c.

3062 {
3063 #ifndef WIN32
3065 #endif
3066 }
static bool always_ignore_sigpipe
Definition: print.c:45
#define SIG_DFL
Definition: win32_port.h:171

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

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

◆ set_sigpipe_trap_state()

void set_sigpipe_trap_state ( bool  ignore)

Definition at line 3074 of file print.c.

3075 {
3076  always_ignore_sigpipe = ignore;
3077 }

References always_ignore_sigpipe.

Referenced by setQFout().

◆ setDecimalLocale()

void setDecimalLocale ( void  )

Definition at line 3626 of file print.c.

3627 {
3628  struct lconv *extlconv;
3629 
3630  extlconv = localeconv();
3631 
3632  /* Don't accept an empty decimal_point string */
3633  if (*extlconv->decimal_point)
3634  decimal_point = pg_strdup(extlconv->decimal_point);
3635  else
3636  decimal_point = "."; /* SQL output standard */
3637 
3638  /*
3639  * Although the Open Group standard allows locales to supply more than one
3640  * group width, we consider only the first one, and we ignore any attempt
3641  * to suppress grouping by specifying CHAR_MAX. As in the backend's
3642  * cash.c, we must apply a range check to avoid being fooled by variant
3643  * CHAR_MAX values.
3644  */
3645  groupdigits = *extlconv->grouping;
3646  if (groupdigits <= 0 || groupdigits > 6)
3647  groupdigits = 3; /* most common */
3648 
3649  /* Don't accept an empty thousands_sep string, either */
3650  /* similar code exists in formatting.c */
3651  if (*extlconv->thousands_sep)
3652  thousands_sep = pg_strdup(extlconv->thousands_sep);
3653  /* Make sure thousands separator doesn't match decimal point symbol. */
3654  else if (strcmp(decimal_point, ",") != 0)
3655  thousands_sep = ",";
3656  else
3657  thousands_sep = ".";
3658 }
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().