*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.71 2005/07/18 19:27:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.72 2005/07/18 20:57:53 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
return strlen(my_str) - frac_len;
}
+/* Return additional length required for locale-aware numeric output */
static int
-len_numericseps(const char *my_str)
+additional_numeric_locale_len(const char *my_str)
{
int int_len = integer_digits(my_str), len = 0;
int groupdigits = atoi(grouping);
}
static int
-len_with_numericsep(const char *my_str)
+strlen_with_numeric_locale(const char *my_str)
{
- return strlen(my_str) + len_numericseps(my_str);
+ return strlen(my_str) + additional_numeric_locale_len(my_str);
}
static void
-format_numericsep(char *my_str)
+format_numeric_locale(char *my_str)
{
int i, j, int_len = integer_digits(my_str), leading_digits;
int groupdigits = atoi(grouping);
if (my_str[0] == '-')
my_str++;
- new_str = pg_local_malloc(len_with_numericsep(my_str) + 1);
+ new_str = pg_local_malloc(strlen_with_numeric_locale(my_str) + 1);
leading_digits = (int_len % groupdigits != 0) ?
int_len % groupdigits : groupdigits;
const char *const *cells, const char *const *footers,
const char *opt_align, const char *opt_fieldsep,
const char *opt_recordsep, bool opt_tuples_only,
- bool opt_numericsep, FILE *fout)
+ bool opt_numeric_locale, FILE *fout)
{
unsigned int col_count = 0;
unsigned int i;
fputs(opt_recordsep, fout);
need_recordsep = false;
}
- if (opt_align[i % col_count] == 'r' && opt_numericsep)
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
fputs(my_cell, fout);
free(my_cell);
}
const char *const *cells,
const char *const *footers, const char *opt_align,
const char *opt_fieldsep, const char *opt_recordsep,
- bool opt_tuples_only, bool opt_numericsep, FILE *fout)
+ bool opt_tuples_only, bool opt_numeric_locale, FILE *fout)
{
unsigned int col_count = 0;
unsigned int i;
fputs(headers[i % col_count], fout);
fputs(opt_fieldsep, fout);
- if (opt_align[i % col_count] == 'r' && opt_numericsep)
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
fputs(my_cell, fout);
free(my_cell);
}
static void
print_aligned_text(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
- const char *opt_align, bool opt_tuples_only, bool opt_numericsep,
+ const char *opt_align, bool opt_tuples_only, bool opt_numeric_locale,
unsigned short int opt_border, int encoding,
FILE *fout)
{
for (i = 0, ptr = cells; *ptr; ptr++, i++)
{
- int numericseps;
+ int numeric_locale_len;
- if (opt_align[i % col_count] == 'r' && opt_numericsep)
- numericseps = len_numericseps(*ptr);
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
+ numeric_locale_len = additional_numeric_locale_len(*ptr);
else
- numericseps = 0;
+ numeric_locale_len = 0;
- tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr), encoding) + numericseps;
+ tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr), encoding) + numeric_locale_len;
if (tmp > widths[i % col_count])
widths[i % col_count] = tmp;
cell_w[i] = tmp;
/* content */
if (opt_align[i % col_count] == 'r')
{
- if (opt_numericsep)
+ if (opt_numeric_locale)
{
char *my_cell = pg_local_malloc(cell_w[i] + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
fprintf(fout, "%*s%s", widths[i % col_count] - cell_w[i], "", my_cell);
free(my_cell);
}
print_aligned_vertical(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
int encoding, FILE *fout)
{
unsigned int col_count = 0;
/* find longest data cell */
for (i = 0, ptr = cells; *ptr; ptr++, i++)
{
- int numericseps;
+ int numeric_locale_len;
- if (opt_align[i % col_count] == 'r' && opt_numericsep)
- numericseps = len_numericseps(*ptr);
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
+ numeric_locale_len = additional_numeric_locale_len(*ptr);
else
- numericseps = 0;
+ numeric_locale_len = 0;
- tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr), encoding) + numericseps;
+ tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr), encoding) + numeric_locale_len;
if (tmp > dwidth)
dwidth = tmp;
cell_w[i] = tmp;
char *my_cell = pg_local_malloc(cell_w[i] + 1);
strcpy(my_cell, *ptr);
- if (opt_align[i % col_count] == 'r' && opt_numericsep)
- format_numericsep(my_cell);
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
+ format_numeric_locale(my_cell);
if (opt_border < 2)
puts(my_cell);
else
print_html_text(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
const char *opt_table_attr, FILE *fout)
{
unsigned int col_count = 0;
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
- else if (opt_align[i % col_count] == 'r' && opt_numericsep)
+ else if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
html_escaped_print(my_cell, fout);
free(my_cell);
}
print_html_vertical(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
const char *opt_table_attr, FILE *fout)
{
unsigned int col_count = 0;
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
- else if (opt_align[i % col_count] == 'r' && opt_numericsep)
+ else if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
html_escaped_print(my_cell, fout);
free(my_cell);
}
print_latex_text(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
FILE *fout)
{
unsigned int col_count = 0;
/* print cells */
for (i = 0, ptr = cells; *ptr; i++, ptr++)
{
- if (opt_numericsep)
+ if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
latex_escaped_print(my_cell, fout);
free(my_cell);
}
print_latex_vertical(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
FILE *fout)
{
unsigned int col_count = 0;
if (footers && !opt_tuples_only)
for (ptr = footers; *ptr; ptr++)
{
- if (opt_numericsep)
+ if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
latex_escaped_print(my_cell, fout);
free(my_cell);
}
print_troff_ms_text(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
FILE *fout)
{
unsigned int col_count = 0;
/* print cells */
for (i = 0, ptr = cells; *ptr; i++, ptr++)
{
- if (opt_numericsep)
+ if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
troff_ms_escaped_print(my_cell, fout);
free(my_cell);
}
print_troff_ms_vertical(const char *title, const char *const *headers,
const char *const *cells, const char *const *footers,
const char *opt_align, bool opt_tuples_only,
- bool opt_numericsep, unsigned short int opt_border,
+ bool opt_numeric_locale, unsigned short int opt_border,
FILE *fout)
{
unsigned int col_count = 0;
troff_ms_escaped_print(headers[i % col_count], fout);
fputc('\t', fout);
- if (opt_numericsep)
+ if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
+ char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
strcpy(my_cell, *ptr);
- format_numericsep(my_cell);
+ format_numeric_locale(my_cell);
troff_ms_escaped_print(my_cell, fout);
free(my_cell);
}
/* print the stuff */
if (flog)
- print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, opt->numericSep, border, opt->encoding, flog);
+ print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, opt->numericLocale, border, opt->encoding, flog);
switch (opt->format)
{
if (use_expanded)
print_unaligned_vertical(title, headers, cells, footers, align,
opt->fieldSep, opt->recordSep,
- opt->tuples_only, opt->numericSep, output);
+ opt->tuples_only, opt->numericLocale, output);
else
print_unaligned_text(title, headers, cells, footers, align,
opt->fieldSep, opt->recordSep,
- opt->tuples_only, opt->numericSep, output);
+ opt->tuples_only, opt->numericLocale, output);
break;
case PRINT_ALIGNED:
if (use_expanded)
print_aligned_vertical(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep, border,
+ opt->tuples_only, opt->numericLocale, border,
opt->encoding, output);
else
print_aligned_text(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, opt->encoding, output);
break;
case PRINT_HTML:
if (use_expanded)
print_html_vertical(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, opt->tableAttr, output);
else
print_html_text(title, headers, cells, footers,
- align, opt->tuples_only, opt->numericSep, border,
+ align, opt->tuples_only, opt->numericLocale, border,
opt->tableAttr, output);
break;
case PRINT_LATEX:
if (use_expanded)
print_latex_vertical(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, output);
else
print_latex_text(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, output);
break;
case PRINT_TROFF_MS:
if (use_expanded)
print_troff_ms_vertical(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, output);
else
print_troff_ms_text(title, headers, cells, footers, align,
- opt->tuples_only, opt->numericSep,
+ opt->tuples_only, opt->numericLocale,
border, output);
break;
default: