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

Annotation of mandoc/term.c, Revision 1.116

1.116   ! kristaps    1: /*     $Id: term.c,v 1.115 2009/10/27 08:26:12 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:  */
                     17: #include <assert.h>
1.23      kristaps   18: #include <err.h>
1.22      kristaps   19: #include <stdio.h>
1.1       kristaps   20: #include <stdlib.h>
                     21: #include <string.h>
1.113     kristaps   22: #include <time.h>
1.1       kristaps   23:
1.101     kristaps   24: #include "chars.h"
1.107     kristaps   25: #include "out.h"
1.71      kristaps   26: #include "term.h"
                     27: #include "man.h"
                     28: #include "mdoc.h"
1.105     kristaps   29: #include "main.h"
1.1       kristaps   30:
1.103     kristaps   31: /* FIXME: accomodate non-breaking, non-collapsing white-space. */
                     32: /* FIXME: accomodate non-breaking, collapsing white-space. */
                     33:
1.71      kristaps   34: static struct termp     *term_alloc(enum termenc);
                     35: static void              term_free(struct termp *);
1.95      kristaps   36:
                     37: static void              do_escaped(struct termp *, const char **);
                     38: static void              do_special(struct termp *,
1.71      kristaps   39:                                const char *, size_t);
1.95      kristaps   40: static void              do_reserved(struct termp *,
1.94      kristaps   41:                                const char *, size_t);
1.95      kristaps   42: static void              buffer(struct termp *, char);
                     43: static void              encode(struct termp *, char);
1.1       kristaps   44:
                     45:
1.71      kristaps   46: void *
                     47: ascii_alloc(void)
1.10      kristaps   48: {
1.1       kristaps   49:
1.71      kristaps   50:        return(term_alloc(TERMENC_ASCII));
1.1       kristaps   51: }
                     52:
                     53:
1.99      kristaps   54: void
1.71      kristaps   55: terminal_free(void *arg)
1.11      kristaps   56: {
                     57:
1.71      kristaps   58:        term_free((struct termp *)arg);
1.11      kristaps   59: }
                     60:
                     61:
1.71      kristaps   62: static void
                     63: term_free(struct termp *p)
1.14      kristaps   64: {
                     65:
1.71      kristaps   66:        if (p->buf)
                     67:                free(p->buf);
1.102     kristaps   68:        if (p->symtab)
1.101     kristaps   69:                chars_free(p->symtab);
1.14      kristaps   70:
1.71      kristaps   71:        free(p);
1.14      kristaps   72: }
                     73:
                     74:
1.71      kristaps   75: static struct termp *
                     76: term_alloc(enum termenc enc)
1.14      kristaps   77: {
1.71      kristaps   78:        struct termp *p;
1.14      kristaps   79:
1.116   ! kristaps   80:        if (NULL == (p = calloc(1, sizeof(struct termp))))
1.98      kristaps   81:                return(NULL);
1.80      kristaps   82:        p->maxrmargin = 78;
1.71      kristaps   83:        p->enc = enc;
                     84:        return(p);
1.14      kristaps   85: }
                     86:
                     87:
1.71      kristaps   88: /*
                     89:  * Flush a line of text.  A "line" is loosely defined as being something
                     90:  * that should be followed by a newline, regardless of whether it's
                     91:  * broken apart by newlines getting there.  A line can also be a
                     92:  * fragment of a columnar list.
                     93:  *
                     94:  * Specifically, a line is whatever's in p->buf of length p->col, which
                     95:  * is zeroed after this function returns.
                     96:  *
1.84      kristaps   97:  * The usage of termp:flags is as follows:
1.71      kristaps   98:  *
                     99:  *  - TERMP_NOLPAD: when beginning to write the line, don't left-pad the
                    100:  *    offset value.  This is useful when doing columnar lists where the
                    101:  *    prior column has right-padded.
                    102:  *
                    103:  *  - TERMP_NOBREAK: this is the most important and is used when making
                    104:  *    columns.  In short: don't print a newline and instead pad to the
                    105:  *    right margin.  Used in conjunction with TERMP_NOLPAD.
                    106:  *
1.91      kristaps  107:  *  - TERMP_TWOSPACE: when padding, make sure there are at least two
                    108:  *    space characters of padding.  Otherwise, rather break the line.
                    109:  *
1.84      kristaps  110:  *  - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
                    111:  *    the line is overrun, and don't pad-right if it's underrun.
                    112:  *
                    113:  *  - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
                    114:  *    overruning, instead save the position and continue at that point
                    115:  *    when the next invocation.
1.71      kristaps  116:  *
                    117:  *  In-line line breaking:
                    118:  *
                    119:  *  If TERMP_NOBREAK is specified and the line overruns the right
                    120:  *  margin, it will break and pad-right to the right margin after
                    121:  *  writing.  If maxrmargin is violated, it will break and continue
1.114     kristaps  122:  *  writing from the right-margin, which will lead to the above scenario
                    123:  *  upon exit.  Otherwise, the line will break at the right margin.
1.71      kristaps  124:  */
                    125: void
                    126: term_flushln(struct termp *p)
