PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define DEFAULT_PAGER   "more"

Definition at line 21 of file print.h.

Referenced by PageOutput().

Typedef Documentation

Enumeration Type Documentation

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 };
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
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
Enumerator
UNICODE_LINESTYLE_SINGLE 
UNICODE_LINESTYLE_DOUBLE 

Definition at line 84 of file print.h.

Function Documentation

void ClosePager ( FILE *  pagerpipe)

Definition at line 2900 of file print.c.

References _, cancel_pressed, and restore_sigpipe_trap().

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

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

Definition at line 3350 of file print.c.

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

Referenced by printCrosstab(), and printQuery().

3351 {
3352  char align;
3353 
3354  switch (ftype)
3355  {
3356  case INT2OID:
3357  case INT4OID:
3358  case INT8OID:
3359  case FLOAT4OID:
3360  case FLOAT8OID:
3361  case NUMERICOID:
3362  case OIDOID:
3363  case XIDOID:
3364  case CIDOID:
3365  case CASHOID:
3366  align = 'r';
3367  break;
3368  default:
3369  align = 'l';
3370  break;
3371  }
3372  return align;
3373 }
#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
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 SIG_IGN
Definition: win32.h:185
#define SIGPIPE
Definition: win32.h:193
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
const printTextFormat* get_line_style ( const printTableOpt opt)

Definition at line 3412 of file print.c.

References printTableOpt::line_style, NULL, and pg_asciiformat.

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

3413 {
3414  /*
3415  * Note: this function mainly exists to preserve the convention that a
3416  * printTableOpt struct can be initialized to zeroes to get default
3417  * behavior.
3418  */
3419  if (opt->line_style != NULL)
3420  return opt->line_style;
3421  else
3422  return &pg_asciiformat;
3423 }
const printTextFormat * line_style
Definition: print.h:112
#define NULL
Definition: c.h:229
const printTextFormat pg_asciiformat
Definition: print.c:59
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 }
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, restore_sigpipe_trap(), and result.

Referenced by exec_command_sf(), exec_command_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("PAGER");
2874  if (!pagerprog)
2875  pagerprog = DEFAULT_PAGER;
2876  else
2877  {
2878  /* if PAGER is empty or all-white-space, don't use pager */
2879  if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
2880  return stdout;
2881  }
2883  pagerpipe = popen(pagerprog, "w");
2884  if (pagerpipe)
2885  return pagerpipe;
2886  /* if popen fails, silently proceed without pager */
2888  }
2889  }
2890 
2891  return stdout;
2892 }
void disable_sigpipe_trap(void)
Definition: print.c:2801
return result
Definition: formatting.c:1632
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
void printQuery ( const PGresult result,
const printQueryOpt opt,
FILE *  fout,
bool  is_pager,
FILE *  flog 
)

Definition at line 3285 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, NULL, 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(), 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().

