* mdocml: Allow string lengths to account for escapes.
@ 2010-09-15 14:36 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-09-15 14:36 UTC (permalink / raw)
To: source
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-09-15 14:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-15 14:36 mdocml: Allow string lengths to account for escapes kristaps
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).