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

Annotation of mandoc/man.c, Revision 1.85

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

CVSweb