1.53      kristaps  127: {
1.114     kristaps  128:        int              i;     /* current input position in p->buf */
                    129:        size_t           vis;   /* current visual position on output */
                    130:        size_t           vbl;   /* number of blanks to prepend to output */
                    131:        size_t           vsz;   /* visual characters to write to output */
                    132:        size_t           bp;    /* visual right border position */
                    133:        int              j;     /* temporary loop index */
                    134:        size_t           maxvis, mmax;
1.91      kristaps  135:        static int       overstep = 0;
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.114     kristaps  146:        maxvis = (int)(p->rmargin - p->offset) - overstep < 0 ?
                    147:                        0 : p->rmargin - p->offset - overstep;
                    148:        mmax = (int)(p->maxrmargin - p->offset) - overstep < 0 ?
                    149:                        0 : p->maxrmargin - p->offset - overstep;
1.92      kristaps  150:
1.71      kristaps  151:        bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
1.115     kristaps  152:
                    153:        /*
                    154:         * FIXME: if bp is zero, we still output the first word before
                    155:         * breaking the line.
                    156:         */
                    157:
1.71      kristaps  158:        vis = 0;
1.84      kristaps  159:
1.71      kristaps  160:        /*
                    161:         * If in the standard case (left-justified), then begin with our
                    162:         * indentation, otherwise (columns, etc.) just start spitting
                    163:         * out text.
                    164:         */
1.53      kristaps  165:
1.71      kristaps  166:        if ( ! (p->flags & TERMP_NOLPAD))
                    167:                /* LINTED */
                    168:                for (j = 0; j < (int)p->offset; j++)
                    169:                        putchar(' ');
                    170:
                    171:        for (i = 0; i < (int)p->col; i++) {
                    172:                /*
                    173:                 * Count up visible word characters.  Control sequences
                    174:                 * (starting with the CSI) aren't counted.  A space
                    175:                 * generates a non-printing word, which is valid (the
                    176:                 * space is printed according to regular spacing rules).
                    177:                 */
                    178:
                    179:                /* LINTED */
                    180:                for (j = i, vsz = 0; j < (int)p->col; j++) {
1.93      kristaps  181:                        if (j && ' ' == p->buf[j])
1.71      kristaps  182:                                break;
                    183:                        else if (8 == p->buf[j])
1.89      kristaps  184:                                vsz--;
1.71      kristaps  185:                        else
                    186:                                vsz++;
                    187:                }
1.53      kristaps  188:
1.71      kristaps  189:                /*
1.81      kristaps  190:                 * Choose the number of blanks to prepend: no blank at the
                    191:                 * beginning of a line, one between words -- but do not
                    192:                 * actually write them yet.
1.71      kristaps  193:                 */
1.81      kristaps  194:                vbl = (size_t)(0 == vis ? 0 : 1);
1.71      kristaps  195:
1.81      kristaps  196:                /*
                    197:                 * Find out whether we would exceed the right margin.
                    198:                 * If so, break to the next line.  (TODO: hyphenate)
                    199:                 * Otherwise, write the chosen number of blanks now.
                    200:                 */
                    201:                if (vis && vis + vbl + vsz > bp) {
                    202:                        putchar('\n');
                    203:                        if (TERMP_NOBREAK & p->flags) {
                    204:                                for (j = 0; j < (int)p->rmargin; j++)
                    205:                                        putchar(' ');
                    206:                                vis = p->rmargin - p->offset;
                    207:                        } else {
1.71      kristaps  208:                                for (j = 0; j < (int)p->offset; j++)
                    209:                                        putchar(' ');
                    210:                                vis = 0;
1.81      kristaps  211:                        }
1.104     kristaps  212:                        /* Remove the overstep width. */
1.112     kristaps  213:                        bp += (int)/* LINTED */
                    214:                                overstep;
1.110     kristaps  215:                        overstep = 0;
1.81      kristaps  216:                } else {
                    217:                        for (j = 0; j < (int)vbl; j++)
1.71      kristaps  218:                                putchar(' ');
1.81      kristaps  219:                        vis += vbl;
1.71      kristaps  220:                }
1.53      kristaps  221:
1.78      kristaps  222:                /*
1.81      kristaps  223:                 * Finally, write out the word.
1.71      kristaps  224:                 */
                    225:                for ( ; i < (int)p->col; i++) {
                    226:                        if (' ' == p->buf[i])
                    227:                                break;
                    228:                        putchar(p->buf[i]);
                    229:                }
                    230:                vis += vsz;
                    231:        }
1.111     kristaps  232:
1.91      kristaps  233:        p->col = 0;
1.111     kristaps  234:        overstep = 0;
1.15      kristaps  235:
1.91      kristaps  236:        if ( ! (TERMP_NOBREAK & p->flags)) {
                    237:                putchar('\n');
1.15      kristaps  238:                return;
1.71      kristaps  239:        }
1.15      kristaps  240:
1.91      kristaps  241:        if (TERMP_HANG & p->flags) {
                    242:                /* We need one blank after the tag. */
1.92      kristaps  243:                overstep = /* LINTED */
                    244:                        vis - maxvis + 1;
1.91      kristaps  245:
                    246:                /*
                    247:                 * Behave exactly the same way as groff:
1.92      kristaps  248:                 * If we have overstepped the margin, temporarily move
                    249:                 * it to the right and flag the rest of the line to be
                    250:                 * shorter.
1.91      kristaps  251:                 * If we landed right at the margin, be happy.
1.92      kristaps  252:                 * If we are one step before the margin, temporarily
                    253:                 * move it one step LEFT and flag the rest of the line
                    254:                 * to be longer.
1.91      kristaps  255:                 */
1.92      kristaps  256:                if (overstep >= -1) {
                    257:                        assert((int)maxvis + overstep >= 0);
                    258:                        /* LINTED */
1.91      kristaps  259:                        maxvis += overstep;
1.92      kristaps  260:                } else
1.91      kristaps  261:                        overstep = 0;
                    262:
                    263:        } else if (TERMP_DANGLE & p->flags)
                    264:                return;
1.15      kristaps  265:
1.92      kristaps  266:        /* Right-pad. */
                    267:        if (maxvis > vis + /* LINTED */
                    268:                        ((TERMP_TWOSPACE & p->flags) ? 1 : 0))
1.91      kristaps  269:                for ( ; vis < maxvis; vis++)
                    270:                        putchar(' ');
1.92      kristaps  271:        else {  /* ...or newline break. */
1.71      kristaps  272:                putchar('\n');
1.91      kristaps  273:                for (i = 0; i < (int)p->rmargin; i++)
                    274:                        putchar(' ');
                    275:        }
1.15      kristaps  276: }
                    277:
                    278:
1.71      kristaps  279: /*
                    280:  * A newline only breaks an existing line; it won't assert vertical
                    281:  * space.  All data in the output buffer is flushed prior to the newline
                    282:  * assertion.
                    283:  */
                    284: void
                    285: term_newln(struct termp *p)
1.15      kristaps  286: {
                    287:
1.71      kristaps  288:        p->flags |= TERMP_NOSPACE;
                    289:        if (0 == p->col) {
                    290:                p->flags &= ~TERMP_NOLPAD;
1.15      kristaps  291:                return;
1.16      kristaps  292:        }
1.71      kristaps  293:        term_flushln(p);
                    294:        p->flags &= ~TERMP_NOLPAD;
1.16      kristaps  295: }
                    296:
                    297:
1.71      kristaps  298: /*
                    299:  * Asserts a vertical space (a full, empty line-break between lines).
                    300:  * Note that if used twice, this will cause two blank spaces and so on.
                    301:  * All data in the output buffer is flushed prior to the newline
                    302:  * assertion.
                    303:  */
                    304: void
                    305: term_vspace(struct termp *p)
1.16      kristaps  306: {
                    307:
1.62      kristaps  308:        term_newln(p);
1.71      kristaps  309:        putchar('\n');
1.16      kristaps  310: }
                    311:
                    312:
1.71      kristaps  313: static void
1.95      kristaps  314: do_special(struct termp *p, const char *word, size_t len)
1.17      kristaps  315: {
1.71      kristaps  316:        const char      *rhs;
                    317:        size_t           sz;
1.79      kristaps  318:        int              i;
1.17      kristaps  319:
1.101     kristaps  320:        rhs = chars_a2ascii(p->symtab, word, len, &sz);
1.86      kristaps  321:
1.96      kristaps  322:        if (NULL == rhs) {
1.97      kristaps  323: #if 0
1.96      kristaps  324:                fputs("Unknown special character: ", stderr);
                    325:                for (i = 0; i < (int)len; i++)
                    326:                        fputc(word[i], stderr);
                    327:                fputc('\n', stderr);
                    328: #endif
1.94      kristaps  329:                return;
1.96      kristaps  330:        }
1.94      kristaps  331:        for (i = 0; i < (int)sz; i++)
1.95      kristaps  332:                encode(p, rhs[i]);
1.94      kristaps  333: }
                    334:
                    335:
                    336: static void
1.95      kristaps  337: do_reserved(struct termp *p, const char *word, size_t len)
1.94      kristaps  338: {
                    339:        const char      *rhs;
                    340:        size_t           sz;
                    341:        int              i;
                    342:
1.101     kristaps  343:        rhs = chars_a2res(p->symtab, word, len, &sz);
1.94      kristaps  344:
1.96      kristaps  345:        if (NULL == rhs) {
                    346: #if 0
                    347:                fputs("Unknown reserved word: ", stderr);
                    348:                for (i = 0; i < (int)len; i++)
                    349:                        fputc(word[i], stderr);
                    350:                fputc('\n', stderr);
                    351: #endif
1.94      kristaps  352:                return;
1.96      kristaps  353:        }
1.94      kristaps  354:        for (i = 0; i < (int)sz; i++)
1.95      kristaps  355:                encode(p, rhs[i]);
1.17      kristaps  356: }
                    357:
                    358:
1.71      kristaps  359: /*
                    360:  * Handle an escape sequence: determine its length and pass it to the
                    361:  * escape-symbol look table.  Note that we assume mdoc(3) has validated
                    362:  * the escape sequence (we assert upon badly-formed escape sequences).
                    363:  */
                    364: static void
1.95      kristaps  365: do_escaped(struct termp *p, const char **word)
1.17      kristaps  366: {
1.97      kristaps  367:        int              j, type;
1.86      kristaps  368:        const char      *wp;
                    369:
                    370:        wp = *word;
1.97      kristaps  371:        type = 1;
1.17      kristaps  372:
1.86      kristaps  373:        if (0 == *(++wp)) {
                    374:                *word = wp;
1.71      kristaps  375:                return;
1.86      kristaps  376:        }
1.17      kristaps  377:
1.86      kristaps  378:        if ('(' == *wp) {
                    379:                wp++;
                    380:                if (0 == *wp || 0 == *(wp + 1)) {
                    381:                        *word = 0 == *wp ? wp : wp + 1;
1.71      kristaps  382:                        return;
1.86      kristaps  383:                }
1.22      kristaps  384:
1.95      kristaps  385:                do_special(p, wp, 2);
1.86      kristaps  386:                *word = ++wp;
1.71      kristaps  387:                return;
1.22      kristaps  388:
1.86      kristaps  389:        } else if ('*' == *wp) {
                    390:                if (0 == *(++wp)) {
                    391:                        *word = wp;
1.71      kristaps  392:                        return;
1.86      kristaps  393:                }
1.22      kristaps  394:
1.86      kristaps  395:                switch (*wp) {
1.71      kristaps  396:                case ('('):
1.86      kristaps  397:                        wp++;
                    398:                        if (0 == *wp || 0 == *(wp + 1)) {
                    399:                                *word = 0 == *wp ? wp : wp + 1;
1.71      kristaps  400:                                return;
1.86      kristaps  401:                        }
1.65      kristaps  402:
1.95      kristaps  403:                        do_reserved(p, wp, 2);
1.86      kristaps  404:                        *word = ++wp;
1.71      kristaps  405:                        return;
                    406:                case ('['):
1.97      kristaps  407:                        type = 0;
1.71      kristaps  408:                        break;
                    409:                default:
1.95      kristaps  410:                        do_reserved(p, wp, 1);
1.86      kristaps  411:                        *word = wp;
1.71      kristaps  412:                        return;
                    413:                }
                    414:
1.86      kristaps  415:        } else if ('f' == *wp) {
                    416:                if (0 == *(++wp)) {
                    417:                        *word = wp;
1.71      kristaps  418:                        return;
1.86      kristaps  419:                }
                    420:
                    421:                switch (*wp) {
1.71      kristaps  422:                case ('B'):
1.98      kristaps  423:                        p->bold++;
1.71      kristaps  424:                        break;
                    425:                case ('I'):
1.98      kristaps  426:                        p->under++;
1.71      kristaps  427:                        break;
                    428:                case ('P'):
                    429:                        /* FALLTHROUGH */
                    430:                case ('R'):
1.98      kristaps  431:                        p->bold = p->under = 0;
1.71      kristaps  432:                        break;
                    433:                default:
                    434:                        break;
                    435:                }
1.86      kristaps  436:
                    437:                *word = wp;
1.71      kristaps  438:                return;
1.22      kristaps  439:
1.86      kristaps  440:        } else if ('[' != *wp) {
1.95      kristaps  441:                do_special(p, wp, 1);
1.86      kristaps  442:                *word = wp;
1.71      kristaps  443:                return;
                    444:        }
1.28      kristaps  445:
1.86      kristaps  446:        wp++;
                    447:        for (j = 0; *wp && ']' != *wp; wp++, j++)
1.71      kristaps  448:                /* Loop... */ ;
1.28      kristaps  449:
1.86      kristaps  450:        if (0 == *wp) {
                    451:                *word = wp;
1.71      kristaps  452:                return;
1.86      kristaps  453:        }
1.48      kristaps  454:
1.97      kristaps  455:        if (type)
                    456:                do_special(p, wp - j, (size_t)j);
                    457:        else
                    458:                do_reserved(p, wp - j, (size_t)j);
1.86      kristaps  459:        *word = wp;
1.48      kristaps  460: }
                    461:
                    462:
