Header And Logo

PostgreSQL
| The world's most advanced open source database.

print.h

Go to the documentation of this file.
00001 /*
00002  * psql - the PostgreSQL interactive terminal
00003  *
00004  * Copyright (c) 2000-2013, PostgreSQL Global Development Group
00005  *
00006  * src/bin/psql/print.h
00007  */
00008 #ifndef PRINT_H
00009 #define PRINT_H
00010 
00011 #include "libpq-fe.h"
00012 
00013 
00014 enum printFormat
00015 {
00016     PRINT_NOTHING = 0,          /* to make sure someone initializes this */
00017     PRINT_UNALIGNED,
00018     PRINT_ALIGNED,
00019     PRINT_WRAPPED,
00020     PRINT_HTML,
00021     PRINT_LATEX,
00022     PRINT_LATEX_LONGTABLE,
00023     PRINT_TROFF_MS
00024     /* add your favourite output format here ... */
00025 };
00026 
00027 typedef struct printTextLineFormat
00028 {
00029     /* Line drawing characters to be used in various contexts */
00030     const char *hrule;          /* horizontal line character */
00031     const char *leftvrule;      /* left vertical line (+horizontal) */
00032     const char *midvrule;       /* intra-column vertical line (+horizontal) */
00033     const char *rightvrule;     /* right vertical line (+horizontal) */
00034 } printTextLineFormat;
00035 
00036 typedef enum printTextRule
00037 {
00038     /* Additional context for selecting line drawing characters */
00039     PRINT_RULE_TOP,             /* top horizontal line */
00040     PRINT_RULE_MIDDLE,          /* intra-data horizontal line */
00041     PRINT_RULE_BOTTOM,          /* bottom horizontal line */
00042     PRINT_RULE_DATA             /* data line (hrule is unused here) */
00043 } printTextRule;
00044 
00045 typedef enum printTextLineWrap
00046 {
00047     /* Line wrapping conditions */
00048     PRINT_LINE_WRAP_NONE,       /* No wrapping */
00049     PRINT_LINE_WRAP_WRAP,       /* Wraparound due to overlength line */
00050     PRINT_LINE_WRAP_NEWLINE     /* Newline in data */
00051 } printTextLineWrap;
00052 
00053 typedef struct printTextFormat
00054 {
00055     /* A complete line style */
00056     const char *name;           /* for display purposes */
00057     printTextLineFormat lrule[4];       /* indexed by enum printTextRule */
00058     const char *midvrule_nl;    /* vertical line for continue after newline */
00059     const char *midvrule_wrap;  /* vertical line for wrapped data */
00060     const char *midvrule_blank; /* vertical line for blank data */
00061     const char *header_nl_left; /* left mark after newline */
00062     const char *header_nl_right;    /* right mark for newline */
00063     const char *nl_left;        /* left mark after newline */
00064     const char *nl_right;       /* right mark for newline */
00065     const char *wrap_left;      /* left mark after wrapped data */
00066     const char *wrap_right;     /* right mark for wrapped data */
00067     bool        wrap_right_border;      /* use right-hand border for wrap
00068                                          * marks when border=0? */
00069 } printTextFormat;
00070 
00071 struct separator
00072 {
00073     char       *separator;
00074     bool        separator_zero;
00075 };
00076 
00077 typedef struct printTableOpt
00078 {
00079     enum printFormat format;    /* see enum above */
00080     unsigned short int expanded;/* expanded/vertical output (if supported by
00081                                  * output format); 0=no, 1=yes, 2=auto */
00082     unsigned short int border;  /* Print a border around the table. 0=none,
00083                                  * 1=dividing lines, 2=full */
00084     unsigned short int pager;   /* use pager for output (if to stdout and
00085                                  * stdout is a tty) 0=off 1=on 2=always */
00086     bool        tuples_only;    /* don't output headers, row counts, etc. */
00087     bool        start_table;    /* print start decoration, eg <table> */
00088     bool        stop_table;     /* print stop decoration, eg </table> */
00089     bool        default_footer; /* allow "(xx rows)" default footer */
00090     unsigned long prior_records;    /* start offset for record counters */
00091     const printTextFormat *line_style;  /* line style (NULL for default) */
00092     struct separator fieldSep;  /* field separator for unaligned text mode */
00093     struct separator recordSep; /* record separator for unaligned text mode */
00094     bool        numericLocale;  /* locale-aware numeric units separator and
00095                                  * decimal marker */
00096     char       *tableAttr;      /* attributes for HTML <table ...> */
00097     int         encoding;       /* character encoding */
00098     int         env_columns;    /* $COLUMNS on psql start, 0 is unset */
00099     int         columns;        /* target width for wrapped format */
00100 } printTableOpt;
00101 
00102 /*
00103  * Table footers are implemented as a singly-linked list.
00104  *
00105  * This is so that you don't need to know the number of footers in order to
00106  * initialise the printTableContent struct, which is very convenient when
00107  * preparing complex footers (as in describeOneTableDetails).
00108  */
00109 typedef struct printTableFooter
00110 {
00111     char       *data;
00112     struct printTableFooter *next;
00113 } printTableFooter;
00114 
00115 /*
00116  * The table content struct holds all the information which will be displayed
00117  * by printTable().
00118  */
00119 typedef struct printTableContent
00120 {
00121     const printTableOpt *opt;
00122     const char *title;          /* May be NULL */
00123     int         ncolumns;       /* Specified in Init() */
00124     int         nrows;          /* Specified in Init() */
00125     const char **headers;       /* NULL-terminated array of header strings */
00126     const char **header;        /* Pointer to the last added header */
00127     const char **cells;         /* NULL-terminated array of cell content
00128                                  * strings */
00129     const char **cell;          /* Pointer to the last added cell */
00130     long        cellsadded;     /* Number of cells added this far */
00131     bool       *cellmustfree;   /* true for cells that need to be free()d */
00132     printTableFooter *footers;  /* Pointer to the first footer */
00133     printTableFooter *footer;   /* Pointer to the last added footer */
00134     char       *aligns;         /* Array of alignment specifiers; 'l' or 'r',
00135                                  * one per column */
00136     char       *align;          /* Pointer to the last added alignment */
00137 } printTableContent;
00138 
00139 typedef struct printQueryOpt
00140 {
00141     printTableOpt topt;         /* the options above */
00142     char       *nullPrint;      /* how to print null entities */
00143     bool        quote;          /* quote all values as much as possible */
00144     char       *title;          /* override title */
00145     char      **footers;        /* override footer (default is "(xx rows)") */
00146     bool        translate_header;       /* do gettext on column headers */
00147     const bool *translate_columns;      /* translate_columns[i-1] => do
00148                                          * gettext on col i */
00149 } printQueryOpt;
00150 
00151 
00152 extern const printTextFormat pg_asciiformat;
00153 extern const printTextFormat pg_asciiformat_old;
00154 extern const printTextFormat pg_utf8format;
00155 
00156 
00157 extern FILE *PageOutput(int lines, unsigned short int pager);
00158 extern void ClosePager(FILE *pagerpipe);
00159 
00160 extern void html_escaped_print(const char *in, FILE *fout);
00161 
00162 extern void printTableInit(printTableContent *const content,
00163                const printTableOpt *opt, const char *title,
00164                const int ncolumns, const int nrows);
00165 extern void printTableAddHeader(printTableContent *const content,
00166                     char *header, const bool translate, const char align);
00167 extern void printTableAddCell(printTableContent *const content,
00168                   char *cell, const bool translate, const bool mustfree);
00169 extern void printTableAddFooter(printTableContent *const content,
00170                     const char *footer);
00171 extern void printTableSetFooter(printTableContent *const content,
00172                     const char *footer);
00173 extern void printTableCleanup(printTableContent *const content);
00174 extern void printTable(const printTableContent *cont, FILE *fout, FILE *flog);
00175 extern void printQuery(const PGresult *result, const printQueryOpt *opt,
00176            FILE *fout, FILE *flog);
00177 
00178 extern void setDecimalLocale(void);
00179 extern const printTextFormat *get_line_style(const printTableOpt *opt);
00180 
00181 #ifndef __CYGWIN__
00182 #define DEFAULT_PAGER "more"
00183 #else
00184 #define DEFAULT_PAGER "less"
00185 #endif
00186 
00187 #endif   /* PRINT_H */