From d447f8bb823e9978d453eef38c203d6fa5ed044b Mon Sep 17 00:00:00 2001 From: Bjarni Ingi Gislason Date: Fri, 3 Dec 2021 01:20:35 +0000 Subject: [PATCH] tbl/table.cpp: avoid creating a trailing space when the last column is centered Directory: src/preproc/ The padding character is "^C" in ".fc ^B^C" ('^' means a control character) Example: .TS c . centered .TE /usr/bin/tbl : [...] .fc ^B^C [...] .nr 3cl0 0*\n[3sep] [...] \&\h'|\n[3cl0]u'^B^Ccentered^C^B The last padding character is interpreted as a space character(?), but is removed in "env.cpp" (strip trailing spaces) without reporting it. Signed-off-by: Bjarni Ingi Gislason --- src/preproc/tbl/table.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp index 435ac6bf7..364c26f19 100644 --- a/src/preproc/tbl/table.cpp +++ b/src/preproc/tbl/table.cpp @@ -546,10 +546,15 @@ center_text_entry::center_text_entry(const table *p, void center_text_entry::simple_print(int) { + extern int center_ncolumns; printfs("\\h'|\\n[%1]u'", column_start_reg(start_col)); prints("\002\003"); print_contents(); - prints("\003\002"); +/* Avoid creating a trailing space in the last column */ + if (start_col == (center_ncolumns - 1) ) + prints("\002"); + else + prints("\003\002"); } void center_text_entry::add_tab() @@ -1238,6 +1243,9 @@ void vertical_rule::print() } } +/* Used in function center_text_entry::simple_print(int) */ +int center_ncolumns; + table::table(int nc, unsigned f, int ls, char dpc) : nrows(0), ncolumns(nc), linesize(ls), decimal_point_char(dpc), vrule_list(0), stuff_list(0), span_list(0), @@ -1245,6 +1253,7 @@ table::table(int nc, unsigned f, int ls, char dpc) vline(0), row_is_all_lines(0), left_separation(0), right_separation(0), total_separation(0), allocated_rows(0), flags(f) { + center_ncolumns = nc; minimum_width = new string[ncolumns]; column_separation = ncolumns > 1 ? new int[ncolumns - 1] : 0; equal = new char[ncolumns]; @@ -1913,7 +1922,7 @@ void table::init_output() ".nr " SAVED_DN_REG " \\n[dn]\n" ".ne \\n[dn]u+\\n[.V]u\n" ".ie \\n[.t]<=\\n[" SAVED_DN_REG "] \\{\\\n" - ". tmc \\n[.F]: around line \\n[.c]: error:\n" + ". tmc tbl:\\n[.F]: around line \\n[.c]: error:\n" ". tmc \" table will not fit on page \\n%;\n" ". tm1 \" use .TS H/.TH with a supporting macro package\n" ".\\}\n" @@ -2023,14 +2032,14 @@ string column_end_reg(int col) string column_divide_reg(int col) { - static char name[sizeof(COLUMN_DIVIDE_PREFIX)+INT_DIGITS]; + static char name[sizeof(COLUMN_DIVIDE_PREFIX)+INT_DIGITS+1]; /* Added 1, BG */ sprintf(name, COLUMN_DIVIDE_PREFIX "%d", col); return string(name); } string row_top_reg(int row) { - static char name[sizeof(ROW_TOP_PREFIX)+INT_DIGITS]; + static char name[sizeof(ROW_TOP_PREFIX)+INT_DIGITS+1]; /* Added 1, BG */ sprintf(name, ROW_TOP_PREFIX "%d", row); return string(name); } @@ -2177,7 +2186,7 @@ void table::compute_expand_width() "delim off\n" ".EN\n" "..\n"); - prints(".tmc \\n[.F]: around line \\n[.c]: warning:\n" + prints(".tmc tbl:\\n[.F]: around line \\n[.c]: warning:\n" ".tm1 \" table wider than line width\n"); prints(".ig\n" ".EQ\n" @@ -2230,7 +2239,7 @@ void table::compute_separation_factor() "delim off\n" ".EN\n" "..\n"); - prints(".tmc \\n[.F]: around line \\n[.c]: warning:\n" + prints(".tmc tbl:\\n[.F]: around line \\n[.c]: warning:\n" ".tm1 \" table column separation set to zero\n" ".nr " SEPARATION_FACTOR_REG " 0\n"); } @@ -2238,7 +2247,7 @@ void table::compute_separation_factor() ".el .if \\n[" SEPARATION_FACTOR_REG "]<1n \\{\\\n"); entry_list->set_location(); if (!(flags & NOWARN)) { - prints(".tmc \\n[.F]: around line \\n[.c]: warning:\n" + prints(".tmc tbl:\\n[.F]: around line \\n[.c]: warning:\n" ".tm1 \" table squeezed horizontally to fit line length\n"); prints(".ig\n" ".EQ\n" -- 2.33.0