PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
print.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * Query-result printing support for frontend code
4  *
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/fe_utils/print.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef PRINT_H
14 #define PRINT_H
15 
16 #include "libpq-fe.h"
17 
18 
19 /* This is not a particularly great place for this ... */
20 #ifndef __CYGWIN__
21 #define DEFAULT_PAGER "more"
22 #else
23 #define DEFAULT_PAGER "less"
24 #endif
25 
27 {
28  PRINT_NOTHING = 0, /* to make sure someone initializes this */
37  /* add your favourite output format here ... */
38 };
39 
40 typedef struct printTextLineFormat
41 {
42  /* Line drawing characters to be used in various contexts */
43  const char *hrule; /* horizontal line character */
44  const char *leftvrule; /* left vertical line (+horizontal) */
45  const char *midvrule; /* intra-column vertical line (+horizontal) */
46  const char *rightvrule; /* right vertical line (+horizontal) */
48 
49 typedef enum printTextRule
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) */
57 
58 typedef enum printTextLineWrap
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 */
65 
66 typedef struct printTextFormat
67 {
68  /* A complete line style */
69  const char *name; /* for display purposes */
70  printTextLineFormat lrule[4]; /* indexed by enum printTextRule */
71  const char *midvrule_nl; /* vertical line for continue after newline */
72  const char *midvrule_wrap; /* vertical line for wrapped data */
73  const char *midvrule_blank; /* vertical line for blank data */
74  const char *header_nl_left; /* left mark after newline */
75  const char *header_nl_right; /* right mark for newline */
76  const char *nl_left; /* left mark after newline */
77  const char *nl_right; /* right mark for newline */
78  const char *wrap_left; /* left mark after wrapped data */
79  const char *wrap_right; /* right mark for wrapped data */
80  bool wrap_right_border; /* use right-hand border for wrap
81  * marks when border=0? */
83 
84 typedef enum unicode_linestyle
85 {
89 
90 struct separator
91 {
92  char *separator;
94 };
95 
96 typedef struct printTableOpt
97 {
98  enum printFormat format; /* see enum above */
99  unsigned short int expanded;/* expanded/vertical output (if supported by
100  * output format); 0=no, 1=yes, 2=auto */
101  unsigned short int border; /* Print a border around the table. 0=none,
102  * 1=dividing lines, 2=full */
103  unsigned short int pager; /* use pager for output (if to stdout and
104  * stdout is a tty) 0=off 1=on 2=always */
105  int pager_min_lines;/* don't use pager unless there are at least
106  * this many lines */
107  bool tuples_only; /* don't output headers, row counts, etc. */
108  bool start_table; /* print start decoration, eg <table> */
109  bool stop_table; /* print stop decoration, eg </table> */
110  bool default_footer; /* allow "(xx rows)" default footer */
111  unsigned long prior_records; /* start offset for record counters */
112  const printTextFormat *line_style; /* line style (NULL for default) */
113  struct separator fieldSep; /* field separator for unaligned text mode */
114  struct separator recordSep; /* record separator for unaligned text mode */
115  bool numericLocale; /* locale-aware numeric units separator and
116  * decimal marker */
117  char *tableAttr; /* attributes for HTML <table ...> */
118  int encoding; /* character encoding */
119  int env_columns; /* $COLUMNS on psql start, 0 is unset */
120  int columns; /* target width for wrapped format */
124 } printTableOpt;
125 
126 /*
127  * Table footers are implemented as a singly-linked list.
128  *
129  * This is so that you don't need to know the number of footers in order to
130  * initialise the printTableContent struct, which is very convenient when
131  * preparing complex footers (as in describeOneTableDetails).
132  */
133 typedef struct printTableFooter
134 {
135  char *data;
138 
139 /*
140  * The table content struct holds all the information which will be displayed
141  * by printTable().
142  */
143 typedef struct printTableContent
144 {
146  const char *title; /* May be NULL */
147  int ncolumns; /* Specified in Init() */
148  int nrows; /* Specified in Init() */
149  const char **headers; /* NULL-terminated array of header strings */
150  const char **header; /* Pointer to the last added header */
151  const char **cells; /* NULL-terminated array of cell content
152  * strings */
153  const char **cell; /* Pointer to the last added cell */
154  long cellsadded; /* Number of cells added this far */
155  bool *cellmustfree; /* true for cells that need to be free()d */
156  printTableFooter *footers; /* Pointer to the first footer */
157  printTableFooter *footer; /* Pointer to the last added footer */
158  char *aligns; /* Array of alignment specifiers; 'l' or 'r',
159  * one per column */
160  char *align; /* Pointer to the last added alignment */
162 
163 typedef struct printQueryOpt
164 {
165  printTableOpt topt; /* the options above */
166  char *nullPrint; /* how to print null entities */
167  char *title; /* override title */
168  char **footers; /* override footer (default is "(xx rows)") */
169  bool translate_header; /* do gettext on column headers */
170  const bool *translate_columns; /* translate_columns[i-1] => do
171  * gettext on col i */
172  int n_translate_columns; /* length of translate_columns[] */
173 } printQueryOpt;
174 
175 
176 extern volatile bool cancel_pressed;
177 
178 extern const printTextFormat pg_asciiformat;
180 extern printTextFormat pg_utf8format; /* ideally would be const, but... */
181 
182 
183 extern void disable_sigpipe_trap(void);
184 extern void restore_sigpipe_trap(void);
185 extern void set_sigpipe_trap_state(bool ignore);
186 
187 extern FILE *PageOutput(int lines, const printTableOpt *topt);
188 extern void ClosePager(FILE *pagerpipe);
189 
190 extern void html_escaped_print(const char *in, FILE *fout);
191 
192 extern void printTableInit(printTableContent *const content,
193  const printTableOpt *opt, const char *title,
194  const int ncolumns, const int nrows);
195 extern void printTableAddHeader(printTableContent *const content,
196  char *header, const bool translate, const char align);
197 extern void printTableAddCell(printTableContent *const content,
198  char *cell, const bool translate, const bool mustfree);
199 extern void printTableAddFooter(printTableContent *const content,
200  const char *footer);
201 extern void printTableSetFooter(printTableContent *const content,
202  const char *footer);
203 extern void printTableCleanup(printTableContent *const content);
204 extern void printTable(const printTableContent *cont,
205  FILE *fout, bool is_pager, FILE *flog);
206 extern void printQuery(const PGresult *result, const printQueryOpt *opt,
207  FILE *fout, bool is_pager, FILE *flog);
208 
209 extern char column_type_alignment(Oid);
210 
211 extern void setDecimalLocale(void);
212 extern const printTextFormat *get_line_style(const printTableOpt *opt);
213 extern void refresh_utf8format(const printTableOpt *opt);
214 
215 #endif /* PRINT_H */
const char * midvrule
Definition: print.h:45
int env_columns
Definition: print.h:119
const char * title
Definition: print.h:146
char * nullPrint
Definition: print.h:166
int encoding
Definition: print.h:118
const printTextFormat * line_style
Definition: print.h:112
const char * midvrule_wrap
Definition: print.h:72
const char * header_nl_left
Definition: print.h:74
bool wrap_right_border
Definition: print.h:80
bool start_table
Definition: print.h:108
enum printFormat format
Definition: print.h:98
printTableOpt topt
Definition: print.h:165
unicode_linestyle
Definition: print.h:84
printTextFormat pg_utf8format
Definition: print.c:102
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2968
unicode_linestyle unicode_header_linestyle
Definition: print.h:123
return result
Definition: formatting.c:1618
printTextLineFormat lrule[4]
Definition: print.h:70
void set_sigpipe_trap_state(bool ignore)
Definition: print.c:2837
void disable_sigpipe_trap(void)
Definition: print.c:2801
unsigned int Oid
Definition: postgres_ext.h:31
const printTableOpt * opt
Definition: print.h:145
const char * name
Definition: print.h:69
printTextLineWrap
Definition: print.h:58
void refresh_utf8format(const printTableOpt *opt)
Definition: print.c:3426
unsigned long prior_records
Definition: print.h:111
bool separator_zero
Definition: print.h:93
void ClosePager(FILE *pagerpipe)
Definition: print.c:2900
volatile bool cancel_pressed
Definition: print.c:46
const char * midvrule_blank
Definition: print.h:73
unicode_linestyle unicode_border_linestyle
Definition: print.h:121
Datum translate(PG_FUNCTION_ARGS)
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3188
struct printTextLineFormat printTextLineFormat
struct printTableFooter * next
Definition: print.h:136
const char ** cell
Definition: print.h:153
struct printTableContent printTableContent
const char * header_nl_right
Definition: print.h:75
bool * cellmustfree
Definition: print.h:155
unsigned short int border
Definition: print.h:101
char * aligns
Definition: print.h:158
unsigned short int expanded
Definition: print.h:99
const char * hrule
Definition: print.h:43
void restore_sigpipe_trap(void)
Definition: print.c:2824
unicode_linestyle unicode_column_linestyle
Definition: print.h:122
const char * midvrule_nl
Definition: print.h:71
bool tuples_only
Definition: print.h:107
printTextRule
Definition: print.h:49
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3008
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3056
const char ** cells
Definition: print.h:151
long cellsadded
Definition: print.h:154
void printTableCleanup(printTableContent *const content)
Definition: print.c:3099
char * tableAttr
Definition: print.h:117
bool translate_header
Definition: print.h:169
const char ** header
Definition: print.h:150
const char * leftvrule
Definition: print.h:44
struct printTableOpt printTableOpt
printTableFooter * footer
Definition: print.h:157
const printTextFormat * get_line_style(const printTableOpt *opt)
Definition: print.c:3412
unsigned short int pager
Definition: print.h:103
bool stop_table
Definition: print.h:109
struct separator fieldSep
Definition: print.h:113
char * title
Definition: print.h:167
int pager_min_lines
Definition: print.h:105
char ** footers
Definition: print.h:168
bool default_footer
Definition: print.h:110
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
const char * nl_right
Definition: print.h:77
int n_translate_columns
Definition: print.h:172
const printTextFormat pg_asciiformat_old
Definition: print.c:80
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
printTableFooter * footers
Definition: print.h:156
void setDecimalLocale(void)
Definition: print.c:3376
bool numericLocale
Definition: print.h:115
void html_escaped_print(const char *in, FILE *fout)
Definition: print.c:1745
const char * nl_left
Definition: print.h:76
const char * rightvrule
Definition: print.h:46
const printTextFormat pg_asciiformat
Definition: print.c:59
const char * wrap_left
Definition: print.h:78
char * data
Definition: print.h:135
char * separator
Definition: print.h:92
char column_type_alignment(Oid)
Definition: print.c:3350
printFormat
Definition: print.h:26
const char * wrap_right
Definition: print.h:79
char * align
Definition: print.h:160
void printTableSetFooter(printTableContent *const content, const char *footer)
Definition: print.c:3081
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2931
const char ** headers
Definition: print.h:149
struct separator recordSep
Definition: print.h:114
const bool * translate_columns
Definition: print.h:170
int columns
Definition: print.h:120
struct printQueryOpt printQueryOpt
struct printTextFormat printTextFormat
FILE * PageOutput(int lines, const printTableOpt *topt)
Definition: print.c:2851
struct printTableFooter printTableFooter