From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15985 invoked from network); 8 Apr 2022 17:02:34 -0000 Received: from bsd.lv (HELO mandoc.bsd.lv) (66.111.2.12) by inbox.vuxu.org with ESMTPUTF8; 8 Apr 2022 17:02:34 -0000 Received: from fantadrom.bsd.lv (localhost [127.0.0.1]) by mandoc.bsd.lv (OpenSMTPD) with ESMTP id 5194fac3 for ; Fri, 8 Apr 2022 12:02:32 -0500 (EST) Received: from scc-mailout-kit-01.scc.kit.edu (scc-mailout-kit-01.scc.kit.edu [129.13.231.81]) by mandoc.bsd.lv (OpenSMTPD) with ESMTP id 8e2f24b0 for ; Fri, 8 Apr 2022 12:02:32 -0500 (EST) Received: from hekate.asta.kit.edu ([2a00:1398:5:f401::77]) by scc-mailout-kit-01.scc.kit.edu with esmtps (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (envelope-from ) id 1ncs0E-00FMWp-ML; Fri, 08 Apr 2022 19:02:31 +0200 Received: from login-1.asta.kit.edu ([2a00:1398:5:f400::72]) by hekate.asta.kit.edu with esmtp (Exim 4.94.2) (envelope-from ) id 1ncs0C-004HBh-Uv; Fri, 08 Apr 2022 19:02:29 +0200 Received: from schwarze by login-1.asta.kit.edu with local (Exim 4.92) (envelope-from ) id 1ncs0D-0007Ri-BO; Fri, 08 Apr 2022 19:02:29 +0200 Date: Fri, 8 Apr 2022 19:02:29 +0200 From: Ingo Schwarze To: Simon Branch Cc: discuss@mandoc.bsd.lv Subject: Re: tbl: incorrect width calculation in cs[s..] Message-ID: References: <20220403201427.bugtqtlzdcygb45l@pine.sigxcpu.com> X-Mailinglist: mandoc-discuss Reply-To: discuss@mandoc.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220403201427.bugtqtlzdcygb45l@pine.sigxcpu.com> Hello Simon, Simon Branch wrote on Sun, Apr 03, 2022 at 01:14:27PM -0700: > Hello! mandoc has some slightly odd behavior when formatting a table > like this, where the author wants a centered title: > > .TS > tab(#); > csss > l1 l3 l1 l. > heading > 00#NUL#01#SOH > .TE > > Groff outputs this: > > heading > 00 NUL 01 SOH Which makes sense: 4 spaces before and after the heading. > mandoc outputs this: > > heading > 00 NUL 01 SOH Which is clearly not right. > There are three problems here: > > - The space after the first column isn't counted. > - The imaginary spaces after the last column are counted, even though > they aren't output. Well, as long as we assume the spacing is always 3n (as the old code did), we can't really say whether the magic constant "3" in the code refers to the spacing before or after the column, so these two perfectly cancel each other and do not represent additional bugs. > - Mandoc assumes that each column has three trailing spaces. Yes. That is indeed the issue here. > In other words, the control flow works like this: > > - Start with the first column's width. > - If there are any continuation columns, add their widths and trailing > spaces. > > But I think it should work like this: > > - Start with the first column's width. > - If there are any continuation columns, add the widths of the rest of > the columns, and all the trailing spaces *except* for the ones after > the last column. Yes. Thank you for the good analysis and the perfect patch. I committed it to openbsd.org and bsd.lv. > This might still be incorrect (?) if there are more columns after > "cs...", but I think a partial fix is better than no fix at all. Actually, my impression is it works just fine even in that case, too. Besides, it survives the complete regression test suite, which contains many tbl(7) tests, though admittedly few that explicitly set the spacing between columns. I had to apply your patch by hand because you converted tabs to spaces. When sending patches, please use "cvs diff -up" and make sure neither you nor your mail program mangle the patch. I'm including the committed patch below; please compare it to the version you sent to see how they differ. Yours, Ingo Log Message: ----------- When calculating the with of spanned columns, which for example matters for centering text spanning multiple tbl(7) columns, correctly account for the spacing between columns instead of wrongly assuming the default spacing of 3n. Patch from Simon Branch . Modified Files: -------------- mandoc: tbl_term.c Revision Data ------------- Index: tbl_term.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/tbl_term.c,v retrieving revision 1.75 retrieving revision 1.76 diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.75 -r1.76 --- tbl_term.c +++ tbl_term.c @@ -820,8 +820,11 @@ tbl_literal(struct termp *tp, const stru width = col->width; ic = dp->layout->col; hspans = dp->hspans; - while (hspans--) - width += tp->tbl.cols[++ic].width + 3; + while (hspans--) { + width += tp->tbl.cols[ic].spacing; + ic++; + width += tp->tbl.cols[ic].width; + } padr = width > len ? width - len : 0; padl = 0; -- To unsubscribe send an email to discuss+unsubscribe@mandoc.bsd.lv