2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2012, PostgreSQL Global Development Group
16 PRINT_NOTHING = 0, /* to make sure someone initializes this */
23 /* add your favourite output format here ... */
26 typedef struct printTextLineFormat
28 /* Line drawing characters to be used in various contexts */
29 const char *hrule; /* horizontal line character */
30 const char *leftvrule; /* left vertical line (+horizontal) */
31 const char *midvrule; /* intra-column vertical line (+horizontal) */
32 const char *rightvrule; /* right vertical line (+horizontal) */
33 } printTextLineFormat;
35 typedef enum printTextRule
37 /* Additional context for selecting line drawing characters */
38 PRINT_RULE_TOP, /* top horizontal line */
39 PRINT_RULE_MIDDLE, /* intra-data horizontal line */
40 PRINT_RULE_BOTTOM, /* bottom horizontal line */
41 PRINT_RULE_DATA /* data line (hrule is unused here) */
44 typedef enum printTextLineWrap
46 /* Line wrapping conditions */
47 PRINT_LINE_WRAP_NONE, /* No wrapping */
48 PRINT_LINE_WRAP_WRAP, /* Wraparound due to overlength line */
49 PRINT_LINE_WRAP_NEWLINE /* Newline in data */
52 typedef struct printTextFormat
54 /* A complete line style */
55 const char *name; /* for display purposes */
56 printTextLineFormat lrule[4]; /* indexed by enum printTextRule */
57 const char *midvrule_nl; /* vertical line for continue after newline */
58 const char *midvrule_wrap; /* vertical line for wrapped data */
59 const char *midvrule_blank; /* vertical line for blank data */
60 const char *header_nl_left; /* left mark after newline */
61 const char *header_nl_right; /* right mark for newline */
62 const char *nl_left; /* left mark after newline */
63 const char *nl_right; /* right mark for newline */
64 const char *wrap_left; /* left mark after wrapped data */
65 const char *wrap_right; /* right mark for wrapped data */
66 bool wrap_right_border; /* use right-hand border for wrap
67 * marks when border=0? */
76 typedef struct printTableOpt
78 enum printFormat format; /* see enum above */
79 unsigned short int expanded;/* expanded/vertical output (if supported by
80 * output format); 0=no, 1=yes, 2=auto */
81 unsigned short int border; /* Print a border around the table. 0=none,
82 * 1=dividing lines, 2=full */
83 unsigned short int pager; /* use pager for output (if to stdout and
84 * stdout is a tty) 0=off 1=on 2=always */
85 bool tuples_only; /* don't output headers, row counts, etc. */
86 bool start_table; /* print start decoration, eg <table> */
87 bool stop_table; /* print stop decoration, eg </table> */
88 bool default_footer; /* allow "(xx rows)" default footer */
89 unsigned long prior_records; /* start offset for record counters */
90 const printTextFormat *line_style; /* line style (NULL for default) */
91 struct separator fieldSep; /* field separator for unaligned text mode */
92 struct separator recordSep; /* record separator for unaligned text mode */
93 bool numericLocale; /* locale-aware numeric units separator and
95 char *tableAttr; /* attributes for HTML <table ...> */
96 int encoding; /* character encoding */
97 int env_columns; /* $COLUMNS on psql start, 0 is unset */
98 int columns; /* target width for wrapped format */
102 * Table footers are implemented as a singly-linked list.
104 * This is so that you don't need to know the number of footers in order to
105 * initialise the printTableContent struct, which is very convenient when
106 * preparing complex footers (as in describeOneTableDetails).
108 typedef struct printTableFooter
111 struct printTableFooter *next;
115 * The table content struct holds all the information which will be displayed
118 typedef struct printTableContent
120 const printTableOpt *opt;
121 const char *title; /* May be NULL */
122 int ncolumns; /* Specified in Init() */
123 int nrows; /* Specified in Init() */
124 const char **headers; /* NULL-terminated array of header strings */
125 const char **header; /* Pointer to the last added header */
126 const char **cells; /* NULL-terminated array of cell content
128 const char **cell; /* Pointer to the last added cell */
129 long cellsadded; /* Number of cells added this far */
130 bool *cellmustfree; /* true for cells that need to be free()d */
131 printTableFooter *footers; /* Pointer to the first footer */
132 printTableFooter *footer; /* Pointer to the last added footer */
133 char *aligns; /* Array of alignment specifiers; 'l' or 'r',
135 char *align; /* Pointer to the last added alignment */
138 typedef struct printQueryOpt
140 printTableOpt topt; /* the options above */
141 char *nullPrint; /* how to print null entities */
142 bool quote; /* quote all values as much as possible */
143 char *title; /* override title */
144 char **footers; /* override footer (default is "(xx rows)") */
145 bool translate_header; /* do gettext on column headers */
146 const bool *translate_columns; /* translate_columns[i-1] => do
147 * gettext on col i */
151 extern const printTextFormat pg_asciiformat;
152 extern const printTextFormat pg_asciiformat_old;
153 extern const printTextFormat pg_utf8format;
156 extern FILE *PageOutput(int lines, unsigned short int pager);
157 extern void ClosePager(FILE *pagerpipe);
159 extern void html_escaped_print(const char *in, FILE *fout);
161 extern void printTableInit(printTableContent *const content,
162 const printTableOpt *opt, const char *title,
163 const int ncolumns, const int nrows);
164 extern void printTableAddHeader(printTableContent *const content,
165 char *header, const bool translate, const char align);
166 extern void printTableAddCell(printTableContent *const content,
167 char *cell, const bool translate, const bool mustfree);
168 extern void printTableAddFooter(printTableContent *const content,
170 extern void printTableSetFooter(printTableContent *const content,
172 extern void printTableCleanup(printTableContent *const content);
173 extern void printTable(const printTableContent *cont, FILE *fout, FILE *flog);
174 extern void printQuery(const PGresult *result, const printQueryOpt *opt,
175 FILE *fout, FILE *flog);
177 extern void setDecimalLocale(void);
178 extern const printTextFormat *get_line_style(const printTableOpt *opt);
181 #define DEFAULT_PAGER "more"
183 #define DEFAULT_PAGER "less"