gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
7.8KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * Query-result printing support for frontend code
  4. *
  5. *
  6. * Portions Copyright (c) 1996-2019, 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. #include "libpq-fe.h"
  16. /* This is not a particularly great place for this ... */
  17. #ifndef __CYGWIN__
  18. #define DEFAULT_PAGER "more"
  19. #else
  20. #define DEFAULT_PAGER "less"
  21. #endif
  22. enum printFormat
  23. {
  24. PRINT_NOTHING = 0, /* to make sure someone initializes this */
  25. PRINT_ALIGNED,
  26. PRINT_ASCIIDOC,
  27. PRINT_CSV,
  28. PRINT_HTML,
  29. PRINT_LATEX,
  30. PRINT_LATEX_LONGTABLE,
  31. PRINT_TROFF_MS,
  32. PRINT_UNALIGNED,
  33. PRINT_WRAPPED
  34. /* add your favourite output format here ... */
  35. };
  36. typedef struct printTextLineFormat
  37. {
  38. /* Line drawing characters to be used in various contexts */
  39. const char *hrule; /* horizontal line character */
  40. const char *leftvrule; /* left vertical line (+horizontal) */
  41. const char *midvrule; /* intra-column vertical line (+horizontal) */
  42. const char *rightvrule; /* right vertical line (+horizontal) */
  43. } printTextLineFormat;
  44. typedef enum printTextRule
  45. {
  46. /* Additional context for selecting line drawing characters */
  47. PRINT_RULE_TOP, /* top horizontal line */
  48. PRINT_RULE_MIDDLE, /* intra-data horizontal line */
  49. PRINT_RULE_BOTTOM, /* bottom horizontal line */
  50. PRINT_RULE_DATA /* data line (hrule is unused here) */
  51. } printTextRule;
  52. typedef enum printTextLineWrap
  53. {
  54. /* Line wrapping conditions */
  55. PRINT_LINE_WRAP_NONE, /* No wrapping */
  56. PRINT_LINE_WRAP_WRAP, /* Wraparound due to overlength line */
  57. PRINT_LINE_WRAP_NEWLINE /* Newline in data */
  58. } printTextLineWrap;
  59. typedef struct printTextFormat
  60. {
  61. /* A complete line style */
  62. const char *name; /* for display purposes */
  63. printTextLineFormat lrule[4]; /* indexed by enum printTextRule */
  64. const char *midvrule_nl; /* vertical line for continue after newline */
  65. const char *midvrule_wrap; /* vertical line for wrapped data */
  66. const char *midvrule_blank; /* vertical line for blank data */
  67. const char *header_nl_left; /* left mark after newline */
  68. const char *header_nl_right; /* right mark for newline */
  69. const char *nl_left; /* left mark after newline */
  70. const char *nl_right; /* right mark for newline */
  71. const char *wrap_left; /* left mark after wrapped data */
  72. const char *wrap_right; /* right mark for wrapped data */
  73. bool wrap_right_border; /* use right-hand border for wrap marks
  74. * when border=0? */
  75. } printTextFormat;
  76. typedef enum unicode_linestyle
  77. {
  78. UNICODE_LINESTYLE_SINGLE = 0,
  79. UNICODE_LINESTYLE_DOUBLE
  80. } unicode_linestyle;
  81. struct separator
  82. {
  83. char *separator;
  84. bool separator_zero;
  85. };
  86. typedef struct printTableOpt
  87. {
  88. enum printFormat format; /* see enum above */
  89. unsigned short int expanded; /* expanded/vertical output (if supported
  90. * by output format); 0=no, 1=yes, 2=auto */
  91. unsigned short int border; /* Print a border around the table. 0=none,
  92. * 1=dividing lines, 2=full */
  93. unsigned short int pager; /* use pager for output (if to stdout and
  94. * stdout is a tty) 0=off 1=on 2=always */
  95. int pager_min_lines; /* don't use pager unless there are at
  96. * least this many lines */
  97. bool tuples_only; /* don't output headers, row counts, etc. */
  98. bool start_table; /* print start decoration, eg <table> */
  99. bool stop_table; /* print stop decoration, eg </table> */
  100. bool default_footer; /* allow "(xx rows)" default footer */
  101. unsigned long prior_records; /* start offset for record counters */
  102. const printTextFormat *line_style; /* line style (NULL for default) */
  103. struct separator fieldSep; /* field separator for unaligned text mode */
  104. struct separator recordSep; /* record separator for unaligned text mode */
  105. char csvFieldSep[2]; /* field separator for csv format */
  106. bool numericLocale; /* locale-aware numeric units separator and
  107. * decimal marker */
  108. char *tableAttr; /* attributes for HTML <table ...> */
  109. int encoding; /* character encoding */
  110. int env_columns; /* $COLUMNS on psql start, 0 is unset */
  111. int columns; /* target width for wrapped format */
  112. unicode_linestyle unicode_border_linestyle;
  113. unicode_linestyle unicode_column_linestyle;
  114. unicode_linestyle unicode_header_linestyle;
  115. } printTableOpt;
  116. /*
  117. * Table footers are implemented as a singly-linked list.
  118. *
  119. * This is so that you don't need to know the number of footers in order to
  120. * initialise the printTableContent struct, which is very convenient when
  121. * preparing complex footers (as in describeOneTableDetails).
  122. */
  123. typedef struct printTableFooter
  124. {
  125. char *data;
  126. struct printTableFooter *next;
  127. } printTableFooter;
  128. /*
  129. * The table content struct holds all the information which will be displayed
  130. * by printTable().
  131. */
  132. typedef struct printTableContent
  133. {
  134. const printTableOpt *opt;
  135. const char *title; /* May be NULL */
  136. int ncolumns; /* Specified in Init() */
  137. int nrows; /* Specified in Init() */
  138. const char **headers; /* NULL-terminated array of header strings */
  139. const char **header; /* Pointer to the last added header */
  140. const char **cells; /* NULL-terminated array of cell content
  141. * strings */
  142. const char **cell; /* Pointer to the last added cell */
  143. long cellsadded; /* Number of cells added this far */
  144. bool *cellmustfree; /* true for cells that need to be free()d */
  145. printTableFooter *footers; /* Pointer to the first footer */
  146. printTableFooter *footer; /* Pointer to the last added footer */
  147. char *aligns; /* Array of alignment specifiers; 'l' or 'r',
  148. * one per column */
  149. char *align; /* Pointer to the last added alignment */
  150. } printTableContent;
  151. typedef struct printQueryOpt
  152. {
  153. printTableOpt topt; /* the options above */
  154. char *nullPrint; /* how to print null entities */
  155. char *title; /* override title */
  156. char **footers; /* override footer (default is "(xx rows)") */
  157. bool translate_header; /* do gettext on column headers */
  158. const bool *translate_columns; /* translate_columns[i-1] => do gettext on
  159. * col i */
  160. int n_translate_columns; /* length of translate_columns[] */
  161. } printQueryOpt;
  162. extern volatile bool cancel_pressed;
  163. extern const printTextFormat pg_asciiformat;
  164. extern const printTextFormat pg_asciiformat_old;
  165. extern printTextFormat pg_utf8format; /* ideally would be const, but... */
  166. extern void disable_sigpipe_trap(void);
  167. extern void restore_sigpipe_trap(void);
  168. extern void set_sigpipe_trap_state(bool ignore);
  169. extern FILE *PageOutput(int lines, const printTableOpt *topt);
  170. extern void ClosePager(FILE *pagerpipe);
  171. extern void html_escaped_print(const char *in, FILE *fout);
  172. extern void printTableInit(printTableContent *const content,
  173. const printTableOpt *opt, const char *title,
  174. const int ncolumns, const int nrows);
  175. extern void printTableAddHeader(printTableContent *const content,
  176. char *header, const bool translate, const char align);
  177. extern void printTableAddCell(printTableContent *const content,
  178. char *cell, const bool translate, const bool mustfree);
  179. extern void printTableAddFooter(printTableContent *const content,
  180. const char *footer);
  181. extern void printTableSetFooter(printTableContent *const content,
  182. const char *footer);
  183. extern void printTableCleanup(printTableContent *const content);
  184. extern void printTable(const printTableContent *cont,
  185. FILE *fout, bool is_pager, FILE *flog);
  186. extern void printQuery(const PGresult *result, const printQueryOpt *opt,
  187. FILE *fout, bool is_pager, FILE *flog);
  188. extern char column_type_alignment(Oid);
  189. extern void setDecimalLocale(void);
  190. extern const printTextFormat *get_line_style(const printTableOpt *opt);
  191. extern void refresh_utf8format(const printTableOpt *opt);
  192. #endif /* PRINT_H */
上海开阖软件有限公司 沪ICP备12045867号-1