diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c new file mode 100644 index 6d13b57..c9e11c2 *** a/src/bin/psql/crosstabview.c --- b/src/bin/psql/crosstabview.c *************** printCrosstab(const PGresult *results, *** 203,209 **** * alignment is determined by PQftype(). Otherwise the contents are * made-up strings, so the alignment is 'l' */ ! if (PQnfields(results) == 3) { int colnum; /* column placed inside the grid */ /* --- 203,213 ---- * alignment is determined by PQftype(). Otherwise the contents are * made-up strings, so the alignment is 'l' */ ! if (PQnfields(results) == 2) ! { ! col_align = 'c'; ! } ! else if (PQnfields(results) == 3) { int colnum; /* column placed inside the grid */ /* diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c new file mode 100644 index b2f8c2b..6e2cc6e *** a/src/bin/psql/print.c --- b/src/bin/psql/print.c *************** print_aligned_text(const printTableConte *** 1042,1059 **** { /* spaces first */ fprintf(fout, "%*s", width_wrap[j] - chars_to_output, ""); - fputnbytes(fout, - (char *) (this_line->ptr + bytes_output[j]), - bytes_to_output); } ! else /* Left aligned cell */ { ! /* spaces second */ ! fputnbytes(fout, ! (char *) (this_line->ptr + bytes_output[j]), ! bytes_to_output); } bytes_output[j] += bytes_to_output; /* Do we have more text to wrap? */ --- 1042,1059 ---- { /* spaces first */ fprintf(fout, "%*s", width_wrap[j] - chars_to_output, ""); } ! else if (cont->aligns[j] == 'c') /* Center aligned cell */ { ! /* spaces first */ ! fprintf(fout, "%*s", ! (width_wrap[j] - chars_to_output) / 2, ""); } + fputnbytes(fout, + (char *) (this_line->ptr + bytes_output[j]), + bytes_to_output); + bytes_output[j] += bytes_to_output; /* Do we have more text to wrap? */ *************** print_aligned_text(const printTableConte *** 1083,1095 **** * If left-aligned, pad out remaining space if needed (not * last column, and/or wrap marks required). */ ! if (cont->aligns[j] != 'r') /* Left aligned cell */ { ! if (finalspaces || ! wrap[j] == PRINT_LINE_WRAP_WRAP || ! wrap[j] == PRINT_LINE_WRAP_NEWLINE) fprintf(fout, "%*s", ! width_wrap[j] - chars_to_output, ""); } /* Print right-hand wrap or newline mark */ --- 1083,1104 ---- * If left-aligned, pad out remaining space if needed (not * last column, and/or wrap marks required). */ ! if (finalspaces || ! wrap[j] == PRINT_LINE_WRAP_WRAP || ! wrap[j] == PRINT_LINE_WRAP_NEWLINE) { ! if (cont->aligns[j] == 'c') ! { ! /* last spaces */ fprintf(fout, "%*s", ! width_wrap[j] - chars_to_output ! - ((width_wrap[j] - chars_to_output) / 2 ), ""); ! } ! else if (cont->aligns[j] == 'l') ! { ! /* last spaces */ ! fprintf(fout, "%*s", width_wrap[j] - chars_to_output, ""); ! } } /* Print right-hand wrap or newline mark */ *************** html_escaped_print(const char *in, FILE *** 1778,1783 **** --- 1787,1805 ---- } } + /* + * Returns align value in html format + */ + static const char * + format_html_align_attr(char align) + { + if (align == 'r') + return "right"; + else if (align == 'c') + return "center"; + else + return "left"; + } static void print_html_text(const printTableContent *cont, FILE *fout) *************** print_html_text(const printTableContent *** 1830,1836 **** fputs(" \n", fout); } ! fprintf(fout, " ", cont->aligns[(i) % cont->ncolumns] == 'r' ? "right" : "left"); /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') fputs("  ", fout); --- 1852,1860 ---- fputs(" \n", fout); } ! fprintf(fout, " ", ! format_html_align_attr(cont->aligns[(i) % cont->ncolumns])); ! /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') fputs("  ", fout); *************** print_html_vertical(const printTableCont *** 1916,1922 **** html_escaped_print(cont->headers[i % cont->ncolumns], fout); fputs("\n", fout); ! fprintf(fout, " ", cont->aligns[i % cont->ncolumns] == 'r' ? "right" : "left"); /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') fputs("  ", fout); --- 1940,1950 ---- html_escaped_print(cont->headers[i % cont->ncolumns], fout); fputs("\n", fout); ! ! ! fprintf(fout, " ", ! format_html_align_attr(cont->aligns[i % cont->ncolumns])); ! /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') fputs("  ", fout); *************** asciidoc_escaped_print(const char *in, F *** 1971,1976 **** --- 1999,2015 ---- } } + static const char * + format_asciidoc_align_attr(char align) + { + if (align == 'r') + return ">l"; + else if (align == 'c') + return "^l"; + else + return "aligns[(i) % cont->ncolumns] == 'r' ? ">l" : "aligns[(i) % cont->ncolumns])); } fputs("\"", fout); switch (opt_border) *************** print_asciidoc_vertical(const printTable *** 2142,2148 **** fputs("headers[i % cont->ncolumns], fout); ! fprintf(fout, " %s|", cont->aligns[i % cont->ncolumns] == 'r' ? ">l" : "headers[i % cont->ncolumns], fout); ! fprintf(fout, " %s|", ! format_asciidoc_align_attr(cont->aligns[(i) % cont->ncolumns])); ! /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') fputs(" ", fout); *************** print_latex_longtable_text(const printTa *** 2343,2349 **** for (i = 0; i < cont->ncolumns; i++) { ! /* longtable supports either a width (p) or an alignment (l/r) */ /* Are we left-justified and was a proportional width specified? */ if (*(cont->aligns + i) == 'l' && opt_table_attr) { --- 2385,2391 ---- for (i = 0; i < cont->ncolumns; i++) { ! /* longtable supports either a width (p) or an alignment (l/c/r) */ /* Are we left-justified and was a proportional width specified? */ if (*(cont->aligns + i) == 'l' && opt_table_attr) { *************** printTableInit(printTableContent *const *** 2950,2957 **** * If translate is true, the function will pass the header through gettext. * Otherwise, the header will not be translated. * ! * align is either 'l' or 'r', and specifies the alignment for cells in this ! * column. */ void printTableAddHeader(printTableContent *const content, char *header, --- 2992,2999 ---- * If translate is true, the function will pass the header through gettext. * Otherwise, the header will not be translated. * ! * align is either 'l' or 'c' or'r', and specifies the alignment for cells ! * in this column. */ void printTableAddHeader(printTableContent *const content, char *header,