1.71      kristaps  463: /*
                    464:  * Handle pwords, partial words, which may be either a single word or a
                    465:  * phrase that cannot be broken down (such as a literal string).  This
                    466:  * handles word styling.
                    467:  */
1.86      kristaps  468: void
                    469: term_word(struct termp *p, const char *word)
1.65      kristaps  470: {
1.88      kristaps  471:        const char       *sv;
1.71      kristaps  472:
1.100     kristaps  473:        sv = word;
                    474:
                    475:        if (word[0] && 0 == word[1])
                    476:                switch (word[0]) {
                    477:                case('.'):
                    478:                        /* FALLTHROUGH */
                    479:                case(','):
                    480:                        /* FALLTHROUGH */
                    481:                case(';'):
                    482:                        /* FALLTHROUGH */
                    483:                case(':'):
                    484:                        /* FALLTHROUGH */
                    485:                case('?'):
                    486:                        /* FALLTHROUGH */
                    487:                case('!'):
                    488:                        /* FALLTHROUGH */
                    489:                case(')'):
                    490:                        /* FALLTHROUGH */
                    491:                case(']'):
                    492:                        /* FALLTHROUGH */
                    493:                case('}'):
                    494:                        if ( ! (TERMP_IGNDELIM & p->flags))
                    495:                                p->flags |= TERMP_NOSPACE;
                    496:                        break;
                    497:                default:
                    498:                        break;
                    499:                }
1.65      kristaps  500:
1.71      kristaps  501:        if ( ! (TERMP_NOSPACE & p->flags))
1.95      kristaps  502:                buffer(p, ' ');
1.65      kristaps  503:
1.71      kristaps  504:        if ( ! (p->flags & TERMP_NONOSPACE))
                    505:                p->flags &= ~TERMP_NOSPACE;
1.65      kristaps  506:
1.100     kristaps  507:        for ( ; *word; word++)
1.86      kristaps  508:                if ('\\' != *word)
1.95      kristaps  509:                        encode(p, *word);
1.79      kristaps  510:                else
1.95      kristaps  511:                        do_escaped(p, &word);
1.65      kristaps  512:
1.100     kristaps  513:        if (sv[0] && 0 == sv[1])
                    514:                switch (sv[0]) {
                    515:                case('('):
                    516:                        /* FALLTHROUGH */
                    517:                case('['):
                    518:                        /* FALLTHROUGH */
                    519:                case('{'):
                    520:                        p->flags |= TERMP_NOSPACE;
                    521:                        break;
                    522:                default:
                    523:                        break;
                    524:                }
1.65      kristaps  525: }
                    526:
                    527:
1.71      kristaps  528: /*
                    529:  * Insert a single character into the line-buffer.  If the buffer's
                    530:  * space is exceeded, then allocate more space by doubling the buffer
                    531:  * size.
                    532:  */
                    533: static void
