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

Annotation of mandoc/term.c, Revision 1.133

1.133   ! kristaps    1: /*     $Id: term.c,v 1.132 2010/05/07 04:50:44 kristaps Exp $ */
1.1       kristaps    2: /*
1.75      kristaps    3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1       kristaps    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
1.74      kristaps    6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       kristaps    8:  *
1.74      kristaps    9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       kristaps   16:  */
1.128     kristaps   17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
1.126     kristaps   21: #include <sys/types.h>
                     22:
1.1       kristaps   23: #include <assert.h>
1.122     kristaps   24: #include <ctype.h>
1.22      kristaps   25: #include <stdio.h>
1.1       kristaps   26: #include <stdlib.h>
                     27: #include <string.h>
1.113     kristaps   28: #include <time.h>
1.1       kristaps   29:
1.101     kristaps   30: #include "chars.h"
1.107     kristaps   31: #include "out.h"
1.71      kristaps   32: #include "term.h"
                     33: #include "man.h"
                     34: #include "mdoc.h"
1.105     kristaps   35: #include "main.h"
1.1       kristaps   36:
1.71      kristaps   37: static struct termp     *term_alloc(enum termenc);
                     38: static void              term_free(struct termp *);
1.125     kristaps   39: static void              spec(struct termp *, const char *, size_t);
                     40: static void              res(struct termp *, const char *, size_t);
                     41: static void              buffera(struct termp *, const char *, size_t);
                     42: static void              bufferc(struct termp *, char);
                     43: static void              adjbuf(struct termp *p, size_t);
                     44: static void              encode(struct termp *, const char *, size_t);
1.1       kristaps   45:
                     46:
1.71      kristaps   47: void *
                     48: ascii_alloc(void)
1.10      kristaps   49: {
1.1       kristaps   50:
1.71      kristaps   51:        return(term_alloc(TERMENC_ASCII));
1.1       kristaps   52: }
                     53:
                     54:
1.99      kristaps   55: void
1.71      kristaps   56: terminal_free(void *arg)
1.11      kristaps   57: {
                     58:
1.71      kristaps   59:        term_free((struct termp *)arg);
1.11      kristaps   60: }
                     61:
                     62:
1.71      kristaps   63: static void
                     64: term_free(struct termp *p)
1.14      kristaps   65: {
                     66:
1.71      kristaps   67:        if (p->buf)
                     68:                free(p->buf);
1.102     kristaps   69:        if (p->symtab)
1.101     kristaps   70:                chars_free(p->symtab);
1.14      kristaps   71:
1.71      kristaps   72:        free(p);
1.14      kristaps   73: }
                     74:
                     75:
1.71      kristaps   76: static struct termp *
                     77: term_alloc(enum termenc enc)
1.14      kristaps   78: {
1.71      kristaps   79:        struct termp *p;
1.14      kristaps   80:
1.117     kristaps   81:        p = calloc(1, sizeof(struct termp));
                     82:        if (NULL == p) {
1.120     kristaps   83:                perror(NULL);
1.117     kristaps   84:                exit(EXIT_FAILURE);
                     85:        }
1.71      kristaps   86:        p->enc = enc;
                     87:        return(p);
1.14      kristaps   88: }
                     89:
                     90:
1.71      kristaps   91: /*
                     92:  * Flush a line of text.  A "line" is loosely defined as being something
                     93:  * that should be followed by a newline, regardless of whether it's
                     94:  * broken apart by newlines getting there.  A line can also be a
1.130     kristaps   95:  * fragment of a columnar list (`Bl -tag' or `Bl -column'), which does
                     96:  * not have a trailing newline.
1.71      kristaps   97:  *
1.130     kristaps   98:  * The following flags may be specified:
1.71      kristaps   99:  *
                    100:  *  - TERMP_NOLPAD: when beginning to write the line, don't left-pad the
                    101:  *    offset value.  This is useful when doing columnar lists where the
                    102:  *    prior column has right-padded.
                    103:  *
                    104:  *  - TERMP_NOBREAK: this is the most important and is used when making
                    105:  *    columns.  In short: don't print a newline and instead pad to the
                    106:  *    right margin.  Used in conjunction with TERMP_NOLPAD.
                    107:  *
1.91      kristaps  108:  *  - TERMP_TWOSPACE: when padding, make sure there are at least two
                    109:  *    space characters of padding.  Otherwise, rather break the line.
                    110:  *
1.84      kristaps  111:  *  - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
                    112:  *    the line is overrun, and don't pad-right if it's underrun.
                    113:  *
                    114:  *  - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
                    115:  *    overruning, instead save the position and continue at that point
                    116:  *    when the next invocation.
1.71      kristaps  117:  *
                    118:  *  In-line line breaking:
                    119:  *
                    120:  *  If TERMP_NOBREAK is specified and the line overruns the right
                    121:  *  margin, it will break and pad-right to the right margin after
                    122:  *  writing.  If maxrmargin is violated, it will break and continue
1.114     kristaps  123:  *  writing from the right-margin, which will lead to the above scenario
                    124:  *  upon exit.  Otherwise, the line will break at the right margin.
1.71      kristaps  125:  */
                    126: void
                    127: term_flushln(struct termp *p)
1.53      kristaps  128: {
1.114     kristaps  129:        int              i;     /* current input position in p->buf */
                    130:        size_t           vis;   /* current visual position on output */
                    131:        size_t           vbl;   /* number of blanks to prepend to output */
                    132:        size_t           vsz;   /* visual characters to write to output */
                    133:        size_t           bp;    /* visual right border position */
                    134:        int              j;     /* temporary loop index */
                    135:        size_t           maxvis, mmax;
1.53      kristaps  136:
1.71      kristaps  137:        /*
                    138:         * First, establish the maximum columns of "visible" content.
                    139:         * This is usually the difference between the right-margin and
                    140:         * an indentation, but can be, for tagged lists or columns, a
1.115     kristaps  141:         * small set of values.
1.71      kristaps  142:         */
1.53      kristaps  143:
1.71      kristaps  144:        assert(p->offset < p->rmargin);
1.92      kristaps  145:
1.129     kristaps  146:        maxvis = (int)(p->rmargin - p->offset) - p->overstep < 0 ?
1.119     kristaps  147:                /* LINTED */
1.129     kristaps  148:                0 : p->rmargin - p->offset - p->overstep;
                    149:        mmax = (int)(p->maxrmargin - p->offset) - p->overstep < 0 ?
1.119     kristaps  150:                /* LINTED */
1.129     kristaps  151:                0 : p->maxrmargin - p->offset - p->overstep;
1.92      kristaps  152:
1.71      kristaps  153:        bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
1.115     kristaps  154:
                    155:        /*
                    156:         * FIXME: if bp is zero, we still output the first word before
                    157:         * breaking the line.
                    158:         */
                    159:
1.71      kristaps  160:        vis = 0;
1.84      kristaps  161:
1.71      kristaps  162:        /*
                    163:         * If in the standard case (left-justified), then begin with our
                    164:         * indentation, otherwise (columns, etc.) just start spitting
                    165:         * out text.
                    166:         */
1.53      kristaps  167:
1.71      kristaps  168:        if ( ! (p->flags & TERMP_NOLPAD))
                    169:                /* LINTED */
                    170:                for (j = 0; j < (int)p->offset; j++)
                    171:                        putchar(' ');
                    172:
                    173:        for (i = 0; i < (int)p->col; i++) {
                    174:                /*
                    175:                 * Count up visible word characters.  Control sequences
                    176:                 * (starting with the CSI) aren't counted.  A space
                    177:                 * generates a non-printing word, which is valid (the
                    178:                 * space is printed according to regular spacing rules).
                    179:                 */
                    180:
                    181:                /* LINTED */
1.132     kristaps  182:                for (j = i, vsz = 0; j < (int)p->col; j++) {
1.93      kristaps  183:                        if (j && ' ' == p->buf[j])
1.71      kristaps  184:                                break;
1.130     kristaps  185:                        if (8 == p->buf[j])
1.89      kristaps  186:                                vsz--;
1.71      kristaps  187:                        else
                    188:                                vsz++;
                    189:                }
1.53      kristaps  190:
1.71      kristaps  191:                /*
1.81      kristaps  192:                 * Choose the number of blanks to prepend: no blank at the
                    193:                 * beginning of a line, one between words -- but do not
                    194:                 * actually write them yet.
1.71      kristaps  195:                 */
1.130     kristaps  196:
1.81      kristaps  197:                vbl = (size_t)(0 == vis ? 0 : 1);
1.71      kristaps  198:
1.81      kristaps  199:                /*
                    200:                 * Find out whether we would exceed the right margin.
1.132     kristaps  201:                 * If so, break to the next line.  Otherwise, write the chosen
                    202:                 * number of blanks.
1.81      kristaps  203:                 */
1.130     kristaps  204:
1.81      kristaps  205:                if (vis && vis + vbl + vsz > bp) {
                    206:                        putchar('\n');
                    207:                        if (TERMP_NOBREAK & p->flags) {
                    208:                                for (j = 0; j < (int)p->rmargin; j++)
                    209:                                        putchar(' ');
                    210:                                vis = p->rmargin - p->offset;
                    211:                        } else {
1.71      kristaps  212:                                for (j = 0; j < (int)p->offset; j++)
                    213:                                        putchar(' ');
                    214:                                vis = 0;
1.81      kristaps  215:                        }
1.130     kristaps  216:
1.129     kristaps  217:                        /* Remove the p->overstep width. */
1.130     kristaps  218:
1.112     kristaps  219:                        bp += (int)/* LINTED */
1.129     kristaps  220:                                p->overstep;
                    221:                        p->overstep = 0;
1.81      kristaps  222:                } else {
                    223:                        for (j = 0; j < (int)vbl; j++)
1.71      kristaps  224:                                putchar(' ');
1.81      kristaps  225:                        vis += vbl;
1.71      kristaps  226:                }
1.53      kristaps  227:
1.130     kristaps  228:                /* Write out the [remaining] word. */
                    229:                for ( ; i < (int)p->col; i++)
1.71      kristaps  230:                        if (' ' == p->buf[i])
                    231:                                break;
1.130     kristaps  232:                        else if (31 == p->buf[i])
1.121     kristaps  233:                                putchar(' ');
                    234:                        else
                    235:                                putchar(p->buf[i]);
1.130     kristaps  236:
1.71      kristaps  237:                vis += vsz;
                    238:        }
1.111     kristaps  239:
1.91      kristaps  240:        p->col = 0;
1.129     kristaps  241:        p->overstep = 0;
1.15      kristaps  242:
1.91      kristaps  243:        if ( ! (TERMP_NOBREAK & p->flags)) {
                    244:                putchar('\n');
1.15      kristaps  245:                return;
1.71      kristaps  246:        }
1.15      kristaps  247:
1.91      kristaps  248:        if (TERMP_HANG & p->flags) {
                    249:                /* We need one blank after the tag. */
1.129     kristaps  250:                p->overstep = /* LINTED */
1.92      kristaps  251:                        vis - maxvis + 1;
1.91      kristaps  252:
                    253:                /*
                    254:                 * Behave exactly the same way as groff:
1.92      kristaps  255:                 * If we have overstepped the margin, temporarily move
                    256:                 * it to the right and flag the rest of the line to be
                    257:                 * shorter.
1.91      kristaps  258:                 * If we landed right at the margin, be happy.
1.92      kristaps  259:                 * If we are one step before the margin, temporarily
                    260:                 * move it one step LEFT and flag the rest of the line
                    261:                 * to be longer.
1.91      kristaps  262:                 */
1.129     kristaps  263:                if (p->overstep >= -1) {
                    264:                        assert((int)maxvis + p->overstep >= 0);
1.92      kristaps  265:                        /* LINTED */
1.129     kristaps  266:                        maxvis += p->overstep;
1.92      kristaps  267:                } else
1.129     kristaps  268:                        p->overstep = 0;
1.91      kristaps  269:
                    270:        } else if (TERMP_DANGLE & p->flags)
                    271:                return;
1.15      kristaps  272:
1.92      kristaps  273:        /* Right-pad. */
                    274:        if (maxvis > vis + /* LINTED */
                    275:                        ((TERMP_TWOSPACE & p->flags) ? 1 : 0))
1.91      kristaps  276:                for ( ; vis < maxvis; vis++)
                    277:                        putchar(' ');
1.92      kristaps  278:        else {  /* ...or newline break. */
1.71      kristaps  279:                putchar('\n');
1.91      kristaps  280:                for (i = 0; i < (int)p->rmargin; i++)
                    281:                        putchar(' ');
                    282:        }
1.15      kristaps  283: }
                    284:
                    285:
1.71      kristaps  286: /*
                    287:  * A newline only breaks an existing line; it won't assert vertical
                    288:  * space.  All data in the output buffer is flushed prior to the newline
                    289:  * assertion.
                    290:  */
                    291: void
                    292: term_newln(struct termp *p)
1.15      kristaps  293: {
                    294:
1.71      kristaps  295:        p->flags |= TERMP_NOSPACE;
                    296:        if (0 == p->col) {
                    297:                p->flags &= ~TERMP_NOLPAD;
1.15      kristaps  298:                return;
1.16      kristaps  299:        }
1.71      kristaps  300:        term_flushln(p);
                    301:        p->flags &= ~TERMP_NOLPAD;
1.16      kristaps  302: }
                    303:
                    304:
1.71      kristaps  305: /*
                    306:  * Asserts a vertical space (a full, empty line-break between lines).
                    307:  * Note that if used twice, this will cause two blank spaces and so on.
                    308:  * All data in the output buffer is flushed prior to the newline
                    309:  * assertion.
                    310:  */
                    311: void
                    312: term_vspace(struct termp *p)
1.16      kristaps  313: {
                    314:
1.62      kristaps  315:        term_newln(p);
1.71      kristaps  316:        putchar('\n');
1.16      kristaps  317: }
                    318:
                    319:
1.71      kristaps  320: static void
1.125     kristaps  321: spec(struct termp *p, const char *word, size_t len)
1.17      kristaps  322: {
1.71      kristaps  323:        const char      *rhs;
                    324:        size_t           sz;
1.17      kristaps  325:
1.101     kristaps  326:        rhs = chars_a2ascii(p->symtab, word, len, &sz);
1.125     kristaps  327:        if (rhs)
                    328:                encode(p, rhs, sz);
1.94      kristaps  329: }
                    330:
                    331:
                    332: static void
1.125     kristaps  333: res(struct termp *p, const char *word, size_t len)
1.94      kristaps  334: {
                    335:        const char      *rhs;
                    336:        size_t           sz;
                    337:
1.101     kristaps  338:        rhs = chars_a2res(p->symtab, word, len, &sz);
1.125     kristaps  339:        if (rhs)
                    340:                encode(p, rhs, sz);
                    341: }
                    342:
                    343:
                    344: void
                    345: term_fontlast(struct termp *p)
                    346: {
                    347:        enum termfont    f;
                    348:
                    349:        f = p->fontl;
                    350:        p->fontl = p->fontq[p->fonti];
                    351:        p->fontq[p->fonti] = f;
                    352: }
                    353:
                    354:
                    355: void
                    356: term_fontrepl(struct termp *p, enum termfont f)
                    357: {
                    358:
                    359:        p->fontl = p->fontq[p->fonti];
                    360:        p->fontq[p->fonti] = f;
                    361: }
                    362:
                    363:
                    364: void
                    365: term_fontpush(struct termp *p, enum termfont f)
                    366: {
                    367:
                    368:        assert(p->fonti + 1 < 10);
                    369:        p->fontl = p->fontq[p->fonti];
                    370:        p->fontq[++p->fonti] = f;
                    371: }
                    372:
                    373:
                    374: const void *
                    375: term_fontq(struct termp *p)
                    376: {
                    377:
                    378:        return(&p->fontq[p->fonti]);
                    379: }
                    380:
                    381:
                    382: enum termfont
                    383: term_fonttop(struct termp *p)
                    384: {
                    385:
                    386:        return(p->fontq[p->fonti]);
                    387: }
                    388:
                    389:
                    390: void
                    391: term_fontpopq(struct termp *p, const void *key)
                    392: {
                    393:
                    394:        while (p->fonti >= 0 && key != &p->fontq[p->fonti])
                    395:                p->fonti--;
                    396:        assert(p->fonti >= 0);
                    397: }
1.94      kristaps  398:
1.125     kristaps  399:
                    400: void
                    401: term_fontpop(struct termp *p)
                    402: {
                    403:
                    404:        assert(p->fonti);
                    405:        p->fonti--;
1.17      kristaps  406: }
                    407:
                    408:
1.71      kristaps  409: /*
                    410:  * Handle pwords, partial words, which may be either a single word or a
                    411:  * phrase that cannot be broken down (such as a literal string).  This
                    412:  * handles word styling.
                    413:  */
1.86      kristaps  414: void
                    415: term_word(struct termp *p, const char *word)
1.65      kristaps  416: {
1.124     kristaps  417:        const char      *sv, *seq;
1.125     kristaps  418:        int              sz;
1.124     kristaps  419:        size_t           ssz;
                    420:        enum roffdeco    deco;
1.71      kristaps  421:
1.100     kristaps  422:        sv = word;
                    423:
1.123     kristaps  424:        if (word[0] && '\0' == word[1])
1.100     kristaps  425:                switch (word[0]) {
                    426:                case('.'):
                    427:                        /* FALLTHROUGH */
                    428:                case(','):
                    429:                        /* FALLTHROUGH */
                    430:                case(';'):
                    431:                        /* FALLTHROUGH */
                    432:                case(':'):
                    433:                        /* FALLTHROUGH */
                    434:                case('?'):
                    435:                        /* FALLTHROUGH */
                    436:                case('!'):
                    437:                        /* FALLTHROUGH */
                    438:                case(')'):
                    439:                        /* FALLTHROUGH */
                    440:                case(']'):
                    441:                        if ( ! (TERMP_IGNDELIM & p->flags))
                    442:                                p->flags |= TERMP_NOSPACE;
                    443:                        break;
                    444:                default:
                    445:                        break;
                    446:                }
1.65      kristaps  447:
1.133   ! kristaps  448:        if ( ! (TERMP_NOSPACE & p->flags)) {
1.125     kristaps  449:                bufferc(p, ' ');
1.133   ! kristaps  450:                if (TERMP_SENTENCE & p->flags)
        !           451:                        bufferc(p, ' ');
        !           452:        }
1.65      kristaps  453:
1.71      kristaps  454:        if ( ! (p->flags & TERMP_NONOSPACE))
                    455:                p->flags &= ~TERMP_NOSPACE;
1.133   ! kristaps  456:
        !           457:        p->flags &= ~TERMP_SENTENCE;
1.65      kristaps  458:
1.125     kristaps  459:        /* FIXME: use strcspn. */
1.124     kristaps  460:
                    461:        while (*word) {
                    462:                if ('\\' != *word) {
1.125     kristaps  463:                        encode(p, word, 1);
1.124     kristaps  464:                        word++;
                    465:                        continue;
                    466:                }
                    467:
                    468:                seq = ++word;
                    469:                sz = a2roffdeco(&deco, &seq, &ssz);
                    470:
                    471:                switch (deco) {
                    472:                case (DECO_RESERVED):
1.125     kristaps  473:                        res(p, seq, ssz);
1.124     kristaps  474:                        break;
                    475:                case (DECO_SPECIAL):
1.125     kristaps  476:                        spec(p, seq, ssz);
1.124     kristaps  477:                        break;
                    478:                case (DECO_BOLD):
1.125     kristaps  479:                        term_fontrepl(p, TERMFONT_BOLD);
1.124     kristaps  480:                        break;
                    481:                case (DECO_ITALIC):
1.125     kristaps  482:                        term_fontrepl(p, TERMFONT_UNDER);
1.124     kristaps  483:                        break;
                    484:                case (DECO_ROMAN):
1.125     kristaps  485:                        term_fontrepl(p, TERMFONT_NONE);
1.124     kristaps  486:                        break;
                    487:                case (DECO_PREVIOUS):
1.125     kristaps  488:                        term_fontlast(p);
1.124     kristaps  489:                        break;
                    490:                default:
                    491:                        break;
                    492:                }
1.127     kristaps  493:
1.124     kristaps  494:                word += sz;
1.127     kristaps  495:                if (DECO_NOSPACE == deco && '\0' == *word)
                    496:                        p->flags |= TERMP_NOSPACE;
1.124     kristaps  497:        }
1.65      kristaps  498:
1.131     kristaps  499:        /*
                    500:         * Note that we don't process the pipe: the parser sees it as
                    501:         * punctuation, but we don't in terms of typography.
                    502:         */
1.100     kristaps  503:        if (sv[0] && 0 == sv[1])
                    504:                switch (sv[0]) {
                    505:                case('('):
                    506:                        /* FALLTHROUGH */
                    507:                case('['):
                    508:                        p->flags |= TERMP_NOSPACE;
                    509:                        break;
                    510:                default:
                    511:                        break;
                    512:                }
1.65      kristaps  513: }
                    514:
                    515:
1.71      kristaps  516: static void
1.125     kristaps  517: adjbuf(struct termp *p, size_t sz)
1.51      kristaps  518: {
                    519:
1.125     kristaps  520:        if (0 == p->maxcols)
                    521:                p->maxcols = 1024;
                    522:        while (sz >= p->maxcols)
                    523:                p->maxcols <<= 2;
                    524:
                    525:        p->buf = realloc(p->buf, p->maxcols);
                    526:        if (NULL == p->buf) {
                    527:                perror(NULL);
                    528:                exit(EXIT_FAILURE);
1.71      kristaps  529:        }
1.51      kristaps  530: }
                    531:
1.79      kristaps  532:
                    533: static void
1.125     kristaps  534: buffera(struct termp *p, const char *word, size_t sz)
1.79      kristaps  535: {
1.125     kristaps  536:
                    537:        if (p->col + sz >= p->maxcols)
                    538:                adjbuf(p, p->col + sz);
                    539:
1.126     kristaps  540:        memcpy(&p->buf[(int)p->col], word, sz);
1.125     kristaps  541:        p->col += sz;
                    542: }
                    543:
                    544:
                    545: static void
                    546: bufferc(struct termp *p, char c)
                    547: {
                    548:
                    549:        if (p->col + 1 >= p->maxcols)
                    550:                adjbuf(p, p->col + 1);
                    551:
1.126     kristaps  552:        p->buf[(int)p->col++] = c;
1.125     kristaps  553: }
                    554:
                    555:
                    556: static void
                    557: encode(struct termp *p, const char *word, size_t sz)
                    558: {
                    559:        enum termfont     f;
                    560:        int               i;
                    561:
                    562:        /*
                    563:         * Encode and buffer a string of characters.  If the current
                    564:         * font mode is unset, buffer directly, else encode then buffer
                    565:         * character by character.
                    566:         */
                    567:
                    568:        if (TERMFONT_NONE == (f = term_fonttop(p))) {
                    569:                buffera(p, word, sz);
                    570:                return;
                    571:        }
                    572:
                    573:        for (i = 0; i < (int)sz; i++) {
                    574:                if ( ! isgraph((u_char)word[i])) {
                    575:                        bufferc(p, word[i]);
                    576:                        continue;
1.79      kristaps  577:                }
1.125     kristaps  578:
                    579:                if (TERMFONT_UNDER == f)
                    580:                        bufferc(p, '_');
                    581:                else
                    582:                        bufferc(p, word[i]);
                    583:
                    584:                bufferc(p, 8);
                    585:                bufferc(p, word[i]);
1.79      kristaps  586:        }
                    587: }
1.106     kristaps  588:
                    589:
1.107     kristaps  590: size_t
                    591: term_vspan(const struct roffsu *su)
1.106     kristaps  592: {
                    593:        double           r;
                    594:
1.107     kristaps  595:        switch (su->unit) {
1.106     kristaps  596:        case (SCALE_CM):
1.107     kristaps  597:                r = su->scale * 2;
1.106     kristaps  598:                break;
                    599:        case (SCALE_IN):
1.107     kristaps  600:                r = su->scale * 6;
1.106     kristaps  601:                break;
                    602:        case (SCALE_PC):
1.107     kristaps  603:                r = su->scale;
1.106     kristaps  604:                break;
                    605:        case (SCALE_PT):
1.107     kristaps  606:                r = su->scale / 8;
1.106     kristaps  607:                break;
                    608:        case (SCALE_MM):
1.107     kristaps  609:                r = su->scale / 1000;
1.106     kristaps  610:                break;
                    611:        case (SCALE_VS):
1.107     kristaps  612:                r = su->scale;
1.106     kristaps  613:                break;
                    614:        default:
1.107     kristaps  615:                r = su->scale - 1;
1.106     kristaps  616:                break;
                    617:        }
                    618:
                    619:        if (r < 0.0)
                    620:                r = 0.0;
1.107     kristaps  621:        return(/* LINTED */(size_t)
1.106     kristaps  622:                        r);
                    623: }
                    624:
                    625:
1.107     kristaps  626: size_t
                    627: term_hspan(const struct roffsu *su)
1.106     kristaps  628: {
                    629:        double           r;
                    630:
1.108     kristaps  631:        /* XXX: CM, IN, and PT are approximations. */
                    632:
1.107     kristaps  633:        switch (su->unit) {
1.106     kristaps  634:        case (SCALE_CM):
1.108     kristaps  635:                r = 4 * su->scale;
1.106     kristaps  636:                break;
                    637:        case (SCALE_IN):
1.108     kristaps  638:                /* XXX: this is an approximation. */
                    639:                r = 10 * su->scale;
1.106     kristaps  640:                break;
                    641:        case (SCALE_PC):
1.108     kristaps  642:                r = (10 * su->scale) / 6;
1.106     kristaps  643:                break;
                    644:        case (SCALE_PT):
1.108     kristaps  645:                r = (10 * su->scale) / 72;
1.106     kristaps  646:                break;
                    647:        case (SCALE_MM):
1.107     kristaps  648:                r = su->scale / 1000; /* FIXME: double-check. */
1.106     kristaps  649:                break;
                    650:        case (SCALE_VS):
1.107     kristaps  651:                r = su->scale * 2 - 1; /* FIXME: double-check. */
1.106     kristaps  652:                break;
                    653:        default:
1.107     kristaps  654:                r = su->scale;
1.106     kristaps  655:                break;
                    656:        }
                    657:
                    658:        if (r < 0.0)
                    659:                r = 0.0;
1.107     kristaps  660:        return((size_t)/* LINTED */
1.106     kristaps  661:                        r);
                    662: }
                    663:
                    664:

CVSweb