3287 {
3288  printTableContent cont;
3289  int i,
3290  r,
3291  c;
3292 
3293  if (cancel_pressed)
3294  return;
3295 
3296  printTableInit(&cont, &opt->topt, opt->title,
3297  PQnfields(result), PQntuples(result));
3298 
3299  /* Assert caller supplied enough translate_columns[] entries */
3300  Assert(opt->translate_columns == NULL ||
3301  opt->n_translate_columns >= cont.ncolumns);
3302 
3303  for (i = 0; i < cont.ncolumns; i++)
3304  {
3305  printTableAddHeader(&cont, PQfname(result, i),
3306  opt->translate_header,
3307  column_type_alignment(PQftype(result, i)));
3308  }
3309 
3310  /* set cells */
3311  for (r = 0; r < cont.nrows; r++)
3312  {
3313  for (c = 0; c < cont.ncolumns; c++)
3314  {
3315  char *cell;
3316  bool mustfree = false;
3317  bool translate;
3318 
3319  if (PQgetisnull(result, r, c))
3320  cell = opt->nullPrint ? opt->nullPrint : "";
3321  else
3322  {
3323  cell = PQgetvalue(result, r, c);
3324  if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3325  {
3326  cell = format_numeric_locale(cell);
3327  mustfree = true;
3328  }
3329  }
3330 
3331  translate = (opt->translate_columns && opt->translate_columns[c]);
3332  printTableAddCell(&cont, cell, translate, mustfree);
3333  }
3334  }
3335 
3336  /* set footers */
3337  if (opt->footers)
3338  {
3339  char **footer;
3340 
3341  for (footer = opt->footers; *footer; footer++)
3342  printTableAddFooter(&cont, *footer);
3343  }
3344 
3345  printTable(&cont, fout, is_pager, flog);
3346  printTableCleanup(&cont);
3347 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
char * nullPrint
Definition: print.h:166
void printTableCleanup(printTableContent *const content)
Definition: print.c:3099
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2759
printTableOpt topt
Definition: print.h:165
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
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:2968
char * aligns
Definition: print.h:158
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3008
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2911
char * c
bool translate_header
Definition: print.h:169
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3188
char column_type_alignment(Oid ftype)
Definition: print.c:3350
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3056
char * title
Definition: print.h:167
char ** footers
Definition: print.h:168
#define NULL
Definition: c.h:229
static char * format_numeric_locale(const char *my_str)
Definition: print.c:247
#define Assert(condition)
Definition: c.h:675
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:2931
bool numericLocale
Definition: print.h:115
int i
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
const bool * translate_columns
Definition: print.h:170
void printTable ( const printTableContent cont,
FILE *  fout,
bool  is_pager,
FILE *  flog 
)

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

3190 {
3191  bool is_local_pager = false;
3192 
3193  if (cancel_pressed)
3194  return;
3195 
3196  if (cont->opt->format == PRINT_NOTHING)
3197  return;
3198 
3199  /* print_aligned_*() handle the pager themselves */
3200  if (!is_pager &&
3201  cont->opt->format != PRINT_ALIGNED &&
3202  cont->opt->format != PRINT_WRAPPED)
3203  {
3204  IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
3205  is_local_pager = is_pager;
3206  }
3207 
3208  /* print the stuff */
3209 
3210  if (flog)
3211  print_aligned_text(cont, flog, false);
3212 
3213  switch (cont->opt->format)
3214  {
3215  case PRINT_UNALIGNED:
3216  if (cont->opt->expanded == 1)
3217  print_unaligned_vertical(cont, fout);
3218  else
3219  print_unaligned_text(cont, fout);
3220  break;
3221  case PRINT_ALIGNED:
3222  case PRINT_WRAPPED:
3223 
3224  /*
3225  * In expanded-auto mode, force vertical if a pager is passed in;
3226  * else we may make different decisions for different hunks of the
3227  * query result.
3228  */
3229  if (cont->opt->expanded == 1 ||
3230  (cont->opt->expanded == 2 && is_pager))
3231  print_aligned_vertical(cont, fout, is_pager);
3232  else
3233  print_aligned_text(cont, fout, is_pager);
3234  break;
3235  case PRINT_HTML:
3236  if (cont->opt->expanded == 1)
3237  print_html_vertical(cont, fout);
3238  else
3239  print_html_text(cont, fout);
3240  break;
3241  case PRINT_ASCIIDOC:
3242  if (cont->opt->expanded == 1)
3243  print_asciidoc_vertical(cont, fout);
3244  else
3245  print_asciidoc_text(cont, fout);
3246  break;
3247  case PRINT_LATEX:
3248  if (cont->opt->expanded == 1)
3249  print_latex_vertical(cont, fout);
3250  else
3251  print_latex_text(cont, fout);
3252  break;
3253  case PRINT_LATEX_LONGTABLE:
3254  if (cont->opt->expanded == 1)
3255  print_latex_vertical(cont, fout);
3256  else
3257  print_latex_longtable_text(cont, fout);
3258  break;
3259  case PRINT_TROFF_MS:
3260  if (cont->opt->expanded == 1)
3261  print_troff_ms_vertical(cont, fout);
3262  else
3263  print_troff_ms_text(cont, fout);
3264  break;
3265  default:
3266  fprintf(stderr, _("invalid output format (internal error): %d"),
3267  cont->opt->format);
3268  exit(EXIT_FAILURE);
3269  }
3270 
3271  if (is_local_pager)
3272  ClosePager(fout);
3273 }
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:2900
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:3148
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:151
#define _(x)
Definition: elog.c:84
void printTableAddCell ( printTableContent *const  content,
char *  cell,
const bool  translate,
const bool  mustfree 
)

Definition at line 3008 of file print.c.

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

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

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

Definition at line 3056 of file print.c.

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

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

3057 {
3058  printTableFooter *f;
3059 
3060  f = pg_malloc0(sizeof(*f));
3061  f->data = pg_strdup(footer);
3062 
3063  if (content->footers == NULL)
3064  content->footers = f;
3065  else
3066  content->footer->next = f;
3067 
3068  content->footer = f;
3069 }
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
#define NULL
Definition: c.h:229
printTableFooter * footers
Definition: print.h:156
char * data
Definition: print.h:135
void printTableAddHeader ( printTableContent *const  content,
char *  header,
const bool  translate,
const char  align 
)

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

2970 {
2971 #ifndef ENABLE_NLS
2972  (void) translate; /* unused parameter */
2973 #endif
2974 
2975  if (content->header >= content->headers + content->ncolumns)
2976  {
2977  fprintf(stderr, _("Cannot add header to table content: "
2978  "column count of %d exceeded.\n"),
2979  content->ncolumns);
2980  exit(EXIT_FAILURE);
2981  }
2982 
2983  *content->header = (char *) mbvalidate((unsigned char *) header,
2984  content->opt->encoding);
2985 #ifdef ENABLE_NLS
2986  if (translate)
2987  *content->header = _(*content->header);
2988 #endif
2989  content->header++;
2990 
2991  *content->align = align;
2992  content->align++;
2993 }
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:207
#define EXIT_FAILURE
Definition: settings.h:151
char * align
Definition: print.h:160
const char ** headers
Definition: print.h:149
#define _(x)
Definition: elog.c:84
void printTableCleanup ( printTableContent *const  content)

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

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

3100 {
3101  if (content->cellmustfree)
3102  {
3103  int i;
3104 
3105  for (i = 0; i < content->nrows * content->ncolumns; i++)
3106  {
3107  if (content->cellmustfree[i])
3108  free((char *) content->cells[i]);
3109  }
3110  free(content->cellmustfree);
3111  content->cellmustfree = NULL;
3112  }
3113  free(content->headers);
3114  free(content->cells);
3115  free(content->aligns);
3116 
3117  content->opt = NULL;
3118  content->title = NULL;
3119  content->headers = NULL;
3120  content->cells = NULL;
3121  content->aligns = NULL;
3122  content->header = NULL;
3123  content->cell = NULL;
3124  content->align = NULL;
3125 
3126  if (content->footers)
3127  {
3128  for (content->footer = content->footers; content->footer;)
3129  {
3130  printTableFooter *f;
3131 
3132  f = content->footer;
3133  content->footer = f->next;
3134  free(f->data);
3135  free(f);
3136  }
3137  }
3138  content->footers = NULL;
3139  content->footer = NULL;
3140 }
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
#define NULL
Definition: c.h:229
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
void printTableInit ( printTableContent *const  content,
const printTableOpt opt,
const char *  title,
const int  ncolumns,
const int  nrows 
)

Definition at line 2931 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, NULL, printTableContent::opt, pg_malloc0(), and printTableContent::title.

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

2933 {
2934  content->opt = opt;
2935  content->title = title;
2936  content->ncolumns = ncolumns;
2937  content->nrows = nrows;
2938 
2939  content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers));
2940 
2941  content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells));
2942 
2943  content->cellmustfree = NULL;
2944  content->footers = NULL;
2945 
2946  content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align));
2947 
2948  content->header = content->headers;
2949  content->cell = content->cells;
2950  content->footer = content->footers;
2951  content->align = content->aligns;
2952  content->cellsadded = 0;
2953 }
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
#define NULL
Definition: c.h:229
printTableFooter * footers
Definition: print.h:156
char * align
Definition: print.h:160
const char ** headers
Definition: print.h:149
void printTableSetFooter ( printTableContent *const  content,
const char *  footer 
)