1.95      kristaps  534: buffer(struct termp *p, char c)
1.51      kristaps  535: {
1.71      kristaps  536:        size_t           s;
1.51      kristaps  537:
1.71      kristaps  538:        if (p->col + 1 >= p->maxcols) {
                    539:                if (0 == p->maxcols)
                    540:                        p->maxcols = 256;
                    541:                s = p->maxcols * 2;
                    542:                p->buf = realloc(p->buf, s);
                    543:                if (NULL == p->buf)
1.98      kristaps  544:                        err(1, "realloc"); /* FIXME: shouldn't be here! */
1.71      kristaps  545:                p->maxcols = s;
                    546:        }
                    547:        p->buf[(int)(p->col)++] = c;
1.51      kristaps  548: }
                    549:
1.79      kristaps  550:
                    551: static void
1.95      kristaps  552: encode(struct termp *p, char c)
1.79      kristaps  553: {
1.89      kristaps  554:
1.98      kristaps  555:        if (' ' != c) {
1.109     kristaps  556:                if (p->under) {
                    557:                        buffer(p, '_');
                    558:                        buffer(p, 8);
                    559:                }
1.98      kristaps  560:                if (p->bold) {
1.95      kristaps  561:                        buffer(p, c);
                    562:                        buffer(p, 8);
1.79      kristaps  563:                }
                    564:        }
1.95      kristaps  565:        buffer(p, c);
1.79      kristaps  566: }
1.106     kristaps  567:
                    568:
1.107     kristaps  569: size_t
                    570: term_vspan(const struct roffsu *su)
1.106     kristaps  571: {
                    572:        double           r;
                    573:
1.107     kristaps  574:        switch (su->unit) {
1.106     kristaps  575:        case (SCALE_CM):
1.107     kristaps  576:                r = su->scale * 2;
1.106     kristaps  577:                break;
                    578:        case (SCALE_IN):
1.107     kristaps  579:                r = su->scale * 6;
1.106     kristaps  580:                break;
                    581:        case (SCALE_PC):
1.107     kristaps  582:                r = su->scale;
1.106     kristaps  583:                break;
                    584:        case (SCALE_PT):
1.107     kristaps  585:                r = su->scale / 8;
1.106     kristaps  586:                break;
                    587:        case (SCALE_MM):
1.107     kristaps  588:                r = su->scale / 1000;
1.106     kristaps  589:                break;
                    590:        case (SCALE_VS):
1.107     kristaps  591:                r = su->scale;
1.106     kristaps  592:                break;
                    593:        default:
1.107     kristaps  594:                r = su->scale - 1;
1.106     kristaps  595:                break;
                    596:        }
                    597:
                    598:        if (r < 0.0)
                    599:                r = 0.0;
1.107     kristaps  600:        return(/* LINTED */(size_t)
1.106     kristaps  601:                        r);
                    602: }
                    603:
                    604:
1.107     kristaps  605: size_t
                    606: term_hspan(const struct roffsu *su)
1.106     kristaps  607: {
                    608:        double           r;
                    609:
1.108     kristaps  610:        /* XXX: CM, IN, and PT are approximations. */
                    611:
1.107     kristaps  612:        switch (su->unit) {
1.106     kristaps  613:        case (SCALE_CM):
1.108     kristaps  614:                r = 4 * su->scale;
1.106     kristaps  615:                break;
                    616:        case (SCALE_IN):
1.108     kristaps  617:                /* XXX: this is an approximation. */
                    618:                r = 10 * su->scale;
1.106     kristaps  619:                break;
                    620:        case (SCALE_PC):
1.108     kristaps  621:                r = (10 * su->scale) / 6;
1.106     kristaps  622:                break;
                    623:        case (SCALE_PT):
1.108     kristaps  624:                r = (10 * su->scale) / 72;
1.106     kristaps  625:                break;
                    626:        case (SCALE_MM):
1.107     kristaps  627:                r = su->scale / 1000; /* FIXME: double-check. */
1.106     kristaps  628:                break;
                    629:        case (SCALE_VS):
1.107     kristaps  630:                r = su->scale * 2 - 1; /* FIXME: double-check. */
1.106     kristaps  631:                break;
                    632:        default:
1.107     kristaps  633:                r = su->scale;
1.106     kristaps  634:                break;
                    635:        }
                    636:
                    637:        if (r < 0.0)
                    638:                r = 0.0;
1.107     kristaps  639:        return((size_t)/* LINTED */
1.106     kristaps  640:                        r);
                    641: }
                    642:
                    643:

CVSweb