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

Annotation of mandoc/man.c, Revision 1.94

1.94    ! kristaps    1: /*     $Id: man.c,v 1.93 2011/01/01 10:51:30 kristaps Exp $ */
1.1       kristaps    2: /*
1.82      schwarze    3:  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
1.18      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.18      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.47      kristaps   17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
1.41      kristaps   21: #include <sys/types.h>
                     22:
1.1       kristaps   23: #include <assert.h>
                     24: #include <stdarg.h>
                     25: #include <stdlib.h>
                     26: #include <stdio.h>
                     27: #include <string.h>
                     28:
1.74      kristaps   29: #include "mandoc.h"
1.1       kristaps   30: #include "libman.h"
1.45      kristaps   31: #include "libmandoc.h"
1.1       kristaps   32:
                     33: const  char *const __man_macronames[MAN_MAX] = {
1.21      kristaps   34:        "br",           "TH",           "SH",           "SS",
1.1       kristaps   35:        "TP",           "LP",           "PP",           "P",
                     36:        "IP",           "HP",           "SM",           "SB",
                     37:        "BI",           "IB",           "BR",           "RB",
1.11      kristaps   38:        "R",            "B",            "I",            "IR",
1.92      kristaps   39:        "RI",           "na",           "sp",           "nf",
                     40:        "fi",           "RE",           "RS",           "DT",
                     41:        "UC",           "PD",           "AT",           "in",
                     42:        "ft"
1.1       kristaps   43:        };
                     44:
                     45: const  char * const *man_macronames = __man_macronames;
                     46:
1.16      kristaps   47: static struct man_node *man_node_alloc(int, int,
1.53      kristaps   48:                                enum man_type, enum mant);
1.1       kristaps   49: static int              man_node_append(struct man *,
                     50:                                struct man_node *);
1.94    ! kristaps   51: static int              man_span_alloc(struct man *,
        !            52:                                const struct tbl_span *);
1.54      kristaps   53: static void             man_node_free(struct man_node *);
                     54: static void             man_node_unlink(struct man *,
                     55:                                struct man_node *);
1.72      kristaps   56: static int              man_ptext(struct man *, int, char *, int);
1.79      kristaps   57: static int              man_pmacro(struct man *, int, char *, int);
1.2       kristaps   58: static void             man_free1(struct man *);
1.45      kristaps   59: static void             man_alloc1(struct man *);
1.94    ! kristaps   60: static int              man_descope(struct man *, int, int);
1.1       kristaps   61:
                     62:
                     63: const struct man_node *
1.2       kristaps   64: man_node(const struct man *m)
1.1       kristaps   65: {
                     66:
1.2       kristaps   67:        return(MAN_HALT & m->flags ? NULL : m->first);
1.1       kristaps   68: }
                     69:
                     70:
                     71: const struct man_meta *
1.2       kristaps   72: man_meta(const struct man *m)
1.1       kristaps   73: {
                     74:
1.2       kristaps   75:        return(MAN_HALT & m->flags ? NULL : &m->meta);
1.1       kristaps   76: }
                     77:
                     78:
1.45      kristaps   79: void
1.1       kristaps   80: man_reset(struct man *man)
                     81: {
                     82:
1.2       kristaps   83:        man_free1(man);
1.45      kristaps   84:        man_alloc1(man);
1.1       kristaps   85: }
                     86:
                     87:
                     88: void
                     89: man_free(struct man *man)
                     90: {
                     91:
1.2       kristaps   92:        man_free1(man);
1.1       kristaps   93:        free(man);
                     94: }
                     95:
                     96:
                     97: struct man *
1.87      schwarze   98: man_alloc(struct regset *regs, void *data, mandocmsg msg)
1.1       kristaps   99: {
                    100:        struct man      *p;
                    101:
1.45      kristaps  102:        p = mandoc_calloc(1, sizeof(struct man));
1.2       kristaps  103:
1.40      kristaps  104:        man_hash_init();
1.4       kristaps  105:        p->data = data;
1.74      kristaps  106:        p->msg = msg;
1.79      kristaps  107:        p->regs = regs;
1.45      kristaps  108:
                    109:        man_alloc1(p);
1.1       kristaps  110:        return(p);
                    111: }
                    112:
                    113:
                    114: int
                    115: man_endparse(struct man *m)
                    116: {
                    117:
1.3       kristaps  118:        if (MAN_HALT & m->flags)
                    119:                return(0);
                    120:        else if (man_macroend(m))
                    121:                return(1);
                    122:        m->flags |= MAN_HALT;
                    123:        return(0);
1.1       kristaps  124: }
                    125:
                    126:
                    127: int
1.79      kristaps  128: man_parseln(struct man *m, int ln, char *buf, int offs)
1.1       kristaps  129: {
                    130:
1.72      kristaps  131:        if (MAN_HALT & m->flags)
                    132:                return(0);
                    133:
                    134:        return(('.' == buf[offs] || '\'' == buf[offs]) ?
1.79      kristaps  135:                        man_pmacro(m, ln, buf, offs) :
1.72      kristaps  136:                        man_ptext(m, ln, buf, offs));
1.1       kristaps  137: }
                    138:
                    139:
1.2       kristaps  140: static void
                    141: man_free1(struct man *man)
                    142: {
                    143:
                    144:        if (man->first)
1.54      kristaps  145:                man_node_delete(man, man->first);
1.2       kristaps  146:        if (man->meta.title)
                    147:                free(man->meta.title);
1.6       kristaps  148:        if (man->meta.source)
                    149:                free(man->meta.source);
1.75      kristaps  150:        if (man->meta.rawdate)
                    151:                free(man->meta.rawdate);
1.2       kristaps  152:        if (man->meta.vol)
                    153:                free(man->meta.vol);
1.68      kristaps  154:        if (man->meta.msec)
                    155:                free(man->meta.msec);
1.2       kristaps  156: }
                    157:
                    158:
1.45      kristaps  159: static void
1.2       kristaps  160: man_alloc1(struct man *m)
                    161: {
                    162:
1.44      kristaps  163:        memset(&m->meta, 0, sizeof(struct man_meta));
1.2       kristaps  164:        m->flags = 0;
1.45      kristaps  165:        m->last = mandoc_calloc(1, sizeof(struct man_node));
1.2       kristaps  166:        m->first = m->last;
                    167:        m->last->type = MAN_ROOT;
1.54      kristaps  168:        m->last->tok = MAN_MAX;
1.2       kristaps  169:        m->next = MAN_NEXT_CHILD;
                    170: }
                    171:
                    172:
1.1       kristaps  173: static int
                    174: man_node_append(struct man *man, struct man_node *p)
                    175: {
                    176:
                    177:        assert(man->last);
                    178:        assert(man->first);
                    179:        assert(MAN_ROOT != p->type);
                    180:
                    181:        switch (man->next) {
                    182:        case (MAN_NEXT_SIBLING):
                    183:                man->last->next = p;
                    184:                p->prev = man->last;
                    185:                p->parent = man->last->parent;
                    186:                break;
                    187:        case (MAN_NEXT_CHILD):
                    188:                man->last->child = p;
                    189:                p->parent = man->last;
                    190:                break;
                    191:        default:
                    192:                abort();
                    193:                /* NOTREACHED */
                    194:        }
