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

Annotation of mandoc/mdoc_validate.c, Revision 1.218

1.218   ! schwarze    1: /*     $Id: mdoc_validate.c,v 1.217 2014/07/01 22:37:15 schwarze Exp $ */
1.1       kristaps    2: /*
1.183     schwarze    3:  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.200     schwarze    4:  * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
1.199     schwarze    5:  * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
1.1       kristaps    6:  *
                      7:  * Permission to use, copy, modify, and distribute this software for any
1.5       kristaps    8:  * purpose with or without fee is hereby granted, provided that the above
                      9:  * copyright notice and this permission notice appear in all copies.
1.1       kristaps   10:  *
1.5       kristaps   11:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     12:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     13:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     14:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     15:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     16:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     17:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       kristaps   18:  */
1.56      kristaps   19: #ifdef HAVE_CONFIG_H
                     20: #include "config.h"
                     21: #endif
                     22:
1.196     schwarze   23: #ifndef OSNAME
1.132     kristaps   24: #include <sys/utsname.h>
                     25: #endif
                     26:
1.1       kristaps   27: #include <sys/types.h>
                     28:
                     29: #include <assert.h>
                     30: #include <ctype.h>
1.35      kristaps   31: #include <limits.h>
1.81      kristaps   32: #include <stdio.h>
1.1       kristaps   33: #include <stdlib.h>
1.2       kristaps   34: #include <string.h>
1.132     kristaps   35: #include <time.h>
1.1       kristaps   36:
1.165     kristaps   37: #include "mdoc.h"
1.79      kristaps   38: #include "mandoc.h"
1.203     schwarze   39: #include "mandoc_aux.h"
1.1       kristaps   40: #include "libmdoc.h"
1.18      kristaps   41: #include "libmandoc.h"
1.1       kristaps   42:
                     43: /* FIXME: .Bl -diag can't have non-text children in HEAD. */
                     44:
1.91      kristaps   45: #define        PRE_ARGS  struct mdoc *mdoc, struct mdoc_node *n
1.32      kristaps   46: #define        POST_ARGS struct mdoc *mdoc
1.1       kristaps   47:
1.120     kristaps   48: enum   check_ineq {
                     49:        CHECK_LT,
                     50:        CHECK_GT,
                     51:        CHECK_EQ
                     52: };
                     53:
                     54: enum   check_lvl {
                     55:        CHECK_WARN,
                     56:        CHECK_ERROR,
                     57: };
                     58:
1.1       kristaps   59: typedef        int     (*v_pre)(PRE_ARGS);
                     60: typedef        int     (*v_post)(POST_ARGS);
                     61:
                     62: struct valids {
                     63:        v_pre   *pre;
                     64:        v_post  *post;
                     65: };
                     66:
1.210     schwarze   67: static int      check_count(struct mdoc *, enum mdoc_type,
1.120     kristaps   68:                        enum check_lvl, enum check_ineq, int);
1.59      kristaps   69: static int      check_parent(PRE_ARGS, enum mdoct, enum mdoc_type);
1.133     kristaps   70: static void     check_text(struct mdoc *, int, int, char *);
1.210     schwarze   71: static void     check_argv(struct mdoc *,
1.92      kristaps   72:                        struct mdoc_node *, struct mdoc_argv *);
1.133     kristaps   73: static void     check_args(struct mdoc *, struct mdoc_node *);
1.161     kristaps   74: static enum mdoc_sec   a2sec(const char *);
                     75: static size_t          macro2len(enum mdoct);
1.132     kristaps   76:
1.120     kristaps   77: static int      ebool(POST_ARGS);
1.32      kristaps   78: static int      berr_ge1(POST_ARGS);
                     79: static int      bwarn_ge1(POST_ARGS);
1.116     kristaps   80: static int      ewarn_eq0(POST_ARGS);
1.151     schwarze   81: static int      ewarn_eq1(POST_ARGS);
1.32      kristaps   82: static int      ewarn_ge1(POST_ARGS);
1.151     schwarze   83: static int      ewarn_le1(POST_ARGS);
1.120     kristaps   84: static int      hwarn_eq0(POST_ARGS);
1.32      kristaps   85: static int      hwarn_eq1(POST_ARGS);
1.151     schwarze   86: static int      hwarn_ge1(POST_ARGS);
1.32      kristaps   87: static int      hwarn_le1(POST_ARGS);
                     88:
                     89: static int      post_an(POST_ARGS);
                     90: static int      post_at(POST_ARGS);
                     91: static int      post_bf(POST_ARGS);
                     92: static int      post_bl(POST_ARGS);
1.131     kristaps   93: static int      post_bl_block(POST_ARGS);
                     94: static int      post_bl_block_width(POST_ARGS);
                     95: static int      post_bl_block_tag(POST_ARGS);
1.32      kristaps   96: static int      post_bl_head(POST_ARGS);
1.154     kristaps   97: static int      post_bx(POST_ARGS);
1.196     schwarze   98: static int      post_defaults(POST_ARGS);
1.132     kristaps   99: static int      post_dd(POST_ARGS);
                    100: static int      post_dt(POST_ARGS);
1.218   ! schwarze  101: static int      post_en(POST_ARGS);
        !           102: static int      post_es(POST_ARGS);
1.123     kristaps  103: static int      post_eoln(POST_ARGS);
1.196     schwarze  104: static int      post_hyph(POST_ARGS);
                    105: static int      post_ignpar(POST_ARGS);
1.32      kristaps  106: static int      post_it(POST_ARGS);
                    107: static int      post_lb(POST_ARGS);
1.196     schwarze  108: static int      post_literal(POST_ARGS);
1.32      kristaps  109: static int      post_nm(POST_ARGS);
1.155     kristaps  110: static int      post_ns(POST_ARGS);
1.132     kristaps  111: static int      post_os(POST_ARGS);
1.188     schwarze  112: static int      post_par(POST_ARGS);
1.132     kristaps  113: static int      post_prol(POST_ARGS);
1.32      kristaps  114: static int      post_root(POST_ARGS);
1.43      kristaps  115: static int      post_rs(POST_ARGS);
1.32      kristaps  116: static int      post_sh(POST_ARGS);
                    117: static int      post_sh_body(POST_ARGS);
                    118: static int      post_sh_head(POST_ARGS);
                    119: static int      post_st(POST_ARGS);
1.132     kristaps  120: static int      post_std(POST_ARGS);
1.57      kristaps  121: static int      post_vt(POST_ARGS);
1.32      kristaps  122: static int      pre_an(PRE_ARGS);
                    123: static int      pre_bd(PRE_ARGS);
                    124: static int      pre_bl(PRE_ARGS);
                    125: static int      pre_dd(PRE_ARGS);
                    126: static int      pre_display(PRE_ARGS);
                    127: static int      pre_dt(PRE_ARGS);
                    128: static int      pre_it(PRE_ARGS);
1.128     kristaps  129: static int      pre_literal(PRE_ARGS);
1.218   ! schwarze  130: static int      pre_obsolete(PRE_ARGS);
1.32      kristaps  131: static int      pre_os(PRE_ARGS);
1.124     kristaps  132: static int      pre_par(PRE_ARGS);
1.32      kristaps  133: static int      pre_sh(PRE_ARGS);
                    134: static int      pre_ss(PRE_ARGS);
1.133     kristaps  135: static int      pre_std(PRE_ARGS);
1.32      kristaps  136:
                    137: static v_post   posts_an[] = { post_an, NULL };
1.126     kristaps  138: static v_post   posts_at[] = { post_at, post_defaults, NULL };
1.128     kristaps  139: static v_post   posts_bd[] = { post_literal, hwarn_eq0, bwarn_ge1, NULL };
1.32      kristaps  140: static v_post   posts_bf[] = { hwarn_le1, post_bf, NULL };
1.128     kristaps  141: static v_post   posts_bk[] = { hwarn_eq0, bwarn_ge1, NULL };
1.32      kristaps  142: static v_post   posts_bl[] = { bwarn_ge1, post_bl, NULL };
1.154     kristaps  143: static v_post   posts_bx[] = { post_bx, NULL };
1.151     schwarze  144: static v_post   posts_bool[] = { ebool, NULL };
1.84      kristaps  145: static v_post   posts_eoln[] = { post_eoln, NULL };
1.123     kristaps  146: static v_post   posts_defaults[] = { post_defaults, NULL };
1.196     schwarze  147: static v_post   posts_d1[] = { bwarn_ge1, post_hyph, NULL };
1.158     schwarze  148: static v_post   posts_dd[] = { post_dd, post_prol, NULL };
1.151     schwarze  149: static v_post   posts_dl[] = { post_literal, bwarn_ge1, NULL };
1.132     kristaps  150: static v_post   posts_dt[] = { post_dt, post_prol, NULL };
1.218   ! schwarze  151: static v_post   posts_en[] = { post_en, NULL };
        !           152: static v_post   posts_es[] = { post_es, NULL };
1.32      kristaps  153: static v_post   posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
1.196     schwarze  154: static v_post   posts_hyph[] = { post_hyph, NULL };
                    155: static v_post   posts_hyphtext[] = { ewarn_ge1, post_hyph, NULL };
1.143     kristaps  156: static v_post   posts_it[] = { post_it, NULL };
1.151     schwarze  157: static v_post   posts_lb[] = { post_lb, NULL };
1.196     schwarze  158: static v_post   posts_nd[] = { berr_ge1, post_hyph, NULL };
1.32      kristaps  159: static v_post   posts_nm[] = { post_nm, NULL };
1.116     kristaps  160: static v_post   posts_notext[] = { ewarn_eq0, NULL };
1.155     kristaps  161: static v_post   posts_ns[] = { post_ns, NULL };
1.132     kristaps  162: static v_post   posts_os[] = { post_os, post_prol, NULL };
1.188     schwarze  163: static v_post   posts_pp[] = { post_par, ewarn_eq0, NULL };
1.151     schwarze  164: static v_post   posts_rs[] = { post_rs, NULL };
1.196     schwarze  165: static v_post   posts_sh[] = { post_ignpar,hwarn_ge1,post_sh,post_hyph,NULL };
1.188     schwarze  166: static v_post   posts_sp[] = { post_par, ewarn_le1, NULL };
1.196     schwarze  167: static v_post   posts_ss[] = { post_ignpar, hwarn_ge1, post_hyph, NULL };
1.151     schwarze  168: static v_post   posts_st[] = { post_st, NULL };
1.132     kristaps  169: static v_post   posts_std[] = { post_std, NULL };
1.152     schwarze  170: static v_post   posts_text[] = { ewarn_ge1, NULL };
1.151     schwarze  171: static v_post   posts_text1[] = { ewarn_eq1, NULL };
1.57      kristaps  172: static v_post   posts_vt[] = { post_vt, NULL };
1.32      kristaps  173: static v_pre    pres_an[] = { pre_an, NULL };
1.128     kristaps  174: static v_pre    pres_bd[] = { pre_display, pre_bd, pre_literal, pre_par, NULL };
1.124     kristaps  175: static v_pre    pres_bl[] = { pre_bl, pre_par, NULL };
1.32      kristaps  176: static v_pre    pres_d1[] = { pre_display, NULL };
1.128     kristaps  177: static v_pre    pres_dl[] = { pre_literal, pre_display, NULL };
1.32      kristaps  178: static v_pre    pres_dd[] = { pre_dd, NULL };
                    179: static v_pre    pres_dt[] = { pre_dt, NULL };
1.141     kristaps  180: static v_pre    pres_it[] = { pre_it, pre_par, NULL };
1.218   ! schwarze  181: static v_pre    pres_obsolete[] = { pre_obsolete, NULL };
1.32      kristaps  182: static v_pre    pres_os[] = { pre_os, NULL };
1.124     kristaps  183: static v_pre    pres_pp[] = { pre_par, NULL };
1.32      kristaps  184: static v_pre    pres_sh[] = { pre_sh, NULL };
                    185: static v_pre    pres_ss[] = { pre_ss, NULL };
