*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.75 2005/09/26 18:09:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.76 2005/09/27 16:30:25 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
return strlen(my_str) + additional_numeric_locale_len(my_str);
}
-static void
-format_numeric_locale(char *my_str)
+static char *
+format_numeric_locale(const char *my_str)
{
int i, j, int_len = integer_digits(my_str), leading_digits;
int groupdigits = atoi(grouping);
- char *new_str;
-
- if (my_str[0] == '-')
- my_str++;
-
- new_str = pg_local_malloc(strlen_with_numeric_locale(my_str) + 1);
+ int new_str_start = 0;
+ char *new_str = new_str = pg_local_malloc(
+ strlen_with_numeric_locale(my_str) + 1);
leading_digits = (int_len % groupdigits != 0) ?
int_len % groupdigits : groupdigits;
- for (i=0, j=0; ; i++, j++)
+ if (my_str[0] == '-') /* skip over sign, affects grouping calculations */
+ {
+ new_str[0] = my_str[0];
+ my_str++;
+ new_str_start = 1;
+ }
+
+ for (i=0, j=new_str_start; ; i++, j++)
{
/* Hit decimal point? */
if (my_str[i] == '.')
new_str[j] = my_str[i];
}
- strcpy(my_str, new_str);
- free(new_str);
+ return new_str;
}
/*************************/
}
if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
fputs(my_cell, fout);
free(my_cell);
}
fputs(opt_fieldsep, fout);
if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
fputs(my_cell, fout);
free(my_cell);
}
{
if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(cell_w[i] + 1);
+ char *my_cell = format_numeric_locale(*ptr);
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
fprintf(fout, "%*s%s", widths[i % col_count] - cell_w[i], "", my_cell);
free(my_cell);
- }
+ }
else
fprintf(fout, "%*s%s", widths[i % col_count] - cell_w[i], "", *ptr);
}
else
fputs(" ", fout);
+ if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(cell_w[i] + 1);
-
- strcpy(my_cell, *ptr);
- if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
if (opt_border < 2)
fprintf(fout, "%s\n", my_cell);
else
fprintf(fout, "%-s%*s |\n", my_cell, dwidth - cell_w[i], "");
free(my_cell);
}
+ else
+ {
+ if (opt_border < 2)
+ fprintf(fout, "%s\n", *ptr);
+ else
+ fprintf(fout, "%-s%*s |\n", *ptr, dwidth - cell_w[i], "");
+ }
}
if (opt_border == 2)
fputs(" ", fout);
else if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
+ char *my_cell = format_numeric_locale(*ptr);
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
html_escaped_print(my_cell, fout);
free(my_cell);
}
fputs(" ", fout);
else if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
html_escaped_print(my_cell, fout);
free(my_cell);
}
{
if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
latex_escaped_print(my_cell, fout);
free(my_cell);
}
{
if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
+ char *my_cell = format_numeric_locale(*ptr);
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
latex_escaped_print(my_cell, fout);
free(my_cell);
}
{
if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
troff_ms_escaped_print(my_cell, fout);
free(my_cell);
}
fputc('\t', fout);
if (opt_numeric_locale)
{
- char *my_cell = pg_local_malloc(strlen_with_numeric_locale(*ptr) + 1);
-
- strcpy(my_cell, *ptr);
- format_numeric_locale(my_cell);
+ char *my_cell = format_numeric_locale(*ptr);
+
troff_ms_escaped_print(my_cell, fout);
free(my_cell);
}