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

Annotation of mandoc/man_validate.c, Revision 1.102

1.102   ! schwarze    1: /*     $Id: man_validate.c,v 1.101 2014/07/30 23:01:39 schwarze Exp $ */
1.1       kristaps    2: /*
1.63      schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.88      schwarze    4:  * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
1.8       kristaps    7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
1.1       kristaps    9:  *
1.8       kristaps   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       kristaps   17:  */
1.28      kristaps   18: #ifdef HAVE_CONFIG_H
                     19: #include "config.h"
                     20: #endif
                     21:
1.1       kristaps   22: #include <sys/types.h>
                     23:
                     24: #include <assert.h>
                     25: #include <ctype.h>
1.16      kristaps   26: #include <errno.h>
                     27: #include <limits.h>
1.1       kristaps   28: #include <stdarg.h>
                     29: #include <stdlib.h>
1.46      kristaps   30: #include <string.h>
1.50      kristaps   31: #include <time.h>
1.1       kristaps   32:
1.66      kristaps   33: #include "man.h"
1.41      kristaps   34: #include "mandoc.h"
1.89      schwarze   35: #include "mandoc_aux.h"
1.1       kristaps   36: #include "libman.h"
1.15      kristaps   37: #include "libmandoc.h"
1.1       kristaps   38:
1.85      schwarze   39: #define        CHKARGS   struct man *man, struct man_node *n
1.1       kristaps   40:
1.17      kristaps   41: typedef        int     (*v_check)(CHKARGS);
1.1       kristaps   42:
                     43: struct man_valid {
1.17      kristaps   44:        v_check  *pres;
                     45:        v_check  *posts;
1.1       kristaps   46: };
                     47:
1.17      kristaps   48: static int       check_eq0(CHKARGS);
1.80      kristaps   49: static int       check_eq2(CHKARGS);
1.25      kristaps   50: static int       check_le1(CHKARGS);
1.17      kristaps   51: static int       check_ge2(CHKARGS);
                     52: static int       check_le5(CHKARGS);
1.86      schwarze   53: static int       check_head1(CHKARGS);
1.17      kristaps   54: static int       check_par(CHKARGS);
1.23      kristaps   55: static int       check_part(CHKARGS);
1.17      kristaps   56: static int       check_root(CHKARGS);
1.75      kristaps   57: static void      check_text(CHKARGS);
1.17      kristaps   58:
1.51      kristaps   59: static int       post_AT(CHKARGS);
1.83      schwarze   60: static int       post_IP(CHKARGS);
1.70      kristaps   61: static int       post_vs(CHKARGS);
1.51      kristaps   62: static int       post_fi(CHKARGS);
1.73      kristaps   63: static int       post_ft(CHKARGS);
1.51      kristaps   64: static int       post_nf(CHKARGS);
                     65: static int       post_TH(CHKARGS);
                     66: static int       post_UC(CHKARGS);
1.73      kristaps   67: static int       pre_sec(CHKARGS);
1.51      kristaps   68:
                     69: static v_check   posts_at[] = { post_AT, NULL };