1.133     kristaps  186: static v_pre    pres_std[] = { pre_std, NULL };
1.1       kristaps  187:
1.163     kristaps  188: static const struct valids mdoc_valids[MDOC_MAX] = {
1.10      kristaps  189:        { NULL, NULL },                         /* Ap */
1.132     kristaps  190:        { pres_dd, posts_dd },                  /* Dd */
1.85      kristaps  191:        { pres_dt, posts_dt },                  /* Dt */
1.132     kristaps  192:        { pres_os, posts_os },                  /* Os */
1.210     schwarze  193:        { pres_sh, posts_sh },                  /* Sh */
                    194:        { pres_ss, posts_ss },                  /* Ss */
                    195:        { pres_pp, posts_pp },                  /* Pp */
1.196     schwarze  196:        { pres_d1, posts_d1 },                  /* D1 */
1.128     kristaps  197:        { pres_dl, posts_dl },                  /* Dl */
                    198:        { pres_bd, posts_bd },                  /* Bd */
1.1       kristaps  199:        { NULL, NULL },                         /* Ed */
1.210     schwarze  200:        { pres_bl, posts_bl },                  /* Bl */
1.1       kristaps  201:        { NULL, NULL },                         /* El */
                    202:        { pres_it, posts_it },                  /* It */
1.210     schwarze  203:        { NULL, NULL },                         /* Ad */
                    204:        { pres_an, posts_an },                  /* An */
1.123     kristaps  205:        { NULL, posts_defaults },               /* Ar */
1.210     schwarze  206:        { NULL, NULL },                         /* Cd */
1.1       kristaps  207:        { NULL, NULL },                         /* Cm */
1.210     schwarze  208:        { NULL, NULL },                         /* Dv */
                    209:        { NULL, NULL },                         /* Er */
                    210:        { NULL, NULL },                         /* Ev */
                    211:        { pres_std, posts_std },                /* Ex */
                    212:        { NULL, NULL },                         /* Fa */
1.196     schwarze  213:        { NULL, posts_text },                   /* Fd */
1.1       kristaps  214:        { NULL, NULL },                         /* Fl */
1.210     schwarze  215:        { NULL, NULL },                         /* Fn */
                    216:        { NULL, NULL },                         /* Ft */
                    217:        { NULL, NULL },                         /* Ic */
                    218:        { NULL, posts_text1 },                  /* In */
1.123     kristaps  219:        { NULL, posts_defaults },               /* Li */
1.27      kristaps  220:        { NULL, posts_nd },                     /* Nd */
1.1       kristaps  221:        { NULL, posts_nm },                     /* Nm */
1.139     kristaps  222:        { NULL, NULL },                         /* Op */
1.218   ! schwarze  223:        { pres_obsolete, NULL },                /* Ot */
1.129     kristaps  224:        { NULL, posts_defaults },               /* Pa */
1.133     kristaps  225:        { pres_std, posts_std },                /* Rv */
1.210     schwarze  226:        { NULL, posts_st },                     /* St */
1.1       kristaps  227:        { NULL, NULL },                         /* Va */
1.210     schwarze  228:        { NULL, posts_vt },                     /* Vt */
                    229:        { NULL, posts_text },                   /* Xr */
1.1       kristaps  230:        { NULL, posts_text },                   /* %A */
1.196     schwarze  231:        { NULL, posts_hyphtext },               /* %B */ /* FIXME: can be used outside Rs/Re. */
1.158     schwarze  232:        { NULL, posts_text },                   /* %D */
1.1       kristaps  233:        { NULL, posts_text },                   /* %I */
                    234:        { NULL, posts_text },                   /* %J */
1.196     schwarze  235:        { NULL, posts_hyphtext },               /* %N */
                    236:        { NULL, posts_hyphtext },               /* %O */
1.1       kristaps  237:        { NULL, posts_text },                   /* %P */
1.196     schwarze  238:        { NULL, posts_hyphtext },               /* %R */
                    239:        { NULL, posts_hyphtext },               /* %T */ /* FIXME: can be used outside Rs/Re. */
1.1       kristaps  240:        { NULL, posts_text },                   /* %V */
                    241:        { NULL, NULL },                         /* Ac */
                    242:        { NULL, NULL },                         /* Ao */
1.139     kristaps  243:        { NULL, NULL },                         /* Aq */
1.210     schwarze  244:        { NULL, posts_at },                     /* At */
1.1       kristaps  245:        { NULL, NULL },                         /* Bc */
                    246:        { NULL, posts_bf },                     /* Bf */
                    247:        { NULL, NULL },                         /* Bo */
1.139     kristaps  248:        { NULL, NULL },                         /* Bq */
1.1       kristaps  249:        { NULL, NULL },                         /* Bsx */
1.154     kristaps  250:        { NULL, posts_bx },                     /* Bx */
1.1       kristaps  251:        { NULL, posts_bool },                   /* Db */
                    252:        { NULL, NULL },                         /* Dc */
                    253:        { NULL, NULL },                         /* Do */
1.139     kristaps  254:        { NULL, NULL },                         /* Dq */
1.1       kristaps  255:        { NULL, NULL },                         /* Ec */
1.210     schwarze  256:        { NULL, NULL },                         /* Ef */
                    257:        { NULL, NULL },                         /* Em */
1.1       kristaps  258:        { NULL, NULL },                         /* Eo */
                    259:        { NULL, NULL },                         /* Fx */
1.210     schwarze  260:        { NULL, NULL },                         /* Ms */
1.1       kristaps  261:        { NULL, posts_notext },                 /* No */
1.155     kristaps  262:        { NULL, posts_ns },                     /* Ns */
1.1       kristaps  263:        { NULL, NULL },                         /* Nx */
                    264:        { NULL, NULL },                         /* Ox */
                    265:        { NULL, NULL },                         /* Pc */
1.51      kristaps  266:        { NULL, posts_text1 },                  /* Pf */
1.1       kristaps  267:        { NULL, NULL },                         /* Po */
1.139     kristaps  268:        { NULL, NULL },                         /* Pq */
1.1       kristaps  269:        { NULL, NULL },                         /* Qc */
1.139     kristaps  270:        { NULL, NULL },                         /* Ql */
1.1       kristaps  271:        { NULL, NULL },                         /* Qo */
1.139     kristaps  272:        { NULL, NULL },                         /* Qq */
1.1       kristaps  273:        { NULL, NULL },                         /* Re */
1.43      kristaps  274:        { NULL, posts_rs },                     /* Rs */
1.1       kristaps  275:        { NULL, NULL },                         /* Sc */
                    276:        { NULL, NULL },                         /* So */
1.139     kristaps  277:        { NULL, NULL },                         /* Sq */
1.210     schwarze  278:        { NULL, posts_bool },                   /* Sm */
1.196     schwarze  279:        { NULL, posts_hyph },                   /* Sx */
1.152     schwarze  280:        { NULL, NULL },                         /* Sy */
                    281:        { NULL, NULL },                         /* Tn */
1.1       kristaps  282:        { NULL, NULL },                         /* Ux */
                    283:        { NULL, NULL },                         /* Xc */
                    284:        { NULL, NULL },                         /* Xo */
1.210     schwarze  285:        { NULL, posts_fo },                     /* Fo */
                    286:        { NULL, NULL },                         /* Fc */
1.1       kristaps  287:        { NULL, NULL },                         /* Oo */
                    288:        { NULL, NULL },                         /* Oc */
1.128     kristaps  289:        { NULL, posts_bk },                     /* Bk */
1.1       kristaps  290:        { NULL, NULL },                         /* Ek */
1.84      kristaps  291:        { NULL, posts_eoln },                   /* Bt */
1.1       kristaps  292:        { NULL, NULL },                         /* Hf */
1.218   ! schwarze  293:        { pres_obsolete, NULL },                /* Fr */
1.84      kristaps  294:        { NULL, posts_eoln },                   /* Ud */
1.83      kristaps  295:        { NULL, posts_lb },                     /* Lb */
1.210     schwarze  296:        { pres_pp, posts_pp },                  /* Lp */
                    297:        { NULL, NULL },                         /* Lk */
                    298:        { NULL, posts_defaults },               /* Mt */
                    299:        { NULL, NULL },                         /* Brq */
                    300:        { NULL, NULL },                         /* Bro */
                    301:        { NULL, NULL },                         /* Brc */
1.1       kristaps  302:        { NULL, posts_text },                   /* %C */
1.218   ! schwarze  303:        { pres_obsolete, posts_es },            /* Es */
        !           304:        { pres_obsolete, posts_en },            /* En */
1.1       kristaps  305:        { NULL, NULL },                         /* Dx */
                    306:        { NULL, posts_text },                   /* %Q */
1.188     schwarze  307:        { NULL, posts_pp },                     /* br */
                    308:        { NULL, posts_sp },                     /* sp */
1.51      kristaps  309:        { NULL, posts_text1 },                  /* %U */
1.88      kristaps  310:        { NULL, NULL },                         /* Ta */
1.206     schwarze  311:        { NULL, NULL },                         /* ll */
1.1       kristaps  312: };
                    313:
1.122     kristaps  314: #define        RSORD_MAX 14 /* Number of `Rs' blocks. */
                    315:
                    316: static const enum mdoct rsord[RSORD_MAX] = {
                    317:        MDOC__A,
                    318:        MDOC__T,
                    319:        MDOC__B,
                    320:        MDOC__I,
                    321:        MDOC__J,
                    322:        MDOC__R,
                    323:        MDOC__N,
                    324:        MDOC__V,
1.186     schwarze  325:        MDOC__U,
1.122     kristaps  326:        MDOC__P,
                    327:        MDOC__Q,
1.192     schwarze  328:        MDOC__C,
1.122     kristaps  329:        MDOC__D,
1.192     schwarze  330:        MDOC__O
1.122     kristaps  331: };
                    332:
1.160     kristaps  333: static const char * const secnames[SEC__MAX] = {
                    334:        NULL,
                    335:        "NAME",
                    336:        "LIBRARY",
                    337:        "SYNOPSIS",
                    338:        "DESCRIPTION",
1.208     schwarze  339:        "CONTEXT",
1.160     kristaps  340:        "IMPLEMENTATION NOTES",
                    341:        "RETURN VALUES",
                    342:        "ENVIRONMENT",
                    343:        "FILES",
                    344:        "EXIT STATUS",
                    345:        "EXAMPLES",
                    346:        "DIAGNOSTICS",
                    347:        "COMPATIBILITY",
                    348:        "ERRORS",
                    349:        "SEE ALSO",
                    350:        "STANDARDS",
                    351:        "HISTORY",
                    352:        "AUTHORS",
                    353:        "CAVEATS",
                    354:        "BUGS",
                    355:        "SECURITY CONSIDERATIONS",
                    356:        NULL
                    357: };
1.1       kristaps  358:
1.210     schwarze  359:
1.1       kristaps  360: int
1.91      kristaps  361: mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
1.1       kristaps  362: {
                    363:        v_pre           *p;
                    364:        int              line, pos;
1.92      kristaps  365:        char            *tp;
1.1       kristaps  366:
1.150     kristaps  367:        switch (n->type) {
1.210     schwarze  368:        case MDOC_TEXT:
1.1       kristaps  369:                tp = n->string;
                    370:                line = n->line;
                    371:                pos = n->pos;
1.133     kristaps  372:                check_text(mdoc, line, pos, tp);
1.150     kristaps  373:                /* FALLTHROUGH */
1.210     schwarze  374:        case MDOC_TBL:
1.156     kristaps  375:                /* FALLTHROUGH */
1.210     schwarze  376:        case MDOC_EQN:
1.150     kristaps  377:                /* FALLTHROUGH */
1.210     schwarze  378:        case MDOC_ROOT:
1.133     kristaps  379:                return(1);
1.150     kristaps  380:        default:
                    381:                break;
1.1       kristaps  382:        }
                    383:
1.133     kristaps  384:        check_args(mdoc, n);
                    385:
1.1       kristaps  386:        if (NULL == mdoc_valids[n->tok].pre)
                    387:                return(1);
                    388:        for (p = mdoc_valids[n->tok].pre; *p; p++)
1.210     schwarze  389:                if ( ! (*p)(mdoc, n))
1.1       kristaps  390:                        return(0);
                    391:        return(1);
                    392: }
                    393:
                    394: int
                    395: mdoc_valid_post(struct mdoc *mdoc)
                    396: {
                    397:        v_post          *p;
                    398:
                    399:        if (MDOC_VALID & mdoc->last->flags)
                    400:                return(1);
                    401:        mdoc->last->flags |= MDOC_VALID;
                    402:
1.150     kristaps  403:        switch (mdoc->last->type) {
1.210     schwarze  404:        case MDOC_TEXT:
1.157     kristaps  405:                /* FALLTHROUGH */
1.210     schwarze  406:        case MDOC_EQN:
1.150     kristaps  407:                /* FALLTHROUGH */
1.210     schwarze  408:        case MDOC_TBL:
1.1       kristaps  409:                return(1);
1.210     schwarze  410:        case MDOC_ROOT:
1.1       kristaps  411:                return(post_root(mdoc));
1.150     kristaps  412:        default:
                    413:                break;
                    414:        }
1.1       kristaps  415:
                    416:        if (NULL == mdoc_valids[mdoc->last->tok].post)
                    417:                return(1);
                    418:        for (p = mdoc_valids[mdoc->last->tok].post; *p; p++)
1.210     schwarze  419:                if ( ! (*p)(mdoc))
1.1       kristaps  420:                        return(0);
                    421:
                    422:        return(1);
                    423: }
                    424:
1.120     kristaps  425: static int
1.210     schwarze  426: check_count(struct mdoc *mdoc, enum mdoc_type type,
1.120     kristaps  427:                enum check_lvl lvl, enum check_ineq ineq, int val)
                    428: {
                    429:        const char      *p;
1.151     schwarze  430:        enum mandocerr   t;
1.120     kristaps  431:
1.191     schwarze  432:        if (mdoc->last->type != type)
1.120     kristaps  433:                return(1);
1.210     schwarze  434:
1.120     kristaps  435:        switch (ineq) {
1.210     schwarze  436:        case CHECK_LT:
1.120     kristaps  437:                p = "less than ";
1.191     schwarze  438:                if (mdoc->last->nchild < val)
1.120     kristaps  439:                        return(1);
                    440:                break;
1.210     schwarze  441:        case CHECK_GT:
1.151     schwarze  442:                p = "more than ";
1.191     schwarze  443:                if (mdoc->last->nchild > val)
1.120     kristaps  444:                        return(1);
                    445:                break;
1.210     schwarze  446:        case CHECK_EQ:
1.120     kristaps  447:                p = "";
1.191     schwarze  448:                if (val == mdoc->last->nchild)
1.120     kristaps  449:                        return(1);
                    450:                break;
1.133     kristaps  451:        default:
                    452:                abort();
                    453:                /* NOTREACHED */
1.120     kristaps  454:        }
                    455:
1.151     schwarze  456:        t = lvl == CHECK_WARN ? MANDOCERR_ARGCWARN : MANDOCERR_ARGCOUNT;
1.210     schwarze  457:        mandoc_vmsg(t, mdoc->parse, mdoc->last->line,
                    458:            mdoc->last->pos, "want %s%d children (have %d)",
                    459:            p, val, mdoc->last->nchild);
1.162     kristaps  460:        return(1);
1.120     kristaps  461: }
                    462:
                    463: static int
                    464: berr_ge1(POST_ARGS)
                    465: {
                    466:
1.151     schwarze  467:        return(check_count(mdoc, MDOC_BODY, CHECK_ERROR, CHECK_GT, 0));
1.120     kristaps  468: }
                    469:
                    470: static int
                    471: bwarn_ge1(POST_ARGS)
                    472: {
                    473:        return(check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0));
                    474: }
                    475:
                    476: static int
1.151     schwarze  477: ewarn_eq0(POST_ARGS)
1.120     kristaps  478: {
1.151     schwarze  479:        return(check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0));
1.120     kristaps  480: }
1.1       kristaps  481:
1.120     kristaps  482: static int
1.151     schwarze  483: ewarn_eq1(POST_ARGS)
1.1       kristaps  484: {
1.151     schwarze  485:        return(check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1));
1.120     kristaps  486: }
1.1       kristaps  487:
1.120     kristaps  488: static int
                    489: ewarn_ge1(POST_ARGS)
                    490: {
                    491:        return(check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0));
1.1       kristaps  492: }
                    493:
1.120     kristaps  494: static int
1.151     schwarze  495: ewarn_le1(POST_ARGS)
1.120     kristaps  496: {
1.151     schwarze  497:        return(check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2));
1.120     kristaps  498: }
1.1       kristaps  499:
1.120     kristaps  500: static int
1.151     schwarze  501: hwarn_eq0(POST_ARGS)
1.120     kristaps  502: {
1.151     schwarze  503:        return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0));
1.120     kristaps  504: }
1.1       kristaps  505:
1.120     kristaps  506: static int
1.151     schwarze  507: hwarn_eq1(POST_ARGS)
1.120     kristaps  508: {
1.151     schwarze  509:        return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 1));
1.1       kristaps  510: }
                    511:
1.120     kristaps  512: static int
1.151     schwarze  513: hwarn_ge1(POST_ARGS)
1.120     kristaps  514: {
1.151     schwarze  515:        return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_GT, 0));
1.120     kristaps  516: }
1.1       kristaps  517:
1.120     kristaps  518: static int
                    519: hwarn_le1(POST_ARGS)
                    520: {
                    521:        return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_LT, 2));
                    522: }
1.1       kristaps  523:
1.133     kristaps  524: static void
1.191     schwarze  525: check_args(struct mdoc *mdoc, struct mdoc_node *n)
1.1       kristaps  526: {
                    527:        int              i;
                    528:
                    529:        if (NULL == n->args)
1.133     kristaps  530:                return;
1.1       kristaps  531:
                    532:        assert(n->args->argc);
                    533:        for (i = 0; i < (int)n->args->argc; i++)
1.191     schwarze  534:                check_argv(mdoc, n, &n->args->argv[i]);
1.1       kristaps  535: }
                    536:
1.133     kristaps  537: static void
1.191     schwarze  538: check_argv(struct mdoc *mdoc, struct mdoc_node *n, struct mdoc_argv *v)
1.1       kristaps  539: {
                    540:        int              i;
                    541:
                    542:        for (i = 0; i < (int)v->sz; i++)
1.191     schwarze  543:                check_text(mdoc, v->line, v->pos, v->value[i]);
1.1       kristaps  544:
1.133     kristaps  545:        /* FIXME: move to post_std(). */
1.1       kristaps  546:
1.133     kristaps  547:        if (MDOC_Std == v->arg)
1.191     schwarze  548:                if ( ! (v->sz || mdoc->meta.name))
                    549:                        mdoc_nmsg(mdoc, n, MANDOCERR_NONAME);
1.1       kristaps  550: }
                    551:
1.133     kristaps  552: static void
1.191     schwarze  553: check_text(struct mdoc *mdoc, int ln, int pos, char *p)
1.1       kristaps  554: {
1.172     kristaps  555:        char            *cp;
1.102     kristaps  556:
1.191     schwarze  557:        if (MDOC_LITERAL & mdoc->flags)
1.177     schwarze  558:                return;
                    559:
                    560:        for (cp = p; NULL != (p = strchr(p, '\t')); p++)
1.191     schwarze  561:                mdoc_pmsg(mdoc, ln, pos + (int)(p - cp), MANDOCERR_BADTAB);
1.1       kristaps  562: }
                    563:
                    564: static int
1.59      kristaps  565: check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
1.1       kristaps  566: {
                    567:
                    568:        assert(n->parent);
                    569:        if ((MDOC_ROOT == t || tok == n->parent->tok) &&
                    570:                        (t == n->parent->type))
                    571:                return(1);
                    572:
1.210     schwarze  573:        mandoc_vmsg(MANDOCERR_SYNTCHILD, mdoc->parse,
                    574:            n->line, n->pos, "want parent %s",
                    575:            MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok]);
1.79      kristaps  576:        return(0);
1.1       kristaps  577: }
                    578:
                    579:
                    580: static int
                    581: pre_display(PRE_ARGS)
                    582: {
                    583:        struct mdoc_node *node;
                    584:
                    585:        if (MDOC_BLOCK != n->type)
                    586:                return(1);
                    587:
1.210     schwarze  588:        for (node = mdoc->last->parent; node; node = node->parent)
1.1       kristaps  589:                if (MDOC_BLOCK == node->type)
                    590:                        if (MDOC_Bd == node->tok)
                    591:                                break;
1.128     kristaps  592:
1.135     kristaps  593:        if (node)
                    594:                mdoc_nmsg(mdoc, n, MANDOCERR_NESTEDDISP);
1.1       kristaps  595:
1.135     kristaps  596:        return(1);
1.1       kristaps  597: }
                    598:
                    599: static int
                    600: pre_bl(PRE_ARGS)
                    601: {
1.104     kristaps  602:        int               i, comp, dup;
                    603:        const char       *offs, *width;
                    604:        enum mdoc_list    lt;
                    605:        struct mdoc_node *np;
1.1       kristaps  606:
1.91      kristaps  607:        if (MDOC_BLOCK != n->type) {
1.104     kristaps  608:                if (ENDBODY_NOT != n->end) {
                    609:                        assert(n->pending);
                    610:                        np = n->pending->parent;
                    611:                } else
                    612:                        np = n->parent;
                    613:
                    614:                assert(np);
                    615:                assert(MDOC_BLOCK == np->type);
                    616:                assert(MDOC_Bl == np->tok);
1.1       kristaps  617:                return(1);
1.79      kristaps  618:        }
1.1       kristaps  619:
1.210     schwarze  620:        /*
1.91      kristaps  621:         * First figure out which kind of list to use: bind ourselves to
                    622:         * the first mentioned list type and warn about any remaining
                    623:         * ones.  If we find no list type, we default to LIST_item.
                    624:         */
1.1       kristaps  625:
1.91      kristaps  626:        for (i = 0; n->args && i < (int)n->args->argc; i++) {
                    627:                lt = LIST__NONE;
1.97      kristaps  628:                dup = comp = 0;
1.99      kristaps  629:                width = offs = NULL;
1.91      kristaps  630:                switch (n->args->argv[i].arg) {
                    631:                /* Set list types. */
1.210     schwarze  632:                case MDOC_Bullet:
1.91      kristaps  633:                        lt = LIST_bullet;
                    634:                        break;
1.210     schwarze  635:                case MDOC_Dash:
1.91      kristaps  636:                        lt = LIST_dash;
                    637:                        break;
1.210     schwarze  638:                case MDOC_Enum:
1.91      kristaps  639:                        lt = LIST_enum;
                    640:                        break;
1.210     schwarze  641:                case MDOC_Hyphen:
1.91      kristaps  642:                        lt = LIST_hyphen;
                    643:                        break;
1.210     schwarze  644:                case MDOC_Item:
1.91      kristaps  645:                        lt = LIST_item;
                    646:                        break;
1.210     schwarze  647:                case MDOC_Tag:
1.91      kristaps  648:                        lt = LIST_tag;
                    649:                        break;
1.210     schwarze  650:                case MDOC_Diag:
1.91      kristaps  651:                        lt = LIST_diag;
                    652:                        break;
1.210     schwarze  653:                case MDOC_Hang:
1.91      kristaps  654:                        lt = LIST_hang;
                    655:                        break;
1.210     schwarze  656:                case MDOC_Ohang:
1.91      kristaps  657:                        lt = LIST_ohang;
                    658:                        break;
1.210     schwarze  659:                case MDOC_Inset:
1.91      kristaps  660:                        lt = LIST_inset;
                    661:                        break;
1.210     schwarze  662:                case MDOC_Column:
1.91      kristaps  663:                        lt = LIST_column;
                    664:                        break;
                    665:                /* Set list arguments. */
1.210     schwarze  666:                case MDOC_Compact:
1.147     kristaps  667:                        dup = n->norm->Bl.comp;
1.97      kristaps  668:                        comp = 1;
1.91      kristaps  669:                        break;
1.210     schwarze  670:                case MDOC_Width:
1.182     kristaps  671:                        /* NB: this can be empty! */
                    672:                        if (n->args->argv[i].sz) {
                    673:                                width = n->args->argv[i].value[0];
                    674:                                dup = (NULL != n->norm->Bl.width);
                    675:                                break;
                    676:                        }
                    677:                        mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
1.8       kristaps  678:                        break;
1.210     schwarze  679:                case MDOC_Offset:
1.98      kristaps  680:                        /* NB: this can be empty! */
                    681:                        if (n->args->argv[i].sz) {
                    682:                                offs = n->args->argv[i].value[0];
1.147     kristaps  683:                                dup = (NULL != n->norm->Bl.offs);
1.98      kristaps  684:                                break;
                    685:                        }
1.133     kristaps  686:                        mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
1.1       kristaps  687:                        break;
1.113     kristaps  688:                default:
                    689:                        continue;
1.1       kristaps  690:                }
                    691:
1.91      kristaps  692:                /* Check: duplicate auxiliary arguments. */
                    693:
1.133     kristaps  694:                if (dup)
                    695:                        mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
1.97      kristaps  696:
                    697:                if (comp && ! dup)
1.147     kristaps  698:                        n->norm->Bl.comp = comp;
1.98      kristaps  699:                if (offs && ! dup)
1.147     kristaps  700:                        n->norm->Bl.offs = offs;
1.99      kristaps  701:                if (width && ! dup)
1.147     kristaps  702:                        n->norm->Bl.width = width;
1.91      kristaps  703:
                    704:                /* Check: multiple list types. */
                    705:
1.147     kristaps  706:                if (LIST__NONE != lt && n->norm->Bl.type != LIST__NONE)
1.133     kristaps  707:                        mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP);
1.91      kristaps  708:
                    709:                /* Assign list type. */
                    710:
1.147     kristaps  711:                if (LIST__NONE != lt && n->norm->Bl.type == LIST__NONE) {
                    712:                        n->norm->Bl.type = lt;
1.109     kristaps  713:                        /* Set column information, too. */
                    714:                        if (LIST_column == lt) {
1.210     schwarze  715:                                n->norm->Bl.ncols =
                    716:                                    n->args->argv[i].sz;
1.175     kristaps  717:                                n->norm->Bl.cols = (void *)
1.210     schwarze  718:                                    n->args->argv[i].value;
1.109     kristaps  719:                        }
                    720:                }
1.91      kristaps  721:
                    722:                /* The list type should come first. */
                    723:
1.147     kristaps  724:                if (n->norm->Bl.type == LIST__NONE)
1.210     schwarze  725:                        if (n->norm->Bl.width ||
                    726:                            n->norm->Bl.offs ||
                    727:                            n->norm->Bl.comp)
1.133     kristaps  728:                                mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST);
1.91      kristaps  729:
                    730:                continue;
                    731:        }
                    732:
                    733:        /* Allow lists to default to LIST_item. */
                    734:
1.147     kristaps  735:        if (LIST__NONE == n->norm->Bl.type) {
1.133     kristaps  736:                mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE);
1.147     kristaps  737:                n->norm->Bl.type = LIST_item;
1.79      kristaps  738:        }
1.1       kristaps  739:
1.210     schwarze  740:        /*
1.8       kristaps  741:         * Validate the width field.  Some list types don't need width
                    742:         * types and should be warned about them.  Others should have it
1.185     schwarze  743:         * and must also be warned.  Yet others have a default and need
                    744:         * no warning.
1.8       kristaps  745:         */
                    746:
1.147     kristaps  747:        switch (n->norm->Bl.type) {
1.210     schwarze  748:        case LIST_tag:
1.185     schwarze  749:                if (NULL == n->norm->Bl.width)
                    750:                        mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG);
1.133     kristaps  751:                break;
1.210     schwarze  752:        case LIST_column:
1.1       kristaps  753:                /* FALLTHROUGH */
1.210     schwarze  754:        case LIST_diag:
1.1       kristaps  755:                /* FALLTHROUGH */
1.210     schwarze  756:        case LIST_ohang:
1.53      kristaps  757:                /* FALLTHROUGH */
1.210     schwarze  758:        case LIST_inset:
1.1       kristaps  759:                /* FALLTHROUGH */
1.210     schwarze  760:        case LIST_item:
1.147     kristaps  761:                if (n->norm->Bl.width)
1.137     kristaps  762:                        mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
1.185     schwarze  763:                break;
1.210     schwarze  764:        case LIST_bullet:
1.185     schwarze  765:                /* FALLTHROUGH */
1.210     schwarze  766:        case LIST_dash:
1.185     schwarze  767:                /* FALLTHROUGH */
1.210     schwarze  768:        case LIST_hyphen:
1.185     schwarze  769:                if (NULL == n->norm->Bl.width)
                    770:                        n->norm->Bl.width = "2n";
                    771:                break;
1.210     schwarze  772:        case LIST_enum:
1.185     schwarze  773:                if (NULL == n->norm->Bl.width)
                    774:                        n->norm->Bl.width = "3n";
1.133     kristaps  775:                break;
1.8       kristaps  776:        default:
                    777:                break;
                    778:        }
                    779:
1.1       kristaps  780:        return(1);
                    781: }
                    782:
                    783: static int
                    784: pre_bd(PRE_ARGS)
                    785: {
1.104     kristaps  786:        int               i, dup, comp;
1.210     schwarze  787:        enum mdoc_disp    dt;
1.104     kristaps  788:        const char       *offs;
                    789:        struct mdoc_node *np;
1.1       kristaps  790:
1.93      kristaps  791:        if (MDOC_BLOCK != n->type) {
1.104     kristaps  792:                if (ENDBODY_NOT != n->end) {
                    793:                        assert(n->pending);
                    794:                        np = n->pending->parent;
                    795:                } else
                    796:                        np = n->parent;
                    797:
                    798:                assert(np);
                    799:                assert(MDOC_BLOCK == np->type);
                    800:                assert(MDOC_Bd == np->tok);
1.1       kristaps  801:                return(1);
1.79      kristaps  802:        }
1.1       kristaps  803:
1.93      kristaps  804:        for (i = 0; n->args && i < (int)n->args->argc; i++) {
                    805:                dt = DISP__NONE;
1.94      kristaps  806:                dup = comp = 0;
                    807:                offs = NULL;
                    808:
1.1       kristaps  809:                switch (n->args->argv[i].arg) {
1.210     schwarze  810:                case MDOC_Centred:
1.93      kristaps  811:                        dt = DISP_centred;
                    812:                        break;
1.210     schwarze  813:                case MDOC_Ragged:
1.93      kristaps  814:                        dt = DISP_ragged;
                    815:                        break;
1.210     schwarze  816:                case MDOC_Unfilled:
1.93      kristaps  817:                        dt = DISP_unfilled;
                    818:                        break;
1.210     schwarze  819:                case MDOC_Filled:
1.93      kristaps  820:                        dt = DISP_filled;
                    821:                        break;
1.210     schwarze  822:                case MDOC_Literal:
1.93      kristaps  823:                        dt = DISP_literal;
1.79      kristaps  824:                        break;
1.210     schwarze  825:                case MDOC_File:
1.93      kristaps  826:                        mdoc_nmsg(mdoc, n, MANDOCERR_BADDISP);
                    827:                        return(0);
1.210     schwarze  828:                case MDOC_Offset:
1.94      kristaps  829:                        /* NB: this can be empty! */
                    830:                        if (n->args->argv[i].sz) {
                    831:                                offs = n->args->argv[i].value[0];
1.147     kristaps  832:                                dup = (NULL != n->norm->Bd.offs);
1.94      kristaps  833:                                break;
                    834:                        }
1.133     kristaps  835:                        mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
1.94      kristaps  836:                        break;
1.210     schwarze  837:                case MDOC_Compact:
1.94      kristaps  838:                        comp = 1;
1.147     kristaps  839:                        dup = n->norm->Bd.comp;
1.94      kristaps  840:                        break;
1.1       kristaps  841:                default:
1.94      kristaps  842:                        abort();
                    843:                        /* NOTREACHED */
1.1       kristaps  844:                }
                    845:
1.94      kristaps  846:                /* Check whether we have duplicates. */
                    847:
1.133     kristaps  848:                if (dup)
                    849:                        mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
1.94      kristaps  850:
                    851:                /* Make our auxiliary assignments. */
                    852:
                    853:                if (offs && ! dup)
1.147     kristaps  854:                        n->norm->Bd.offs = offs;
1.94      kristaps  855:                if (comp && ! dup)
1.147     kristaps  856:                        n->norm->Bd.comp = comp;
1.94      kristaps  857:
                    858:                /* Check whether a type has already been assigned. */
                    859:
1.147     kristaps  860:                if (DISP__NONE != dt && n->norm->Bd.type != DISP__NONE)
1.133     kristaps  861:                        mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP);
1.93      kristaps  862:
1.94      kristaps  863:                /* Make our type assignment. */
                    864:
1.147     kristaps  865:                if (DISP__NONE != dt && n->norm->Bd.type == DISP__NONE)
                    866:                        n->norm->Bd.type = dt;
1.93      kristaps  867:        }
                    868:
1.147     kristaps  869:        if (DISP__NONE == n->norm->Bd.type) {
1.133     kristaps  870:                mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
1.147     kristaps  871:                n->norm->Bd.type = DISP_ragged;
1.93      kristaps  872:        }
                    873:
                    874:        return(1);
1.1       kristaps  875: }
                    876:
                    877: static int
                    878: pre_ss(PRE_ARGS)
                    879: {
                    880:
                    881:        if (MDOC_BLOCK != n->type)
                    882:                return(1);
                    883:        return(check_parent(mdoc, n, MDOC_Sh, MDOC_BODY));
                    884: }
                    885:
                    886: static int
                    887: pre_sh(PRE_ARGS)
                    888: {
                    889:
                    890:        if (MDOC_BLOCK != n->type)
                    891:                return(1);
1.70      kristaps  892:        return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT));
1.1       kristaps  893: }
                    894:
                    895: static int
                    896: pre_it(PRE_ARGS)
                    897: {
                    898:
                    899:        if (MDOC_BLOCK != n->type)
                    900:                return(1);
1.133     kristaps  901:
1.1       kristaps  902:        return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
                    903: }
                    904:
                    905: static int
                    906: pre_an(PRE_ARGS)
                    907: {
1.121     kristaps  908:        int              i;
1.1       kristaps  909:
1.107     kristaps  910:        if (NULL == n->args)
1.1       kristaps  911:                return(1);
1.210     schwarze  912:
1.121     kristaps  913:        for (i = 1; i < (int)n->args->argc; i++)
1.210     schwarze  914:                mdoc_pmsg(mdoc, n->args->argv[i].line,
                    915:                    n->args->argv[i].pos, MANDOCERR_IGNARGV);
1.120     kristaps  916:
1.107     kristaps  917:        if (MDOC_Split == n->args->argv[0].arg)
1.147     kristaps  918:                n->norm->An.auth = AUTH_split;
1.107     kristaps  919:        else if (MDOC_Nosplit == n->args->argv[0].arg)
1.147     kristaps  920:                n->norm->An.auth = AUTH_nosplit;
1.107     kristaps  921:        else
                    922:                abort();
                    923:
                    924:        return(1);
1.1       kristaps  925: }
                    926:
                    927: static int
1.133     kristaps  928: pre_std(PRE_ARGS)
1.1       kristaps  929: {
                    930:
1.133     kristaps  931:        if (n->args && 1 == n->args->argc)
                    932:                if (MDOC_Std == n->args->argv[0].arg)
                    933:                        return(1);
                    934:
                    935:        mdoc_nmsg(mdoc, n, MANDOCERR_NOARGV);
                    936:        return(1);
1.1       kristaps  937: }
                    938:
1.85      kristaps  939: static int
1.218   ! schwarze  940: pre_obsolete(PRE_ARGS)
        !           941: {
        !           942:
        !           943:        if (MDOC_ELEM == n->type || MDOC_BLOCK == n->type)
        !           944:                mandoc_msg(MANDOCERR_MACRO_OBS, mdoc->parse,
        !           945:                    n->line, n->pos, mdoc_macronames[n->tok]);
        !           946:        return(1);
        !           947: }
        !           948:
        !           949: static int
1.1       kristaps  950: pre_dt(PRE_ARGS)
                    951: {
1.54      kristaps  952:
1.158     schwarze  953:        if (NULL == mdoc->meta.date || mdoc->meta.os)
1.217     schwarze  954:                mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
                    955:                    n->line, n->pos, "Dt");
1.133     kristaps  956:
1.1       kristaps  957:        if (mdoc->meta.title)
1.217     schwarze  958:                mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
                    959:                    n->line, n->pos, "Dt");
1.133     kristaps  960:
1.1       kristaps  961:        return(1);
                    962: }
                    963:
                    964: static int
                    965: pre_os(PRE_ARGS)
                    966: {
                    967:
1.158     schwarze  968:        if (NULL == mdoc->meta.title || NULL == mdoc->meta.date)
1.217     schwarze  969:                mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
                    970:                    n->line, n->pos, "Os");
1.133     kristaps  971:
1.1       kristaps  972:        if (mdoc->meta.os)
1.217     schwarze  973:                mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
                    974:                    n->line, n->pos, "Os");
1.133     kristaps  975:
1.1       kristaps  976:        return(1);
                    977: }
                    978:
                    979: static int
                    980: pre_dd(PRE_ARGS)
                    981: {
                    982:
                    983:        if (mdoc->meta.title || mdoc->meta.os)
1.217     schwarze  984:                mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
                    985:                    n->line, n->pos, "Dd");
1.133     kristaps  986:
1.1       kristaps  987:        if (mdoc->meta.date)
1.217     schwarze  988:                mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
                    989:                    n->line, n->pos, "Dd");
1.133     kristaps  990:
1.1       kristaps  991:        return(1);
                    992: }
                    993:
                    994: static int
                    995: post_bf(POST_ARGS)
                    996: {
1.105     kristaps  997:        struct mdoc_node *np;
1.113     kristaps  998:        enum mdocargt     arg;
1.105     kristaps  999:
                   1000:        /*
                   1001:         * Unlike other data pointers, these are "housed" by the HEAD
                   1002:         * element, which contains the goods.
                   1003:         */
1.1       kristaps 1004:
1.105     kristaps 1005:        if (MDOC_HEAD != mdoc->last->type) {
                   1006:                if (ENDBODY_NOT != mdoc->last->end) {
                   1007:                        assert(mdoc->last->pending);
                   1008:                        np = mdoc->last->pending->parent->head;
                   1009:                } else if (MDOC_BLOCK != mdoc->last->type) {
                   1010:                        np = mdoc->last->parent->head;
1.210     schwarze 1011:                } else
1.105     kristaps 1012:                        np = mdoc->last->head;
                   1013:
                   1014:                assert(np);
                   1015:                assert(MDOC_HEAD == np->type);
                   1016:                assert(MDOC_Bf == np->tok);
1.1       kristaps 1017:                return(1);
1.105     kristaps 1018:        }
1.1       kristaps 1019:
1.105     kristaps 1020:        np = mdoc->last;
1.106     kristaps 1021:        assert(MDOC_BLOCK == np->parent->type);
                   1022:        assert(MDOC_Bf == np->parent->tok);
1.1       kristaps 1023:
1.210     schwarze 1024:        /*
1.105     kristaps 1025:         * Cannot have both argument and parameter.
1.210     schwarze 1026:         * If neither is specified, let it through with a warning.
1.105     kristaps 1027:         */
                   1028:
1.106     kristaps 1029:        if (np->parent->args && np->child) {
1.105     kristaps 1030:                mdoc_nmsg(mdoc, np, MANDOCERR_SYNTARGVCOUNT);
1.79      kristaps 1031:                return(0);
1.133     kristaps 1032:        } else if (NULL == np->parent->args && NULL == np->child) {
                   1033:                mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE);
                   1034:                return(1);
                   1035:        }
1.105     kristaps 1036:
                   1037:        /* Extract argument into data. */
1.210     schwarze 1038:
1.106     kristaps 1039:        if (np->parent->args) {
                   1040:                arg = np->parent->args->argv[0].arg;
1.105     kristaps 1041:                if (MDOC_Emphasis == arg)
1.147     kristaps 1042:                        np->norm->Bf.font = FONT_Em;
1.105     kristaps 1043:                else if (MDOC_Literal == arg)
1.147     kristaps 1044:                        np->norm->Bf.font = FONT_Li;
1.105     kristaps 1045:                else if (MDOC_Symbolic == arg)
1.147     kristaps 1046:                        np->norm->Bf.font = FONT_Sy;
1.105     kristaps 1047:                else
                   1048:                        abort();
1.13      kristaps 1049:                return(1);
1.79      kristaps 1050:        }
1.1       kristaps 1051:
1.105     kristaps 1052:        /* Extract parameter into data. */
1.1       kristaps 1053:
1.105     kristaps 1054:        if (0 == strcmp(np->child->string, "Em"))
1.147     kristaps 1055:                np->norm->Bf.font = FONT_Em;
1.105     kristaps 1056:        else if (0 == strcmp(np->child->string, "Li"))
1.147     kristaps 1057:                np->norm->Bf.font = FONT_Li;
1.105     kristaps 1058:        else if (0 == strcmp(np->child->string, "Sy"))
1.147     kristaps 1059:                np->norm->Bf.font = FONT_Sy;
1.210     schwarze 1060:        else
1.133     kristaps 1061:                mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE);
1.1       kristaps 1062:
1.105     kristaps 1063:        return(1);
1.1       kristaps 1064: }
                   1065:
                   1066: static int
1.31      kristaps 1067: post_lb(POST_ARGS)
                   1068: {
1.212     schwarze 1069:        struct mdoc_node        *n;
                   1070:        const char              *stdlibname;
                   1071:        char                    *libname;
1.127     kristaps 1072:
1.151     schwarze 1073:        check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
                   1074:
1.212     schwarze 1075:        n = mdoc->last->child;
1.127     kristaps 1076:
1.212     schwarze 1077:        assert(n);
                   1078:        assert(MDOC_TEXT == n->type);
1.127     kristaps 1079:
1.212     schwarze 1080:        if (NULL == (stdlibname = mdoc_a2lib(n->string)))
                   1081:                mandoc_asprintf(&libname,
                   1082:                    "library \\(lq%s\\(rq", n->string);
                   1083:        else
                   1084:                libname = mandoc_strdup(stdlibname);
1.127     kristaps 1085:
1.212     schwarze 1086:        free(n->string);
                   1087:        n->string = libname;
1.127     kristaps 1088:        return(1);
1.84      kristaps 1089: }
                   1090:
                   1091: static int
                   1092: post_eoln(POST_ARGS)
                   1093: {
                   1094:
1.133     kristaps 1095:        if (mdoc->last->child)
                   1096:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST);
                   1097:        return(1);
1.31      kristaps 1098: }
                   1099:
                   1100: static int
1.57      kristaps 1101: post_vt(POST_ARGS)
                   1102: {
                   1103:        const struct mdoc_node *n;
                   1104:
                   1105:        /*
                   1106:         * The Vt macro comes in both ELEM and BLOCK form, both of which
                   1107:         * have different syntaxes (yet more context-sensitive
1.152     schwarze 1108:         * behaviour).  ELEM types must have a child, which is already
                   1109:         * guaranteed by the in_line parsing routine; BLOCK types,
1.57      kristaps 1110:         * specifically the BODY, should only have TEXT children.
                   1111:         */
                   1112:
                   1113:        if (MDOC_BODY != mdoc->last->type)
                   1114:                return(1);
1.210     schwarze 1115:
1.57      kristaps 1116:        for (n = mdoc->last->child; n; n = n->next)
1.210     schwarze 1117:                if (MDOC_TEXT != n->type)
1.133     kristaps 1118:                        mdoc_nmsg(mdoc, n, MANDOCERR_CHILD);
1.57      kristaps 1119:
                   1120:        return(1);
                   1121: }
                   1122:
                   1123: static int
1.1       kristaps 1124: post_nm(POST_ARGS)
                   1125: {
1.129     kristaps 1126:
1.187     schwarze 1127:        if (NULL != mdoc->meta.name)
                   1128:                return(1);
1.1       kristaps 1129:
1.205     schwarze 1130:        mdoc_deroff(&mdoc->meta.name, mdoc->last);
1.129     kristaps 1131:
1.205     schwarze 1132:        if (NULL == mdoc->meta.name) {
1.187     schwarze 1133:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);
                   1134:                mdoc->meta.name = mandoc_strdup("UNKNOWN");
1.173     kristaps 1135:        }
1.129     kristaps 1136:        return(1);
1.1       kristaps 1137: }
                   1138:
1.123     kristaps 1139: static int
1.128     kristaps 1140: post_literal(POST_ARGS)
                   1141: {
1.210     schwarze 1142:
1.128     kristaps 1143:        /*
                   1144:         * The `Dl' (note "el" not "one") and `Bd' macros unset the
                   1145:         * MDOC_LITERAL flag as they leave.  Note that `Bd' only sets
                   1146:         * this in literal mode, but it doesn't hurt to just switch it
                   1147:         * off in general since displays can't be nested.
                   1148:         */
                   1149:
                   1150:        if (MDOC_BODY == mdoc->last->type)
1.134     kristaps 1151:                mdoc->flags &= ~MDOC_LITERAL;
1.128     kristaps 1152:
                   1153:        return(1);
                   1154: }
                   1155:
                   1156: static int
1.123     kristaps 1157: post_defaults(POST_ARGS)
                   1158: {
                   1159:        struct mdoc_node *nn;
                   1160:
                   1161:        /*
                   1162:         * The `Ar' defaults to "file ..." if no value is provided as an
1.129     kristaps 1163:         * argument; the `Mt' and `Pa' macros use "~"; the `Li' just
                   1164:         * gets an empty string.
1.123     kristaps 1165:         */
                   1166:
                   1167:        if (mdoc->last->child)
                   1168:                return(1);
1.210     schwarze 1169:
1.123     kristaps 1170:        nn = mdoc->last;
                   1171:        mdoc->next = MDOC_NEXT_CHILD;
                   1172:
                   1173:        switch (nn->tok) {
1.210     schwarze 1174:        case MDOC_Ar:
1.123     kristaps 1175:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "file"))
                   1176:                        return(0);
                   1177:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "..."))
                   1178:                        return(0);
                   1179:                break;
1.210     schwarze 1180:        case MDOC_At:
1.126     kristaps 1181:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "AT&T"))
                   1182:                        return(0);
                   1183:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "UNIX"))
                   1184:                        return(0);
                   1185:                break;
1.210     schwarze 1186:        case MDOC_Li:
1.123     kristaps 1187:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, ""))
                   1188:                        return(0);
                   1189:                break;
1.210     schwarze 1190:        case MDOC_Pa:
1.129     kristaps 1191:                /* FALLTHROUGH */
1.210     schwarze 1192:        case MDOC_Mt:
1.123     kristaps 1193:                if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "~"))
                   1194:                        return(0);
                   1195:                break;
                   1196:        default:
                   1197:                abort();
                   1198:                /* NOTREACHED */
1.210     schwarze 1199:        }
1.123     kristaps 1200:
                   1201:        mdoc->last = nn;
                   1202:        return(1);
                   1203: }
