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

Annotation of mandoc/mdoc_validate.c, Revision 1.233

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

CVSweb