1.70      kristaps   70: static v_check   posts_br[] = { post_vs, check_eq0, NULL };
1.17      kristaps   71: static v_check   posts_eq0[] = { check_eq0, NULL };
1.80      kristaps   72: static v_check   posts_eq2[] = { check_eq2, NULL };
1.51      kristaps   73: static v_check   posts_fi[] = { check_eq0, post_fi, NULL };
1.73      kristaps   74: static v_check   posts_ft[] = { post_ft, NULL };
1.83      schwarze   75: static v_check   posts_ip[] = { post_IP, NULL };
1.84      schwarze   76: static v_check   posts_le1[] = { check_le1, NULL };
1.51      kristaps   77: static v_check   posts_nf[] = { check_eq0, post_nf, NULL };
1.17      kristaps   78: static v_check   posts_par[] = { check_par, NULL };
1.23      kristaps   79: static v_check   posts_part[] = { check_part, NULL };
1.70      kristaps   80: static v_check   posts_sp[] = { post_vs, check_le1, NULL };
1.60      schwarze   81: static v_check   posts_th[] = { check_ge2, check_le5, post_TH, NULL };
1.51      kristaps   82: static v_check   posts_uc[] = { post_UC, NULL };
1.86      schwarze   83: static v_check   posts_ur[] = { check_head1, check_part, NULL };
1.78      schwarze   84: static v_check   pres_sec[] = { pre_sec, NULL };
1.1       kristaps   85:
                     86: static const struct man_valid man_valids[MAN_MAX] = {
1.70      kristaps   87:        { NULL, posts_br }, /* br */
1.78      schwarze   88:        { NULL, posts_th }, /* TH */
1.101     schwarze   89:        { pres_sec, NULL }, /* SH */
                     90:        { pres_sec, NULL }, /* SS */
1.78      schwarze   91:        { NULL, NULL }, /* TP */
                     92:        { NULL, posts_par }, /* LP */
                     93:        { NULL, posts_par }, /* PP */
                     94:        { NULL, posts_par }, /* P */
1.83      schwarze   95:        { NULL, posts_ip }, /* IP */
1.78      schwarze   96:        { NULL, NULL }, /* HP */
1.22      kristaps   97:        { NULL, NULL }, /* SM */
                     98:        { NULL, NULL }, /* SB */
1.17      kristaps   99:        { NULL, NULL }, /* BI */
                    100:        { NULL, NULL }, /* IB */
                    101:        { NULL, NULL }, /* BR */
                    102:        { NULL, NULL }, /* RB */
1.22      kristaps  103:        { NULL, NULL }, /* R */
                    104:        { NULL, NULL }, /* B */
                    105:        { NULL, NULL }, /* I */
1.17      kristaps  106:        { NULL, NULL }, /* IR */
                    107:        { NULL, NULL }, /* RI */
1.80      kristaps  108:        { NULL, posts_eq0 }, /* na */
                    109:        { NULL, posts_sp }, /* sp */
1.78      schwarze  110:        { NULL, posts_nf }, /* nf */
                    111:        { NULL, posts_fi }, /* fi */
1.19      kristaps  112:        { NULL, NULL }, /* RE */
1.23      kristaps  113:        { NULL, posts_part }, /* RS */
1.21      kristaps  114:        { NULL, NULL }, /* DT */
1.51      kristaps  115:        { NULL, posts_uc }, /* UC */
1.84      schwarze  116:        { NULL, posts_le1 }, /* PD */
1.51      kristaps  117:        { NULL, posts_at }, /* AT */
1.47      kristaps  118:        { NULL, NULL }, /* in */
1.55      kristaps  119:        { NULL, posts_ft }, /* ft */
1.80      kristaps  120:        { NULL, posts_eq2 }, /* OP */
1.81      schwarze  121:        { NULL, posts_nf }, /* EX */
                    122:        { NULL, posts_fi }, /* EE */
1.86      schwarze  123:        { NULL, posts_ur }, /* UR */
                    124:        { NULL, NULL }, /* UE */
1.90      schwarze  125:        { NULL, NULL }, /* ll */
1.1       kristaps  126: };
                    127:
                    128:
                    129: int
1.85      schwarze  130: man_valid_pre(struct man *man, struct man_node *n)
1.17      kristaps  131: {
                    132:        v_check         *cp;
                    133:
1.57      kristaps  134:        switch (n->type) {
1.91      schwarze  135:        case MAN_TEXT:
1.57      kristaps  136:                /* FALLTHROUGH */
1.91      schwarze  137:        case MAN_ROOT:
1.61      kristaps  138:                /* FALLTHROUGH */
1.91      schwarze  139:        case MAN_EQN:
1.57      kristaps  140:                /* FALLTHROUGH */
1.91      schwarze  141:        case MAN_TBL:
1.17      kristaps  142:                return(1);
1.57      kristaps  143:        default:
                    144:                break;
                    145:        }
1.17      kristaps  146:
                    147:        if (NULL == (cp = man_valids[n->tok].pres))
                    148:                return(1);
                    149:        for ( ; *cp; cp++)
1.91      schwarze  150:                if ( ! (*cp)(man, n))
1.17      kristaps  151:                        return(0);
                    152:        return(1);
                    153: }
                    154:
                    155: int