1.1       kristaps 1204:
                   1205: static int
                   1206: post_at(POST_ARGS)
                   1207: {
1.213     schwarze 1208:        struct mdoc_node        *n;
                   1209:        const char              *std_att;
                   1210:        char                    *att;
1.1       kristaps 1211:
1.126     kristaps 1212:        /*
                   1213:         * If we have a child, look it up in the standard keys.  If a
                   1214:         * key exist, use that instead of the child; if it doesn't,
                   1215:         * prefix "AT&T UNIX " to the existing data.
                   1216:         */
1.210     schwarze 1217:
1.213     schwarze 1218:        if (NULL == (n = mdoc->last->child))
1.1       kristaps 1219:                return(1);
1.126     kristaps 1220:
1.213     schwarze 1221:        assert(MDOC_TEXT == n->type);
                   1222:        if (NULL == (std_att = mdoc_a2att(n->string))) {
1.126     kristaps 1223:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT);
1.213     schwarze 1224:                mandoc_asprintf(&att, "AT&T UNIX %s", n->string);
                   1225:        } else
                   1226:                att = mandoc_strdup(std_att);
1.126     kristaps 1227:
1.213     schwarze 1228:        free(n->string);
                   1229:        n->string = att;
1.126     kristaps 1230:        return(1);
1.1       kristaps 1231: }
                   1232:
                   1233: static int
                   1234: post_an(POST_ARGS)
                   1235: {
1.107     kristaps 1236:        struct mdoc_node *np;
1.1       kristaps 1237:
1.107     kristaps 1238:        np = mdoc->last;
1.152     schwarze 1239:        if (AUTH__NONE == np->norm->An.auth) {
                   1240:                if (0 == np->child)
                   1241:                        check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0);
                   1242:        } else if (np->child)
1.151     schwarze 1243:                check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0);
1.133     kristaps 1244:
1.218   ! schwarze 1245:        return(1);
        !          1246: }
        !          1247:
        !          1248: static int
        !          1249: post_en(POST_ARGS)
        !          1250: {
        !          1251:
        !          1252:        if (MDOC_BLOCK == mdoc->last->type)
        !          1253:                mdoc->last->norm->Es = mdoc->last_es;
        !          1254:        return(1);
        !          1255: }
        !          1256:
        !          1257: static int
        !          1258: post_es(POST_ARGS)
        !          1259: {
        !          1260:
        !          1261:        mdoc->last_es = mdoc->last;
1.133     kristaps 1262:        return(1);
1.1       kristaps 1263: }
                   1264:
                   1265: static int
                   1266: post_it(POST_ARGS)
                   1267: {
1.162     kristaps 1268:        int               i, cols;
1.89      kristaps 1269:        enum mdoc_list    lt;
1.1       kristaps 1270:        struct mdoc_node *n, *c;
1.89      kristaps 1271:        enum mandocerr    er;
1.1       kristaps 1272:
                   1273:        if (MDOC_BLOCK != mdoc->last->type)
                   1274:                return(1);
                   1275:
                   1276:        n = mdoc->last->parent->parent;
1.147     kristaps 1277:        lt = n->norm->Bl.type;
1.89      kristaps 1278:
                   1279:        if (LIST__NONE == lt) {
1.79      kristaps 1280:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
1.133     kristaps 1281:                return(1);
1.79      kristaps 1282:        }
1.1       kristaps 1283:
1.89      kristaps 1284:        switch (lt) {
1.210     schwarze 1285:        case LIST_tag:
1.89      kristaps 1286:                if (mdoc->last->head->child)
1.1       kristaps 1287:                        break;
1.89      kristaps 1288:                /* FIXME: give this a dummy value. */
1.133     kristaps 1289:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS);
1.1       kristaps 1290:                break;
1.210     schwarze 1291:        case LIST_hang:
1.1       kristaps 1292:                /* FALLTHROUGH */
1.210     schwarze 1293:        case LIST_ohang:
1.1       kristaps 1294:                /* FALLTHROUGH */
1.210     schwarze 1295:        case LIST_inset:
1.1       kristaps 1296:                /* FALLTHROUGH */
1.210     schwarze 1297:        case LIST_diag:
1.1       kristaps 1298:                if (NULL == mdoc->last->head->child)
1.133     kristaps 1299:                        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS);
1.1       kristaps 1300:                break;
1.210     schwarze 1301:        case LIST_bullet:
1.1       kristaps 1302:                /* FALLTHROUGH */
1.210     schwarze 1303:        case LIST_dash:
1.1       kristaps 1304:                /* FALLTHROUGH */
1.210     schwarze 1305:        case LIST_enum:
1.1       kristaps 1306:                /* FALLTHROUGH */
1.210     schwarze 1307:        case LIST_hyphen:
1.108     schwarze 1308:                if (NULL == mdoc->last->body->child)
1.133     kristaps 1309:                        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY);
1.1       kristaps 1310:                /* FALLTHROUGH */
1.210     schwarze 1311:        case LIST_item:
1.1       kristaps 1312:                if (mdoc->last->head->child)
1.133     kristaps 1313:                        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST);
1.1       kristaps 1314:                break;
1.210     schwarze 1315:        case LIST_column:
1.147     kristaps 1316:                cols = (int)n->norm->Bl.ncols;
1.89      kristaps 1317:
1.87      kristaps 1318:                assert(NULL == mdoc->last->head->child);
1.89      kristaps 1319:
1.87      kristaps 1320:                if (NULL == mdoc->last->body->child)
1.133     kristaps 1321:                        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY);
1.87      kristaps 1322:
1.89      kristaps 1323:                for (i = 0, c = mdoc->last->child; c; c = c->next)
1.87      kristaps 1324:                        if (MDOC_BODY == c->type)
                   1325:                                i++;
1.38      kristaps 1326:
1.89      kristaps 1327:                if (i < cols)
                   1328:                        er = MANDOCERR_ARGCOUNT;
                   1329:                else if (i == cols || i == cols + 1)
1.38      kristaps 1330:                        break;
1.89      kristaps 1331:                else
                   1332:                        er = MANDOCERR_SYNTARGCOUNT;
1.38      kristaps 1333:
1.210     schwarze 1334:                mandoc_vmsg(er, mdoc->parse,
                   1335:                    mdoc->last->line, mdoc->last->pos,
                   1336:                    "columns == %d (have %d)", cols, i);
1.162     kristaps 1337:                return(MANDOCERR_ARGCOUNT == er);
1.1       kristaps 1338:        default:
                   1339:                break;
                   1340:        }
                   1341:
                   1342:        return(1);
                   1343: }
                   1344:
1.131     kristaps 1345: static int
1.210     schwarze 1346: post_bl_block(POST_ARGS)
1.131     kristaps 1347: {
1.189     schwarze 1348:        struct mdoc_node *n, *ni, *nc;
1.131     kristaps 1349:
                   1350:        /*
                   1351:         * These are fairly complicated, so we've broken them into two
                   1352:         * functions.  post_bl_block_tag() is called when a -tag is
                   1353:         * specified, but no -width (it must be guessed).  The second
                   1354:         * when a -width is specified (macro indicators must be
                   1355:         * rewritten into real lengths).
                   1356:         */
                   1357:
                   1358:        n = mdoc->last;
                   1359:
1.210     schwarze 1360:        if (LIST_tag == n->norm->Bl.type &&
                   1361:            NULL == n->norm->Bl.width) {
1.131     kristaps 1362:                if ( ! post_bl_block_tag(mdoc))
                   1363:                        return(0);
1.189     schwarze 1364:                assert(n->norm->Bl.width);
1.147     kristaps 1365:        } else if (NULL != n->norm->Bl.width) {
1.131     kristaps 1366:                if ( ! post_bl_block_width(mdoc))
                   1367:                        return(0);
1.189     schwarze 1368:                assert(n->norm->Bl.width);
                   1369:        }
1.131     kristaps 1370:
1.189     schwarze 1371:        for (ni = n->body->child; ni; ni = ni->next) {
                   1372:                if (NULL == ni->body)
                   1373:                        continue;
                   1374:                nc = ni->body->last;
                   1375:                while (NULL != nc) {
                   1376:                        switch (nc->tok) {
1.210     schwarze 1377:                        case MDOC_Pp:
1.189     schwarze 1378:                                /* FALLTHROUGH */
1.210     schwarze 1379:                        case MDOC_Lp:
1.189     schwarze 1380:                                /* FALLTHROUGH */
1.210     schwarze 1381:                        case MDOC_br:
1.189     schwarze 1382:                                break;
                   1383:                        default:
                   1384:                                nc = NULL;
                   1385:                                continue;
                   1386:                        }
                   1387:                        if (NULL == ni->next) {
                   1388:                                mdoc_nmsg(mdoc, nc, MANDOCERR_MOVEPAR);
                   1389:                                if ( ! mdoc_node_relink(mdoc, nc))
                   1390:                                        return(0);
                   1391:                        } else if (0 == n->norm->Bl.comp &&
                   1392:                            LIST_column != n->norm->Bl.type) {
                   1393:                                mdoc_nmsg(mdoc, nc, MANDOCERR_IGNPAR);
                   1394:                                mdoc_node_delete(mdoc, nc);
                   1395:                        } else
                   1396:                                break;
                   1397:                        nc = ni->body->last;
                   1398:                }
                   1399:        }
1.131     kristaps 1400:        return(1);
                   1401: }
                   1402:
                   1403: static int
                   1404: post_bl_block_width(POST_ARGS)
                   1405: {
                   1406:        size_t            width;
                   1407:        int               i;
                   1408:        enum mdoct        tok;
                   1409:        struct mdoc_node *n;
1.211     schwarze 1410:        char              buf[24];
1.131     kristaps 1411:
                   1412:        n = mdoc->last;
                   1413:
                   1414:        /*
                   1415:         * Calculate the real width of a list from the -width string,
                   1416:         * which may contain a macro (with a known default width), a
                   1417:         * literal string, or a scaling width.
                   1418:         *
                   1419:         * If the value to -width is a macro, then we re-write it to be
                   1420:         * the macro's width as set in share/tmac/mdoc/doc-common.
                   1421:         */
                   1422:
1.147     kristaps 1423:        if (0 == strcmp(n->norm->Bl.width, "Ds"))
1.131     kristaps 1424:                width = 6;
1.147     kristaps 1425:        else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width)))
1.131     kristaps 1426:                return(1);
1.161     kristaps 1427:        else if (0 == (width = macro2len(tok)))  {
1.133     kristaps 1428:                mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH);
                   1429:                return(1);
                   1430:        }
1.131     kristaps 1431:
                   1432:        /* The value already exists: free and reallocate it. */
                   1433:
                   1434:        assert(n->args);
                   1435:
1.210     schwarze 1436:        for (i = 0; i < (int)n->args->argc; i++)
1.131     kristaps 1437:                if (MDOC_Width == n->args->argv[i].arg)
                   1438:                        break;
                   1439:
                   1440:        assert(i < (int)n->args->argc);
                   1441:
1.211     schwarze 1442:        (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)width);
1.131     kristaps 1443:        free(n->args->argv[i].value[0]);
                   1444:        n->args->argv[i].value[0] = mandoc_strdup(buf);
                   1445:
                   1446:        /* Set our width! */
1.147     kristaps 1447:        n->norm->Bl.width = n->args->argv[i].value[0];
1.131     kristaps 1448:        return(1);
                   1449: }
                   1450:
                   1451: static int
                   1452: post_bl_block_tag(POST_ARGS)
                   1453: {
                   1454:        struct mdoc_node *n, *nn;
                   1455:        size_t            sz, ssz;
                   1456:        int               i;
1.211     schwarze 1457:        char              buf[24];
1.131     kristaps 1458:
                   1459:        /*
                   1460:         * Calculate the -width for a `Bl -tag' list if it hasn't been
                   1461:         * provided.  Uses the first head macro.  NOTE AGAIN: this is
                   1462:         * ONLY if the -width argument has NOT been provided.  See
                   1463:         * post_bl_block_width() for converting the -width string.
                   1464:         */
                   1465:
                   1466:        sz = 10;
                   1467:        n = mdoc->last;
                   1468:
                   1469:        for (nn = n->body->child; nn; nn = nn->next) {
                   1470:                if (MDOC_It != nn->tok)
                   1471:                        continue;
                   1472:
                   1473:                assert(MDOC_BLOCK == nn->type);
                   1474:                nn = nn->head->child;
                   1475:
1.138     kristaps 1476:                if (nn == NULL)
1.131     kristaps 1477:                        break;
                   1478:
                   1479:                if (MDOC_TEXT == nn->type) {
                   1480:                        sz = strlen(nn->string) + 1;
                   1481:                        break;
                   1482:                }
                   1483:
1.161     kristaps 1484:                if (0 != (ssz = macro2len(nn->tok)))
1.131     kristaps 1485:                        sz = ssz;
                   1486:
                   1487:                break;
1.210     schwarze 1488:        }
1.131     kristaps 1489:
                   1490:        /* Defaults to ten ens. */
                   1491:
1.211     schwarze 1492:        (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)sz);
1.131     kristaps 1493:
                   1494:        /*
                   1495:         * We have to dynamically add this to the macro's argument list.
                   1496:         * We're guaranteed that a MDOC_Width doesn't already exist.
                   1497:         */
                   1498:
                   1499:        assert(n->args);
                   1500:        i = (int)(n->args->argc)++;
                   1501:
1.214     schwarze 1502:        n->args->argv = mandoc_reallocarray(n->args->argv,
                   1503:            n->args->argc, sizeof(struct mdoc_argv));
1.131     kristaps 1504:
                   1505:        n->args->argv[i].arg = MDOC_Width;
                   1506:        n->args->argv[i].line = n->line;
                   1507:        n->args->argv[i].pos = n->pos;
                   1508:        n->args->argv[i].sz = 1;
                   1509:        n->args->argv[i].value = mandoc_malloc(sizeof(char *));
                   1510:        n->args->argv[i].value[0] = mandoc_strdup(buf);
                   1511:
                   1512:        /* Set our width! */
1.147     kristaps 1513:        n->norm->Bl.width = n->args->argv[i].value[0];
1.131     kristaps 1514:        return(1);
                   1515: }
                   1516:
1.1       kristaps 1517: static int
1.210     schwarze 1518: post_bl_head(POST_ARGS)
1.14      kristaps 1519: {
1.130     kristaps 1520:        struct mdoc_node *np, *nn, *nnp;
                   1521:        int               i, j;
1.14      kristaps 1522:
1.147     kristaps 1523:        if (LIST_column != mdoc->last->norm->Bl.type)
1.130     kristaps 1524:                /* FIXME: this should be ERROR class... */
                   1525:                return(hwarn_eq0(mdoc));
1.14      kristaps 1526:
1.130     kristaps 1527:        /*
                   1528:         * Convert old-style lists, where the column width specifiers
                   1529:         * trail as macro parameters, to the new-style ("normal-form")
                   1530:         * lists where they're argument values following -column.
                   1531:         */
                   1532:
                   1533:        /* First, disallow both types and allow normal-form. */
                   1534:
1.210     schwarze 1535:        /*
1.130     kristaps 1536:         * TODO: technically, we can accept both and just merge the two
                   1537:         * lists, but I'll leave that for another day.
                   1538:         */
                   1539:
1.147     kristaps 1540:        if (mdoc->last->norm->Bl.ncols && mdoc->last->nchild) {
1.130     kristaps 1541:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_COLUMNS);
                   1542:                return(0);
                   1543:        } else if (NULL == mdoc->last->child)
