Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4a8bbbd

Browse files
committed
Add numeric separator support for latex and troff output methods.
1 parent 75c76e9 commit 4a8bbbd

File tree

1 file changed

+67
-19
lines changed

1 file changed

+67
-19
lines changed

src/bin/psql/print.c

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.65 2005/07/14 06:49:58 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.66 2005/07/14 07:32:01 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -37,7 +37,7 @@ pg_local_malloc(size_t size)
3737
tmp = malloc(size);
3838
if (!tmp)
3939
{
40-
psql_error("out of memory\n");
40+
fprintf(stderr, _("out of memory\n"));
4141
exit(EXIT_FAILURE);
4242
}
4343
return tmp;
@@ -999,7 +999,8 @@ static void
999999
print_latex_text(const char *title, const char *const *headers,
10001000
const char *const *cells, const char *const *footers,
10011001
const char *opt_align, bool opt_tuples_only,
1002-
unsigned short int opt_border, FILE *fout)
1002+
char *opt_numericsep, unsigned short int opt_border,
1003+
FILE *fout)
10031004
{
10041005
unsigned int col_count = 0;
10051006
unsigned int i;
@@ -1059,7 +1060,18 @@ print_latex_text(const char *title, const char *const *headers,
10591060
/* print cells */
10601061
for (i = 0, ptr = cells; *ptr; i++, ptr++)
10611062
{
1062-
latex_escaped_print(*ptr, fout);
1063+
if (strlen(*ptr) != 0 &&
1064+
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
1065+
{
1066+
char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
1067+
1068+
strcpy(my_cell, *ptr);
1069+
format_numericsep(my_cell, opt_numericsep);
1070+
latex_escaped_print(my_cell, fout);
1071+
free(my_cell);
1072+
}
1073+
else
1074+
latex_escaped_print(*ptr, fout);
10631075

10641076
if ((i + 1) % col_count == 0)
10651077
fputs(" \\\\\n", fout);
@@ -1091,7 +1103,8 @@ static void
10911103
print_latex_vertical(const char *title, const char *const *headers,
10921104
const char *const *cells, const char *const *footers,
10931105
const char *opt_align, bool opt_tuples_only,
1094-
unsigned short int opt_border, FILE *fout)
1106+
char *opt_numericsep, unsigned short int opt_border,
1107+
FILE *fout)
10951108
{
10961109
unsigned int col_count = 0;
10971110
unsigned int i;
@@ -1161,7 +1174,18 @@ print_latex_vertical(const char *title, const char *const *headers,
11611174
if (footers && !opt_tuples_only)
11621175
for (ptr = footers; *ptr; ptr++)
11631176
{
1164-
latex_escaped_print(*ptr, fout);
1177+
if (strlen(*ptr) != 0 &&
1178+
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
1179+
{
1180+
char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
1181+
1182+
strcpy(my_cell, *ptr);
1183+
format_numericsep(my_cell, opt_numericsep);
1184+
latex_escaped_print(my_cell, fout);
1185+
free(my_cell);
1186+
}
1187+
else
1188+
latex_escaped_print(*ptr, fout);
11651189
fputs(" \\\\\n", fout);
11661190
}
11671191

@@ -1197,7 +1221,8 @@ static void
11971221
print_troff_ms_text(const char *title, const char *const *headers,
11981222
const char *const *cells, const char *const *footers,
11991223
const char *opt_align, bool opt_tuples_only,
1200-
unsigned short int opt_border, FILE *fout)
1224+
char *opt_numericsep, unsigned short int opt_border,
1225+
FILE *fout)
12011226
{
12021227
unsigned int col_count = 0;
12031228
unsigned int i;
@@ -1245,14 +1270,23 @@ print_troff_ms_text(const char *title, const char *const *headers,
12451270
}
12461271

12471272
if (!opt_tuples_only)
1248-
{
12491273
fputs("\n_\n", fout);
1250-
}
12511274

12521275
/* print cells */
12531276
for (i = 0, ptr = cells; *ptr; i++, ptr++)
12541277
{
1255-
troff_ms_escaped_print(*ptr, fout);
1278+
if (strlen(*ptr) != 0 &&
1279+
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
1280+
{
1281+
char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
1282+
1283+
strcpy(my_cell, *ptr);
1284+
format_numericsep(my_cell, opt_numericsep);
1285+
troff_ms_escaped_print(my_cell, fout);
1286+
free(my_cell);
1287+
}
1288+
else
1289+
troff_ms_escaped_print(*ptr, fout);
12561290

12571291
if ((i + 1) % col_count == 0)
12581292
fputc('\n', fout);
@@ -1281,7 +1315,8 @@ static void
12811315
print_troff_ms_vertical(const char *title, const char *const *headers,
12821316
const char *const *cells, const char *const *footers,
12831317
const char *opt_align, bool opt_tuples_only,
1284-
unsigned short int opt_border, FILE *fout)
1318+
char *opt_numericsep, unsigned short int opt_border,
1319+
FILE *fout)
12851320
{
12861321
unsigned int col_count = 0;
12871322
unsigned int i;
@@ -1324,7 +1359,6 @@ print_troff_ms_vertical(const char *title, const char *const *headers,
13241359
{
13251360
if (!opt_tuples_only)
13261361
{
1327-
13281362
if (current_format != 1)
13291363
{
13301364
if (opt_border == 2 && i > 0)
@@ -1356,7 +1390,19 @@ print_troff_ms_vertical(const char *title, const char *const *headers,
13561390

13571391
troff_ms_escaped_print(headers[i % col_count], fout);
13581392
fputc('\t', fout);
1359-
troff_ms_escaped_print(*ptr, fout);
1393+
if (strlen(*ptr) != 0 &&
1394+
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
1395+
{
1396+
char *my_cell = pg_local_malloc(len_with_numericsep(*ptr) + 1);
1397+
1398+
strcpy(my_cell, *ptr);
1399+
format_numericsep(my_cell, opt_numericsep);
1400+
troff_ms_escaped_print(my_cell, fout);
1401+
free(my_cell);
1402+
}
1403+
else
1404+
troff_ms_escaped_print(*ptr, fout);
1405+
13601406
fputc('\n', fout);
13611407
}
13621408

@@ -1529,19 +1575,21 @@ printTable(const char *title,
15291575
case PRINT_LATEX:
15301576
if (use_expanded)
15311577
print_latex_vertical(title, headers, cells, footers, align,
1532-
opt->tuples_only, border, output);
1578+
opt->tuples_only, opt->numericSep,
1579+
border, output);
15331580
else
15341581
print_latex_text(title, headers, cells, footers, align,
1535-
opt->tuples_only, border, output);
1582+
opt->tuples_only, opt->numericSep,
1583+
border, output);
15361584
break;
15371585
case PRINT_TROFF_MS:
15381586
if (use_expanded)
1539-
print_troff_ms_vertical(title, headers, cells, footers,
1540-
align, opt->tuples_only,
1587+
print_troff_ms_vertical(title, headers, cells, footers, align,
1588+
opt->tuples_only, opt->numericSep,
15411589
border, output);
15421590
else
1543-
print_troff_ms_text(title, headers, cells, footers,
1544-
align, opt->tuples_only,
1591+
print_troff_ms_text(title, headers, cells, footers, align,
1592+
opt->tuples_only, opt->numericSep,
15451593
border, output);
15461594
break;
15471595
default:

0 commit comments

Comments
 (0)