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

Annotation of mandoc/man.c, Revision 1.108

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

CVSweb