*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.63 2005/07/10 15:53:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.64 2005/07/14 06:46:17 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
#include "mbprint.h"
+static void *
+pg_local_malloc(size_t size)
+{
+ void *tmp;
+
+ tmp = malloc(size);
+ if (!tmp)
+ {
+ psql_error("out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+ return tmp;
+}
+
static int
num_numericseps(const char *my_str)
{
else
return int_len / 3 - 1; /* no leading separator */
}
+
static int
len_with_numericsep(const char *my_str)
{
if (digits_before_sep == 0)
new_len--; /* no leading separator */
- new_str = malloc(new_len);
- if (!new_str)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
+ new_str = pg_local_malloc(new_len + 1);
for (i=0, j=0; ; i++, j++)
{
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) > 0 &&
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
{
- char *my_cell = malloc(len_with_numericsep(*ptr));
+ char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
format_numericsep(my_cell, opt_numericsep);
fputs(my_cell, fout);
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
{
- char *my_cell = malloc(len_with_numericsep(*ptr));
+ char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
format_numericsep(my_cell, opt_numericsep);
fputs(my_cell, fout);
{
if (strlen(*ptr) > 0 && opt_numericsep != NULL && strlen(opt_numericsep) > 0)
{
- char *my_cell = malloc(cell_w[i]);
+ char *my_cell = pg_local_malloc(cell_w[i] + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
format_numericsep(my_cell, opt_numericsep);
fprintf(fout, "%*s%s", widths[i % col_count] - cell_w[i], "", my_cell);
fprintf(fout, "%s\n", title);
/* make horizontal border */
- divider = malloc(hwidth + dwidth + 10);
- if (!divider)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
+ divider = pg_local_malloc(hwidth + dwidth + 10);
divider[0] = '\0';
if (opt_border == 2)
strcat(divider, "+-");
{
if (!opt_barebones)
{
- char *record_str = malloc(32);
+ char *record_str = pg_local_malloc(32);
size_t record_str_len;
- if (!record_str)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
-
if (opt_border == 0)
snprintf(record_str, 32, "* Record %d", record++);
else
fputs(" ", fout);
{
- char *my_cell = malloc(cell_w[i]);
+ char *my_cell = pg_local_malloc(cell_w[i] + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
else if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
{
- char *my_cell = malloc(len_with_numericsep(*ptr));
+ char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
format_numericsep(my_cell, opt_numericsep);
html_escaped_print(my_cell, fout);
else if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
{
- char *my_cell = malloc(len_with_numericsep(*ptr));
+ char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
- if (!my_cell)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
strcpy(my_cell, *ptr);
format_numericsep(my_cell, opt_numericsep);
html_escaped_print(my_cell, fout);
exit(EXIT_FAILURE);
}
- footers[0] = malloc(100);
- if (!footers[0])
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
+ footers[0] = pg_local_malloc(100);
if (PQntuples(result) == 1)
snprintf(footers[0], 100, _("(1 row)"));
else