Definition at line 3081 of file print.c.

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

Referenced by add_tablespace_footer().

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

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

3427 {
3428  printTextFormat *popt = &pg_utf8format;
3429 
3430  const unicodeStyleBorderFormat *border;
3432  const unicodeStyleColumnFormat *column;
3433 
3434  popt->name = "unicode";
3435 
3439 
3440  popt->lrule[PRINT_RULE_TOP].hrule = border->horizontal;
3441  popt->lrule[PRINT_RULE_TOP].leftvrule = border->down_and_right;
3443  popt->lrule[PRINT_RULE_TOP].rightvrule = border->down_and_left;
3444 
3445  popt->lrule[PRINT_RULE_MIDDLE].hrule = header->horizontal;
3449 
3450  popt->lrule[PRINT_RULE_BOTTOM].hrule = border->horizontal;
3451  popt->lrule[PRINT_RULE_BOTTOM].leftvrule = border->up_and_right;
3454 
3455  /* N/A */
3456  popt->lrule[PRINT_RULE_DATA].hrule = "";
3457  popt->lrule[PRINT_RULE_DATA].leftvrule = border->vertical;
3458  popt->lrule[PRINT_RULE_DATA].midvrule = column->vertical;
3459  popt->lrule[PRINT_RULE_DATA].rightvrule = border->vertical;
3460 
3461  popt->midvrule_nl = column->vertical;
3462  popt->midvrule_wrap = column->vertical;
3463  popt->midvrule_blank = column->vertical;
3464 
3465  /* Same for all unicode today */
3468  popt->nl_left = unicode_style.nl_left;
3473 
3474  return;
3475 }
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:207
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
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 SIG_IGN
Definition: win32.h:185
static bool always_ignore_sigpipe
Definition: print.c:48
#define SIGPIPE
Definition: win32.h:193
#define SIG_DFL
Definition: win32.h:183
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
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
void setDecimalLocale ( void  )

Definition at line 3376 of file print.c.

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

Referenced by main().

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

const printTextFormat pg_asciiformat

Definition at line 59 of file print.c.

Referenced by do_pset(), and get_line_style().

const printTextFormat pg_asciiformat_old

Definition at line 80 of file print.c.

Referenced by do_pset().

printTextFormat pg_utf8format

Definition at line 102 of file print.c.

Referenced by do_pset(), and refresh_utf8format().