1.90      kristaps 1544:                return(1);
1.130     kristaps 1545:
                   1546:        np = mdoc->last->parent;
                   1547:        assert(np->args);
                   1548:
1.210     schwarze 1549:        for (j = 0; j < (int)np->args->argc; j++)
1.130     kristaps 1550:                if (MDOC_Column == np->args->argv[j].arg)
                   1551:                        break;
                   1552:
                   1553:        assert(j < (int)np->args->argc);
                   1554:        assert(0 == np->args->argv[j].sz);
                   1555:
                   1556:        /*
1.169     kristaps 1557:         * Accommodate for new-style groff column syntax.  Shuffle the
1.130     kristaps 1558:         * child nodes, all of which must be TEXT, as arguments for the
                   1559:         * column field.  Then, delete the head children.
                   1560:         */
                   1561:
                   1562:        np->args->argv[j].sz = (size_t)mdoc->last->nchild;
1.214     schwarze 1563:        np->args->argv[j].value = mandoc_reallocarray(NULL,
                   1564:            (size_t)mdoc->last->nchild, sizeof(char *));
1.130     kristaps 1565:
1.147     kristaps 1566:        mdoc->last->norm->Bl.ncols = np->args->argv[j].sz;
1.175     kristaps 1567:        mdoc->last->norm->Bl.cols = (void *)np->args->argv[j].value;
1.130     kristaps 1568:
                   1569:        for (i = 0, nn = mdoc->last->child; nn; i++) {
                   1570:                np->args->argv[j].value[i] = nn->string;
                   1571:                nn->string = NULL;
                   1572:                nnp = nn;
                   1573:                nn = nn->next;
                   1574:                mdoc_node_delete(NULL, nnp);
1.65      kristaps 1575:        }
1.14      kristaps 1576:
1.130     kristaps 1577:        mdoc->last->nchild = 0;
                   1578:        mdoc->last->child = NULL;
                   1579:
                   1580:        return(1);
1.14      kristaps 1581: }
                   1582:
                   1583: static int
1.1       kristaps 1584: post_bl(POST_ARGS)
                   1585: {
1.195     schwarze 1586:        struct mdoc_node        *nparent, *nprev; /* of the Bl block */
                   1587:        struct mdoc_node        *nblock, *nbody;  /* of the Bl */
                   1588:        struct mdoc_node        *nchild, *nnext;  /* of the Bl body */
                   1589:
                   1590:        nbody = mdoc->last;
                   1591:        switch (nbody->type) {
1.210     schwarze 1592:        case MDOC_BLOCK:
1.195     schwarze 1593:                return(post_bl_block(mdoc));
1.210     schwarze 1594:        case MDOC_HEAD:
1.14      kristaps 1595:                return(post_bl_head(mdoc));
1.210     schwarze 1596:        case MDOC_BODY:
1.195     schwarze 1597:                break;
                   1598:        default:
1.1       kristaps 1599:                return(1);
1.195     schwarze 1600:        }
1.1       kristaps 1601:
1.195     schwarze 1602:        nchild = nbody->child;
                   1603:        while (NULL != nchild) {
                   1604:                if (MDOC_It == nchild->tok || MDOC_Sm == nchild->tok) {
                   1605:                        nchild = nchild->next;
1.55      kristaps 1606:                        continue;
1.141     kristaps 1607:                }
                   1608:
1.195     schwarze 1609:                mdoc_nmsg(mdoc, nchild, MANDOCERR_CHILD);
                   1610:
                   1611:                /*
                   1612:                 * Move the node out of the Bl block.
                   1613:                 * First, collect all required node pointers.
                   1614:                 */
                   1615:
                   1616:                nblock  = nbody->parent;
                   1617:                nprev   = nblock->prev;
                   1618:                nparent = nblock->parent;
                   1619:                nnext   = nchild->next;
                   1620:
                   1621:                /*
                   1622:                 * Unlink this child.
                   1623:                 */
                   1624:
                   1625:                assert(NULL == nchild->prev);
                   1626:                if (0 == --nbody->nchild) {
                   1627:                        nbody->child = NULL;
                   1628:                        nbody->last  = NULL;
                   1629:                        assert(NULL == nnext);
                   1630:                } else {
                   1631:                        nbody->child = nnext;
                   1632:                        nnext->prev = NULL;
                   1633:                }
                   1634:
                   1635:                /*
                   1636:                 * Relink this child.
                   1637:                 */
                   1638:
                   1639:                nchild->parent = nparent;
                   1640:                nchild->prev   = nprev;
                   1641:                nchild->next   = nblock;
                   1642:
                   1643:                nblock->prev = nchild;
                   1644:                nparent->nchild++;
                   1645:                if (NULL == nprev)
                   1646:                        nparent->child = nchild;
                   1647:                else
                   1648:                        nprev->next = nchild;
                   1649:
                   1650:                nchild = nnext;
1.1       kristaps 1651:        }
                   1652:
                   1653:        return(1);
                   1654: }
                   1655:
                   1656: static int
                   1657: ebool(struct mdoc *mdoc)
                   1658: {
                   1659:
1.151     schwarze 1660:        if (NULL == mdoc->last->child) {
                   1661:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_MACROEMPTY);
                   1662:                mdoc_node_delete(mdoc, mdoc->last);
1.133     kristaps 1663:                return(1);
1.151     schwarze 1664:        }
                   1665:        check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
1.133     kristaps 1666:
                   1667:        assert(MDOC_TEXT == mdoc->last->child->type);
1.1       kristaps 1668:
1.197     schwarze 1669:        if (0 == strcmp(mdoc->last->child->string, "on")) {
                   1670:                if (MDOC_Sm == mdoc->last->tok)
                   1671:                        mdoc->flags &= ~MDOC_SMOFF;
1.1       kristaps 1672:                return(1);
1.197     schwarze 1673:        }
                   1674:        if (0 == strcmp(mdoc->last->child->string, "off")) {
                   1675:                if (MDOC_Sm == mdoc->last->tok)
                   1676:                        mdoc->flags |= MDOC_SMOFF;
1.133     kristaps 1677:                return(1);
1.197     schwarze 1678:        }
1.133     kristaps 1679:
                   1680:        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADBOOL);
                   1681:        return(1);
1.1       kristaps 1682: }
                   1683:
                   1684: static int
                   1685: post_root(POST_ARGS)
                   1686: {
1.216     schwarze 1687:        int               ret;
1.133     kristaps 1688:        struct mdoc_node *n;
1.1       kristaps 1689:
1.216     schwarze 1690:        ret = 1;
1.133     kristaps 1691:
                   1692:        /* Check that we have a finished prologue. */
                   1693:
                   1694:        if ( ! (MDOC_PBODY & mdoc->flags)) {
1.216     schwarze 1695:                ret = 0;
1.79      kristaps 1696:                mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG);
1.133     kristaps 1697:        }
                   1698:
                   1699:        n = mdoc->first;
                   1700:        assert(n);
1.210     schwarze 1701:
1.133     kristaps 1702:        /* Check that we begin with a proper `Sh'. */
                   1703:
1.216     schwarze 1704:        if (NULL == n->child)
                   1705:                mdoc_nmsg(mdoc, n, MANDOCERR_DOC_EMPTY);
1.217     schwarze 1706:        else if (MDOC_Sh != n->child->tok)
                   1707:                mandoc_msg(MANDOCERR_SEC_BEFORE, mdoc->parse,
                   1708:                    n->child->line, n->child->pos,
                   1709:                    mdoc_macronames[n->child->tok]);
1.1       kristaps 1710:
1.216     schwarze 1711:        return(ret);
1.1       kristaps 1712: }
                   1713:
                   1714: static int
                   1715: post_st(POST_ARGS)
                   1716: {
1.151     schwarze 1717:        struct mdoc_node         *ch;
                   1718:        const char               *p;
1.128     kristaps 1719:
1.151     schwarze 1720:        if (NULL == (ch = mdoc->last->child)) {
                   1721:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_MACROEMPTY);
                   1722:                mdoc_node_delete(mdoc, mdoc->last);
                   1723:                return(1);
                   1724:        }
1.128     kristaps 1725:
1.151     schwarze 1726:        assert(MDOC_TEXT == ch->type);
1.128     kristaps 1727:
1.151     schwarze 1728:        if (NULL == (p = mdoc_a2st(ch->string))) {
1.128     kristaps 1729:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADSTANDARD);
                   1730:                mdoc_node_delete(mdoc, mdoc->last);
                   1731:        } else {
1.151     schwarze 1732:                free(ch->string);
                   1733:                ch->string = mandoc_strdup(p);
1.128     kristaps 1734:        }
1.1       kristaps 1735:
1.128     kristaps 1736:        return(1);
1.1       kristaps 1737: }
                   1738:
                   1739: static int
1.43      kristaps 1740: post_rs(POST_ARGS)
                   1741: {
1.122     kristaps 1742:        struct mdoc_node *nn, *next, *prev;
                   1743:        int               i, j;
1.43      kristaps 1744:
1.151     schwarze 1745:        switch (mdoc->last->type) {
1.210     schwarze 1746:        case MDOC_HEAD:
1.151     schwarze 1747:                check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0);
                   1748:                return(1);
1.210     schwarze 1749:        case MDOC_BODY:
1.151     schwarze 1750:                if (mdoc->last->child)
                   1751:                        break;
                   1752:                check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0);
                   1753:                return(1);
                   1754:        default:
1.43      kristaps 1755:                return(1);
1.151     schwarze 1756:        }
1.43      kristaps 1757:
1.122     kristaps 1758:        /*
                   1759:         * Make sure only certain types of nodes are allowed within the
                   1760:         * the `Rs' body.  Delete offending nodes and raise a warning.
                   1761:         * Do this before re-ordering for the sake of clarity.
                   1762:         */
                   1763:
                   1764:        next = NULL;
                   1765:        for (nn = mdoc->last->child; nn; nn = next) {
                   1766:                for (i = 0; i < RSORD_MAX; i++)
                   1767:                        if (nn->tok == rsord[i])
                   1768:                                break;
                   1769:
                   1770:                if (i < RSORD_MAX) {
1.153     kristaps 1771:                        if (MDOC__J == rsord[i] || MDOC__B == rsord[i])
                   1772:                                mdoc->last->norm->Rs.quote_T++;
1.122     kristaps 1773:                        next = nn->next;
                   1774:                        continue;
                   1775:                }
                   1776:
                   1777:                next = nn->next;
                   1778:                mdoc_nmsg(mdoc, nn, MANDOCERR_CHILD);
                   1779:                mdoc_node_delete(mdoc, nn);
                   1780:        }
1.178     joerg    1781:
1.179     schwarze 1782:        /*
                   1783:         * Nothing to sort if only invalid nodes were found
                   1784:         * inside the `Rs' body.
                   1785:         */
                   1786:
1.178     joerg    1787:        if (NULL == mdoc->last->child)
                   1788:                return(1);
1.122     kristaps 1789:
                   1790:        /*
                   1791:         * The full `Rs' block needs special handling to order the
                   1792:         * sub-elements according to `rsord'.  Pick through each element
                   1793:         * and correctly order it.  This is a insertion sort.
                   1794:         */
                   1795:
                   1796:        next = NULL;
                   1797:        for (nn = mdoc->last->child->next; nn; nn = next) {
                   1798:                /* Determine order of `nn'. */
                   1799:                for (i = 0; i < RSORD_MAX; i++)
                   1800:                        if (rsord[i] == nn->tok)
                   1801:                                break;
                   1802:
1.210     schwarze 1803:                /*
1.122     kristaps 1804:                 * Remove `nn' from the chain.  This somewhat
                   1805:                 * repeats mdoc_node_unlink(), but since we're
                   1806:                 * just re-ordering, there's no need for the
                   1807:                 * full unlink process.
                   1808:                 */
1.210     schwarze 1809:
1.122     kristaps 1810:                if (NULL != (next = nn->next))
                   1811:                        next->prev = nn->prev;
                   1812:
                   1813:                if (NULL != (prev = nn->prev))
                   1814:                        prev->next = nn->next;
                   1815:
                   1816:                nn->prev = nn->next = NULL;
                   1817:
1.210     schwarze 1818:                /*
1.122     kristaps 1819:                 * Scan back until we reach a node that's
                   1820:                 * ordered before `nn'.
                   1821:                 */
                   1822:
                   1823:                for ( ; prev ; prev = prev->prev) {
                   1824:                        /* Determine order of `prev'. */
                   1825:                        for (j = 0; j < RSORD_MAX; j++)
                   1826:                                if (rsord[j] == prev->tok)
                   1827:                                        break;
                   1828:
                   1829:                        if (j <= i)
                   1830:                                break;
                   1831:                }
                   1832:
                   1833:                /*
                   1834:                 * Set `nn' back into its correct place in front
                   1835:                 * of the `prev' node.
                   1836:                 */
                   1837:
                   1838:                nn->prev = prev;
                   1839:
                   1840:                if (prev) {
                   1841:                        if (prev->next)
                   1842:                                prev->next->prev = nn;
                   1843:                        nn->next = prev->next;
                   1844:                        prev->next = nn;
                   1845:                } else {
                   1846:                        mdoc->last->child->prev = nn;
                   1847:                        nn->next = mdoc->last->child;
                   1848:                        mdoc->last->child = nn;
1.43      kristaps 1849:                }
1.122     kristaps 1850:        }
1.43      kristaps 1851:
1.196     schwarze 1852:        return(1);
                   1853: }
                   1854:
                   1855: /*
                   1856:  * For some arguments of some macros,
                   1857:  * convert all breakable hyphens into ASCII_HYPH.
                   1858:  */
                   1859: static int
                   1860: post_hyph(POST_ARGS)
                   1861: {
                   1862:        struct mdoc_node        *n, *nch;
                   1863:        char                    *cp;
                   1864:
                   1865:        n = mdoc->last;
                   1866:        switch (n->type) {
1.210     schwarze 1867:        case MDOC_HEAD:
1.196     schwarze 1868:                if (MDOC_Sh == n->tok || MDOC_Ss == n->tok)
                   1869:                        break;
                   1870:                return(1);
1.210     schwarze 1871:        case MDOC_BODY:
1.196     schwarze 1872:                if (MDOC_D1 == n->tok || MDOC_Nd == n->tok)
                   1873:                        break;
                   1874:                return(1);
1.210     schwarze 1875:        case MDOC_ELEM:
1.196     schwarze 1876:                break;
                   1877:        default:
                   1878:                return(1);
                   1879:        }
                   1880:
                   1881:        for (nch = n->child; nch; nch = nch->next) {
                   1882:                if (MDOC_TEXT != nch->type)
                   1883:                        continue;
                   1884:                cp = nch->string;
1.202     schwarze 1885:                if ('\0' == *cp)
1.196     schwarze 1886:                        continue;
                   1887:                while ('\0' != *(++cp))
                   1888:                        if ('-' == *cp &&
                   1889:                            isalpha((unsigned char)cp[-1]) &&
                   1890:                            isalpha((unsigned char)cp[1]))
                   1891:                                *cp = ASCII_HYPH;
                   1892:        }
1.155     kristaps 1893:        return(1);
                   1894: }
                   1895:
                   1896: static int
                   1897: post_ns(POST_ARGS)
                   1898: {
                   1899:
                   1900:        if (MDOC_LINE & mdoc->last->flags)
                   1901:                mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNNS);