1.85      schwarze  156: man_valid_post(struct man *man)
1.1       kristaps  157: {
1.17      kristaps  158:        v_check         *cp;
1.1       kristaps  159:
1.85      schwarze  160:        if (MAN_VALID & man->last->flags)
1.1       kristaps  161:                return(1);
1.85      schwarze  162:        man->last->flags |= MAN_VALID;
1.1       kristaps  163:
1.85      schwarze  164:        switch (man->last->type) {
1.91      schwarze  165:        case MAN_TEXT:
1.85      schwarze  166:                check_text(man, man->last);
1.75      kristaps  167:                return(1);
1.91      schwarze  168:        case MAN_ROOT:
1.85      schwarze  169:                return(check_root(man, man->last));
1.91      schwarze  170:        case MAN_EQN:
1.62      kristaps  171:                /* FALLTHROUGH */
1.91      schwarze  172:        case MAN_TBL:
1.57      kristaps  173:                return(1);
1.1       kristaps  174:        default:
                    175:                break;
                    176:        }
                    177:
1.85      schwarze  178:        if (NULL == (cp = man_valids[man->last->tok].posts))
1.1       kristaps  179:                return(1);
                    180:        for ( ; *cp; cp++)
1.85      schwarze  181:                if ( ! (*cp)(man, man->last))
1.1       kristaps  182:                        return(0);
                    183:
                    184:        return(1);
                    185: }
                    186:
1.11      kristaps  187: static int
1.91      schwarze  188: check_root(CHKARGS)
1.14      kristaps  189: {
1.17      kristaps  190:
1.101     schwarze  191:        assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
1.17      kristaps  192:
1.93      schwarze  193:        if (NULL == man->first->child)
                    194:                man_nmsg(man, n, MANDOCERR_DOC_EMPTY);
                    195:        else
                    196:                man->meta.hasbody = 1;
                    197:
                    198:        if (NULL == man->meta.title) {
1.92      schwarze  199:                man_nmsg(man, n, MANDOCERR_TH_MISSING);
1.54      kristaps  200:
1.34      kristaps  201:                /*
                    202:                 * If a title hasn't been set, do so now (by
                    203:                 * implication, date and section also aren't set).
                    204:                 */
1.54      kristaps  205:
1.91      schwarze  206:                man->meta.title = mandoc_strdup("unknown");
1.85      schwarze  207:                man->meta.msec = mandoc_strdup("1");
1.88      schwarze  208:                man->meta.date = man->quick ? mandoc_strdup("") :
                    209:                    mandoc_normdate(man->parse, NULL, n->line, n->pos);
1.34      kristaps  210:        }
1.32      kristaps  211:
                    212:        return(1);
1.75      kristaps  213: }
                    214:
                    215: static void
                    216: check_text(CHKARGS)
                    217: {
                    218:        char            *cp, *p;
                    219:
1.85      schwarze  220:        if (MAN_LITERAL & man->flags)
1.76      schwarze  221:                return;
                    222:
                    223:        cp = n->string;
                    224:        for (p = cp; NULL != (p = strchr(p, '\t')); p++)
1.99      schwarze  225:                mandoc_msg(MANDOCERR_FI_TAB, man->parse,
                    226:                    n->line, n->pos + (p - cp), NULL);
1.1       kristaps  227: }
                    228:
                    229: #define        INEQ_DEFINE(x, ineq, name) \
                    230: static int \
