#include "libpq-fe.h"
Go to the source code of this file.
typedef struct printQueryOpt printQueryOpt |
typedef struct printTableContent printTableContent |
typedef struct printTableFooter printTableFooter |
typedef struct printTableOpt printTableOpt |
typedef struct printTextFormat printTextFormat |
typedef struct printTextLineFormat printTextLineFormat |
typedef enum printTextLineWrap printTextLineWrap |
typedef enum printTextRule printTextRule |
enum printFormat |
PRINT_NOTHING | |
PRINT_UNALIGNED | |
PRINT_ALIGNED | |
PRINT_WRAPPED | |
PRINT_HTML | |
PRINT_LATEX | |
PRINT_LATEX_LONGTABLE | |
PRINT_TROFF_MS |
Definition at line 14 of file print.h.
{ PRINT_NOTHING = 0, /* to make sure someone initializes this */ PRINT_UNALIGNED, PRINT_ALIGNED, PRINT_WRAPPED, PRINT_HTML, PRINT_LATEX, PRINT_LATEX_LONGTABLE, PRINT_TROFF_MS /* add your favourite output format here ... */ };
enum printTextLineWrap |
Definition at line 45 of file print.h.
{ /* Line wrapping conditions */ PRINT_LINE_WRAP_NONE, /* No wrapping */ PRINT_LINE_WRAP_WRAP, /* Wraparound due to overlength line */ PRINT_LINE_WRAP_NEWLINE /* Newline in data */ } printTextLineWrap;
enum printTextRule |
Definition at line 36 of file print.h.
{ /* Additional context for selecting line drawing characters */ PRINT_RULE_TOP, /* top horizontal line */ PRINT_RULE_MIDDLE, /* intra-data horizontal line */ PRINT_RULE_BOTTOM, /* bottom horizontal line */ PRINT_RULE_DATA /* data line (hrule is unused here) */ } printTextRule;
void ClosePager | ( | FILE * | pagerpipe | ) |
Definition at line 2226 of file print.c.
References _, cancel_pressed, pqsignal(), SIG_DFL, and SIGPIPE.
Referenced by exec_command(), ExecQueryUsingCursor(), helpSQL(), print_aligned_text(), print_aligned_vertical(), printTable(), and slashUsage().
{ if (pagerpipe && pagerpipe != stdout) { /* * If printing was canceled midstream, warn about it. * * Some pagers like less use Ctrl-C as part of their command set. Even * so, we abort our processing and warn the user what we did. If the * pager quit as a result of the SIGINT, this message won't go * anywhere ... */ if (cancel_pressed) fprintf(pagerpipe, _("Interrupted\n")); pclose(pagerpipe); #ifndef WIN32 pqsignal(SIGPIPE, SIG_DFL); #endif } }
const printTextFormat* get_line_style | ( | const printTableOpt * | opt | ) |
Definition at line 2695 of file print.c.
References printTableOpt::line_style, and NULL.
Referenced by do_pset(), print_aligned_text(), print_aligned_vertical(), and print_aligned_vertical_line().
{ /* * Note: this function mainly exists to preserve the convention that a * printTableOpt struct can be initialized to zeroes to get default * behavior. */ if (opt->line_style != NULL) return opt->line_style; else return &pg_asciiformat; }
void html_escaped_print | ( | const char * | in, | |
FILE * | fout | |||
) |
Definition at line 1354 of file print.c.
Referenced by print_html_text(), print_html_vertical(), and PrintQueryStatus().
{ const char *p; bool leading_space = true; for (p = in; *p; p++) { switch (*p) { case '&': fputs("&", fout); break; case '<': fputs("<", fout); break; case '>': fputs(">", fout); break; case '\n': fputs("<br />\n", fout); break; case '"': fputs(""", fout); break; case ' ': /* protect leading space, for EXPLAIN output */ if (leading_space) fputs(" ", fout); else fputs(" ", fout); break; default: fputc(*p, fout); } if (*p != ' ') leading_space = false; } }
FILE* PageOutput | ( | int | lines, | |
unsigned short int | pager | |||
) |
Definition at line 2185 of file print.c.
References pqsignal(), SIG_IGN, and SIGPIPE.
Referenced by exec_command(), ExecQueryUsingCursor(), helpSQL(), IsPagerNeeded(), print_aligned_text(), and slashUsage().
{ /* check whether we need / can / are supposed to use pager */ if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout))) { const char *pagerprog; FILE *pagerpipe; #ifdef TIOCGWINSZ int result; struct winsize screen_size; result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); /* >= accounts for a one-line prompt */ if (result == -1 || lines >= screen_size.ws_row || pager > 1) { #endif pagerprog = getenv("PAGER"); if (!pagerprog) pagerprog = DEFAULT_PAGER; #ifndef WIN32 pqsignal(SIGPIPE, SIG_IGN); #endif pagerpipe = popen(pagerprog, "w"); if (pagerpipe) return pagerpipe; #ifdef TIOCGWINSZ } #endif } return stdout; }
void printQuery | ( | const PGresult * | result, | |
const printQueryOpt * | opt, | |||
FILE * | fout, | |||
FILE * | flog | |||
) |
Definition at line 2586 of file print.c.
References printTableContent::aligns, cancel_pressed, CASHOID, CIDOID, FLOAT4OID, FLOAT8OID, printQueryOpt::footers, format_numeric_locale(), i, INT2OID, INT4OID, INT8OID, printTableContent::ncolumns, printTableContent::nrows, printQueryOpt::nullPrint, printTableOpt::numericLocale, NUMERICOID, OIDOID, PQfname(), PQftype(), PQgetisnull(), PQgetvalue(), PQnfields(), PQntuples(), printTable(), printTableAddCell(), printTableAddFooter(), printTableAddHeader(), printTableCleanup(), printTableInit(), printQueryOpt::title, printQueryOpt::topt, printQueryOpt::translate_columns, printQueryOpt::translate_header, and XIDOID.
Referenced by describeAggregates(), describeFunctions(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describeTablespaces(), describeTypes(), do_lo_list(), do_watch(), ExecQueryUsingCursor(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listSchemas(), listTables(), listTSConfigs(), listTSDictionaries(), listTSParsers(), listTSTemplates(), listUserMappings(), main(), objectDescription(), permissionsList(), and PrintQueryTuples().
{ printTableContent cont; int i, r, c; if (cancel_pressed) return; printTableInit(&cont, &opt->topt, opt->title, PQnfields(result), PQntuples(result)); for (i = 0; i < cont.ncolumns; i++) { char align; Oid ftype = PQftype(result, i); switch (ftype) { case INT2OID: case INT4OID: case INT8OID: case FLOAT4OID: case FLOAT8OID: case NUMERICOID: case OIDOID: case XIDOID: case CIDOID: case CASHOID: align = 'r'; break; default: align = 'l'; break; } printTableAddHeader(&cont, PQfname(result, i), opt->translate_header, align); } /* set cells */ for (r = 0; r < cont.nrows; r++) { for (c = 0; c < cont.ncolumns; c++) { char *cell; bool mustfree = false; bool translate; if (PQgetisnull(result, r, c)) cell = opt->nullPrint ? opt->nullPrint : ""; else { cell = PQgetvalue(result, r, c); if (cont.aligns[c] == 'r' && opt->topt.numericLocale) { cell = format_numeric_locale(cell); mustfree = true; } } translate = (opt->translate_columns && opt->translate_columns[c]); printTableAddCell(&cont, cell, translate, mustfree); } } /* set footers */ if (opt->footers) { char **footer; for (footer = opt->footers; *footer; footer++) printTableAddFooter(&cont, *footer); } printTable(&cont, fout, flog); printTableCleanup(&cont); }
void printTable | ( | const printTableContent * | cont, | |
FILE * | fout, | |||
FILE * | flog | |||
) |
Definition at line 2511 of file print.c.
References _, cancel_pressed, ClosePager(), EXIT_FAILURE, printTableOpt::expanded, printTableOpt::format, IsPagerNeeded(), printTableContent::opt, PRINT_ALIGNED, print_aligned_text(), print_aligned_vertical(), PRINT_HTML, print_html_text(), print_html_vertical(), PRINT_LATEX, PRINT_LATEX_LONGTABLE, print_latex_longtable_text(), print_latex_text(), print_latex_vertical(), PRINT_NOTHING, PRINT_TROFF_MS, print_troff_ms_text(), print_troff_ms_vertical(), PRINT_UNALIGNED, print_unaligned_text(), print_unaligned_vertical(), and PRINT_WRAPPED.
Referenced by describeOneTableDetails(), describeRoles(), and printQuery().
{ bool is_pager = false; if (cancel_pressed) return; if (cont->opt->format == PRINT_NOTHING) return; /* print_aligned_*() handles the pager themselves */ if (cont->opt->format != PRINT_ALIGNED && cont->opt->format != PRINT_WRAPPED) IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager); /* print the stuff */ if (flog) print_aligned_text(cont, flog); switch (cont->opt->format) { case PRINT_UNALIGNED: if (cont->opt->expanded == 1) print_unaligned_vertical(cont, fout); else print_unaligned_text(cont, fout); break; case PRINT_ALIGNED: case PRINT_WRAPPED: if (cont->opt->expanded == 1) print_aligned_vertical(cont, fout); else print_aligned_text(cont, fout); break; case PRINT_HTML: if (cont->opt->expanded == 1) print_html_vertical(cont, fout); else print_html_text(cont, fout); break; case PRINT_LATEX: if (cont->opt->expanded == 1) print_latex_vertical(cont, fout); else print_latex_text(cont, fout); break; case PRINT_LATEX_LONGTABLE: if (cont->opt->expanded == 1) print_latex_vertical(cont, fout); else print_latex_longtable_text(cont, fout); break; case PRINT_TROFF_MS: if (cont->opt->expanded == 1) print_troff_ms_vertical(cont, fout); else print_troff_ms_text(cont, fout); break; default: fprintf(stderr, _("invalid output format (internal error): %d"), cont->opt->format); exit(EXIT_FAILURE); } if (is_pager) ClosePager(fout); }
void printTableAddCell | ( | printTableContent *const | content, | |
char * | cell, | |||
const bool | translate, | |||
const bool | mustfree | |||
) |
Definition at line 2336 of file print.c.
References _, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cellsadded, printTableOpt::encoding, EXIT_FAILURE, mbvalidate(), printTableContent::ncolumns, printTableContent::nrows, NULL, printTableContent::opt, and pg_malloc0().
Referenced by describeOneTableDetails(), describeRoles(), and printQuery().
{ #ifndef ENABLE_NLS (void) translate; /* unused parameter */ #endif if (content->cellsadded >= content->ncolumns * content->nrows) { fprintf(stderr, _("Cannot add cell to table content: " "total cell count of %d exceeded.\n"), content->ncolumns * content->nrows); exit(EXIT_FAILURE); } *content->cell = (char *) mbvalidate((unsigned char *) cell, content->opt->encoding); #ifdef ENABLE_NLS if (translate) *content->cell = _(*content->cell); #endif if (mustfree) { if (content->cellmustfree == NULL) content->cellmustfree = pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool)); content->cellmustfree[content->cellsadded] = true; } content->cell++; content->cellsadded++; }
void printTableAddFooter | ( | printTableContent *const | content, | |
const char * | footer | |||
) |
Definition at line 2384 of file print.c.
References printTableFooter::data, printTableContent::footer, printTableContent::footers, printTableFooter::next, NULL, pg_malloc0(), and pg_strdup().
Referenced by add_tablespace_footer(), describeOneTableDetails(), printQuery(), and printTableSetFooter().
{ printTableFooter *f; f = pg_malloc0(sizeof(*f)); f->data = pg_strdup(footer); if (content->footers == NULL) content->footers = f; else content->footer->next = f; content->footer = f; }
void printTableAddHeader | ( | printTableContent *const | content, | |
char * | header, | |||
const bool | translate, | |||
const char | align | |||
) |
Definition at line 2296 of file print.c.
References _, printTableContent::align, printTableOpt::encoding, EXIT_FAILURE, printTableContent::header, printTableContent::headers, mbvalidate(), printTableContent::ncolumns, and printTableContent::opt.
Referenced by describeOneTableDetails(), describeRoles(), and printQuery().
{ #ifndef ENABLE_NLS (void) translate; /* unused parameter */ #endif if (content->header >= content->headers + content->ncolumns) { fprintf(stderr, _("Cannot add header to table content: " "column count of %d exceeded.\n"), content->ncolumns); exit(EXIT_FAILURE); } *content->header = (char *) mbvalidate((unsigned char *) header, content->opt->encoding); #ifdef ENABLE_NLS if (translate) *content->header = _(*content->header); #endif content->header++; *content->align = align; content->align++; }
void printTableCleanup | ( | printTableContent *const | content | ) |
Definition at line 2427 of file print.c.
References printTableContent::align, printTableContent::aligns, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cells, printTableFooter::data, printTableContent::footer, printTableContent::footers, free, printTableContent::header, printTableContent::headers, i, printTableContent::ncolumns, printTableFooter::next, printTableContent::nrows, printTableContent::opt, and printTableContent::title.
Referenced by describeOneTableDetails(), describeRoles(), and printQuery().
{ if (content->cellmustfree) { int i; for (i = 0; i < content->nrows * content->ncolumns; i++) { if (content->cellmustfree[i]) free((char *) content->cells[i]); } free(content->cellmustfree); content->cellmustfree = NULL; } free(content->headers); free(content->cells); free(content->aligns); content->opt = NULL; content->title = NULL; content->headers = NULL; content->cells = NULL; content->aligns = NULL; content->header = NULL; content->cell = NULL; content->align = NULL; if (content->footers) { for (content->footer = content->footers; content->footer;) { printTableFooter *f; f = content->footer; content->footer = f->next; free(f->data); free(f); } } content->footers = NULL; content->footer = NULL; }
void printTableInit | ( | printTableContent *const | content, | |
const printTableOpt * | opt, | |||
const char * | title, | |||
const int | ncolumns, | |||
const int | nrows | |||
) |
Definition at line 2259 of file print.c.
References printTableContent::align, printTableContent::aligns, printTableContent::cell, printTableContent::cellmustfree, printTableContent::cells, printTableContent::cellsadded, printTableContent::footer, printTableContent::footers, printTableContent::header, printTableContent::headers, printTableContent::ncolumns, printTableContent::nrows, printTableContent::opt, pg_malloc0(), and printTableContent::title.
Referenced by describeOneTableDetails(), describeRoles(), and printQuery().
{ content->opt = opt; content->title = title; content->ncolumns = ncolumns; content->nrows = nrows; content->headers = pg_malloc0((ncolumns + 1) * sizeof(*content->headers)); content->cells = pg_malloc0((ncolumns * nrows + 1) * sizeof(*content->cells)); content->cellmustfree = NULL; content->footers = NULL; content->aligns = pg_malloc0((ncolumns + 1) * sizeof(*content->align)); content->header = content->headers; content->cell = content->cells; content->footer = content->footers; content->align = content->aligns; content->cellsadded = 0; }
void printTableSetFooter | ( | printTableContent *const | content, | |
const char * | footer | |||
) |
Definition at line 2409 of file print.c.
References printTableFooter::data, printTableContent::footer, printTableContent::footers, free, NULL, pg_strdup(), and printTableAddFooter().
Referenced by add_tablespace_footer().
void setDecimalLocale | ( | void | ) |
Definition at line 2668 of file print.c.
References decimal_point, grouping, pg_strdup(), and thousands_sep.
Referenced by main().
{ struct lconv *extlconv; extlconv = localeconv(); if (*extlconv->decimal_point) decimal_point = pg_strdup(extlconv->decimal_point); else decimal_point = "."; /* SQL output standard */ if (*extlconv->grouping && atoi(extlconv->grouping) > 0) grouping = pg_strdup(extlconv->grouping); else grouping = "3"; /* most common */ /* similar code exists in formatting.c */ if (*extlconv->thousands_sep) thousands_sep = pg_strdup(extlconv->thousands_sep); /* Make sure thousands separator doesn't match decimal point symbol. */ else if (strcmp(decimal_point, ",") != 0) thousands_sep = ","; else thousands_sep = "."; }
const printTextFormat pg_utf8format |