source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Slightly improve \w width measurements: Count special characters
Date: Thu, 22 Jan 2015 17:52:13 -0500 (EST)	[thread overview]
Message-ID: <5242133268407992565.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
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@.

Modified Files:
--------------
    mdocml:
        roff.c

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.252
retrieving revision 1.253
diff -Lroff.c -Lroff.c -u -p -r1.252 -r1.253
--- roff.c
+++ roff.c
@@ -1004,8 +1004,9 @@ roff_res(struct roff *r, struct buf *buf
 
 		/* 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
 			}
 			if (maxl == 0 && *cp == term) {
 				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;
 			}
 		}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-01-22 22:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5242133268407992565.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).