1.17      kristaps  231: check_##name(CHKARGS) \
1.1       kristaps  232: { \
1.11      kristaps  233:        if (n->nchild ineq (x)) \
1.1       kristaps  234:                return(1); \
1.85      schwarze  235:        mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \
1.91      schwarze  236:            "line arguments %s %d (have %d)", \
                    237:            #ineq, (x), n->nchild); \
1.60      schwarze  238:        return(1); \
1.1       kristaps  239: }
                    240:
                    241: INEQ_DEFINE(0, ==, eq0)
1.80      kristaps  242: INEQ_DEFINE(2, ==, eq2)
1.25      kristaps  243: INEQ_DEFINE(1, <=, le1)
1.1       kristaps  244: INEQ_DEFINE(2, >=, ge2)
                    245: INEQ_DEFINE(5, <=, le5)
1.86      schwarze  246:
                    247: static int
                    248: check_head1(CHKARGS)
                    249: {
                    250:
                    251:        if (MAN_HEAD == n->type && 1 != n->nchild)
                    252:                mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
                    253:                    n->pos, "line arguments eq 1 (have %d)", n->nchild);
                    254:
                    255:        return(1);
                    256: }
1.1       kristaps  257:
1.55      kristaps  258: static int
1.73      kristaps  259: post_ft(CHKARGS)
1.55      kristaps  260: {
                    261:        char    *cp;
                    262:        int      ok;
                    263:
                    264:        if (0 == n->nchild)
                    265:                return(1);
                    266:
                    267:        ok = 0;
                    268:        cp = n->child->string;
                    269:        switch (*cp) {
1.91      schwarze  270:        case '1':
1.55      kristaps  271:                /* FALLTHROUGH */
1.91      schwarze  272:        case '2':
1.55      kristaps  273:                /* FALLTHROUGH */
1.91      schwarze  274:        case '3':
1.55      kristaps  275:                /* FALLTHROUGH */
1.91      schwarze  276:        case '4':
1.55      kristaps  277:                /* FALLTHROUGH */
1.91      schwarze  278:        case 'I':
1.55      kristaps  279:                /* FALLTHROUGH */
1.91      schwarze  280:        case 'P':
1.55      kristaps  281:                /* FALLTHROUGH */
1.91      schwarze  282:        case 'R':
1.55      kristaps  283:                if ('\0' == cp[1])
                    284:                        ok = 1;
                    285:                break;
1.91      schwarze  286:        case 'B':
1.55      kristaps  287:                if ('\0' == cp[1] || ('I' == cp[1] && '\0' == cp[2]))
                    288:                        ok = 1;
                    289:                break;
1.91      schwarze  290:        case 'C':
1.55      kristaps  291:                if ('W' == cp[1] && '\0' == cp[2])
                    292:                        ok = 1;
                    293:                break;
                    294:        default:
                    295:                break;
                    296:        }
                    297:
                    298:        if (0 == ok) {
1.98      schwarze  299:                mandoc_vmsg(MANDOCERR_FT_BAD, man->parse,
                    300:                    n->line, n->pos, "ft %s", cp);
1.55      kristaps  301:                *cp = '\0';
                    302:        }
                    303:
                    304:        if (1 < n->nchild)
1.91      schwarze  305:                mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
                    306:                    n->pos, "want one child (have %d)", n->nchild);
1.55      kristaps  307:
                    308:        return(1);
                    309: }
1.16      kristaps  310:
                    311: static int
1.73      kristaps  312: pre_sec(CHKARGS)
                    313: {
                    314:
                    315:        if (MAN_BLOCK == n->type)
1.85      schwarze  316:                man->flags &= ~MAN_LITERAL;
1.73      kristaps  317:        return(1);
1.16      kristaps  318: }
1.17      kristaps  319:
                    320: static int