1.22      kristaps  195:
1.54      kristaps  196:        assert(p->parent);
1.22      kristaps  197:        p->parent->nchild++;
1.1       kristaps  198:
1.29      kristaps  199:        if ( ! man_valid_pre(man, p))
                    200:                return(0);
                    201:
                    202:        switch (p->type) {
                    203:        case (MAN_HEAD):
                    204:                assert(MAN_BLOCK == p->parent->type);
                    205:                p->parent->head = p;
                    206:                break;
                    207:        case (MAN_BODY):
                    208:                assert(MAN_BLOCK == p->parent->type);
                    209:                p->parent->body = p;
                    210:                break;
                    211:        default:
                    212:                break;
                    213:        }
                    214:
1.2       kristaps  215:        man->last = p;
                    216:
1.1       kristaps  217:        switch (p->type) {
1.94    ! kristaps  218:        case (MAN_TBL):
        !           219:                /* FALLTHROUGH */
1.2       kristaps  220:        case (MAN_TEXT):
                    221:                if ( ! man_valid_post(man))
                    222:                        return(0);
1.1       kristaps  223:                break;
                    224:        default:
                    225:                break;
                    226:        }
                    227:
                    228:        return(1);
                    229: }
                    230:
                    231:
                    232: static struct man_node *
1.53      kristaps  233: man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
1.1       kristaps  234: {
                    235:        struct man_node *p;
                    236:
1.45      kristaps  237:        p = mandoc_calloc(1, sizeof(struct man_node));
1.1       kristaps  238:        p->line = line;
                    239:        p->pos = pos;
                    240:        p->type = type;
1.16      kristaps  241:        p->tok = tok;
1.1       kristaps  242:        return(p);
                    243: }
                    244:
                    245:
                    246: int