1.43      kristaps 1902:        return(1);
                   1903: }
                   1904:
                   1905: static int
1.1       kristaps 1906: post_sh(POST_ARGS)
                   1907: {
                   1908:
                   1909:        if (MDOC_HEAD == mdoc->last->type)
                   1910:                return(post_sh_head(mdoc));
                   1911:        if (MDOC_BODY == mdoc->last->type)
                   1912:                return(post_sh_body(mdoc));
                   1913:
                   1914:        return(1);
                   1915: }
                   1916:
                   1917: static int
                   1918: post_sh_body(POST_ARGS)
                   1919: {
                   1920:        struct mdoc_node *n;
                   1921:
1.29      kristaps 1922:        if (SEC_NAME != mdoc->lastsec)
1.1       kristaps 1923:                return(1);
                   1924:
                   1925:        /*
                   1926:         * Warn if the NAME section doesn't contain the `Nm' and `Nd'
                   1927:         * macros (can have multiple `Nm' and one `Nd').  Note that the
                   1928:         * children of the BODY declaration can also be "text".
                   1929:         */
                   1930:
1.133     kristaps 1931:        if (NULL == (n = mdoc->last->child)) {
1.217     schwarze 1932:                mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
                   1933:                    mdoc->last->line, mdoc->last->pos, "empty");
1.133     kristaps 1934:                return(1);
                   1935:        }
1.1       kristaps 1936:
                   1937:        for ( ; n && n->next; n = n->next) {
                   1938:                if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
                   1939:                        continue;
1.28      kristaps 1940:                if (MDOC_TEXT == n->type)
                   1941:                        continue;
1.217     schwarze 1942:                mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
                   1943:                    n->line, n->pos, mdoc_macronames[n->tok]);
1.1       kristaps 1944:        }
                   1945:
1.41      kristaps 1946:        assert(n);
1.27      kristaps 1947:        if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok)
1.1       kristaps 1948:                return(1);
1.133     kristaps 1949:
1.217     schwarze 1950:        mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
                   1951:            n->line, n->pos, mdoc_macronames[n->tok]);
1.133     kristaps 1952:        return(1);
1.1       kristaps 1953: }
                   1954:
                   1955: static int
                   1956: post_sh_head(POST_ARGS)
                   1957: {
1.181     schwarze 1958:        struct mdoc_node *n;
1.217     schwarze 1959:        const char      *goodsec;
1.209     schwarze 1960:        char            *secname;
1.132     kristaps 1961:        enum mdoc_sec    sec;
1.1       kristaps 1962:
                   1963:        /*
                   1964:         * Process a new section.  Sections are either "named" or
1.125     kristaps 1965:         * "custom".  Custom sections are user-defined, while named ones
                   1966:         * follow a conventional order and may only appear in certain
                   1967:         * manual sections.
1.1       kristaps 1968:         */
                   1969:
1.205     schwarze 1970:        secname = NULL;
1.173     kristaps 1971:        sec = SEC_CUSTOM;
1.209     schwarze 1972:        mdoc_deroff(&secname, mdoc->last);
                   1973:        sec = NULL == secname ? SEC_CUSTOM : a2sec(secname);
1.1       kristaps 1974:
1.125     kristaps 1975:        /* The NAME should be first. */
1.1       kristaps 1976:
1.72      kristaps 1977:        if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
1.217     schwarze 1978:                mandoc_msg(MANDOCERR_NAMESEC_FIRST, mdoc->parse,
                   1979:                    mdoc->last->line, mdoc->last->pos, secname);
1.125     kristaps 1980:
                   1981:        /* The SYNOPSIS gets special attention in other areas. */
                   1982:
1.194     schwarze 1983:        if (SEC_SYNOPSIS == sec) {
1.198     schwarze 1984:                roff_setreg(mdoc->roff, "nS", 1, '=');
1.125     kristaps 1985:                mdoc->flags |= MDOC_SYNOPSIS;
1.194     schwarze 1986:        } else {
1.198     schwarze 1987:                roff_setreg(mdoc->roff, "nS", 0, '=');
1.125     kristaps 1988:                mdoc->flags &= ~MDOC_SYNOPSIS;
1.194     schwarze 1989:        }
1.125     kristaps 1990:
                   1991:        /* Mark our last section. */
                   1992:
                   1993:        mdoc->lastsec = sec;
1.181     schwarze 1994:
                   1995:        /*
                   1996:         * Set the section attribute for the current HEAD, for its
                   1997:         * parent BLOCK, and for the HEAD children; the latter can
                   1998:         * only be TEXT nodes, so no recursion is needed.
                   1999:         * For other blocks and elements, including .Sh BODY, this is
                   2000:         * done when allocating the node data structures, but for .Sh
                   2001:         * BLOCK and HEAD, the section is still unknown at that time.
                   2002:         */
                   2003:
                   2004:        mdoc->last->parent->sec = sec;
                   2005:        mdoc->last->sec = sec;
                   2006:        for (n = mdoc->last->child; n; n = n->next)
                   2007:                n->sec = sec;
1.125     kristaps 2008:
                   2009:        /* We don't care about custom sections after this. */
1.72      kristaps 2010:
1.209     schwarze 2011:        if (SEC_CUSTOM == sec) {
                   2012:                free(secname);
1.1       kristaps 2013:                return(1);
1.209     schwarze 2014:        }
1.72      kristaps 2015:
1.125     kristaps 2016:        /*
                   2017:         * Check whether our non-custom section is being repeated or is
                   2018:         * out of order.
                   2019:         */
                   2020:
1.1       kristaps 2021:        if (sec == mdoc->lastnamed)
1.217     schwarze 2022:                mandoc_msg(MANDOCERR_SEC_REP, mdoc->parse,
                   2023:                    mdoc->last->line, mdoc->last->pos, secname);
1.72      kristaps 2024:
1.1       kristaps 2025:        if (sec < mdoc->lastnamed)
1.217     schwarze 2026:                mandoc_msg(MANDOCERR_SEC_ORDER, mdoc->parse,
                   2027:                    mdoc->last->line, mdoc->last->pos, secname);
1.125     kristaps 2028:
                   2029:        /* Mark the last named section. */
                   2030:
                   2031:        mdoc->lastnamed = sec;
                   2032:
                   2033:        /* Check particular section/manual conventions. */
1.1       kristaps 2034:
1.125     kristaps 2035:        assert(mdoc->meta.msec);
1.1       kristaps 2036:
1.217     schwarze 2037:        goodsec = NULL;
1.1       kristaps 2038:        switch (sec) {
1.210     schwarze 2039:        case SEC_ERRORS:
1.207     schwarze 2040:                if (*mdoc->meta.msec == '4')
                   2041:                        break;
1.217     schwarze 2042:                goodsec = "2, 3, 4, 9";
1.207     schwarze 2043:                /* FALLTHROUGH */
1.210     schwarze 2044:        case SEC_RETURN_VALUES:
1.125     kristaps 2045:                /* FALLTHROUGH */
1.210     schwarze 2046:        case SEC_LIBRARY:
1.78      kristaps 2047:                if (*mdoc->meta.msec == '2')
                   2048:                        break;
                   2049:                if (*mdoc->meta.msec == '3')
                   2050:                        break;
1.217     schwarze 2051:                if (NULL == goodsec)
                   2052:                        goodsec = "2, 3, 9";
1.208     schwarze 2053:                /* FALLTHROUGH */
1.210     schwarze 2054:        case SEC_CONTEXT:
1.78      kristaps 2055:                if (*mdoc->meta.msec == '9')
1.1       kristaps 2056:                        break;
1.217     schwarze 2057:                if (NULL == goodsec)
                   2058:                        goodsec = "9";
                   2059:                mandoc_vmsg(MANDOCERR_SEC_MSEC, mdoc->parse,
                   2060:                    mdoc->last->line, mdoc->last->pos,
                   2061:                    "%s for %s only", secname, goodsec);
1.125     kristaps 2062:                break;
1.1       kristaps 2063:        default:
                   2064:                break;
                   2065:        }
1.140     kristaps 2066:
1.209     schwarze 2067:        free(secname);
1.140     kristaps 2068:        return(1);
                   2069: }
                   2070:
                   2071: static int
                   2072: post_ignpar(POST_ARGS)
                   2073: {
                   2074:        struct mdoc_node *np;
                   2075:
                   2076:        if (MDOC_BODY != mdoc->last->type)
                   2077:                return(1);
                   2078:
1.143     kristaps 2079:        if (NULL != (np = mdoc->last->child))
1.140     kristaps 2080:                if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
                   2081:                        mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
                   2082:                        mdoc_node_delete(mdoc, np);
                   2083:                }
                   2084:
                   2085:        if (NULL != (np = mdoc->last->last))
                   2086:                if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
                   2087:                        mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
                   2088:                        mdoc_node_delete(mdoc, np);
                   2089:                }
1.1       kristaps 2090:
1.117     kristaps 2091:        return(1);
                   2092: }
                   2093:
                   2094: static int
1.124     kristaps 2095: pre_par(PRE_ARGS)
1.117     kristaps 2096: {
                   2097:
1.118     kristaps 2098:        if (NULL == mdoc->last)
                   2099:                return(1);
1.141     kristaps 2100:        if (MDOC_ELEM != n->type && MDOC_BLOCK != n->type)
                   2101:                return(1);
1.118     kristaps 2102:
1.210     schwarze 2103:        /*
1.124     kristaps 2104:         * Don't allow prior `Lp' or `Pp' prior to a paragraph-type
                   2105:         * block:  `Lp', `Pp', or non-compact `Bd' or `Bl'.
                   2106:         */
1.118     kristaps 2107:
1.188     schwarze 2108:        if (MDOC_Pp != mdoc->last->tok &&
                   2109:            MDOC_Lp != mdoc->last->tok &&
                   2110:            MDOC_br != mdoc->last->tok)
1.117     kristaps 2111:                return(1);
1.147     kristaps 2112:        if (MDOC_Bl == n->tok && n->norm->Bl.comp)
1.117     kristaps 2113:                return(1);
1.147     kristaps 2114:        if (MDOC_Bd == n->tok && n->norm->Bd.comp)
1.141     kristaps 2115:                return(1);
1.147     kristaps 2116:        if (MDOC_It == n->tok && n->parent->norm->Bl.comp)
1.117     kristaps 2117:                return(1);
1.188     schwarze 2118:
                   2119:        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
                   2120:        mdoc_node_delete(mdoc, mdoc->last);
                   2121:        return(1);
                   2122: }
                   2123:
                   2124: static int
                   2125: post_par(POST_ARGS)
                   2126: {
                   2127:
                   2128:        if (MDOC_ELEM != mdoc->last->type &&
                   2129:            MDOC_BLOCK != mdoc->last->type)
                   2130:                return(1);
                   2131:
                   2132:        if (NULL == mdoc->last->prev) {
                   2133:                if (MDOC_Sh != mdoc->last->parent->tok &&
                   2134:                    MDOC_Ss != mdoc->last->parent->tok)
                   2135:                        return(1);
                   2136:        } else {
                   2137:                if (MDOC_Pp != mdoc->last->prev->tok &&
                   2138:                    MDOC_Lp != mdoc->last->prev->tok &&
                   2139:                    (MDOC_br != mdoc->last->tok ||
                   2140:                     (MDOC_sp != mdoc->last->prev->tok &&
                   2141:                      MDOC_br != mdoc->last->prev->tok)))
                   2142:                        return(1);
                   2143:        }
1.117     kristaps 2144:
                   2145:        mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
                   2146:        mdoc_node_delete(mdoc, mdoc->last);
1.128     kristaps 2147:        return(1);
                   2148: }
                   2149:
                   2150: static int
                   2151: pre_literal(PRE_ARGS)
                   2152: {
                   2153:
                   2154:        if (MDOC_BODY != n->type)
                   2155:                return(1);
                   2156:
                   2157:        /*
                   2158:         * The `Dl' (note "el" not "one") and `Bd -literal' and `Bd
                   2159:         * -unfilled' macros set MDOC_LITERAL on entrance to the body.
                   2160:         */
                   2161:
                   2162:        switch (n->tok) {
1.210     schwarze 2163:        case MDOC_Dl:
1.128     kristaps 2164:                mdoc->flags |= MDOC_LITERAL;
                   2165:                break;
1.210     schwarze 2166:        case MDOC_Bd:
1.147     kristaps 2167:                if (DISP_literal == n->norm->Bd.type)
1.128     kristaps 2168:                        mdoc->flags |= MDOC_LITERAL;
1.147     kristaps 2169:                if (DISP_unfilled == n->norm->Bd.type)
1.128     kristaps 2170:                        mdoc->flags |= MDOC_LITERAL;
                   2171:                break;
                   2172:        default:
                   2173:                abort();
                   2174:                /* NOTREACHED */
                   2175:        }
1.210     schwarze 2176:
1.1       kristaps 2177:        return(1);
                   2178: }