1.23      kristaps  321: check_part(CHKARGS)
                    322: {
                    323:
                    324:        if (MAN_BODY == n->type && 0 == n->nchild)
1.91      schwarze  325:                mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line,
                    326:                    n->pos, "want children (have none)");
1.54      kristaps  327:
1.23      kristaps  328:        return(1);
                    329: }
                    330:
                    331: static int
1.17      kristaps  332: check_par(CHKARGS)
                    333: {
                    334:
1.59      kristaps  335:        switch (n->type) {
1.91      schwarze  336:        case MAN_BLOCK:
1.59      kristaps  337:                if (0 == n->body->nchild)
1.85      schwarze  338:                        man_node_delete(man, n);
1.59      kristaps  339:                break;
1.91      schwarze  340:        case MAN_BODY:
1.59      kristaps  341:                if (0 == n->nchild)
1.95      schwarze  342:                        mandoc_vmsg(MANDOCERR_PAR_SKIP,
                    343:                            man->parse, n->line, n->pos,
                    344:                            "%s empty", man_macronames[n->tok]);
1.59      kristaps  345:                break;
1.91      schwarze  346:        case MAN_HEAD:
1.59      kristaps  347:                if (n->nchild)
1.97      schwarze  348:                        mandoc_vmsg(MANDOCERR_ARG_SKIP,
                    349:                            man->parse, n->line, n->pos,
                    350:                            "%s %s%s", man_macronames[n->tok],
                    351:                            n->child->string,
                    352:                            n->nchild > 1 ? " ..." : "");
1.59      kristaps  353:                break;
                    354:        default:
                    355:                break;
                    356:        }
1.17      kristaps  357:
                    358:        return(1);
                    359: }
                    360:
1.83      schwarze  361: static int
                    362: post_IP(CHKARGS)
                    363: {
                    364:
                    365:        switch (n->type) {
1.91      schwarze  366:        case MAN_BLOCK:
1.83      schwarze  367:                if (0 == n->head->nchild && 0 == n->body->nchild)
1.85      schwarze  368:                        man_node_delete(man, n);
1.83      schwarze  369:                break;
1.91      schwarze  370:        case MAN_BODY:
1.83      schwarze  371:                if (0 == n->parent->head->nchild && 0 == n->nchild)
1.95      schwarze  372:                        mandoc_vmsg(MANDOCERR_PAR_SKIP,
                    373:                            man->parse, n->line, n->pos,
                    374:                            "%s empty", man_macronames[n->tok]);
1.83      schwarze  375:                break;
                    376:        default:
                    377:                break;
                    378:        }
                    379:        return(1);
                    380: }
