diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-05-08 15:34:54 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-05-08 15:34:54 +0000 |
commit | 743d8976911a7ef031de0fe12ef9ba67c3e7e5d4 (patch) | |
tree | 932d68bc5071b433591243f7ea70c4f9f7af959a /roff_term.c | |
parent | 3d6c85a4e22160f04975c142bcdf4c4a12f39cbd (diff) | |
download | mandoc-743d8976911a7ef031de0fe12ef9ba67c3e7e5d4.tar.gz |
Basic implementation of the roff(7) .ti (temporary indent) request.
Needed by about four dozen ports (thanks to naddy@ for the research).
Diffstat (limited to 'roff_term.c')
-rw-r--r-- | roff_term.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/roff_term.c b/roff_term.c index 9786e0a6..3c2f24a9 100644 --- a/roff_term.c +++ b/roff_term.c @@ -32,6 +32,7 @@ static void roff_term_pre_ft(ROFF_TERM_ARGS); static void roff_term_pre_ll(ROFF_TERM_ARGS); static void roff_term_pre_sp(ROFF_TERM_ARGS); static void roff_term_pre_ta(ROFF_TERM_ARGS); +static void roff_term_pre_ti(ROFF_TERM_ARGS); static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = { roff_term_pre_br, /* br */ @@ -39,6 +40,7 @@ static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = { roff_term_pre_ll, /* ft */ roff_term_pre_sp, /* sp */ roff_term_pre_ta, /* ta */ + roff_term_pre_ti, /* ti */ }; @@ -121,3 +123,43 @@ roff_term_pre_ta(ROFF_TERM_ARGS) for (n = n->child; n != NULL; n = n->next) term_tab_set(p, n->string); } + +static void +roff_term_pre_ti(ROFF_TERM_ARGS) +{ + struct roffsu su; + const char *cp; + int len, sign; + + roff_term_pre_br(p, n); + + if (n->child == NULL) + return; + cp = n->child->string; + if (*cp == '+') { + sign = 1; + cp++; + } else if (*cp == '-') { + sign = -1; + cp++; + } else + sign = 0; + + if (a2roffsu(cp, &su, SCALE_EM) == 0) + return; + len = term_hspan(p, &su) / 24; + + if (sign == 0) { + p->ti = len - p->offset; + p->offset = len; + } else if (sign == 1) { + p->ti = len; + p->offset += len; + } else if ((size_t)len < p->offset) { + p->ti = -len; + p->offset -= len; + } else { + p->ti = -p->offset; + p->offset = 0; + } +} |