[BACK]Return to term.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/term.c, Revision 1.277

1.277   ! schwarze    1: /*     $Id: term.c,v 1.276 2018/10/25 01:32:41 schwarze Exp $ */
1.1       kristaps    2: /*
1.198     schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.275     schwarze    4:  * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
1.74      kristaps    7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
1.1       kristaps    9:  *
1.246     schwarze   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.74      kristaps   11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.246     schwarze   12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.74      kristaps   13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       kristaps   17:  */
1.128     kristaps   18: #include "config.h"
                     19:
1.126     kristaps   20: #include <sys/types.h>
                     21:
1.1       kristaps   22: #include <assert.h>
1.122     kristaps   23: #include <ctype.h>
1.22      kristaps   24: #include <stdio.h>
1.1       kristaps   25: #include <stdlib.h>
                     26: #include <string.h>
                     27:
1.137     kristaps   28: #include "mandoc.h"
1.218     schwarze   29: #include "mandoc_aux.h"
1.107     kristaps   30: #include "out.h"
1.71      kristaps   31: #include "term.h"
1.105     kristaps   32: #include "main.h"
1.1       kristaps   33:
1.203     schwarze   34: static size_t           cond_width(const struct termp *, int, int *);
1.266     schwarze   35: static void             adjbuf(struct termp_col *, size_t);
1.191     kristaps   36: static void             bufferc(struct termp *, char);
                     37: static void             encode(struct termp *, const char *, size_t);
1.194     kristaps   38: static void             encode1(struct termp *, int);
1.264     schwarze   39: static void             endline(struct termp *);
1.11      kristaps   40:
1.222     schwarze   41:
1.145     kristaps   42: void
1.269     schwarze   43: term_setcol(struct termp *p, size_t maxtcol)
                     44: {
                     45:        if (maxtcol > p->maxtcol) {
                     46:                p->tcols = mandoc_recallocarray(p->tcols,
                     47:                    p->maxtcol, maxtcol, sizeof(*p->tcols));
                     48:                p->maxtcol = maxtcol;
                     49:        }
                     50:        p->lasttcol = maxtcol - 1;
                     51:        p->tcol = p->tcols;
                     52: }
                     53:
                     54: void
1.71      kristaps   55: term_free(struct termp *p)
1.14      kristaps   56: {
1.266     schwarze   57:        for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++)
                     58:                free(p->tcol->buf);
                     59:        free(p->tcols);
1.238     schwarze   60:        free(p->fontq);
1.142     kristaps   61:        free(p);
                     62: }
                     63:
                     64: void
1.222     schwarze   65: term_begin(struct termp *p, term_margin head,
1.246     schwarze   66:                term_margin foot, const struct roff_meta *arg)
1.142     kristaps   67: {
                     68:
                     69:        p->headf = head;
                     70:        p->footf = foot;
                     71:        p->argf = arg;
1.146     kristaps   72:        (*p->begin)(p);
1.142     kristaps   73: }
                     74:
                     75: void
                     76: term_end(struct termp *p)
                     77: {
                     78:
1.146     kristaps   79:        (*p->end)(p);
1.14      kristaps   80: }
                     81:
1.71      kristaps   82: /*
1.221     schwarze   83:  * Flush a chunk of text.  By default, break the output line each time
                     84:  * the right margin is reached, and continue output on the next line
                     85:  * at the same offset as the chunk itself.  By default, also break the
                     86:  * output line at the end of the chunk.
1.130     kristaps   87:  * The following flags may be specified:
1.71      kristaps   88:  *
1.221     schwarze   89:  *  - TERMP_NOBREAK: Do not break the output line at the right margin,
                     90:  *    but only at the max right margin.  Also, do not break the output
                     91:  *    line at the end of the chunk, such that the next call can pad to
                     92:  *    the next column.  However, if less than p->trailspace blanks,
                     93:  *    which can be 0, 1, or 2, remain to the right margin, the line
                     94:  *    will be broken.
1.250     schwarze   95:  *  - TERMP_BRTRSP: Consider trailing whitespace significant
                     96:  *    when deciding whether the chunk fits or not.
1.221     schwarze   97:  *  - TERMP_BRIND: If the chunk does not fit and the output line has
                     98:  *    to be broken, start the next line at the right margin instead
                     99:  *    of at the offset.  Used together with TERMP_NOBREAK for the tags
                    100:  *    in various kinds of tagged lists.
1.263     schwarze  101:  *  - TERMP_HANG: Do not break the output line at the right margin,
1.221     schwarze  102:  *    append the next chunk after it even if this one is too long.
                    103:  *    To be used together with TERMP_NOBREAK.
1.263     schwarze  104:  *  - TERMP_NOPAD: Start writing at the current position,
                    105:  *    do not pad with blank characters up to the offset.
1.71      kristaps  106:  */
                    107: void
                    108: term_flushln(struct termp *p)
1.53      kristaps  109: {
1.114     kristaps  110:        size_t           vis;   /* current visual position on output */
                    111:        size_t           vbl;   /* number of blanks to prepend to output */
1.136     schwarze  112:        size_t           vend;  /* end of word visual position on output */
1.114     kristaps  113:        size_t           bp;    /* visual right border position */
1.172     schwarze  114:        size_t           dv;    /* temporary for visual pos calculations */
1.266     schwarze  115:        size_t           j;     /* temporary loop index for p->tcol->buf */
1.210     schwarze  116:        size_t           jhy;   /* last hyph before overflow w/r/t j */
1.152     kristaps  117:        size_t           maxvis; /* output position of visible boundary */
1.266     schwarze  118:        int              ntab;  /* number of tabs to prepend */
1.270     schwarze  119:        int              breakline; /* after this word */
1.53      kristaps  120:
1.266     schwarze  121:        vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ?
                    122:            0 : p->tcol->offset - p->viscol;
1.263     schwarze  123:        if (p->minbl && vbl < p->minbl)
                    124:                vbl = p->minbl;
1.266     schwarze  125:        maxvis = p->tcol->rmargin > p->viscol + vbl ?
                    126:            p->tcol->rmargin - p->viscol - vbl : 0;
1.263     schwarze  127:        bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
                    128:            p->maxrmargin > p->viscol + vbl ?
                    129:            p->maxrmargin - p->viscol - vbl : 0;
1.174     schwarze  130:        vis = vend = 0;
1.115     kristaps  131:
1.274     schwarze  132:        if ((p->flags & TERMP_MULTICOL) == 0)
1.267     schwarze  133:                p->tcol->col = 0;
1.269     schwarze  134:        while (p->tcol->col < p->tcol->lastcol) {
1.267     schwarze  135:
1.71      kristaps  136:                /*
1.154     kristaps  137:                 * Handle literal tab characters: collapse all
                    138:                 * subsequent tabs into a single huge set of spaces.
1.138     schwarze  139:                 */
1.267     schwarze  140:
1.205     schwarze  141:                ntab = 0;
1.269     schwarze  142:                while (p->tcol->col < p->tcol->lastcol &&
1.267     schwarze  143:                    p->tcol->buf[p->tcol->col] == '\t') {
1.260     schwarze  144:                        vend = term_tab_next(vis);
1.138     schwarze  145:                        vbl += vend - vis;
                    146:                        vis = vend;
1.205     schwarze  147:                        ntab++;
1.267     schwarze  148:                        p->tcol->col++;
1.138     schwarze  149:                }
                    150:
                    151:                /*
1.71      kristaps  152:                 * Count up visible word characters.  Control sequences
                    153:                 * (starting with the CSI) aren't counted.  A space
                    154:                 * generates a non-printing word, which is valid (the
                    155:                 * space is printed according to regular spacing rules).
                    156:                 */
                    157:
1.267     schwarze  158:                jhy = 0;
1.270     schwarze  159:                breakline = 0;
1.269     schwarze  160:                for (j = p->tcol->col; j < p->tcol->lastcol; j++) {
1.270     schwarze  161:                        if (p->tcol->buf[j] == '\n') {
                    162:                                if ((p->flags & TERMP_BRIND) == 0)
                    163:                                        breakline = 1;
                    164:                                continue;
                    165:                        }
1.266     schwarze  166:                        if (p->tcol->buf[j] == ' ' || p->tcol->buf[j] == '\t')
1.71      kristaps  167:                                break;
1.154     kristaps  168:
1.257     schwarze  169:                        /* Back over the last printed character. */
1.266     schwarze  170:                        if (p->tcol->buf[j] == '\b') {
1.153     kristaps  171:                                assert(j);
1.266     schwarze  172:                                vend -= (*p->width)(p, p->tcol->buf[j - 1]);
1.154     kristaps  173:                                continue;
1.153     kristaps  174:                        }
1.154     kristaps  175:
                    176:                        /* Regular word. */
                    177:                        /* Break at the hyphen point if we overrun. */
1.222     schwarze  178:                        if (vend > vis && vend < bp &&
1.266     schwarze  179:                            (p->tcol->buf[j] == ASCII_HYPH||
                    180:                             p->tcol->buf[j] == ASCII_BREAK))
1.154     kristaps  181:                                jhy = j;
                    182:
1.217     schwarze  183:                        /*
                    184:                         * Hyphenation now decided, put back a real
                    185:                         * hyphen such that we get the correct width.
                    186:                         */
1.266     schwarze  187:                        if (p->tcol->buf[j] == ASCII_HYPH)
                    188:                                p->tcol->buf[j] = '-';
1.217     schwarze  189:
1.266     schwarze  190:                        vend += (*p->width)(p, p->tcol->buf[j]);
1.71      kristaps  191:                }
1.53      kristaps  192:
1.71      kristaps  193:                /*
1.81      kristaps  194:                 * Find out whether we would exceed the right margin.
1.136     schwarze  195:                 * If so, break to the next line.
1.81      kristaps  196:                 */
1.267     schwarze  197:
                    198:                if (vend > bp && jhy == 0 && vis > 0 &&
1.264     schwarze  199:                    (p->flags & TERMP_BRNEVER) == 0) {
1.269     schwarze  200:                        if (p->flags & TERMP_MULTICOL)
1.267     schwarze  201:                                return;
                    202:
                    203:                        endline(p);
1.136     schwarze  204:                        vend -= vis;
1.205     schwarze  205:
1.260     schwarze  206:                        /* Use pending tabs on the new line. */
                    207:
                    208:                        vbl = 0;
                    209:                        while (ntab--)
                    210:                                vbl = term_tab_next(vbl);
                    211:
                    212:                        /* Re-establish indentation. */
1.205     schwarze  213:
1.263     schwarze  214:                        if (p->flags & TERMP_BRIND)
1.266     schwarze  215:                                vbl += p->tcol->rmargin;
1.263     schwarze  216:                        else
1.266     schwarze  217:                                vbl += p->tcol->offset;
                    218:                        maxvis = p->tcol->rmargin > vbl ?
                    219:                            p->tcol->rmargin - vbl : 0;
1.263     schwarze  220:                        bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
                    221:                            p->maxrmargin > vbl ?  p->maxrmargin - vbl : 0;
1.71      kristaps  222:                }
1.138     schwarze  223:
1.267     schwarze  224:                /*
                    225:                 * Write out the rest of the word.
                    226:                 */
                    227:
1.269     schwarze  228:                for ( ; p->tcol->col < p->tcol->lastcol; p->tcol->col++) {
1.267     schwarze  229:                        if (vend > bp && jhy > 0 && p->tcol->col > jhy)
1.140     kristaps  230:                                break;
1.270     schwarze  231:                        if (p->tcol->buf[p->tcol->col] == '\n')
                    232:                                continue;
1.267     schwarze  233:                        if (p->tcol->buf[p->tcol->col] == '\t')
1.138     schwarze  234:                                break;
1.267     schwarze  235:                        if (p->tcol->buf[p->tcol->col] == ' ') {
                    236:                                j = p->tcol->col;
1.269     schwarze  237:                                while (p->tcol->col < p->tcol->lastcol &&
1.267     schwarze  238:                                    p->tcol->buf[p->tcol->col] == ' ')
                    239:                                        p->tcol->col++;
                    240:                                dv = (p->tcol->col - j) * (*p->width)(p, ' ');
1.172     schwarze  241:                                vbl += dv;
                    242:                                vend += dv;
1.71      kristaps  243:                                break;
1.136     schwarze  244:                        }
1.267     schwarze  245:                        if (p->tcol->buf[p->tcol->col] == ASCII_NBRSP) {
1.153     kristaps  246:                                vbl += (*p->width)(p, ' ');
1.136     schwarze  247:                                continue;
                    248:                        }
1.267     schwarze  249:                        if (p->tcol->buf[p->tcol->col] == ASCII_BREAK)
1.216     schwarze  250:                                continue;
1.130     kristaps  251:
1.136     schwarze  252:                        /*
                    253:                         * Now we definitely know there will be
                    254:                         * printable characters to output,
                    255:                         * so write preceding white space now.
                    256:                         */
                    257:                        if (vbl) {
1.146     kristaps  258:                                (*p->advance)(p, vbl);
1.139     schwarze  259:                                p->viscol += vbl;
1.136     schwarze  260:                                vbl = 0;
1.200     schwarze  261:                        }
                    262:
1.267     schwarze  263:                        (*p->letter)(p, p->tcol->buf[p->tcol->col]);
                    264:                        if (p->tcol->buf[p->tcol->col] == '\b')
                    265:                                p->viscol -= (*p->width)(p,
                    266:                                    p->tcol->buf[p->tcol->col - 1]);
1.222     schwarze  267:                        else
1.267     schwarze  268:                                p->viscol += (*p->width)(p,
                    269:                                    p->tcol->buf[p->tcol->col]);
1.136     schwarze  270:                }
                    271:                vis = vend;
1.270     schwarze  272:
                    273:                if (breakline == 0)
                    274:                        continue;
                    275:
                    276:                /* Explicitly requested output line break. */
                    277:
                    278:                if (p->flags & TERMP_MULTICOL)
                    279:                        return;
                    280:
                    281:                endline(p);
                    282:                breakline = 0;
                    283:                vis = vend = 0;
                    284:
                    285:                /* Re-establish indentation. */
                    286:
                    287:                vbl = p->tcol->offset;
                    288:                maxvis = p->tcol->rmargin > vbl ?
                    289:                    p->tcol->rmargin - vbl : 0;
                    290:                bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
                    291:                    p->maxrmargin > vbl ?  p->maxrmargin - vbl : 0;
1.71      kristaps  292:        }
1.168     schwarze  293:
                    294:        /*
                    295:         * If there was trailing white space, it was not printed;
                    296:         * so reset the cursor position accordingly.
                    297:         */
1.267     schwarze  298:
1.235     schwarze  299:        if (vis > vbl)
1.200     schwarze  300:                vis -= vbl;
1.235     schwarze  301:        else
                    302:                vis = 0;
1.111     kristaps  303:
1.269     schwarze  304:        p->col = p->tcol->col = p->tcol->lastcol = 0;
1.264     schwarze  305:        p->minbl = p->trailspace;
1.263     schwarze  306:        p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD);
1.15      kristaps  307:
1.269     schwarze  308:        if (p->flags & TERMP_MULTICOL)
                    309:                return;
                    310:
1.250     schwarze  311:        /* Trailing whitespace is significant in some columns. */
1.267     schwarze  312:
1.250     schwarze  313:        if (vis && vbl && (TERMP_BRTRSP & p->flags))
                    314:                vis += vbl;
1.15      kristaps  315:
1.200     schwarze  316:        /* If the column was overrun, break the line. */
1.264     schwarze  317:        if ((p->flags & TERMP_NOBREAK) == 0 ||
                    318:            ((p->flags & TERMP_HANG) == 0 &&
                    319:             vis + p->trailspace * (*p->width)(p, ' ') > maxvis))
                    320:                endline(p);
                    321: }
                    322:
                    323: static void
                    324: endline(struct termp *p)
                    325: {
                    326:        if ((p->flags & (TERMP_NEWMC | TERMP_ENDMC)) == TERMP_ENDMC) {
                    327:                p->mc = NULL;
                    328:                p->flags &= ~TERMP_ENDMC;
                    329:        }
                    330:        if (p->mc != NULL) {
                    331:                if (p->viscol && p->maxrmargin >= p->viscol)
                    332:                        (*p->advance)(p, p->maxrmargin - p->viscol + 1);
                    333:                p->flags |= TERMP_NOBUF | TERMP_NOSPACE;
                    334:                term_word(p, p->mc);
                    335:                p->flags &= ~(TERMP_NOBUF | TERMP_NEWMC);
                    336:        }
                    337:        p->viscol = 0;
                    338:        p->minbl = 0;
                    339:        (*p->endline)(p);
1.15      kristaps  340: }
                    341:
1.222     schwarze  342: /*
1.71      kristaps  343:  * A newline only breaks an existing line; it won't assert vertical
                    344:  * space.  All data in the output buffer is flushed prior to the newline
                    345:  * assertion.
                    346:  */
                    347: void
                    348: term_newln(struct termp *p)
1.15      kristaps  349: {
                    350:
1.71      kristaps  351:        p->flags |= TERMP_NOSPACE;
1.269     schwarze  352:        if (p->tcol->lastcol || p->viscol)
1.200     schwarze  353:                term_flushln(p);
1.16      kristaps  354: }
                    355:
1.71      kristaps  356: /*
                    357:  * Asserts a vertical space (a full, empty line-break between lines).
                    358:  * Note that if used twice, this will cause two blank spaces and so on.
                    359:  * All data in the output buffer is flushed prior to the newline
                    360:  * assertion.
                    361:  */
                    362: void
                    363: term_vspace(struct termp *p)
1.16      kristaps  364: {
                    365:
1.62      kristaps  366:        term_newln(p);
1.139     schwarze  367:        p->viscol = 0;
1.264     schwarze  368:        p->minbl = 0;
1.202     schwarze  369:        if (0 < p->skipvsp)
                    370:                p->skipvsp--;
                    371:        else
                    372:                (*p->endline)(p);
1.16      kristaps  373: }
                    374:
1.238     schwarze  375: /* Swap current and previous font; for \fP and .ft P */
1.125     kristaps  376: void
                    377: term_fontlast(struct termp *p)
                    378: {
                    379:        enum termfont    f;
                    380:
                    381:        f = p->fontl;
                    382:        p->fontl = p->fontq[p->fonti];
                    383:        p->fontq[p->fonti] = f;
                    384: }
                    385:
1.238     schwarze  386: /* Set font, save current, discard previous; for \f, .ft, .B etc. */
1.125     kristaps  387: void
                    388: term_fontrepl(struct termp *p, enum termfont f)
                    389: {
                    390:
                    391:        p->fontl = p->fontq[p->fonti];
                    392:        p->fontq[p->fonti] = f;
                    393: }
                    394:
1.238     schwarze  395: /* Set font, save previous. */
1.125     kristaps  396: void
                    397: term_fontpush(struct termp *p, enum termfont f)
                    398: {
                    399:
                    400:        p->fontl = p->fontq[p->fonti];
1.238     schwarze  401:        if (++p->fonti == p->fontsz) {
                    402:                p->fontsz += 8;
                    403:                p->fontq = mandoc_reallocarray(p->fontq,
1.256     schwarze  404:                    p->fontsz, sizeof(*p->fontq));
1.238     schwarze  405:        }
                    406:        p->fontq[p->fonti] = f;
1.125     kristaps  407: }
                    408:
1.238     schwarze  409: /* Flush to make the saved pointer current again. */
1.125     kristaps  410: void
1.244     schwarze  411: term_fontpopq(struct termp *p, int i)
1.125     kristaps  412: {
                    413:
1.244     schwarze  414:        assert(i >= 0);
                    415:        if (p->fonti > i)
                    416:                p->fonti = i;
1.125     kristaps  417: }
1.94      kristaps  418:
1.238     schwarze  419: /* Pop one font off the stack. */
1.125     kristaps  420: void
                    421: term_fontpop(struct termp *p)
                    422: {
                    423:
                    424:        assert(p->fonti);
                    425:        p->fonti--;
1.17      kristaps  426: }
                    427:
1.71      kristaps  428: /*
                    429:  * Handle pwords, partial words, which may be either a single word or a
                    430:  * phrase that cannot be broken down (such as a literal string).  This
                    431:  * handles word styling.
                    432:  */
1.86      kristaps  433: void
                    434: term_word(struct termp *p, const char *word)
1.65      kristaps  435: {
1.261     schwarze  436:        struct roffsu    su;
1.214     schwarze  437:        const char       nbrsp[2] = { ASCII_NBRSP, 0 };
1.191     kristaps  438:        const char      *seq, *cp;
1.194     kristaps  439:        int              sz, uc;
1.262     schwarze  440:        size_t           csz, lsz, ssz;
1.184     kristaps  441:        enum mandoc_esc  esc;
1.100     kristaps  442:
1.264     schwarze  443:        if ((p->flags & TERMP_NOBUF) == 0) {
                    444:                if ((p->flags & TERMP_NOSPACE) == 0) {
                    445:                        if ((p->flags & TERMP_KEEP) == 0) {
1.151     schwarze  446:                                bufferc(p, ' ');
1.264     schwarze  447:                                if (p->flags & TERMP_SENTENCE)
                    448:                                        bufferc(p, ' ');
                    449:                        } else
                    450:                                bufferc(p, ASCII_NBRSP);
                    451:                }
                    452:                if (p->flags & TERMP_PREKEEP)
                    453:                        p->flags |= TERMP_KEEP;
                    454:                if (p->flags & TERMP_NONOSPACE)
                    455:                        p->flags |= TERMP_NOSPACE;
                    456:                else
                    457:                        p->flags &= ~TERMP_NOSPACE;
                    458:                p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
                    459:                p->skipvsp = 0;
1.133     kristaps  460:        }
1.65      kristaps  461:
1.184     kristaps  462:        while ('\0' != *word) {
1.203     schwarze  463:                if ('\\' != *word) {
1.214     schwarze  464:                        if (TERMP_NBRWORD & p->flags) {
                    465:                                if (' ' == *word) {
                    466:                                        encode(p, nbrsp, 1);
                    467:                                        word++;
                    468:                                        continue;
                    469:                                }
                    470:                                ssz = strcspn(word, "\\ ");
                    471:                        } else
                    472:                                ssz = strcspn(word, "\\");
1.162     kristaps  473:                        encode(p, word, ssz);
1.203     schwarze  474:                        word += (int)ssz;
1.124     kristaps  475:                        continue;
1.203     schwarze  476:                }
1.124     kristaps  477:
1.184     kristaps  478:                word++;
                    479:                esc = mandoc_escape(&word, &seq, &sz);
                    480:                switch (esc) {
1.222     schwarze  481:                case ESCAPE_UNICODE:
1.229     schwarze  482:                        uc = mchars_num2uc(seq + 1, sz - 1);
1.192     kristaps  483:                        break;
1.222     schwarze  484:                case ESCAPE_NUMBERED:
1.233     schwarze  485:                        uc = mchars_num2char(seq, sz);
                    486:                        if (uc < 0)
                    487:                                continue;
1.184     kristaps  488:                        break;
1.222     schwarze  489:                case ESCAPE_SPECIAL:
1.229     schwarze  490:                        if (p->enc == TERMENC_ASCII) {
1.254     schwarze  491:                                cp = mchars_spec2str(seq, sz, &ssz);
1.232     schwarze  492:                                if (cp != NULL)
1.229     schwarze  493:                                        encode(p, cp, ssz);
                    494:                        } else {
1.254     schwarze  495:                                uc = mchars_spec2cp(seq, sz);
1.230     schwarze  496:                                if (uc > 0)
                    497:                                        encode1(p, uc);
1.229     schwarze  498:                        }
1.233     schwarze  499:                        continue;
1.277   ! schwarze  500:                case ESCAPE_UNDEF:
        !           501:                        uc = *seq;
        !           502:                        break;
1.222     schwarze  503:                case ESCAPE_FONTBOLD:
1.125     kristaps  504:                        term_fontrepl(p, TERMFONT_BOLD);
1.233     schwarze  505:                        continue;
1.222     schwarze  506:                case ESCAPE_FONTITALIC:
1.125     kristaps  507:                        term_fontrepl(p, TERMFONT_UNDER);
1.233     schwarze  508:                        continue;
1.222     schwarze  509:                case ESCAPE_FONTBI:
1.209     schwarze  510:                        term_fontrepl(p, TERMFONT_BI);
1.233     schwarze  511:                        continue;
1.222     schwarze  512:                case ESCAPE_FONT:
1.276     schwarze  513:                case ESCAPE_FONTCW:
1.222     schwarze  514:                case ESCAPE_FONTROMAN:
1.125     kristaps  515:                        term_fontrepl(p, TERMFONT_NONE);
1.233     schwarze  516:                        continue;
1.222     schwarze  517:                case ESCAPE_FONTPREV:
1.125     kristaps  518:                        term_fontlast(p);
1.270     schwarze  519:                        continue;
                    520:                case ESCAPE_BREAK:
                    521:                        bufferc(p, '\n');
1.233     schwarze  522:                        continue;
1.222     schwarze  523:                case ESCAPE_NOSPACE:
1.248     schwarze  524:                        if (p->flags & TERMP_BACKAFTER)
                    525:                                p->flags &= ~TERMP_BACKAFTER;
                    526:                        else if (*word == '\0')
1.237     schwarze  527:                                p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
1.261     schwarze  528:                        continue;
1.275     schwarze  529:                case ESCAPE_DEVICE:
                    530:                        if (p->type == TERMTYPE_PDF)
                    531:                                encode(p, "pdf", 3);
                    532:                        else if (p->type == TERMTYPE_PS)
                    533:                                encode(p, "ps", 2);
                    534:                        else if (p->enc == TERMENC_ASCII)
                    535:                                encode(p, "ascii", 5);
                    536:                        else
                    537:                                encode(p, "utf8", 4);
                    538:                        continue;
1.261     schwarze  539:                case ESCAPE_HORIZ:
1.273     schwarze  540:                        if (*seq == '|') {
                    541:                                seq++;
                    542:                                uc = -p->col;
                    543:                        } else
                    544:                                uc = 0;
1.268     schwarze  545:                        if (a2roffsu(seq, &su, SCALE_EM) == NULL)
1.261     schwarze  546:                                continue;
1.273     schwarze  547:                        uc += term_hen(p, &su);
1.261     schwarze  548:                        if (uc > 0)
                    549:                                while (uc-- > 0)
                    550:                                        bufferc(p, ASCII_NBRSP);
                    551:                        else if (p->col > (size_t)(-uc))
                    552:                                p->col += uc;
                    553:                        else {
                    554:                                uc += p->col;
                    555:                                p->col = 0;
1.266     schwarze  556:                                if (p->tcol->offset > (size_t)(-uc)) {
1.261     schwarze  557:                                        p->ti += uc;
1.266     schwarze  558:                                        p->tcol->offset += uc;
1.261     schwarze  559:                                } else {
1.266     schwarze  560:                                        p->ti -= p->tcol->offset;
                    561:                                        p->tcol->offset = 0;
1.261     schwarze  562:                                }
1.262     schwarze  563:                        }
                    564:                        continue;
                    565:                case ESCAPE_HLINE:
1.272     schwarze  566:                        if ((cp = a2roffsu(seq, &su, SCALE_EM)) == NULL)
1.262     schwarze  567:                                continue;
1.271     schwarze  568:                        uc = term_hen(p, &su);
1.262     schwarze  569:                        if (uc <= 0) {
1.266     schwarze  570:                                if (p->tcol->rmargin <= p->tcol->offset)
1.262     schwarze  571:                                        continue;
1.266     schwarze  572:                                lsz = p->tcol->rmargin - p->tcol->offset;
1.262     schwarze  573:                        } else
                    574:                                lsz = uc;
1.272     schwarze  575:                        if (*cp == seq[-1])
1.262     schwarze  576:                                uc = -1;
1.272     schwarze  577:                        else if (*cp == '\\') {
                    578:                                seq = cp + 1;
1.262     schwarze  579:                                esc = mandoc_escape(&seq, &cp, &sz);
                    580:                                switch (esc) {
                    581:                                case ESCAPE_UNICODE:
                    582:                                        uc = mchars_num2uc(cp + 1, sz - 1);
                    583:                                        break;
                    584:                                case ESCAPE_NUMBERED:
                    585:                                        uc = mchars_num2char(cp, sz);
                    586:                                        break;
                    587:                                case ESCAPE_SPECIAL:
                    588:                                        uc = mchars_spec2cp(cp, sz);
                    589:                                        break;
1.277   ! schwarze  590:                                case ESCAPE_UNDEF:
        !           591:                                        uc = *seq;
        !           592:                                        break;
1.262     schwarze  593:                                default:
                    594:                                        uc = -1;
                    595:                                        break;
                    596:                                }
                    597:                        } else
1.272     schwarze  598:                                uc = *cp;
1.262     schwarze  599:                        if (uc < 0x20 || (uc > 0x7E && uc < 0xA0))
                    600:                                uc = '_';
                    601:                        if (p->enc == TERMENC_ASCII) {
                    602:                                cp = ascii_uc2str(uc);
                    603:                                csz = term_strlen(p, cp);
                    604:                                ssz = strlen(cp);
                    605:                        } else
                    606:                                csz = (*p->width)(p, uc);
                    607:                        while (lsz >= csz) {
                    608:                                if (p->enc == TERMENC_ASCII)
                    609:                                        encode(p, cp, ssz);
                    610:                                else
                    611:                                        encode1(p, uc);
                    612:                                lsz -= csz;
1.261     schwarze  613:                        }
1.233     schwarze  614:                        continue;
1.222     schwarze  615:                case ESCAPE_SKIPCHAR:
1.248     schwarze  616:                        p->flags |= TERMP_BACKAFTER;
1.233     schwarze  617:                        continue;
1.243     schwarze  618:                case ESCAPE_OVERSTRIKE:
                    619:                        cp = seq + sz;
                    620:                        while (seq < cp) {
                    621:                                if (*seq == '\\') {
                    622:                                        mandoc_escape(&seq, NULL, NULL);
                    623:                                        continue;
                    624:                                }
                    625:                                encode1(p, *seq++);
1.248     schwarze  626:                                if (seq < cp) {
                    627:                                        if (p->flags & TERMP_BACKBEFORE)
                    628:                                                p->flags |= TERMP_BACKAFTER;
                    629:                                        else
                    630:                                                p->flags |= TERMP_BACKBEFORE;
                    631:                                }
1.243     schwarze  632:                        }
1.249     schwarze  633:                        /* Trim trailing backspace/blank pair. */
1.269     schwarze  634:                        if (p->tcol->lastcol > 2 &&
                    635:                            (p->tcol->buf[p->tcol->lastcol - 1] == ' ' ||
                    636:                             p->tcol->buf[p->tcol->lastcol - 1] == '\t'))
                    637:                                p->tcol->lastcol -= 2;
                    638:                        if (p->col > p->tcol->lastcol)
                    639:                                p->col = p->tcol->lastcol;
1.248     schwarze  640:                        continue;
1.124     kristaps  641:                default:
1.233     schwarze  642:                        continue;
                    643:                }
                    644:
                    645:                /*
                    646:                 * Common handling for Unicode and numbered
                    647:                 * character escape sequences.
                    648:                 */
                    649:
                    650:                if (p->enc == TERMENC_ASCII) {
                    651:                        cp = ascii_uc2str(uc);
                    652:                        encode(p, cp, strlen(cp));
                    653:                } else {
                    654:                        if ((uc < 0x20 && uc != 0x09) ||
                    655:                            (uc > 0x7E && uc < 0xA0))
                    656:                                uc = 0xFFFD;
                    657:                        encode1(p, uc);
1.124     kristaps  658:                }
                    659:        }
1.214     schwarze  660:        p->flags &= ~TERMP_NBRWORD;
1.65      kristaps  661: }
                    662:
1.71      kristaps  663: static void
1.266     schwarze  664: adjbuf(struct termp_col *c, size_t sz)
1.51      kristaps  665: {
1.266     schwarze  666:        if (c->maxcols == 0)
                    667:                c->maxcols = 1024;
                    668:        while (c->maxcols <= sz)
                    669:                c->maxcols <<= 2;
                    670:        c->buf = mandoc_reallocarray(c->buf, c->maxcols, sizeof(*c->buf));
1.51      kristaps  671: }
                    672:
1.79      kristaps  673: static void
1.125     kristaps  674: bufferc(struct termp *p, char c)
                    675: {
1.264     schwarze  676:        if (p->flags & TERMP_NOBUF) {
                    677:                (*p->letter)(p, c);
                    678:                return;
                    679:        }
1.266     schwarze  680:        if (p->col + 1 >= p->tcol->maxcols)
                    681:                adjbuf(p->tcol, p->col + 1);
1.269     schwarze  682:        if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
1.266     schwarze  683:                p->tcol->buf[p->col] = c;
1.269     schwarze  684:        if (p->tcol->lastcol < ++p->col)
                    685:                p->tcol->lastcol = p->col;
1.125     kristaps  686: }
                    687:
1.194     kristaps  688: /*
                    689:  * See encode().
                    690:  * Do this for a single (probably unicode) value.
                    691:  * Does not check for non-decorated glyphs.
                    692:  */
                    693: static void
                    694: encode1(struct termp *p, int c)
                    695: {
                    696:        enum termfont     f;
                    697:
1.264     schwarze  698:        if (p->flags & TERMP_NOBUF) {
                    699:                (*p->letter)(p, c);
                    700:                return;
                    701:        }
                    702:
1.266     schwarze  703:        if (p->col + 7 >= p->tcol->maxcols)
                    704:                adjbuf(p->tcol, p->col + 7);
1.194     kristaps  705:
1.255     schwarze  706:        f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ?
1.248     schwarze  707:            p->fontq[p->fonti] : TERMFONT_NONE;
1.194     kristaps  708:
1.248     schwarze  709:        if (p->flags & TERMP_BACKBEFORE) {
1.266     schwarze  710:                if (p->tcol->buf[p->col - 1] == ' ' ||
                    711:                    p->tcol->buf[p->col - 1] == '\t')
1.249     schwarze  712:                        p->col--;
                    713:                else
1.266     schwarze  714:                        p->tcol->buf[p->col++] = '\b';
1.248     schwarze  715:                p->flags &= ~TERMP_BACKBEFORE;
                    716:        }
1.266     schwarze  717:        if (f == TERMFONT_UNDER || f == TERMFONT_BI) {
                    718:                p->tcol->buf[p->col++] = '_';
                    719:                p->tcol->buf[p->col++] = '\b';
                    720:        }
                    721:        if (f == TERMFONT_BOLD || f == TERMFONT_BI) {
                    722:                if (c == ASCII_HYPH)
                    723:                        p->tcol->buf[p->col++] = '-';
1.209     schwarze  724:                else
1.266     schwarze  725:                        p->tcol->buf[p->col++] = c;
                    726:                p->tcol->buf[p->col++] = '\b';
1.209     schwarze  727:        }
1.269     schwarze  728:        if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
1.266     schwarze  729:                p->tcol->buf[p->col] = c;
1.269     schwarze  730:        if (p->tcol->lastcol < ++p->col)
                    731:                p->tcol->lastcol = p->col;
1.248     schwarze  732:        if (p->flags & TERMP_BACKAFTER) {
                    733:                p->flags |= TERMP_BACKBEFORE;
                    734:                p->flags &= ~TERMP_BACKAFTER;
                    735:        }
1.194     kristaps  736: }
                    737:
1.125     kristaps  738: static void
                    739: encode(struct termp *p, const char *word, size_t sz)
                    740: {
1.210     schwarze  741:        size_t            i;
1.264     schwarze  742:
                    743:        if (p->flags & TERMP_NOBUF) {
                    744:                for (i = 0; i < sz; i++)
                    745:                        (*p->letter)(p, word[i]);
                    746:                return;
                    747:        }
1.188     kristaps  748:
1.266     schwarze  749:        if (p->col + 2 + (sz * 5) >= p->tcol->maxcols)
                    750:                adjbuf(p->tcol, p->col + 2 + (sz * 5));
1.165     kristaps  751:
1.210     schwarze  752:        for (i = 0; i < sz; i++) {
1.209     schwarze  753:                if (ASCII_HYPH == word[i] ||
                    754:                    isgraph((unsigned char)word[i]))
                    755:                        encode1(p, word[i]);
1.259     schwarze  756:                else {
1.269     schwarze  757:                        if (p->tcol->lastcol <= p->col ||
1.265     schwarze  758:                            (word[i] != ' ' && word[i] != ASCII_NBRSP))
1.266     schwarze  759:                                p->tcol->buf[p->col] = word[i];
1.265     schwarze  760:                        p->col++;
1.259     schwarze  761:
                    762:                        /*
                    763:                         * Postpone the effect of \z while handling
                    764:                         * an overstrike sequence from ascii_uc2str().
                    765:                         */
                    766:
                    767:                        if (word[i] == '\b' &&
                    768:                            (p->flags & TERMP_BACKBEFORE)) {
                    769:                                p->flags &= ~TERMP_BACKBEFORE;
                    770:                                p->flags |= TERMP_BACKAFTER;
                    771:                        }
                    772:                }
1.79      kristaps  773:        }
1.269     schwarze  774:        if (p->tcol->lastcol < p->col)
                    775:                p->tcol->lastcol = p->col;
1.219     schwarze  776: }
                    777:
                    778: void
                    779: term_setwidth(struct termp *p, const char *wstr)
                    780: {
                    781:        struct roffsu    su;
1.247     schwarze  782:        int              iop, width;
1.219     schwarze  783:
1.220     schwarze  784:        iop = 0;
                    785:        width = 0;
1.219     schwarze  786:        if (NULL != wstr) {
                    787:                switch (*wstr) {
1.222     schwarze  788:                case '+':
1.219     schwarze  789:                        iop = 1;
                    790:                        wstr++;
                    791:                        break;
1.222     schwarze  792:                case '-':
1.219     schwarze  793:                        iop = -1;
                    794:                        wstr++;
                    795:                        break;
                    796:                default:
                    797:                        break;
                    798:                }
1.268     schwarze  799:                if (a2roffsu(wstr, &su, SCALE_MAX) != NULL)
1.220     schwarze  800:                        width = term_hspan(p, &su);
                    801:                else
1.219     schwarze  802:                        iop = 0;
                    803:        }
                    804:        (*p->setwidth)(p, iop, width);
1.79      kristaps  805: }
1.106     kristaps  806:
1.107     kristaps  807: size_t
1.149     kristaps  808: term_len(const struct termp *p, size_t sz)
                    809: {
                    810:
1.252     schwarze  811:        return (*p->width)(p, ' ') * sz;
1.149     kristaps  812: }
                    813:
1.203     schwarze  814: static size_t
                    815: cond_width(const struct termp *p, int c, int *skip)
                    816: {
                    817:
                    818:        if (*skip) {
                    819:                (*skip) = 0;
1.252     schwarze  820:                return 0;
1.203     schwarze  821:        } else
1.252     schwarze  822:                return (*p->width)(p, c);
1.203     schwarze  823: }
1.149     kristaps  824:
                    825: size_t
                    826: term_strlen(const struct termp *p, const char *cp)
                    827: {
1.184     kristaps  828:        size_t           sz, rsz, i;
1.233     schwarze  829:        int              ssz, skip, uc;
1.171     kristaps  830:        const char      *seq, *rhs;
1.196     kristaps  831:        enum mandoc_esc  esc;
1.216     schwarze  832:        static const char rej[] = { '\\', ASCII_NBRSP, ASCII_HYPH,
                    833:                        ASCII_BREAK, '\0' };
1.171     kristaps  834:
1.184     kristaps  835:        /*
                    836:         * Account for escaped sequences within string length
                    837:         * calculations.  This follows the logic in term_word() as we
                    838:         * must calculate the width of produced strings.
                    839:         */
                    840:
                    841:        sz = 0;
1.203     schwarze  842:        skip = 0;
1.189     kristaps  843:        while ('\0' != *cp) {
                    844:                rsz = strcspn(cp, rej);
                    845:                for (i = 0; i < rsz; i++)
1.203     schwarze  846:                        sz += cond_width(p, *cp++, &skip);
1.189     kristaps  847:
1.184     kristaps  848:                switch (*cp) {
1.222     schwarze  849:                case '\\':
1.189     kristaps  850:                        cp++;
1.277   ! schwarze  851:                        rhs = NULL;
1.196     kristaps  852:                        esc = mandoc_escape(&cp, &seq, &ssz);
                    853:                        switch (esc) {
1.222     schwarze  854:                        case ESCAPE_UNICODE:
1.234     schwarze  855:                                uc = mchars_num2uc(seq + 1, ssz - 1);
1.194     kristaps  856:                                break;
1.222     schwarze  857:                        case ESCAPE_NUMBERED:
1.233     schwarze  858:                                uc = mchars_num2char(seq, ssz);
                    859:                                if (uc < 0)
                    860:                                        continue;
1.171     kristaps  861:                                break;
1.222     schwarze  862:                        case ESCAPE_SPECIAL:
1.233     schwarze  863:                                if (p->enc == TERMENC_ASCII) {
1.254     schwarze  864:                                        rhs = mchars_spec2str(seq, ssz, &rsz);
1.233     schwarze  865:                                        if (rhs != NULL)
                    866:                                                break;
                    867:                                } else {
1.254     schwarze  868:                                        uc = mchars_spec2cp(seq, ssz);
1.233     schwarze  869:                                        if (uc > 0)
                    870:                                                sz += cond_width(p, uc, &skip);
1.229     schwarze  871:                                }
1.233     schwarze  872:                                continue;
1.277   ! schwarze  873:                        case ESCAPE_UNDEF:
        !           874:                                uc = *seq;
        !           875:                                break;
1.275     schwarze  876:                        case ESCAPE_DEVICE:
                    877:                                if (p->type == TERMTYPE_PDF) {
                    878:                                        rhs = "pdf";
                    879:                                        rsz = 3;
                    880:                                } else if (p->type == TERMTYPE_PS) {
                    881:                                        rhs = "ps";
                    882:                                        rsz = 2;
                    883:                                } else if (p->enc == TERMENC_ASCII) {
                    884:                                        rhs = "ascii";
                    885:                                        rsz = 5;
                    886:                                } else {
                    887:                                        rhs = "utf8";
                    888:                                        rsz = 4;
                    889:                                }
                    890:                                break;
1.222     schwarze  891:                        case ESCAPE_SKIPCHAR:
1.203     schwarze  892:                                skip = 1;
1.243     schwarze  893:                                continue;
                    894:                        case ESCAPE_OVERSTRIKE:
                    895:                                rsz = 0;
                    896:                                rhs = seq + ssz;
                    897:                                while (seq < rhs) {
                    898:                                        if (*seq == '\\') {
                    899:                                                mandoc_escape(&seq, NULL, NULL);
                    900:                                                continue;
                    901:                                        }
                    902:                                        i = (*p->width)(p, *seq++);
                    903:                                        if (rsz < i)
                    904:                                                rsz = i;
                    905:                                }
                    906:                                sz += rsz;
1.233     schwarze  907:                                continue;
1.171     kristaps  908:                        default:
1.233     schwarze  909:                                continue;
1.171     kristaps  910:                        }
1.149     kristaps  911:
1.233     schwarze  912:                        /*
                    913:                         * Common handling for Unicode and numbered
                    914:                         * character escape sequences.
                    915:                         */
                    916:
                    917:                        if (rhs == NULL) {
                    918:                                if (p->enc == TERMENC_ASCII) {
                    919:                                        rhs = ascii_uc2str(uc);
                    920:                                        rsz = strlen(rhs);
                    921:                                } else {
                    922:                                        if ((uc < 0x20 && uc != 0x09) ||
                    923:                                            (uc > 0x7E && uc < 0xA0))
                    924:                                                uc = 0xFFFD;
                    925:                                        sz += cond_width(p, uc, &skip);
                    926:                                        continue;
                    927:                                }
                    928:                        }
1.184     kristaps  929:
1.203     schwarze  930:                        if (skip) {
                    931:                                skip = 0;
                    932:                                break;
                    933:                        }
1.233     schwarze  934:
                    935:                        /*
                    936:                         * Common handling for all escape sequences
                    937:                         * printing more than one character.
                    938:                         */
1.203     schwarze  939:
1.184     kristaps  940:                        for (i = 0; i < rsz; i++)
                    941:                                sz += (*p->width)(p, *rhs++);
                    942:                        break;
1.222     schwarze  943:                case ASCII_NBRSP:
1.203     schwarze  944:                        sz += cond_width(p, ' ', &skip);
1.176     kristaps  945:                        cp++;
1.184     kristaps  946:                        break;
1.222     schwarze  947:                case ASCII_HYPH:
1.203     schwarze  948:                        sz += cond_width(p, '-', &skip);
1.176     kristaps  949:                        cp++;
1.184     kristaps  950:                        break;
                    951:                default:
                    952:                        break;
                    953:                }
1.189     kristaps  954:        }
1.149     kristaps  955:
1.252     schwarze  956:        return sz;
1.149     kristaps  957: }
                    958:
1.240     schwarze  959: int
1.149     kristaps  960: term_vspan(const struct termp *p, const struct roffsu *su)
1.106     kristaps  961: {
                    962:        double           r;
1.241     schwarze  963:        int              ri;
1.106     kristaps  964:
1.107     kristaps  965:        switch (su->unit) {
1.239     schwarze  966:        case SCALE_BU:
                    967:                r = su->scale / 40.0;
                    968:                break;
1.222     schwarze  969:        case SCALE_CM:
1.239     schwarze  970:                r = su->scale * 6.0 / 2.54;
                    971:                break;
                    972:        case SCALE_FS:
                    973:                r = su->scale * 65536.0 / 40.0;
1.106     kristaps  974:                break;
1.222     schwarze  975:        case SCALE_IN:
1.225     schwarze  976:                r = su->scale * 6.0;
1.106     kristaps  977:                break;
1.239     schwarze  978:        case SCALE_MM:
                    979:                r = su->scale * 0.006;
                    980:                break;
1.222     schwarze  981:        case SCALE_PC:
1.107     kristaps  982:                r = su->scale;
1.106     kristaps  983:                break;
1.222     schwarze  984:        case SCALE_PT:
1.239     schwarze  985:                r = su->scale / 12.0;
1.106     kristaps  986:                break;
1.239     schwarze  987:        case SCALE_EN:
                    988:        case SCALE_EM:
                    989:                r = su->scale * 0.6;
1.106     kristaps  990:                break;
1.222     schwarze  991:        case SCALE_VS:
1.107     kristaps  992:                r = su->scale;
1.106     kristaps  993:                break;
                    994:        default:
1.239     schwarze  995:                abort();
1.106     kristaps  996:        }
1.241     schwarze  997:        ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
1.252     schwarze  998:        return ri < 66 ? ri : 1;
1.106     kristaps  999: }
                   1000:
1.247     schwarze 1001: /*
1.271     schwarze 1002:  * Convert a scaling width to basic units, rounding towards 0.
1.247     schwarze 1003:  */
1.240     schwarze 1004: int
1.149     kristaps 1005: term_hspan(const struct termp *p, const struct roffsu *su)
1.106     kristaps 1006: {
1.108     kristaps 1007:
1.252     schwarze 1008:        return (*p->hspan)(p, su);
1.271     schwarze 1009: }
                   1010:
                   1011: /*
                   1012:  * Convert a scaling width to basic units, rounding to closest.
                   1013:  */
                   1014: int
                   1015: term_hen(const struct termp *p, const struct roffsu *su)
                   1016: {
                   1017:        int bu;
                   1018:
                   1019:        if ((bu = (*p->hspan)(p, su)) >= 0)
                   1020:                return (bu + 11) / 24;
                   1021:        else
                   1022:                return -((-bu + 11) / 24);
1.106     kristaps 1023: }

CVSweb