1.17      kristaps  381:
1.51      kristaps  382: static int
                    383: post_TH(CHKARGS)
                    384: {
1.92      schwarze  385:        struct man_node *nb;
1.60      schwarze  386:        const char      *p;
1.51      kristaps  387:
1.85      schwarze  388:        free(man->meta.title);
                    389:        free(man->meta.vol);
                    390:        free(man->meta.source);
                    391:        free(man->meta.msec);
                    392:        free(man->meta.date);
1.51      kristaps  393:
1.85      schwarze  394:        man->meta.title = man->meta.vol = man->meta.date =
1.91      schwarze  395:            man->meta.msec = man->meta.source = NULL;
1.51      kristaps  396:
1.92      schwarze  397:        nb = n;
                    398:
1.51      kristaps  399:        /* ->TITLE<- MSEC DATE SOURCE VOL */
                    400:
                    401:        n = n->child;
1.60      schwarze  402:        if (n && n->string) {
                    403:                for (p = n->string; '\0' != *p; p++) {
                    404:                        /* Only warn about this once... */
1.91      schwarze  405:                        if (isalpha((unsigned char)*p) &&
                    406:                            ! isupper((unsigned char)*p)) {
1.102   ! schwarze  407:                                mandoc_vmsg(MANDOCERR_TITLE_CASE,
1.94      schwarze  408:                                    man->parse, n->line,
                    409:                                    n->pos + (p - n->string),
1.102   ! schwarze  410:                                    "TH %s", n->string);
1.60      schwarze  411:                                break;
                    412:                        }
                    413:                }
1.85      schwarze  414:                man->meta.title = mandoc_strdup(n->string);
1.60      schwarze  415:        } else
1.85      schwarze  416:                man->meta.title = mandoc_strdup("");
1.51      kristaps  417:
                    418:        /* TITLE ->MSEC<- DATE SOURCE VOL */
                    419:
1.60      schwarze  420:        if (n)
                    421:                n = n->next;
                    422:        if (n && n->string)
1.85      schwarze  423:                man->meta.msec = mandoc_strdup(n->string);
1.60      schwarze  424:        else
1.85      schwarze  425:                man->meta.msec = mandoc_strdup("");
1.51      kristaps  426:
                    427:        /* TITLE MSEC ->DATE<- SOURCE VOL */
                    428:
1.60      schwarze  429:        if (n)
                    430:                n = n->next;
1.77      schwarze  431:        if (n && n->string && '\0' != n->string[0]) {
1.88      schwarze  432:                man->meta.date = man->quick ?
                    433:                    mandoc_strdup(n->string) :
                    434:                    mandoc_normdate(man->parse, n->string,
                    435:                        n->line, n->pos);
1.92      schwarze  436:        } else {
1.85      schwarze  437:                man->meta.date = mandoc_strdup("");
1.102   ! schwarze  438:                mandoc_msg(MANDOCERR_DATE_MISSING, man->parse,
        !           439:                    n ? n->line : nb->line,
        !           440:                    n ? n->pos : nb->pos, "TH");
1.92      schwarze  441:        }
1.51      kristaps  442:
                    443:        /* TITLE MSEC DATE ->SOURCE<- VOL */
                    444:
                    445:        if (n && (n = n->next))
1.85      schwarze  446:                man->meta.source = mandoc_strdup(n->string);
1.51      kristaps  447:
                    448:        /* TITLE MSEC DATE SOURCE ->VOL<- */
1.79      schwarze  449:        /* If missing, use the default VOL name for MSEC. */
1.51      kristaps  450:
                    451:        if (n && (n = n->next))
1.85      schwarze  452:                man->meta.vol = mandoc_strdup(n->string);
                    453:        else if ('\0' != man->meta.msec[0] &&
                    454:            (NULL != (p = mandoc_a2msec(man->meta.msec))))
                    455:                man->meta.vol = mandoc_strdup(p);
1.51      kristaps  456:
                    457:        /*
                    458:         * Remove the `TH' node after we've processed it for our
                    459:         * meta-data.
                    460:         */
1.85      schwarze  461:        man_node_delete(man, man->last);
1.51      kristaps  462:        return(1);
                    463: }
                    464:
                    465: static int
                    466: post_nf(CHKARGS)
                    467: {
                    468:
1.85      schwarze  469:        if (MAN_LITERAL & man->flags)
1.102   ! schwarze  470:                mandoc_msg(MANDOCERR_NF_SKIP, man->parse,
        !           471:                    n->line, n->pos, "nf");
1.51      kristaps  472:
1.85      schwarze  473:        man->flags |= MAN_LITERAL;
1.51      kristaps  474:        return(1);
                    475: }
                    476:
                    477: static int
                    478: post_fi(CHKARGS)
                    479: {
                    480:
1.85      schwarze  481:        if ( ! (MAN_LITERAL & man->flags))
1.102   ! schwarze  482:                mandoc_msg(MANDOCERR_FI_SKIP, man->parse,
        !           483:                    n->line, n->pos, "fi");
1.51      kristaps  484:
1.85      schwarze  485:        man->flags &= ~MAN_LITERAL;
1.51      kristaps  486:        return(1);
                    487: }
                    488:
                    489: static int
                    490: post_UC(CHKARGS)
                    491: {
                    492:        static const char * const bsd_versions[] = {
                    493:            "3rd Berkeley Distribution",
                    494:            "4th Berkeley Distribution",
                    495:            "4.2 Berkeley Distribution",
                    496:            "4.3 Berkeley Distribution",
                    497:            "4.4 Berkeley Distribution",
                    498:        };
                    499:
                    500:        const char      *p, *s;
                    501:
                    502:        n = n->child;
                    503:
                    504:        if (NULL == n || MAN_TEXT != n->type)
                    505:                p = bsd_versions[0];
                    506:        else {
                    507:                s = n->string;
                    508:                if (0 == strcmp(s, "3"))
                    509:                        p = bsd_versions[0];
                    510:                else if (0 == strcmp(s, "4"))
                    511:                        p = bsd_versions[1];
                    512:                else if (0 == strcmp(s, "5"))
                    513:                        p = bsd_versions[2];
                    514:                else if (0 == strcmp(s, "6"))
                    515:                        p = bsd_versions[3];
                    516:                else if (0 == strcmp(s, "7"))
                    517:                        p = bsd_versions[4];
                    518:                else
                    519:                        p = bsd_versions[0];
                    520:        }
                    521:
1.85      schwarze  522:        free(man->meta.source);
                    523:        man->meta.source = mandoc_strdup(p);
1.51      kristaps  524:        return(1);
                    525: }
                    526:
                    527: static int
                    528: post_AT(CHKARGS)
                    529: {
                    530:        static const char * const unix_versions[] = {
                    531:            "7th Edition",
                    532:            "System III",
                    533:            "System V",
                    534:            "System V Release 2",
                    535:        };
                    536:
                    537:        const char      *p, *s;
                    538:        struct man_node *nn;
                    539:
                    540:        n = n->child;
                    541:
                    542:        if (NULL == n || MAN_TEXT != n->type)
                    543:                p = unix_versions[0];
                    544:        else {
                    545:                s = n->string;
                    546:                if (0 == strcmp(s, "3"))
                    547:                        p = unix_versions[0];
                    548:                else if (0 == strcmp(s, "4"))
                    549:                        p = unix_versions[1];
                    550:                else if (0 == strcmp(s, "5")) {
                    551:                        nn = n->next;
                    552:                        if (nn && MAN_TEXT == nn->type && nn->string[0])
                    553:                                p = unix_versions[3];
                    554:                        else
                    555:                                p = unix_versions[2];
                    556:                } else
                    557:                        p = unix_versions[0];
                    558:        }
                    559:
1.85      schwarze  560:        free(man->meta.source);
                    561:        man->meta.source = mandoc_strdup(p);
1.70      kristaps  562:        return(1);
                    563: }
                    564:
                    565: static int
                    566: post_vs(CHKARGS)
                    567: {
                    568:
1.82      schwarze  569:        if (NULL != n->prev)
                    570:                return(1);
                    571:
                    572:        switch (n->parent->tok) {
1.91      schwarze  573:        case MAN_SH:
1.82      schwarze  574:                /* FALLTHROUGH */
1.91      schwarze  575:        case MAN_SS:
1.95      schwarze  576:                mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, n->line, n->pos,
                    577:                    "%s after %s", man_macronames[n->tok],
                    578:                    man_macronames[n->parent->tok]);
1.82      schwarze  579:                /* FALLTHROUGH */
1.91      schwarze  580:        case MAN_MAX:
                    581:                /*
1.82      schwarze  582:                 * Don't warn about this because it occurs in pod2man
                    583:                 * and would cause considerable (unfixable) warnage.
                    584:                 */
1.85      schwarze  585:                man_node_delete(man, n);
1.82      schwarze  586:                break;
                    587:        default:
                    588:                break;
                    589:        }
1.70      kristaps  590:
1.51      kristaps  591:        return(1);
                    592: }

CVSweb