1.132     kristaps 2179:
                   2180: static int
                   2181: post_dd(POST_ARGS)
                   2182: {
                   2183:        struct mdoc_node *n;
1.205     schwarze 2184:        char             *datestr;
1.132     kristaps 2185:
1.158     schwarze 2186:        if (mdoc->meta.date)
                   2187:                free(mdoc->meta.date);
                   2188:
1.132     kristaps 2189:        n = mdoc->last;
1.158     schwarze 2190:        if (NULL == n->child || '\0' == n->child->string[0]) {
1.200     schwarze 2191:                mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
                   2192:                    mandoc_normdate(mdoc->parse, NULL, n->line, n->pos);
1.133     kristaps 2193:                return(1);
1.132     kristaps 2194:        }
                   2195:
1.205     schwarze 2196:        datestr = NULL;
                   2197:        mdoc_deroff(&datestr, n);
                   2198:        if (mdoc->quick)
                   2199:                mdoc->meta.date = datestr;
                   2200:        else {
                   2201:                mdoc->meta.date = mandoc_normdate(mdoc->parse,
                   2202:                    datestr, n->line, n->pos);
                   2203:                free(datestr);
1.173     kristaps 2204:        }
1.132     kristaps 2205:        return(1);
                   2206: }
                   2207:
                   2208: static int
                   2209: post_dt(POST_ARGS)
                   2210: {
                   2211:        struct mdoc_node *nn, *n;
                   2212:        const char       *cp;
                   2213:        char             *p;
                   2214:
                   2215:        n = mdoc->last;
                   2216:
                   2217:        if (mdoc->meta.title)
                   2218:                free(mdoc->meta.title);
                   2219:        if (mdoc->meta.vol)
                   2220:                free(mdoc->meta.vol);
                   2221:        if (mdoc->meta.arch)
                   2222:                free(mdoc->meta.arch);
                   2223:
                   2224:        mdoc->meta.title = mdoc->meta.vol = mdoc->meta.arch = NULL;
                   2225:
1.217     schwarze 2226:        /* First check that all characters are uppercase. */
1.132     kristaps 2227:
                   2228:        if (NULL != (nn = n->child))
                   2229:                for (p = nn->string; *p; p++) {
1.171     kristaps 2230:                        if (toupper((unsigned char)*p) == *p)
1.132     kristaps 2231:                                continue;
1.217     schwarze 2232:                        mandoc_msg(MANDOCERR_TITLE_CASE,
                   2233:                            mdoc->parse, nn->line,
                   2234:                            nn->pos + (p - nn->string),
                   2235:                            nn->string);
1.132     kristaps 2236:                        break;
                   2237:                }
                   2238:
1.210     schwarze 2239:        /* Handles: `.Dt'
                   2240:         * title = unknown, volume = local, msec = 0, arch = NULL
1.132     kristaps 2241:         */
                   2242:
                   2243:        if (NULL == (nn = n->child)) {
                   2244:                /* XXX: make these macro values. */
                   2245:                /* FIXME: warn about missing values. */
                   2246:                mdoc->meta.title = mandoc_strdup("UNKNOWN");
                   2247:                mdoc->meta.vol = mandoc_strdup("LOCAL");
                   2248:                mdoc->meta.msec = mandoc_strdup("1");
                   2249:                return(1);
                   2250:        }
                   2251:
1.210     schwarze 2252:        /* Handles: `.Dt TITLE'
                   2253:         * title = TITLE, volume = local, msec = 0, arch = NULL
1.132     kristaps 2254:         */
                   2255:
1.210     schwarze 2256:        mdoc->meta.title = mandoc_strdup(
                   2257:            '\0' == nn->string[0] ? "UNKNOWN" : nn->string);
1.132     kristaps 2258:
                   2259:        if (NULL == (nn = nn->next)) {
                   2260:                /* FIXME: warn about missing msec. */
                   2261:                /* XXX: make this a macro value. */
                   2262:                mdoc->meta.vol = mandoc_strdup("LOCAL");
                   2263:                mdoc->meta.msec = mandoc_strdup("1");
                   2264:                return(1);
                   2265:        }
                   2266:
                   2267:        /* Handles: `.Dt TITLE SEC'
1.210     schwarze 2268:         * title = TITLE,
                   2269:         * volume = SEC is msec ? format(msec) : SEC,
                   2270:         * msec = SEC is msec ? atoi(msec) : 0,
                   2271:         * arch = NULL
1.132     kristaps 2272:         */
                   2273:
1.180     schwarze 2274:        cp = mandoc_a2msec(nn->string);
1.132     kristaps 2275:        if (cp) {
                   2276:                mdoc->meta.vol = mandoc_strdup(cp);
                   2277:                mdoc->meta.msec = mandoc_strdup(nn->string);
1.133     kristaps 2278:        } else {
1.217     schwarze 2279:                mandoc_msg(MANDOCERR_MSEC_BAD, mdoc->parse,
                   2280:                    nn->line, nn->pos, nn->string);
1.132     kristaps 2281:                mdoc->meta.vol = mandoc_strdup(nn->string);
                   2282:                mdoc->meta.msec = mandoc_strdup(nn->string);
1.210     schwarze 2283:        }
1.132     kristaps 2284:
                   2285:        if (NULL == (nn = nn->next))
                   2286:                return(1);
                   2287:
                   2288:        /* Handles: `.Dt TITLE SEC VOL'
1.210     schwarze 2289:         * title = TITLE,
                   2290:         * volume = VOL is vol ? format(VOL) :
                   2291:         *          VOL is arch ? format(arch) :
                   2292:         *          VOL
1.132     kristaps 2293:         */
                   2294:
                   2295:        cp = mdoc_a2vol(nn->string);
                   2296:        if (cp) {
                   2297:                free(mdoc->meta.vol);
                   2298:                mdoc->meta.vol = mandoc_strdup(cp);
                   2299:        } else {
                   2300:                cp = mdoc_a2arch(nn->string);
                   2301:                if (NULL == cp) {
1.217     schwarze 2302:                        mandoc_msg(MANDOCERR_ARCH_BAD, mdoc->parse,
                   2303:                            nn->line, nn->pos, nn->string);
1.132     kristaps 2304:                        free(mdoc->meta.vol);
                   2305:                        mdoc->meta.vol = mandoc_strdup(nn->string);
1.210     schwarze 2306:                } else
1.132     kristaps 2307:                        mdoc->meta.arch = mandoc_strdup(cp);
1.210     schwarze 2308:        }
1.132     kristaps 2309:
                   2310:        /* Ignore any subsequent parameters... */
                   2311:        /* FIXME: warn about subsequent parameters. */
                   2312:
                   2313:        return(1);
                   2314: }
                   2315:
                   2316: static int
                   2317: post_prol(POST_ARGS)
                   2318: {
                   2319:        /*
                   2320:         * Remove prologue macros from the document after they're
                   2321:         * processed.  The final document uses mdoc_meta for these
                   2322:         * values and discards the originals.
                   2323:         */
                   2324:
                   2325:        mdoc_node_delete(mdoc, mdoc->last);
                   2326:        if (mdoc->meta.title && mdoc->meta.date && mdoc->meta.os)
                   2327:                mdoc->flags |= MDOC_PBODY;
1.154     kristaps 2328:
                   2329:        return(1);
                   2330: }
                   2331:
                   2332: static int
                   2333: post_bx(POST_ARGS)
                   2334: {
                   2335:        struct mdoc_node        *n;
                   2336:
1.210     schwarze 2337:        /*
1.154     kristaps 2338:         * Make `Bx's second argument always start with an uppercase
                   2339:         * letter.  Groff checks if it's an "accepted" term, but we just
                   2340:         * uppercase blindly.
                   2341:         */
                   2342:
                   2343:        n = mdoc->last->child;
                   2344:        if (n && NULL != (n = n->next))
1.210     schwarze 2345:                *n->string = (char)toupper((unsigned char)*n->string);
1.132     kristaps 2346:
                   2347:        return(1);
                   2348: }
                   2349:
                   2350: static int
                   2351: post_os(POST_ARGS)
                   2352: {
                   2353: #ifndef OSNAME
                   2354:        struct utsname    utsname;
1.201     schwarze 2355:        static char      *defbuf;
1.132     kristaps 2356: #endif
1.201     schwarze 2357:        struct mdoc_node *n;
1.132     kristaps 2358:
                   2359:        n = mdoc->last;
                   2360:
                   2361:        /*
1.184     schwarze 2362:         * Set the operating system by way of the `Os' macro.
                   2363:         * The order of precedence is:
                   2364:         * 1. the argument of the `Os' macro, unless empty
                   2365:         * 2. the -Ios=foo command line argument, if provided
                   2366:         * 3. -DOSNAME="\"foo\"", if provided during compilation
                   2367:         * 4. "sysname release" from uname(3)
1.210     schwarze 2368:         */
1.132     kristaps 2369:
1.184     schwarze 2370:        free(mdoc->meta.os);
1.205     schwarze 2371:        mdoc->meta.os = NULL;
                   2372:        mdoc_deroff(&mdoc->meta.os, n);
                   2373:        if (mdoc->meta.os)
1.201     schwarze 2374:                return(1);
                   2375:
                   2376:        if (mdoc->defos) {
                   2377:                mdoc->meta.os = mandoc_strdup(mdoc->defos);
                   2378:                return(1);
                   2379:        }
                   2380:
1.132     kristaps 2381: #ifdef OSNAME
1.201     schwarze 2382:        mdoc->meta.os = mandoc_strdup(OSNAME);
1.132     kristaps 2383: #else /*!OSNAME */
1.201     schwarze 2384:        if (NULL == defbuf) {
1.166     kristaps 2385:                if (-1 == uname(&utsname)) {
1.136     kristaps 2386:                        mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);
1.210     schwarze 2387:                        defbuf = mandoc_strdup("UNKNOWN");
                   2388:                } else
1.204     schwarze 2389:                        mandoc_asprintf(&defbuf, "%s %s",
                   2390:                            utsname.sysname, utsname.release);
1.201     schwarze 2391:        }
                   2392:        mdoc->meta.os = mandoc_strdup(defbuf);
1.132     kristaps 2393: #endif /*!OSNAME*/
                   2394:        return(1);
                   2395: }
                   2396:
                   2397: static int
                   2398: post_std(POST_ARGS)
                   2399: {
                   2400:        struct mdoc_node *nn, *n;
                   2401:
                   2402:        n = mdoc->last;
                   2403:
                   2404:        /*
                   2405:         * Macros accepting `-std' as an argument have the name of the
                   2406:         * current document (`Nm') filled in as the argument if it's not
                   2407:         * provided.
                   2408:         */
                   2409:
                   2410:        if (n->child)
                   2411:                return(1);
1.133     kristaps 2412:
1.132     kristaps 2413:        if (NULL == mdoc->meta.name)
                   2414:                return(1);
1.210     schwarze 2415:
1.132     kristaps 2416:        nn = n;
                   2417:        mdoc->next = MDOC_NEXT_CHILD;
                   2418:
                   2419:        if ( ! mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name))
                   2420:                return(0);
1.133     kristaps 2421:
1.132     kristaps 2422:        mdoc->last = nn;
                   2423:        return(1);
1.160     kristaps 2424: }
                   2425:
1.210     schwarze 2426: static enum mdoc_sec
1.160     kristaps 2427: a2sec(const char *p)
                   2428: {
                   2429:        int              i;
                   2430:
1.210     schwarze 2431:        for (i = 0; i < (int)SEC__MAX; i++)
1.160     kristaps 2432:                if (secnames[i] && 0 == strcmp(p, secnames[i]))
                   2433:                        return((enum mdoc_sec)i);
                   2434:
                   2435:        return(SEC_CUSTOM);
1.132     kristaps 2436: }
                   2437:
1.161     kristaps 2438: static size_t
                   2439: macro2len(enum mdoct macro)
                   2440: {
                   2441:
                   2442:        switch (macro) {
1.210     schwarze 2443:        case MDOC_Ad:
1.161     kristaps 2444:                return(12);
1.210     schwarze 2445:        case MDOC_Ao:
1.161     kristaps 2446:                return(12);
1.210     schwarze 2447:        case MDOC_An:
1.161     kristaps 2448:                return(12);
1.210     schwarze 2449:        case MDOC_Aq:
1.161     kristaps 2450:                return(12);
1.210     schwarze 2451:        case MDOC_Ar:
1.161     kristaps 2452:                return(12);
1.210     schwarze 2453:        case MDOC_Bo:
1.161     kristaps 2454:                return(12);
1.210     schwarze 2455:        case MDOC_Bq:
1.161     kristaps 2456:                return(12);
1.210     schwarze 2457:        case MDOC_Cd:
1.161     kristaps 2458:                return(12);
1.210     schwarze 2459:        case MDOC_Cm:
1.161     kristaps 2460:                return(10);
1.210     schwarze 2461:        case MDOC_Do:
1.161     kristaps 2462:                return(10);
1.210     schwarze 2463:        case MDOC_Dq:
1.161     kristaps 2464:                return(12);
1.210     schwarze 2465:        case MDOC_Dv:
1.161     kristaps 2466:                return(12);
1.210     schwarze 2467:        case MDOC_Eo:
1.161     kristaps 2468:                return(12);
1.210     schwarze 2469:        case MDOC_Em:
1.161     kristaps 2470:                return(10);
1.210     schwarze 2471:        case MDOC_Er:
1.161     kristaps 2472:                return(17);
1.210     schwarze 2473:        case MDOC_Ev:
1.161     kristaps 2474:                return(15);
1.210     schwarze 2475:        case MDOC_Fa:
1.161     kristaps 2476:                return(12);
1.210     schwarze 2477:        case MDOC_Fl:
1.161     kristaps 2478:                return(10);
1.210     schwarze 2479:        case MDOC_Fo:
1.161     kristaps 2480:                return(16);
1.210     schwarze 2481:        case MDOC_Fn:
1.161     kristaps 2482:                return(16);
1.210     schwarze 2483:        case MDOC_Ic:
1.161     kristaps 2484:                return(10);
1.210     schwarze 2485:        case MDOC_Li:
1.161     kristaps 2486:                return(16);
1.210     schwarze 2487:        case MDOC_Ms:
1.161     kristaps 2488:                return(6);
1.210     schwarze 2489:        case MDOC_Nm:
1.161     kristaps 2490:                return(10);
1.210     schwarze 2491:        case MDOC_No:
1.161     kristaps 2492:                return(12);
1.210     schwarze 2493:        case MDOC_Oo:
1.161     kristaps 2494:                return(10);
1.210     schwarze 2495:        case MDOC_Op:
1.161     kristaps 2496:                return(14);
1.210     schwarze 2497:        case MDOC_Pa:
1.161     kristaps 2498:                return(32);
1.210     schwarze 2499:        case MDOC_Pf:
1.161     kristaps 2500:                return(12);
1.210     schwarze 2501:        case MDOC_Po:
1.161     kristaps 2502:                return(12);
1.210     schwarze 2503:        case MDOC_Pq:
1.161     kristaps 2504:                return(12);
1.210     schwarze 2505:        case MDOC_Ql:
1.161     kristaps 2506:                return(16);
1.210     schwarze 2507:        case MDOC_Qo:
1.161     kristaps 2508:                return(12);
1.210     schwarze 2509:        case MDOC_So:
1.161     kristaps 2510:                return(12);
1.210     schwarze 2511:        case MDOC_Sq:
1.161     kristaps 2512:                return(12);
1.210     schwarze 2513:        case MDOC_Sy:
1.161     kristaps 2514:                return(6);
1.210     schwarze 2515:        case MDOC_Sx:
1.161     kristaps 2516:                return(16);
1.210     schwarze 2517:        case MDOC_Tn:
1.161     kristaps 2518:                return(10);
1.210     schwarze 2519:        case MDOC_Va:
1.161     kristaps 2520:                return(12);
1.210     schwarze 2521:        case MDOC_Vt:
1.161     kristaps 2522:                return(12);
1.210     schwarze 2523:        case MDOC_Xr:
1.161     kristaps 2524:                return(10);
                   2525:        default:
                   2526:                break;
                   2527:        };
                   2528:        return(0);
                   2529: }

CVSweb