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

Annotation of mandoc/mdoc_validate.c, Revision 1.210

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

CVSweb