1.53      kristaps  247: man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
1.1       kristaps  248: {
                    249:        struct man_node *p;
                    250:
1.16      kristaps  251:        p = man_node_alloc(line, pos, MAN_ELEM, tok);
1.30      kristaps  252:        if ( ! man_node_append(m, p))
                    253:                return(0);
                    254:        m->next = MAN_NEXT_CHILD;
                    255:        return(1);
1.1       kristaps  256: }
                    257:
                    258:
                    259: int
1.53      kristaps  260: man_head_alloc(struct man *m, int line, int pos, enum mant tok)
1.29      kristaps  261: {
                    262:        struct man_node *p;
                    263:
                    264:        p = man_node_alloc(line, pos, MAN_HEAD, tok);
                    265:        if ( ! man_node_append(m, p))
                    266:                return(0);
                    267:        m->next = MAN_NEXT_CHILD;
                    268:        return(1);
                    269: }
                    270:
                    271:
                    272: int
1.53      kristaps  273: man_body_alloc(struct man *m, int line, int pos, enum mant tok)
1.29      kristaps  274: {
                    275:        struct man_node *p;
                    276:
                    277:        p = man_node_alloc(line, pos, MAN_BODY, tok);
                    278:        if ( ! man_node_append(m, p))
                    279:                return(0);
                    280:        m->next = MAN_NEXT_CHILD;
                    281:        return(1);
                    282: }
                    283:
                    284:
                    285: int
1.53      kristaps  286: man_block_alloc(struct man *m, int line, int pos, enum mant tok)
1.29      kristaps  287: {
                    288:        struct man_node *p;
                    289:
                    290:        p = man_node_alloc(line, pos, MAN_BLOCK, tok);
                    291:        if ( ! man_node_append(m, p))
                    292:                return(0);
                    293:        m->next = MAN_NEXT_CHILD;
                    294:        return(1);
                    295: }
                    296:
1.94    ! kristaps  297: static int
        !           298: man_span_alloc(struct man *m, const struct tbl_span *span)
        !           299: {
        !           300:        struct man_node *n;
        !           301:
        !           302:        /* FIXME: grab from span */
        !           303:        n = man_node_alloc(0, 0, MAN_TBL, MAN_MAX);
        !           304:
        !           305:        if ( ! man_node_append(m, n))
        !           306:                return(0);
        !           307:
        !           308:        m->next = MAN_NEXT_SIBLING;
        !           309:        return(1);
        !           310: }
1.29      kristaps  311:
1.61      kristaps  312: int
                    313: man_word_alloc(struct man *m, int line, int pos, const char *word)
1.1       kristaps  314: {
1.31      kristaps  315:        struct man_node *n;
1.61      kristaps  316:        size_t           sv, len;
                    317:
                    318:        len = strlen(word);
1.1       kristaps  319:
1.53      kristaps  320:        n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
1.45      kristaps  321:        n->string = mandoc_malloc(len + 1);
1.61      kristaps  322:        sv = strlcpy(n->string, word, len + 1);
1.31      kristaps  323:
                    324:        /* Prohibit truncation. */
                    325:        assert(sv < len + 1);
                    326:
                    327:        if ( ! man_node_append(m, n))
1.30      kristaps  328:                return(0);
1.61      kristaps  329:
1.30      kristaps  330:        m->next = MAN_NEXT_SIBLING;
                    331:        return(1);
1.1       kristaps  332: }
                    333:
                    334:
1.54      kristaps  335: /*
                    336:  * Free all of the resources held by a node.  This does NOT unlink a
                    337:  * node from its context; for that, see man_node_unlink().
                    338:  */
                    339: static void
1.1       kristaps  340: man_node_free(struct man_node *p)
                    341: {
                    342:
                    343:        if (p->string)
                    344:                free(p->string);
                    345:        free(p);
                    346: }
                    347:
                    348:
                    349: void
1.54      kristaps  350: man_node_delete(struct man *m, struct man_node *p)
1.1       kristaps  351: {
                    352:
1.54      kristaps  353:        while (p->child)
                    354:                man_node_delete(m, p->child);
                    355:
                    356:        man_node_unlink(m, p);
1.1       kristaps  357:        man_node_free(p);
                    358: }
                    359:
                    360:
1.94    ! kristaps  361: int
        !           362: man_addspan(struct man *m, const struct tbl_span *sp)
        !           363: {
        !           364:
        !           365:        if ( ! man_span_alloc(m, sp))
        !           366:                return(0);
        !           367:        return(man_descope(m, 0, 0));
        !           368: }
        !           369:
        !           370: static int
        !           371: man_descope(struct man *m, int line, int offs)
        !           372: {
        !           373:        /*
        !           374:         * Co-ordinate what happens with having a next-line scope open:
        !           375:         * first close out the element scope (if applicable), then close
        !           376:         * out the block scope (also if applicable).
        !           377:         */
        !           378:
        !           379:        if (MAN_ELINE & m->flags) {
        !           380:                m->flags &= ~MAN_ELINE;
        !           381:                if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
        !           382:                        return(0);
        !           383:        }
        !           384:
        !           385:        if ( ! (MAN_BLINE & m->flags))
        !           386:                return(1);
        !           387:        m->flags &= ~MAN_BLINE;
        !           388:
        !           389:        if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
        !           390:                return(0);
        !           391:        return(man_body_alloc(m, line, offs, m->last->tok));
        !           392: }
        !           393:
        !           394:
1.1       kristaps  395: static int
1.72      kristaps  396: man_ptext(struct man *m, int line, char *buf, int offs)
1.1       kristaps  397: {
1.61      kristaps  398:        int              i;
1.60      kristaps  399:
                    400:        /* Ignore bogus comments. */
                    401:
1.72      kristaps  402:        if ('\\' == buf[offs] &&
                    403:                        '.' == buf[offs + 1] &&
1.93      kristaps  404:                        '"' == buf[offs + 2]) {
                    405:                man_pmsg(m, line, offs, MANDOCERR_BADCOMMENT);
                    406:                return(1);
                    407:        }
1.31      kristaps  408:
1.35      kristaps  409:        /* Literal free-form text whitespace is preserved. */
                    410:
                    411:        if (MAN_LITERAL & m->flags) {
1.72      kristaps  412:                if ( ! man_word_alloc(m, line, offs, buf + offs))
1.35      kristaps  413:                        return(0);
1.94    ! kristaps  414:                return(man_descope(m, line, offs));
1.35      kristaps  415:        }
                    416:
1.61      kristaps  417:        /* Pump blank lines directly into the backend. */
1.31      kristaps  418:
1.72      kristaps  419:        for (i = offs; ' ' == buf[i]; i++)
1.31      kristaps  420:                /* Skip leading whitespace. */ ;
1.48      kristaps  421:
1.49      kristaps  422:        if ('\0' == buf[i]) {
1.61      kristaps  423:                /* Allocate a blank entry. */
1.72      kristaps  424:                if ( ! man_word_alloc(m, line, offs, ""))
1.31      kristaps  425:                        return(0);
1.94    ! kristaps  426:                return(man_descope(m, line, offs));
1.31      kristaps  427:        }
                    428:
1.63      kristaps  429:        /*
                    430:         * Warn if the last un-escaped character is whitespace. Then
                    431:         * strip away the remaining spaces (tabs stay!).
                    432:         */
1.29      kristaps  433:
1.61      kristaps  434:        i = (int)strlen(buf);
                    435:        assert(i);
1.49      kristaps  436:
1.63      kristaps  437:        if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
1.64      kristaps  438:                if (i > 1 && '\\' != buf[i - 2])
1.93      kristaps  439:                        man_pmsg(m, line, i - 1, MANDOCERR_EOLNSPACE);
1.63      kristaps  440:
                    441:                for (--i; i && ' ' == buf[i]; i--)
                    442:                        /* Spin back to non-space. */ ;
                    443:
                    444:                /* Jump ahead of escaped whitespace. */
                    445:                i += '\\' == buf[i] ? 2 : 1;
                    446:
                    447:                buf[i] = '\0';
                    448:        }
1.49      kristaps  449:
1.72      kristaps  450:        if ( ! man_word_alloc(m, line, offs, buf + offs))
1.1       kristaps  451:                return(0);
1.65      kristaps  452:
                    453:        /*
                    454:         * End-of-sentence check.  If the last character is an unescaped
                    455:         * EOS character, then flag the node as being the end of a
                    456:         * sentence.  The front-end will know how to interpret this.
                    457:         */
1.67      kristaps  458:
1.65      kristaps  459:        assert(i);
1.83      schwarze  460:        if (mandoc_eos(buf, (size_t)i, 0))
1.65      kristaps  461:                m->last->flags |= MAN_EOS;
1.31      kristaps  462:
1.94    ! kristaps  463:        return(man_descope(m, line, offs));
1.1       kristaps  464: }
                    465:
                    466:
                    467: int
1.79      kristaps  468: man_pmacro(struct man *m, int ln, char *buf, int offs)
1.1       kristaps  469: {
1.58      kristaps  470:        int              i, j, ppos;
1.53      kristaps  471:        enum mant        tok;
1.34      kristaps  472:        char             mac[5];
                    473:        struct man_node *n;
1.1       kristaps  474:
                    475:        /* Comments and empties are quickly ignored. */
                    476:
1.72      kristaps  477:        offs++;
                    478:
                    479:        if ('\0' == buf[offs])
1.46      kristaps  480:                return(1);
1.1       kristaps  481:
1.72      kristaps  482:        i = offs;
1.9       kristaps  483:
1.56      kristaps  484:        /*
                    485:         * Skip whitespace between the control character and initial
                    486:         * text.  "Whitespace" is both spaces and tabs.
                    487:         */
1.62      kristaps  488:
1.57      kristaps  489:        if (' ' == buf[i] || '\t' == buf[i]) {
1.9       kristaps  490:                i++;
1.56      kristaps  491:                while (buf[i] && (' ' == buf[i] || '\t' == buf[i]))
1.1       kristaps  492:                        i++;
1.48      kristaps  493:                if ('\0' == buf[i])
1.11      kristaps  494:                        goto out;
1.1       kristaps  495:        }
                    496:
1.10      kristaps  497:        ppos = i;
                    498:
1.86      schwarze  499:        /*
                    500:         * Copy the first word into a nil-terminated buffer.
                    501:         * Stop copying when a tab, space, or eoln is encountered.
                    502:         */
1.1       kristaps  503:
1.86      schwarze  504:        j = 0;
                    505:        while (j < 4 && '\0' != buf[i] && ' ' != buf[i] && '\t' != buf[i])
                    506:                mac[j++] = buf[i++];
1.46      kristaps  507:        mac[j] = '\0';
1.1       kristaps  508:
1.87      schwarze  509:        tok = (j > 0 && j < 4) ? man_hash_find(mac) : MAN_MAX;
                    510:        if (MAN_MAX == tok) {
1.90      kristaps  511:                man_vmsg(m, MANDOCERR_MACRO, ln, ppos, "%s", buf + ppos - 1);
1.12      kristaps  512:                return(1);
1.1       kristaps  513:        }
                    514:
                    515:        /* The macro is sane.  Jump to the next word. */
                    516:
                    517:        while (buf[i] && ' ' == buf[i])
                    518:                i++;
                    519:
1.62      kristaps  520:        /*
                    521:         * Trailing whitespace.  Note that tabs are allowed to be passed
                    522:         * into the parser as "text", so we only warn about spaces here.
                    523:         */
1.48      kristaps  524:
                    525:        if ('\0' == buf[i] && ' ' == buf[i - 1])
1.93      kristaps  526:                man_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE);
1.48      kristaps  527:
1.50      kristaps  528:        /*
1.90      kristaps  529:         * Remove prior ELINE macro, as it's being clobbered by a new
1.51      kristaps  530:         * macro.  Note that NSCOPED macros do not close out ELINE
                    531:         * macros---they don't print text---so we let those slip by.
1.50      kristaps  532:         */
1.34      kristaps  533:
1.53      kristaps  534:        if ( ! (MAN_NSCOPED & man_macros[tok].flags) &&
1.51      kristaps  535:                        m->flags & MAN_ELINE) {
1.90      kristaps  536:                n = m->last;
                    537:                assert(MAN_TEXT != n->type);
1.51      kristaps  538:
1.90      kristaps  539:                /* Remove repeated NSCOPED macros causing ELINE. */
1.51      kristaps  540:
1.90      kristaps  541:                if (MAN_NSCOPED & man_macros[n->tok].flags)
                    542:                        n = n->parent;
1.51      kristaps  543:
1.90      kristaps  544:                man_vmsg(m, MANDOCERR_LINESCOPE, n->line, n->pos,
                    545:                                "%s", man_macronames[n->tok]);
1.34      kristaps  546:
1.54      kristaps  547:                man_node_delete(m, n);
1.34      kristaps  548:                m->flags &= ~MAN_ELINE;
                    549:        }
                    550:
1.59      kristaps  551:        /*
                    552:         * Save the fact that we're in the next-line for a block.  In
                    553:         * this way, embedded roff instructions can "remember" state
                    554:         * when they exit.
                    555:         */
                    556:
                    557:        if (MAN_BLINE & m->flags)
                    558:                m->flags |= MAN_BPLINE;
                    559:
                    560:        /* Call to handler... */
1.1       kristaps  561:
1.53      kristaps  562:        assert(man_macros[tok].fp);
1.79      kristaps  563:        if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &i, buf))
1.1       kristaps  564:                goto err;
                    565:
1.11      kristaps  566: out:
1.50      kristaps  567:        /*
                    568:         * We weren't in a block-line scope when entering the
                    569:         * above-parsed macro, so return.
                    570:         */
                    571:
1.58      kristaps  572:        if ( ! (MAN_BPLINE & m->flags)) {
1.50      kristaps  573:                m->flags &= ~MAN_ILINE;
1.29      kristaps  574:                return(1);
1.50      kristaps  575:        }
1.58      kristaps  576:        m->flags &= ~MAN_BPLINE;
1.50      kristaps  577:
                    578:        /*
                    579:         * If we're in a block scope, then allow this macro to slip by
                    580:         * without closing scope around it.
                    581:         */
                    582:
                    583:        if (MAN_ILINE & m->flags) {
                    584:                m->flags &= ~MAN_ILINE;
                    585:                return(1);
                    586:        }
1.29      kristaps  587:
                    588:        /*
                    589:         * If we've opened a new next-line element scope, then return
                    590:         * now, as the next line will close out the block scope.
                    591:         */
                    592:
                    593:        if (MAN_ELINE & m->flags)
                    594:                return(1);
                    595:
                    596:        /* Close out the block scope opened in the prior line.  */
1.11      kristaps  597:
1.29      kristaps  598:        assert(MAN_BLINE & m->flags);
                    599:        m->flags &= ~MAN_BLINE;
1.11      kristaps  600:
1.74      kristaps  601:        if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
1.29      kristaps  602:                return(0);
1.72      kristaps  603:        return(man_body_alloc(m, ln, offs, m->last->tok));
1.1       kristaps  604:
                    605: err:   /* Error out. */
                    606:
1.2       kristaps  607:        m->flags |= MAN_HALT;
1.1       kristaps  608:        return(0);
                    609: }
1.3       kristaps  610:
1.4       kristaps  611:
                    612: int
1.74      kristaps  613: man_vmsg(struct man *man, enum mandocerr t,
                    614:                int ln, int pos, const char *fmt, ...)
1.4       kristaps  615: {
                    616:        char             buf[256];
                    617:        va_list          ap;
                    618:
                    619:        va_start(ap, fmt);
1.74      kristaps  620:        vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
1.4       kristaps  621:        va_end(ap);
1.74      kristaps  622:        return((*man->msg)(t, man->data, ln, pos, buf));
1.51      kristaps  623: }
                    624:
                    625:
1.54      kristaps  626: /*
                    627:  * Unlink a node from its context.  If "m" is provided, the last parse
                    628:  * point will also be adjusted accordingly.
                    629:  */
                    630: static void
1.51      kristaps  631: man_node_unlink(struct man *m, struct man_node *n)
                    632: {
                    633:
1.54      kristaps  634:        /* Adjust siblings. */
                    635:
                    636:        if (n->prev)
1.51      kristaps  637:                n->prev->next = n->next;
1.54      kristaps  638:        if (n->next)
                    639:                n->next->prev = n->prev;
                    640:
                    641:        /* Adjust parent. */
                    642:
                    643:        if (n->parent) {
                    644:                n->parent->nchild--;
                    645:                if (n->parent->child == n)
                    646:                        n->parent->child = n->prev ? n->prev : n->next;
                    647:        }
                    648:
                    649:        /* Adjust parse point, if applicable. */
                    650:
                    651:        if (m && m->last == n) {
                    652:                /*XXX: this can occur when bailing from validation. */
                    653:                /*assert(NULL == n->next);*/
                    654:                if (n->prev) {
1.51      kristaps  655:                        m->last = n->prev;
                    656:                        m->next = MAN_NEXT_SIBLING;
1.54      kristaps  657:                } else {
1.51      kristaps  658:                        m->last = n->parent;
                    659:                        m->next = MAN_NEXT_CHILD;
                    660:                }
                    661:        }
                    662:
1.54      kristaps  663:        if (m && m->first == n)
                    664:                m->first = NULL;
1.23      kristaps  665: }

CVSweb