From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o8FEaHWe022747 for ; Wed, 15 Sep 2010 10:36:17 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id o8FEaGsl003051; Wed, 15 Sep 2010 10:36:16 -0400 (EDT) Date: Wed, 15 Sep 2010 10:36:16 -0400 (EDT) Message-Id: <201009151436.o8FEaGsl003051@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Allow string lengths to account for escapes. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Allow string lengths to account for escapes. Now all calls to calculate column width in -Tascii, -Tpdf, and -Tps will account for "more real" string lengths. Example: .Bl -tag -width \s[+123424]foo .It bar baz .El The size escape will be correctly tossed. .Bl -tag -width \(aqbar .It \(aqbar baz .El The \(aq will be correctly handled. Modified Files: -------------- mdocml: TODO man_term.c term.c Revision Data ------------- Index: term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v retrieving revision 1.170 retrieving revision 1.171 diff -Lterm.c -Lterm.c -u -p -r1.170 -r1.171 --- term.c +++ term.c @@ -458,7 +458,6 @@ void term_word(struct termp *p, const char *word) { const char *sv, *seq; - int sz; size_t ssz; enum roffdeco deco; @@ -515,7 +514,7 @@ term_word(struct termp *p, const char *w continue; seq = ++word; - sz = a2roffdeco(&deco, &seq, &ssz); + word += a2roffdeco(&deco, &seq, &ssz); switch (deco) { case (DECO_RESERVED): @@ -542,7 +541,6 @@ term_word(struct termp *p, const char *w break; } - word += sz; if (DECO_NOSPACE == deco && '\0' == *word) p->flags |= TERMP_NOSPACE; } @@ -645,10 +643,48 @@ term_len(const struct termp *p, size_t s size_t term_strlen(const struct termp *p, const char *cp) { - size_t sz; - - for (sz = 0; *cp; cp++) - sz += (*p->width)(p, *cp); + size_t sz, ssz, rsz, i; + enum roffdeco d; + const char *seq, *rhs; + + for (sz = 0; '\0' != *cp; ) + /* + * Account for escaped sequences within string length + * calculations. This follows the logic in term_word() + * as we must calculate the width of produced strings. + */ + if ('\\' == *cp) { + seq = ++cp; + cp += a2roffdeco(&d, &seq, &ssz); + + switch (d) { + case (DECO_RESERVED): + rhs = chars_res2str + (p->symtab, seq, ssz, &rsz); + break; + case (DECO_SPECIAL): + /* FALLTHROUGH */ + case (DECO_SSPECIAL): + rhs = chars_spec2str + (p->symtab, seq, ssz, &rsz); + + /* Allow for one-char escapes. */ + if (DECO_SSPECIAL != d || rhs) + break; + + rhs = seq; + rsz = ssz; + break; + default: + rhs = NULL; + break; + } + + if (rhs) + for (i = 0; i < rsz; i++) + sz += (*p->width)(p, *rhs++); + } else + sz += (*p->width)(p, *cp++); return(sz); } Index: man_term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v retrieving revision 1.84 retrieving revision 1.85 diff -Lman_term.c -Lman_term.c -u -p -r1.84 -r1.85 --- man_term.c +++ man_term.c @@ -916,6 +916,10 @@ print_man_foot(struct termp *p, const vo p->rmargin = p->maxrmargin - term_strlen(p, buf); p->offset = 0; + /* term_strlen() can return zero. */ + if (p->rmargin == p->maxrmargin) + p->rmargin--; + if (meta->source) term_word(p, meta->source); if (meta->source) Index: TODO =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/TODO,v retrieving revision 1.46 retrieving revision 1.47 diff -LTODO -LTODO -u -p -r1.46 -r1.47 --- TODO +++ TODO @@ -172,11 +172,6 @@ Several areas can be cleaned up to make * structural issues ************************************************************************ -- rendering frontend code can calculate widths only for plain strings, - not for strings containing escape sequences. For example, this - hinders calculation of the indent required for .Nm \&[ in text(1). - comments from kristaps@ Wed, 21 Jul 2010 23:26:08 +0200 - - another example of the same problem: .Bl -tag -width "\eD{format}XX" -compact in OpenBSD ksh(1) gives the wrong width -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv