summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-01-22 22:50:32 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-01-22 22:50:32 +0000
commitdc19c117010d5d4662c8bfc46e13f2ba350efa92 (patch)
tree08e7e1fd24a758c90f3cba7bc799f2ac3903c138 /usr.bin
parent5d93423f0c620f4b2aec4599a450a33d687b9395 (diff)
Slightly improve \w width measurements:
Count special characters with the same width as ASCII characters and treat all other escape sequences as if they had a width of 0. Certainly not perfect, but a bit better. For example, GNU RCS ci(1) needs this; reported by naddy@.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/roff.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 75f45c490c2..6e38f63443c 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.124 2015/01/21 02:16:11 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.125 2015/01/22 22:50:31 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1002,8 +1002,9 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
/* Advance to the end of the name. */
+ naml = 0;
arg_complete = 1;
- for (naml = 0; maxl == 0 || naml < maxl; naml++, cp++) {
+ while (maxl == 0 || naml < maxl) {
if (*cp == '\0') {
mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
ln, (int)(stesc - buf->buf), stesc);
@@ -1014,6 +1015,23 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
cp++;
break;
}
+ if (*cp++ != '\\' || stesc[1] != 'w') {
+ naml++;
+ continue;
+ }
+ switch (mandoc_escape(&cp, NULL, NULL)) {
+ case ESCAPE_SPECIAL:
+ /* FALLTHROUGH */
+ case ESCAPE_UNICODE:
+ /* FALLTHROUGH */
+ case ESCAPE_NUMBERED:
+ /* FALLTHROUGH */
+ case ESCAPE_OVERSTRIKE:
+ naml++;
+ break;
+ default:
+ break;
+ }
}
/*