From 18c87ef68c91b81051bd58c31019aa7c8983ce80 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 23 Oct 2023 20:25:02 +0000 Subject: Support some escape sequences, in particular character escape sequences, inside \w arguments, and skip most other escape sequences when measuring the output length in this way because most escape sequences contribute little or nothing to text width: for example, consider font escapes in terminal output. This implementation is very rudimentary. In particular, it assumes that every character has the same width. No attempt is made to detect double-width or zero-width Unicode characters or to take dependencies on output devices or fonts into account. These limitations are hard to avoid because mandoc has to interpolate \w at the parsing stage when the output device is not yet known. I really do not want the content of the syntax tree to depend on the output device. Feature requested by Paul , who also submitted a patch, but i chose to commit this very different patch with almost the same functionality. His input was still very valuable because complete support for \w is out of the question, and consequently, the main task is identifying subsets of the feature that are needed for real-world manual pages and can be supported without uprooting the whole forest. --- regress/roff/esc/w.in | 16 +++++++++++++++- regress/roff/esc/w.out_ascii | 9 ++++++++- regress/roff/esc/w.out_lint | 9 +++++---- 3 files changed, 28 insertions(+), 6 deletions(-) (limited to 'regress') diff --git a/regress/roff/esc/w.in b/regress/roff/esc/w.in index c30a31ac..59a9bdb5 100644 --- a/regress/roff/esc/w.in +++ b/regress/roff/esc/w.in @@ -1,4 +1,4 @@ -.\" $OpenBSD: w.in,v 1.4 2022/06/08 13:08:00 schwarze Exp $ +.\" $OpenBSD: w.in,v 1.5 2023/10/23 20:07:19 schwarze Exp $ .Dd $Mdocdate$ .Dt ESC-W 1 .Os @@ -13,6 +13,20 @@ character: \w'n' blank: \w' ' .br text: \w'text' +.br +special: \w'\(bu' +.br +numbered: \w'\N'100'' +.br +Unicode: \w'\[u2013]' +.br +overstrike: \w'\o'ab'' +.br +undefined: \w'\G' +.br +zero-width: \w'\fB\&\fP' +.br +skipchar: \w'a\zb\z\(buc' .Ss Argument delimiters unsupported \er: \w\rM\ru .br diff --git a/regress/roff/esc/w.out_ascii b/regress/roff/esc/w.out_ascii index 7ed32ece..a8fdce54 100644 --- a/regress/roff/esc/w.out_ascii +++ b/regress/roff/esc/w.out_ascii @@ -8,6 +8,13 @@ DDEESSCCRRIIPPTTIIOONN character: 24 blank: 24 text: 96 + special: 24 + numbered: 24 + Unicode: 24 + overstrike: 24 + undefined: 24 + zero-width: 0 + skipchar: 48 AArrgguummeenntt ddeelliimmiitteerrss unsupported \r: 24u @@ -27,4 +34,4 @@ DDEESSCCRRIIPPTTIIOONN overstrike: 24u unterminated: 72 -OpenBSD June 8, 2022 OpenBSD +OpenBSD October 23, 2023 OpenBSD diff --git a/regress/roff/esc/w.out_lint b/regress/roff/esc/w.out_lint index fd2a0948..9c6417c5 100644 --- a/regress/roff/esc/w.out_lint +++ b/regress/roff/esc/w.out_lint @@ -1,4 +1,5 @@ -mandoc: w.in:17:20: UNSUPP: unsupported escape sequence: \r -mandoc: w.in:17:23: UNSUPP: unsupported escape sequence: \r -mandoc: w.in:23:16: WARNING: undefined escape, printing literally: \G -mandoc: w.in:51:15: ERROR: incomplete escape sequence: \w'foo +mandoc: w.in:25:15: WARNING: undefined escape, printing literally: \G +mandoc: w.in:31:20: UNSUPP: unsupported escape sequence: \r +mandoc: w.in:31:23: UNSUPP: unsupported escape sequence: \r +mandoc: w.in:37:16: WARNING: undefined escape, printing literally: \G +mandoc: w.in:65:15: ERROR: incomplete escape sequence: \w'foo -- cgit