CVSROOT:        /cvs
Module name:    src
Changes by:     schwa...@cvs.openbsd.org        2025/07/16 08:23:55

Modified files:
        usr.bin/mandoc : man_term.c mdoc_term.c out.c out.h roff_term.c 
                         tbl.h tbl_html.c tbl_layout.c tbl_term.c term.c 
                         term.h term_ascii.c term_ps.c term_tab.c 

Log message:
In 2009, kristaps@ decided that using EN as the basic unit for
horizontal widths on terminal output devices was the simplest option.
It made sense because one EN is the smallest possible horizontal
cursor movement on a terminal.  In 2014, kristaps@ implemented the 'u'
unit (BU, "basic unit") for scaled width input as 1/24 EN, but all
internal variables continued to store widths in units of EN.

This causes compatibility problems with groff, which internally
represents widths in units of BU rather than EN.  Various high-level
macros internally calculate sums of user-controlled widths with a
sub-EN precision.  In mandoc, the coarse internal representation
causes rounding errors, in some cases resulting in wrong indentations.

Fix this by changing many internal variables in the terminal formatter
to store widths in units of BU instead of EN, improving compatibility.

An example of a manual page where mandoc output becomes more
compatible with groff output is clang(1) - a page generated by the
atrocious rst2man(1) tool, which insists, among other insanity, on
indenting by non-integer multiples of EN.

This patch includes the following related changes:
* The termp.advance and endline functions now update termp.viscol.
* Rename termp.width to termp.getwidth to help grep(1).
* Delete term_hen() which becomes the same as term_hspan().
* Delete the unused struct termp_tbl.
* Delete the unused tbl_sulen functions.

In the tbl_term formatter, pass an additional coloff argument to
all the data and fill functions, to deal with mismatches between
the desired and the actual cursor position: the desired position
is now maintained with BU precision, but the actual position is of
course still an integer multiple of EN.

Also simplify tbl_literal() by leaving TERMP_CENTER and TERMP_RIGHT
adjustment to term_flushln(), which already contains code for that
very purpose.

We are really lucky to have the regress/ test suite.  Without it,
tricky and pervasive low-level refactoring of this kind would be
impossible because it would unavoidably cause lots of regressions.

Reply via email to