@@ -44,6 +44,9 @@ static char *decimal_point;
44
44
static char * grouping ;
45
45
static char * thousands_sep ;
46
46
47
+ static char default_footer [100 ];
48
+ static printTableFooter default_footer_cell = { default_footer , NULL };
49
+
47
50
/* Line style control structures */
48
51
const printTextFormat pg_asciiformat =
49
52
{
@@ -278,6 +281,34 @@ print_separator(struct separator sep, FILE *fout)
278
281
}
279
282
280
283
284
+ /*
285
+ * Return the list of explicitly-requested footers or, when applicable, the
286
+ * default "(xx rows)" footer. Always omit the default footer when given
287
+ * non-default footers, "\pset footer off", or a specific instruction to that
288
+ * effect from a calling backslash command. Vertical formats number each row,
289
+ * making the default footer redundant; they do not call this function.
290
+ *
291
+ * The return value may point to static storage; do not keep it across calls.
292
+ */
293
+ static printTableFooter *
294
+ footers_with_default (const printTableContent * cont )
295
+ {
296
+ if (cont -> footers == NULL && cont -> opt -> default_footer )
297
+ {
298
+ unsigned long total_records ;
299
+
300
+ total_records = cont -> opt -> prior_records + cont -> nrows ;
301
+ snprintf (default_footer , sizeof (default_footer ),
302
+ ngettext ("(%lu row)" , "(%lu rows)" , total_records ),
303
+ total_records );
304
+
305
+ return & default_footer_cell ;
306
+ }
307
+ else
308
+ return cont -> footers ;
309
+ }
310
+
311
+
281
312
/*************************/
282
313
/* Unaligned text */
283
314
/*************************/
@@ -340,11 +371,13 @@ print_unaligned_text(const printTableContent *cont, FILE *fout)
340
371
/* print footers */
341
372
if (cont -> opt -> stop_table )
342
373
{
343
- if (!opt_tuples_only && cont -> footers != NULL && !cancel_pressed )
374
+ printTableFooter * footers = footers_with_default (cont );
375
+
376
+ if (!opt_tuples_only && footers != NULL && !cancel_pressed )
344
377
{
345
378
printTableFooter * f ;
346
379
347
- for (f = cont -> footers ; f ; f = f -> next )
380
+ for (f = footers ; f ; f = f -> next )
348
381
{
349
382
if (need_recordsep )
350
383
{
@@ -1034,16 +1067,18 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
1034
1067
1035
1068
if (cont -> opt -> stop_table )
1036
1069
{
1070
+ printTableFooter * footers = footers_with_default (cont );
1071
+
1037
1072
if (opt_border == 2 && !cancel_pressed )
1038
1073
_print_horizontal_line (col_count , width_wrap , opt_border ,
1039
1074
PRINT_RULE_BOTTOM , format , fout );
1040
1075
1041
1076
/* print footers */
1042
- if (cont -> footers && !opt_tuples_only && !cancel_pressed )
1077
+ if (footers && !opt_tuples_only && !cancel_pressed )
1043
1078
{
1044
1079
printTableFooter * f ;
1045
1080
1046
- for (f = cont -> footers ; f ; f = f -> next )
1081
+ for (f = footers ; f ; f = f -> next )
1047
1082
fprintf (fout , "%s\n" , f -> data );
1048
1083
}
1049
1084
@@ -1447,15 +1482,17 @@ print_html_text(const printTableContent *cont, FILE *fout)
1447
1482
1448
1483
if (cont -> opt -> stop_table )
1449
1484
{
1485
+ printTableFooter * footers = footers_with_default (cont );
1486
+
1450
1487
fputs ("</table>\n" , fout );
1451
1488
1452
1489
/* print footers */
1453
- if (!opt_tuples_only && cont -> footers != NULL && !cancel_pressed )
1490
+ if (!opt_tuples_only && footers != NULL && !cancel_pressed )
1454
1491
{
1455
1492
printTableFooter * f ;
1456
1493
1457
1494
fputs ("<p>" , fout );
1458
- for (f = cont -> footers ; f ; f = f -> next )
1495
+ for (f = footers ; f ; f = f -> next )
1459
1496
{
1460
1497
html_escaped_print (f -> data , fout );
1461
1498
fputs ("<br />\n" , fout );
@@ -1668,17 +1705,19 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1668
1705
1669
1706
if (cont -> opt -> stop_table )
1670
1707
{
1708
+ printTableFooter * footers = footers_with_default (cont );
1709
+
1671
1710
if (opt_border == 2 )
1672
1711
fputs ("\\hline\n" , fout );
1673
1712
1674
1713
fputs ("\\end{tabular}\n\n\\noindent " , fout );
1675
1714
1676
1715
/* print footers */
1677
- if (cont -> footers && !opt_tuples_only && !cancel_pressed )
1716
+ if (footers && !opt_tuples_only && !cancel_pressed )
1678
1717
{
1679
1718
printTableFooter * f ;
1680
1719
1681
- for (f = cont -> footers ; f ; f = f -> next )
1720
+ for (f = footers ; f ; f = f -> next )
1682
1721
{
1683
1722
latex_escaped_print (f -> data , fout );
1684
1723
fputs (" \\\\\n" , fout );
@@ -1871,14 +1910,16 @@ print_troff_ms_text(const printTableContent *cont, FILE *fout)
1871
1910
1872
1911
if (cont -> opt -> stop_table )
1873
1912
{
1913
+ printTableFooter * footers = footers_with_default (cont );
1914
+
1874
1915
fputs (".TE\n.DS L\n" , fout );
1875
1916
1876
1917
/* print footers */
1877
- if (cont -> footers && !opt_tuples_only && !cancel_pressed )
1918
+ if (footers && !opt_tuples_only && !cancel_pressed )
1878
1919
{
1879
1920
printTableFooter * f ;
1880
1921
1881
- for (f = cont -> footers ; f ; f = f -> next )
1922
+ for (f = footers ; f ; f = f -> next )
1882
1923
{
1883
1924
troff_ms_escaped_print (f -> data , fout );
1884
1925
fputc ('\n' , fout );
@@ -2481,18 +2522,6 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
2481
2522
for (footer = opt -> footers ; * footer ; footer ++ )
2482
2523
printTableAddFooter (& cont , * footer );
2483
2524
}
2484
- else if (!opt -> topt .expanded && opt -> default_footer )
2485
- {
2486
- unsigned long total_records ;
2487
- char default_footer [100 ];
2488
-
2489
- total_records = opt -> topt .prior_records + cont .nrows ;
2490
- snprintf (default_footer , sizeof (default_footer ),
2491
- ngettext ("(%lu row)" , "(%lu rows)" , total_records ),
2492
- total_records );
2493
-
2494
- printTableAddFooter (& cont , default_footer );
2495
- }
2496
2525
2497
2526
printTable (& cont , fout , flog );
2498
2527
printTableCleanup (& cont );
0 commit comments