]> granicus.if.org Git - postgresql/blob - src/bin/psql/print.h
Remove cvs keywords from all files.
[postgresql] / src / bin / psql / print.h
1 /*
2  * psql - the PostgreSQL interactive terminal
3  *
4  * Copyright (c) 2000-2010, PostgreSQL Global Development Group
5  *
6  * src/bin/psql/print.h
7  */
8 #ifndef PRINT_H
9 #define PRINT_H
10
11 #include "libpq-fe.h"
12
13
14 enum printFormat
15 {
16         PRINT_NOTHING = 0,                      /* to make sure someone initializes this */
17         PRINT_UNALIGNED,
18         PRINT_ALIGNED,
19         PRINT_WRAPPED,
20         PRINT_HTML,
21         PRINT_LATEX,
22         PRINT_TROFF_MS
23         /* add your favourite output format here ... */
24 };
25
26 typedef struct printTextLineFormat
27 {
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;
34
35 typedef enum printTextRule
36 {
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) */
42 } printTextRule;
43
44 typedef enum printTextLineWrap
45 {
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 */
50 } printTextLineWrap;
51
52 typedef struct printTextFormat
53 {
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? */
68 } printTextFormat;
69
70 typedef struct printTableOpt
71 {
72         enum printFormat format;        /* see enum above */
73         bool            expanded;               /* expanded/vertical output (if supported by
74                                                                  * output format) */
75         unsigned short int border;      /* Print a border around the table. 0=none,
76                                                                  * 1=dividing lines, 2=full */
77         unsigned short int pager;       /* use pager for output (if to stdout and
78                                                                  * stdout is a tty) 0=off 1=on 2=always */
79         bool            tuples_only;    /* don't output headers, row counts, etc. */
80         bool            start_table;    /* print start decoration, eg <table> */
81         bool            stop_table;             /* print stop decoration, eg </table> */
82         unsigned long prior_records;    /* start offset for record counters */
83         const printTextFormat *line_style;      /* line style (NULL for default) */
84         char       *fieldSep;           /* field separator for unaligned text mode */
85         char       *recordSep;          /* record separator for unaligned text mode */
86         bool            numericLocale;  /* locale-aware numeric units separator and
87                                                                  * decimal marker */
88         char       *tableAttr;          /* attributes for HTML <table ...> */
89         int                     encoding;               /* character encoding */
90         int                     env_columns;    /* $COLUMNS on psql start, 0 is unset */
91         int                     columns;                /* target width for wrapped format */
92 } printTableOpt;
93
94 /*
95  * Table footers are implemented as a singly-linked list.
96  *
97  * This is so that you don't need to know the number of footers in order to
98  * initialise the printTableContent struct, which is very convenient when
99  * preparing complex footers (as in describeOneTableDetails).
100  */
101 typedef struct printTableFooter
102 {
103         char       *data;
104         struct printTableFooter *next;
105 } printTableFooter;
106
107 /*
108  * The table content struct holds all the information which will be displayed
109  * by printTable().
110  */
111 typedef struct printTableContent
112 {
113         const printTableOpt *opt;
114         const char *title;                      /* May be NULL */
115         int                     ncolumns;               /* Specified in Init() */
116         int                     nrows;                  /* Specified in Init() */
117         const char **headers;           /* NULL-terminated array of header strings */
118         const char **header;            /* Pointer to the last added header */
119         const char **cells;                     /* NULL-terminated array of cell content
120                                                                  * strings */
121         const char **cell;                      /* Pointer to the last added cell */
122         long            cellsadded;             /* Number of cells added this far */
123         bool       *cellmustfree;       /* true for cells that need to be free()d */
124         printTableFooter *footers;      /* Pointer to the first footer */
125         printTableFooter *footer;       /* Pointer to the last added footer */
126         char       *aligns;                     /* Array of alignment specifiers; 'l' or 'r',
127                                                                  * one per column */
128         char       *align;                      /* Pointer to the last added alignment */
129 } printTableContent;
130
131 typedef struct printQueryOpt
132 {
133         printTableOpt topt;                     /* the options above */
134         char       *nullPrint;          /* how to print null entities */
135         bool            quote;                  /* quote all values as much as possible */
136         char       *title;                      /* override title */
137         char      **footers;            /* override footer (default is "(xx rows)") */
138         bool            default_footer; /* print default footer if footers==NULL */
139         bool            translate_header;               /* do gettext on column headers */
140         const bool *translate_columns;          /* translate_columns[i-1] => do
141                                                                                  * gettext on col i */
142 } printQueryOpt;
143
144
145 extern const printTextFormat pg_asciiformat;
146 extern const printTextFormat pg_asciiformat_old;
147 extern const printTextFormat pg_utf8format;
148
149
150 extern FILE *PageOutput(int lines, unsigned short int pager);
151 extern void ClosePager(FILE *pagerpipe);
152
153 extern void html_escaped_print(const char *in, FILE *fout);
154
155 extern void printTableInit(printTableContent *const content,
156                            const printTableOpt *opt, const char *title,
157                            const int ncolumns, const int nrows);
158 extern void printTableAddHeader(printTableContent *const content,
159                                  const char *header, const bool translate, const char align);
160 extern void printTableAddCell(printTableContent *const content,
161                                 const char *cell, const bool translate, const bool mustfree);
162 extern void printTableAddFooter(printTableContent *const content,
163                                         const char *footer);
164 extern void printTableSetFooter(printTableContent *const content,
165                                         const char *footer);
166 extern void printTableCleanup(printTableContent *const content);
167 extern void printTable(const printTableContent *cont, FILE *fout, FILE *flog);
168 extern void printQuery(const PGresult *result, const printQueryOpt *opt,
169                    FILE *fout, FILE *flog);
170
171 extern void setDecimalLocale(void);
172 extern const printTextFormat *get_line_style(const printTableOpt *opt);
173
174 #ifndef __CYGWIN__
175 #define DEFAULT_PAGER "more"
176 #else
177 #define DEFAULT_PAGER "less"
178 #endif
179
180 #endif   /* PRINT_H */