* mdocml: Handle literal tab characters both in literal context (.Bd
@ 2010-05-24 21:34 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2010-05-24 21:34 UTC (permalink / raw)
To: source
Log Message:
-----------
Handle literal tab characters both in literal context (.Bd -literal)
and outside. In literal context, tab stops are at each eigth column;
outside, they are at each fifth column.
from OpenBSD mdoc_term.c rev. 1.75;
"commit" kristaps@
Modified Files:
--------------
mdocml:
term.h
term.c
mdoc_term.c
Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lterm.c -Lterm.c -u -p -r1.137 -r1.138
--- term.c
+++ term.c
@@ -84,6 +84,7 @@ term_alloc(enum termenc enc, size_t widt
perror(NULL);
exit(EXIT_FAILURE);
}
+ p->tabwidth = 5;
p->enc = enc;
/* Enforce some lower boundary. */
if (width < 60)
@@ -171,6 +172,17 @@ term_flushln(struct termp *p)
while (i < (int)p->col) {
/*
+ * Handle literal tab characters.
+ */
+ for (j = i; j < (int)p->col; j++) {
+ if ('\t' != p->buf[j])
+ break;
+ vend = (vis/p->tabwidth+1)*p->tabwidth;
+ vbl += vend - vis;
+ vis = vend;
+ }
+
+ /*
* Count up visible word characters. Control sequences
* (starting with the CSI) aren't counted. A space
* generates a non-printing word, which is valid (the
@@ -178,8 +190,8 @@ term_flushln(struct termp *p)
*/
/* LINTED */
- for (j = i; j < (int)p->col; j++) {
- if (j && ' ' == p->buf[j])
+ for ( ; j < (int)p->col; j++) {
+ if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
break;
if (8 == p->buf[j])
vend--;
@@ -209,8 +221,16 @@ term_flushln(struct termp *p)
p->overstep = 0;
}
+ /*
+ * Skip leading tabs, they were handled above.
+ */
+ while (i < (int)p->col && '\t' == p->buf[i])
+ i++;
+
/* Write out the [remaining] word. */
for ( ; i < (int)p->col; i++) {
+ if ('\t' == p->buf[i])
+ break;
if (' ' == p->buf[i]) {
while (' ' == p->buf[i]) {
vbl++;
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.55
retrieving revision 1.56
diff -Lterm.h -Lterm.h -u -p -r1.55 -r1.56
--- term.h
+++ term.h
@@ -37,6 +37,7 @@ struct termp {
size_t maxrmargin; /* Max right margin. */
size_t maxcols; /* Max size of buf. */
size_t offset; /* Margin offest. */
+ size_t tabwidth; /* Distance of tab positions. */
size_t col; /* Bytes in buf. */
int overstep; /* See termp_flushln(). */
int flags;
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.128 -r1.129
--- mdoc_term.c
+++ mdoc_term.c
@@ -274,6 +274,7 @@ terminal_mdoc(void *arg, const struct md
p->overstep = 0;
p->maxrmargin = p->defrmargin;
+ p->tabwidth = 5;
if (NULL == p->symtab)
switch (p->enc) {
@@ -1593,6 +1594,7 @@ termp_fa_pre(DECL_ARGS)
static int
termp_bd_pre(DECL_ARGS)
{
+ size_t tabwidth;
int i, type;
size_t rm, rmax;
const struct mdoc_node *nn;
@@ -1622,6 +1624,8 @@ termp_bd_pre(DECL_ARGS)
if (MDOC_Literal != type && MDOC_Unfilled != type)
return(1);
+ tabwidth = p->tabwidth;
+ p->tabwidth = 8;
rm = p->rmargin;
rmax = p->maxrmargin;
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
@@ -1636,6 +1640,7 @@ termp_bd_pre(DECL_ARGS)
else if (NULL == nn->prev)
term_flushln(p);
}
+ p->tabwidth = tabwidth;
p->rmargin = rm;
p->maxrmargin = rmax;
--
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-05-24 21:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24 21:34 mdocml: Handle literal tab characters both in literal context (.Bd schwarze
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).