2019-07-26 09:51:35 +00:00
|
|
|
/* $Id: mdoc_validate.c,v 1.374 2019/06/27 15:07:30 schwarze Exp $ */
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
2014-01-31 19:59:03 +00:00
|
|
|
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
|
2019-03-29 13:13:30 +00:00
|
|
|
* Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
|
2014-11-22 18:08:25 +00:00
|
|
|
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
|
2012-10-18 09:55:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2016-01-15 23:08:59 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
2012-10-18 09:55:16 +00:00
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
2016-01-15 23:08:59 +00:00
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
2012-10-18 09:55:16 +00:00
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
#include <sys/types.h>
|
2014-01-31 19:59:03 +00:00
|
|
|
#ifndef OSNAME
|
2012-10-18 09:55:16 +00:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
#include "mandoc_aux.h"
|
2016-01-15 23:08:59 +00:00
|
|
|
#include "mandoc.h"
|
2017-07-31 19:17:54 +00:00
|
|
|
#include "mandoc_xr.h"
|
2016-01-15 23:08:59 +00:00
|
|
|
#include "roff.h"
|
|
|
|
#include "mdoc.h"
|
2012-10-18 09:55:16 +00:00
|
|
|
#include "libmandoc.h"
|
2016-01-15 23:08:59 +00:00
|
|
|
#include "roff_int.h"
|
|
|
|
#include "libmdoc.h"
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* FIXME: .Bl -diag can't have non-text children in HEAD. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
#define POST_ARGS struct roff_man *mdoc
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
enum check_ineq {
|
|
|
|
CHECK_LT,
|
|
|
|
CHECK_GT,
|
|
|
|
CHECK_EQ
|
|
|
|
};
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
typedef void (*v_post)(POST_ARGS);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static int build_list(struct roff_man *, int);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void check_argv(struct roff_man *,
|
|
|
|
struct roff_node *, struct mdoc_argv *);
|
|
|
|
static void check_args(struct roff_man *, struct roff_node *);
|
2018-09-20 07:33:14 +00:00
|
|
|
static void check_text(struct roff_man *, int, int, char *);
|
|
|
|
static void check_text_em(struct roff_man *, int, int, char *);
|
2017-07-31 19:17:54 +00:00
|
|
|
static void check_toptext(struct roff_man *, int, int, const char *);
|
2016-01-15 23:08:59 +00:00
|
|
|
static int child_an(const struct roff_node *);
|
2017-06-08 19:29:07 +00:00
|
|
|
static size_t macro2len(enum roff_tok);
|
|
|
|
static void rewrite_macro2len(struct roff_man *, char **);
|
2017-07-31 19:17:54 +00:00
|
|
|
static int similar(const char *, const char *);
|
2014-12-02 07:34:06 +00:00
|
|
|
|
2019-07-26 09:51:35 +00:00
|
|
|
static void post_abort(POST_ARGS) __attribute__((__noreturn__));
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_an(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_an_norm(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_at(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_bd(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_bf(POST_ARGS);
|
|
|
|
static void post_bk(POST_ARGS);
|
|
|
|
static void post_bl(POST_ARGS);
|
|
|
|
static void post_bl_block(POST_ARGS);
|
|
|
|
static void post_bl_head(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_bl_norm(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_bx(POST_ARGS);
|
|
|
|
static void post_defaults(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_display(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_dd(POST_ARGS);
|
2017-07-31 19:17:54 +00:00
|
|
|
static void post_delim(POST_ARGS);
|
|
|
|
static void post_delim_nb(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_dt(POST_ARGS);
|
|
|
|
static void post_en(POST_ARGS);
|
|
|
|
static void post_es(POST_ARGS);
|
|
|
|
static void post_eoln(POST_ARGS);
|
|
|
|
static void post_ex(POST_ARGS);
|
|
|
|
static void post_fa(POST_ARGS);
|
|
|
|
static void post_fn(POST_ARGS);
|
|
|
|
static void post_fname(POST_ARGS);
|
|
|
|
static void post_fo(POST_ARGS);
|
|
|
|
static void post_hyph(POST_ARGS);
|
|
|
|
static void post_ignpar(POST_ARGS);
|
|
|
|
static void post_it(POST_ARGS);
|
|
|
|
static void post_lb(POST_ARGS);
|
|
|
|
static void post_nd(POST_ARGS);
|
|
|
|
static void post_nm(POST_ARGS);
|
|
|
|
static void post_ns(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_obsolete(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_os(POST_ARGS);
|
|
|
|
static void post_par(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_prevpar(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_root(POST_ARGS);
|
|
|
|
static void post_rs(POST_ARGS);
|
2017-01-21 13:01:39 +00:00
|
|
|
static void post_rv(POST_ARGS);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void post_sh(POST_ARGS);
|
|
|
|
static void post_sh_head(POST_ARGS);
|
|
|
|
static void post_sh_name(POST_ARGS);
|
|
|
|
static void post_sh_see_also(POST_ARGS);
|
|
|
|
static void post_sh_authors(POST_ARGS);
|
|
|
|
static void post_sm(POST_ARGS);
|
|
|
|
static void post_st(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
static void post_std(POST_ARGS);
|
2017-07-31 19:17:54 +00:00
|
|
|
static void post_sx(POST_ARGS);
|
2017-06-08 19:29:07 +00:00
|
|
|
static void post_useless(POST_ARGS);
|
2017-01-21 13:01:39 +00:00
|
|
|
static void post_xr(POST_ARGS);
|
|
|
|
static void post_xx(POST_ARGS);
|
2016-01-15 23:08:59 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = {
|
2016-01-15 23:08:59 +00:00
|
|
|
post_dd, /* Dd */
|
|
|
|
post_dt, /* Dt */
|
|
|
|
post_os, /* Os */
|
|
|
|
post_sh, /* Sh */
|
|
|
|
post_ignpar, /* Ss */
|
|
|
|
post_par, /* Pp */
|
|
|
|
post_display, /* D1 */
|
|
|
|
post_display, /* Dl */
|
|
|
|
post_display, /* Bd */
|
|
|
|
NULL, /* Ed */
|
|
|
|
post_bl, /* Bl */
|
|
|
|
NULL, /* El */
|
|
|
|
post_it, /* It */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Ad */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_an, /* An */
|
2017-06-08 19:29:07 +00:00
|
|
|
NULL, /* Ap */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_defaults, /* Ar */
|
|
|
|
NULL, /* Cd */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Cm */
|
|
|
|
post_delim_nb, /* Dv */
|
|
|
|
post_delim_nb, /* Er */
|
|
|
|
post_delim_nb, /* Ev */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_ex, /* Ex */
|
|
|
|
post_fa, /* Fa */
|
|
|
|
NULL, /* Fd */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Fl */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_fn, /* Fn */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Ft */
|
|
|
|
post_delim_nb, /* Ic */
|
|
|
|
post_delim_nb, /* In */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_defaults, /* Li */
|
|
|
|
post_nd, /* Nd */
|
|
|
|
post_nm, /* Nm */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Op */
|
2019-03-29 13:13:30 +00:00
|
|
|
post_abort, /* Ot */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_defaults, /* Pa */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_rv, /* Rv */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_st, /* St */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Va */
|
|
|
|
post_delim_nb, /* Vt */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xr, /* Xr */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* %A */
|
|
|
|
post_hyph, /* %B */ /* FIXME: can be used outside Rs/Re. */
|
|
|
|
NULL, /* %D */
|
|
|
|
NULL, /* %I */
|
|
|
|
NULL, /* %J */
|
|
|
|
post_hyph, /* %N */
|
|
|
|
post_hyph, /* %O */
|
|
|
|
NULL, /* %P */
|
|
|
|
post_hyph, /* %R */
|
|
|
|
post_hyph, /* %T */ /* FIXME: can be used outside Rs/Re. */
|
|
|
|
NULL, /* %V */
|
|
|
|
NULL, /* Ac */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Ao */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Aq */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_at, /* At */
|
|
|
|
NULL, /* Bc */
|
|
|
|
post_bf, /* Bf */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Bo */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Bq */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Bsx */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_bx, /* Bx */
|
|
|
|
post_obsolete, /* Db */
|
|
|
|
NULL, /* Dc */
|
|
|
|
NULL, /* Do */
|
|
|
|
NULL, /* Dq */
|
|
|
|
NULL, /* Ec */
|
|
|
|
NULL, /* Ef */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Em */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Eo */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Fx */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Ms */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* No */
|
|
|
|
post_ns, /* Ns */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Nx */
|
|
|
|
post_xx, /* Ox */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Pc */
|
|
|
|
NULL, /* Pf */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Po */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Pq */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Qc */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Ql */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Qo */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Qq */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Re */
|
|
|
|
post_rs, /* Rs */
|
|
|
|
NULL, /* Sc */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* So */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Sq */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_sm, /* Sm */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_sx, /* Sx */
|
|
|
|
post_delim_nb, /* Sy */
|
2017-06-08 19:29:07 +00:00
|
|
|
post_useless, /* Tn */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Ux */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Xc */
|
|
|
|
NULL, /* Xo */
|
|
|
|
post_fo, /* Fo */
|
|
|
|
NULL, /* Fc */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Oo */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Oc */
|
|
|
|
post_bk, /* Bk */
|
|
|
|
NULL, /* Ek */
|
|
|
|
post_eoln, /* Bt */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_obsolete, /* Hf */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_obsolete, /* Fr */
|
|
|
|
post_eoln, /* Ud */
|
|
|
|
post_lb, /* Lb */
|
2019-03-29 13:13:30 +00:00
|
|
|
post_abort, /* Lp */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Lk */
|
2016-01-15 23:08:59 +00:00
|
|
|
post_defaults, /* Mt */
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb, /* Brq */
|
2018-09-20 07:33:14 +00:00
|
|
|
NULL, /* Bro */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Brc */
|
|
|
|
NULL, /* %C */
|
|
|
|
post_es, /* Es */
|
|
|
|
post_en, /* En */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Dx */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* %Q */
|
|
|
|
NULL, /* %U */
|
|
|
|
NULL, /* Ta */
|
2012-10-18 09:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define RSORD_MAX 14 /* Number of `Rs' blocks. */
|
|
|
|
|
2017-06-08 19:29:07 +00:00
|
|
|
static const enum roff_tok rsord[RSORD_MAX] = {
|
2012-10-18 09:55:16 +00:00
|
|
|
MDOC__A,
|
|
|
|
MDOC__T,
|
|
|
|
MDOC__B,
|
|
|
|
MDOC__I,
|
|
|
|
MDOC__J,
|
|
|
|
MDOC__R,
|
|
|
|
MDOC__N,
|
|
|
|
MDOC__V,
|
2014-01-31 19:59:03 +00:00
|
|
|
MDOC__U,
|
2012-10-18 09:55:16 +00:00
|
|
|
MDOC__P,
|
|
|
|
MDOC__Q,
|
|
|
|
MDOC__C,
|
2014-01-31 19:59:03 +00:00
|
|
|
MDOC__D,
|
|
|
|
MDOC__O
|
2012-10-18 09:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const secnames[SEC__MAX] = {
|
|
|
|
NULL,
|
|
|
|
"NAME",
|
|
|
|
"LIBRARY",
|
|
|
|
"SYNOPSIS",
|
|
|
|
"DESCRIPTION",
|
2014-11-22 18:08:25 +00:00
|
|
|
"CONTEXT",
|
2012-10-18 09:55:16 +00:00
|
|
|
"IMPLEMENTATION NOTES",
|
|
|
|
"RETURN VALUES",
|
|
|
|
"ENVIRONMENT",
|
|
|
|
"FILES",
|
|
|
|
"EXIT STATUS",
|
|
|
|
"EXAMPLES",
|
|
|
|
"DIAGNOSTICS",
|
|
|
|
"COMPATIBILITY",
|
|
|
|
"ERRORS",
|
|
|
|
"SEE ALSO",
|
|
|
|
"STANDARDS",
|
|
|
|
"HISTORY",
|
|
|
|
"AUTHORS",
|
|
|
|
"CAVEATS",
|
|
|
|
"BUGS",
|
|
|
|
"SECURITY CONSIDERATIONS",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
/* Validate the subtree rooted at mdoc->last. */
|
2014-12-02 07:34:06 +00:00
|
|
|
void
|
2019-03-29 13:13:30 +00:00
|
|
|
mdoc_validate(struct roff_man *mdoc)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2018-09-20 07:33:14 +00:00
|
|
|
struct roff_node *n, *np;
|
2017-06-08 19:29:07 +00:00
|
|
|
const v_post *p;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
/*
|
|
|
|
* Translate obsolete macros to modern macros first
|
|
|
|
* such that later code does not need to look
|
|
|
|
* for the obsolete versions.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
2019-03-29 13:13:30 +00:00
|
|
|
switch (n->tok) {
|
|
|
|
case MDOC_Lp:
|
|
|
|
n->tok = MDOC_Pp;
|
|
|
|
break;
|
|
|
|
case MDOC_Ot:
|
|
|
|
post_obsolete(mdoc);
|
|
|
|
n->tok = MDOC_Ft;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all children, recursing into each one
|
|
|
|
* in turn, depth-first.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc->last = mdoc->last->child;
|
|
|
|
while (mdoc->last != NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mdoc_validate(mdoc);
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->last == n)
|
|
|
|
mdoc->last = mdoc->last->child;
|
|
|
|
else
|
|
|
|
mdoc->last = mdoc->last->next;
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
/* Finally validate the macro itself. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc->last = n;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
2012-10-18 09:55:16 +00:00
|
|
|
switch (n->type) {
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_TEXT:
|
2018-09-20 07:33:14 +00:00
|
|
|
np = n->parent;
|
2017-01-21 13:01:39 +00:00
|
|
|
if (n->sec != SEC_SYNOPSIS ||
|
2018-09-20 07:33:14 +00:00
|
|
|
(np->tok != MDOC_Cd && np->tok != MDOC_Fd))
|
2015-03-02 16:45:41 +00:00
|
|
|
check_text(mdoc, n->line, n->pos, n->string);
|
2019-03-29 13:13:30 +00:00
|
|
|
if ((n->flags & NODE_NOFILL) == 0 &&
|
2018-09-20 07:33:14 +00:00
|
|
|
(np->tok != MDOC_It || np->type != ROFFT_HEAD ||
|
|
|
|
np->parent->parent->norm->Bl.type != LIST_diag))
|
|
|
|
check_text_em(mdoc, n->line, n->pos, n->string);
|
|
|
|
if (np->tok == MDOC_It || (np->type == ROFFT_BODY &&
|
|
|
|
(np->tok == MDOC_Sh || np->tok == MDOC_Ss)))
|
2017-07-31 19:17:54 +00:00
|
|
|
check_toptext(mdoc, n->line, n->pos, n->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2018-09-20 07:33:14 +00:00
|
|
|
case ROFFT_COMMENT:
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_EQN:
|
|
|
|
case ROFFT_TBL:
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_ROOT:
|
2014-12-02 07:34:06 +00:00
|
|
|
post_root(mdoc);
|
|
|
|
break;
|
2012-10-18 09:55:16 +00:00
|
|
|
default:
|
2016-01-15 23:08:59 +00:00
|
|
|
check_args(mdoc, mdoc->last);
|
2014-12-02 07:34:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Closing delimiters are not special at the
|
|
|
|
* beginning of a block, opening delimiters
|
|
|
|
* are not special at the end.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (n->child != NULL)
|
2017-01-21 13:01:39 +00:00
|
|
|
n->child->flags &= ~NODE_DELIMC;
|
2014-12-02 07:34:06 +00:00
|
|
|
if (n->last != NULL)
|
2017-01-21 13:01:39 +00:00
|
|
|
n->last->flags &= ~NODE_DELIMO;
|
2014-12-02 07:34:06 +00:00
|
|
|
|
|
|
|
/* Call the macro's postprocessor. */
|
|
|
|
|
2017-06-08 19:29:07 +00:00
|
|
|
if (n->tok < ROFF_MAX) {
|
2019-03-29 13:13:30 +00:00
|
|
|
roff_validate(mdoc);
|
2017-06-08 19:29:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
|
2019-03-29 13:13:30 +00:00
|
|
|
p = mdoc_valids + (n->tok - MDOC_Dd);
|
2014-12-02 07:34:06 +00:00
|
|
|
if (*p)
|
|
|
|
(*p)(mdoc);
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->last == n)
|
|
|
|
mdoc_state(mdoc, n);
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
check_args(struct roff_man *mdoc, struct roff_node *n)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (NULL == n->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(n->args->argc);
|
|
|
|
for (i = 0; i < (int)n->args->argc; i++)
|
2014-01-31 19:59:03 +00:00
|
|
|
check_argv(mdoc, n, &n->args->argv[i]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
check_argv(struct roff_man *mdoc, struct roff_node *n, struct mdoc_argv *v)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < (int)v->sz; i++)
|
2014-01-31 19:59:03 +00:00
|
|
|
check_text(mdoc, v->line, v->pos, v->value[i]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
check_text(struct roff_man *mdoc, int ln, int pos, char *p)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
if (mdoc->last->flags & NODE_NOFILL)
|
2012-10-18 09:55:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (cp = p; NULL != (p = strchr(p, '\t')); p++)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_FI_TAB, ln, pos + (int)(p - cp), NULL);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 07:33:14 +00:00
|
|
|
static void
|
|
|
|
check_text_em(struct roff_man *mdoc, int ln, int pos, char *p)
|
|
|
|
{
|
|
|
|
const struct roff_node *np, *nn;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
np = mdoc->last->prev;
|
|
|
|
nn = mdoc->last->next;
|
|
|
|
|
|
|
|
/* Look for em-dashes wrongly encoded as "--". */
|
|
|
|
|
|
|
|
for (cp = p; *cp != '\0'; cp++) {
|
|
|
|
if (cp[0] != '-' || cp[1] != '-')
|
|
|
|
continue;
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
/* Skip input sequences of more than two '-'. */
|
|
|
|
|
|
|
|
if (cp[1] == '-') {
|
|
|
|
while (cp[1] == '-')
|
|
|
|
cp++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip "--" directly attached to something else. */
|
|
|
|
|
|
|
|
if ((cp - p > 1 && cp[-2] != ' ') ||
|
|
|
|
(cp[1] != '\0' && cp[1] != ' '))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Require a letter right before or right afterwards. */
|
|
|
|
|
|
|
|
if ((cp - p > 2 ?
|
|
|
|
isalpha((unsigned char)cp[-3]) :
|
|
|
|
np != NULL &&
|
|
|
|
np->type == ROFFT_TEXT &&
|
|
|
|
*np->string != '\0' &&
|
|
|
|
isalpha((unsigned char)np->string[
|
|
|
|
strlen(np->string) - 1])) ||
|
|
|
|
(cp[1] != '\0' && cp[2] != '\0' ?
|
|
|
|
isalpha((unsigned char)cp[2]) :
|
|
|
|
nn != NULL &&
|
|
|
|
nn->type == ROFFT_TEXT &&
|
|
|
|
isalpha((unsigned char)*nn->string))) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DASHDASH,
|
2018-09-20 07:33:14 +00:00
|
|
|
ln, pos + (int)(cp - p) - 1, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 19:29:07 +00:00
|
|
|
static void
|
2017-07-31 19:17:54 +00:00
|
|
|
check_toptext(struct roff_man *mdoc, int ln, int pos, const char *p)
|
2017-06-08 19:29:07 +00:00
|
|
|
{
|
2017-07-31 19:17:54 +00:00
|
|
|
const char *cp, *cpr;
|
|
|
|
|
|
|
|
if (*p == '\0')
|
|
|
|
return;
|
2017-06-08 19:29:07 +00:00
|
|
|
|
|
|
|
if ((cp = strstr(p, "OpenBSD")) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BX, ln, pos + (int)(cp - p), "Ox");
|
2017-06-08 19:29:07 +00:00
|
|
|
if ((cp = strstr(p, "NetBSD")) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BX, ln, pos + (int)(cp - p), "Nx");
|
2017-06-08 19:29:07 +00:00
|
|
|
if ((cp = strstr(p, "FreeBSD")) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BX, ln, pos + (int)(cp - p), "Fx");
|
2017-06-08 19:29:07 +00:00
|
|
|
if ((cp = strstr(p, "DragonFly")) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BX, ln, pos + (int)(cp - p), "Dx");
|
2017-07-31 19:17:54 +00:00
|
|
|
|
|
|
|
cp = p;
|
|
|
|
while ((cp = strstr(cp + 1, "()")) != NULL) {
|
|
|
|
for (cpr = cp - 1; cpr >= p; cpr--)
|
|
|
|
if (*cpr != '_' && !isalnum((unsigned char)*cpr))
|
|
|
|
break;
|
|
|
|
if ((cpr < p || *cpr == ' ') && cpr + 1 < cp) {
|
|
|
|
cpr++;
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_FUNC, ln, pos + (int)(cpr - p),
|
2017-07-31 19:17:54 +00:00
|
|
|
"%.*s()", (int)(cp - cpr), cpr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
static void
|
|
|
|
post_abort(POST_ARGS)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
static void
|
|
|
|
post_delim(POST_ARGS)
|
|
|
|
{
|
|
|
|
const struct roff_node *nch;
|
|
|
|
const char *lc;
|
|
|
|
enum mdelim delim;
|
|
|
|
enum roff_tok tok;
|
|
|
|
|
|
|
|
tok = mdoc->last->tok;
|
|
|
|
nch = mdoc->last->last;
|
|
|
|
if (nch == NULL || nch->type != ROFFT_TEXT)
|
|
|
|
return;
|
|
|
|
lc = strchr(nch->string, '\0') - 1;
|
|
|
|
if (lc < nch->string)
|
|
|
|
return;
|
|
|
|
delim = mdoc_isdelim(lc);
|
|
|
|
if (delim == DELIM_NONE || delim == DELIM_OPEN)
|
|
|
|
return;
|
|
|
|
if (*lc == ')' && (tok == MDOC_Nd || tok == MDOC_Sh ||
|
|
|
|
tok == MDOC_Ss || tok == MDOC_Fo))
|
|
|
|
return;
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DELIM, nch->line,
|
|
|
|
nch->pos + (int)(lc - nch->string), "%s%s %s", roff_name[tok],
|
2017-07-31 19:17:54 +00:00
|
|
|
nch == mdoc->last->child ? "" : " ...", nch->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_delim_nb(POST_ARGS)
|
|
|
|
{
|
|
|
|
const struct roff_node *nch;
|
|
|
|
const char *lc, *cp;
|
|
|
|
int nw;
|
|
|
|
enum mdelim delim;
|
|
|
|
enum roff_tok tok;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find candidates: at least two bytes,
|
|
|
|
* the last one a closing or middle delimiter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tok = mdoc->last->tok;
|
|
|
|
nch = mdoc->last->last;
|
|
|
|
if (nch == NULL || nch->type != ROFFT_TEXT)
|
|
|
|
return;
|
|
|
|
lc = strchr(nch->string, '\0') - 1;
|
|
|
|
if (lc <= nch->string)
|
|
|
|
return;
|
|
|
|
delim = mdoc_isdelim(lc);
|
|
|
|
if (delim == DELIM_NONE || delim == DELIM_OPEN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reduce false positives by allowing various cases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Escaped delimiters. */
|
|
|
|
if (lc > nch->string + 1 && lc[-2] == '\\' &&
|
|
|
|
(lc[-1] == '&' || lc[-1] == 'e'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Specific byte sequences. */
|
|
|
|
switch (*lc) {
|
|
|
|
case ')':
|
|
|
|
for (cp = lc; cp >= nch->string; cp--)
|
|
|
|
if (*cp == '(')
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
if (lc > nch->string + 1 && lc[-2] == '.' && lc[-1] == '.')
|
|
|
|
return;
|
|
|
|
if (lc[-1] == '.')
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
if (tok == MDOC_Vt)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
if (lc[-1] == '?')
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
for (cp = lc; cp >= nch->string; cp--)
|
|
|
|
if (*cp == '[')
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
if (lc == nch->string + 1 && lc[-1] == '|')
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exactly two non-alphanumeric bytes. */
|
|
|
|
if (lc == nch->string + 1 && !isalnum((unsigned char)lc[-1]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* At least three alphabetic words with a sentence ending. */
|
|
|
|
if (strchr("!.:?", *lc) != NULL && (tok == MDOC_Em ||
|
2018-09-20 07:33:14 +00:00
|
|
|
tok == MDOC_Li || tok == MDOC_Pq || tok == MDOC_Sy)) {
|
2017-07-31 19:17:54 +00:00
|
|
|
nw = 0;
|
|
|
|
for (cp = lc - 1; cp >= nch->string; cp--) {
|
|
|
|
if (*cp == ' ') {
|
|
|
|
nw++;
|
|
|
|
if (cp > nch->string && cp[-1] == ',')
|
|
|
|
cp--;
|
|
|
|
} else if (isalpha((unsigned int)*cp)) {
|
|
|
|
if (nw > 1)
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DELIM_NB, nch->line,
|
|
|
|
nch->pos + (int)(lc - nch->string), "%s%s %s", roff_name[tok],
|
2017-07-31 19:17:54 +00:00
|
|
|
nch == mdoc->last->child ? "" : " ...", nch->string);
|
2017-06-08 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_bl_norm(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2014-11-22 18:08:25 +00:00
|
|
|
struct mdoc_argv *argv, *wa;
|
|
|
|
int i;
|
|
|
|
enum mdocargt mdoclt;
|
|
|
|
enum mdoc_list lt;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last->parent;
|
|
|
|
n->norm->Bl.type = LIST__NONE;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/*
|
2012-10-18 09:55:16 +00:00
|
|
|
* First figure out which kind of list to use: bind ourselves to
|
|
|
|
* the first mentioned list type and warn about any remaining
|
|
|
|
* ones. If we find no list type, we default to LIST_item.
|
|
|
|
*/
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
wa = (n->args == NULL) ? NULL : n->args->argv;
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoclt = MDOC_ARG_MAX;
|
2012-10-18 09:55:16 +00:00
|
|
|
for (i = 0; n->args && i < (int)n->args->argc; i++) {
|
2014-11-22 18:08:25 +00:00
|
|
|
argv = n->args->argv + i;
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST__NONE;
|
2014-11-22 18:08:25 +00:00
|
|
|
switch (argv->arg) {
|
2012-10-18 09:55:16 +00:00
|
|
|
/* Set list types. */
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Bullet:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_bullet;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Dash:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_dash;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Enum:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_enum;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Hyphen:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_hyphen;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Item:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_item;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Tag:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_tag;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Diag:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_diag;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Hang:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_hang;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ohang:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_ohang;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Inset:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_inset;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Column:
|
2012-10-18 09:55:16 +00:00
|
|
|
lt = LIST_column;
|
|
|
|
break;
|
|
|
|
/* Set list arguments. */
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Compact:
|
|
|
|
if (n->norm->Bl.comp)
|
|
|
|
mandoc_msg(MANDOCERR_ARG_REP,
|
2019-03-29 13:13:30 +00:00
|
|
|
argv->line, argv->pos, "Bl -compact");
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bl.comp = 1;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Width:
|
|
|
|
wa = argv;
|
|
|
|
if (0 == argv->sz) {
|
|
|
|
mandoc_msg(MANDOCERR_ARG_EMPTY,
|
2019-03-29 13:13:30 +00:00
|
|
|
argv->line, argv->pos, "Bl -width");
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bl.width = "0n";
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (NULL != n->norm->Bl.width)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_REP,
|
|
|
|
argv->line, argv->pos,
|
|
|
|
"Bl -width %s", argv->value[0]);
|
2017-06-08 19:29:07 +00:00
|
|
|
rewrite_macro2len(mdoc, argv->value);
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bl.width = argv->value[0];
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Offset:
|
|
|
|
if (0 == argv->sz) {
|
|
|
|
mandoc_msg(MANDOCERR_ARG_EMPTY,
|
2019-03-29 13:13:30 +00:00
|
|
|
argv->line, argv->pos, "Bl -offset");
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (NULL != n->norm->Bl.offs)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_REP,
|
|
|
|
argv->line, argv->pos,
|
|
|
|
"Bl -offset %s", argv->value[0]);
|
2017-06-08 19:29:07 +00:00
|
|
|
rewrite_macro2len(mdoc, argv->value);
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bl.offs = argv->value[0];
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (LIST__NONE == lt)
|
|
|
|
continue;
|
|
|
|
mdoclt = argv->arg;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Check: multiple list types. */
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (LIST__NONE != n->norm->Bl.type) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_REP, n->line, n->pos,
|
2014-11-22 18:08:25 +00:00
|
|
|
"Bl -%s", mdoc_argnames[argv->arg]);
|
|
|
|
continue;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The list type should come first. */
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (n->norm->Bl.width ||
|
|
|
|
n->norm->Bl.offs ||
|
|
|
|
n->norm->Bl.comp)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_LATETYPE,
|
|
|
|
n->line, n->pos, "Bl -%s",
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc_argnames[n->args->argv[0].arg]);
|
|
|
|
|
|
|
|
n->norm->Bl.type = lt;
|
|
|
|
if (LIST_column == lt) {
|
|
|
|
n->norm->Bl.ncols = argv->sz;
|
|
|
|
n->norm->Bl.cols = (void *)argv->value;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow lists to default to LIST_item. */
|
|
|
|
|
|
|
|
if (LIST__NONE == n->norm->Bl.type) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_NOTYPE, n->line, n->pos, "Bl");
|
2012-10-18 09:55:16 +00:00
|
|
|
n->norm->Bl.type = LIST_item;
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoclt = MDOC_Item;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/*
|
2012-10-18 09:55:16 +00:00
|
|
|
* Validate the width field. Some list types don't need width
|
|
|
|
* types and should be warned about them. Others should have it
|
2014-01-31 19:59:03 +00:00
|
|
|
* and must also be warned. Yet others have a default and need
|
|
|
|
* no warning.
|
2012-10-18 09:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
switch (n->norm->Bl.type) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_tag:
|
2017-07-31 19:17:54 +00:00
|
|
|
if (n->norm->Bl.width == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_NOWIDTH,
|
2014-11-22 18:08:25 +00:00
|
|
|
n->line, n->pos, "Bl -tag");
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_column:
|
|
|
|
case LIST_diag:
|
|
|
|
case LIST_ohang:
|
|
|
|
case LIST_inset:
|
|
|
|
case LIST_item:
|
2017-07-31 19:17:54 +00:00
|
|
|
if (n->norm->Bl.width != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_SKIPW, wa->line, wa->pos,
|
|
|
|
"Bl -%s", mdoc_argnames[mdoclt]);
|
2017-07-31 19:17:54 +00:00
|
|
|
n->norm->Bl.width = NULL;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_bullet:
|
|
|
|
case LIST_dash:
|
|
|
|
case LIST_hyphen:
|
2017-07-31 19:17:54 +00:00
|
|
|
if (n->norm->Bl.width == NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
n->norm->Bl.width = "2n";
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_enum:
|
2017-07-31 19:17:54 +00:00
|
|
|
if (n->norm->Bl.width == NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
n->norm->Bl.width = "3n";
|
|
|
|
break;
|
2012-10-18 09:55:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_bd(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2014-11-22 18:08:25 +00:00
|
|
|
struct mdoc_argv *argv;
|
|
|
|
int i;
|
|
|
|
enum mdoc_disp dt;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
2012-10-18 09:55:16 +00:00
|
|
|
for (i = 0; n->args && i < (int)n->args->argc; i++) {
|
2014-11-22 18:08:25 +00:00
|
|
|
argv = n->args->argv + i;
|
2012-10-18 09:55:16 +00:00
|
|
|
dt = DISP__NONE;
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
switch (argv->arg) {
|
|
|
|
case MDOC_Centred:
|
|
|
|
dt = DISP_centered;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ragged:
|
2012-10-18 09:55:16 +00:00
|
|
|
dt = DISP_ragged;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Unfilled:
|
2012-10-18 09:55:16 +00:00
|
|
|
dt = DISP_unfilled;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Filled:
|
2012-10-18 09:55:16 +00:00
|
|
|
dt = DISP_filled;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Literal:
|
2012-10-18 09:55:16 +00:00
|
|
|
dt = DISP_literal;
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_File:
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BD_FILE, n->line, n->pos, NULL);
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Offset:
|
|
|
|
if (0 == argv->sz) {
|
|
|
|
mandoc_msg(MANDOCERR_ARG_EMPTY,
|
2019-03-29 13:13:30 +00:00
|
|
|
argv->line, argv->pos, "Bd -offset");
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (NULL != n->norm->Bd.offs)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_REP,
|
|
|
|
argv->line, argv->pos,
|
|
|
|
"Bd -offset %s", argv->value[0]);
|
2017-06-08 19:29:07 +00:00
|
|
|
rewrite_macro2len(mdoc, argv->value);
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bd.offs = argv->value[0];
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Compact:
|
|
|
|
if (n->norm->Bd.comp)
|
|
|
|
mandoc_msg(MANDOCERR_ARG_REP,
|
2019-03-29 13:13:30 +00:00
|
|
|
argv->line, argv->pos, "Bd -compact");
|
2014-11-22 18:08:25 +00:00
|
|
|
n->norm->Bd.comp = 1;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (DISP__NONE == dt)
|
|
|
|
continue;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (DISP__NONE == n->norm->Bd.type)
|
2012-10-18 09:55:16 +00:00
|
|
|
n->norm->Bd.type = dt;
|
2014-11-22 18:08:25 +00:00
|
|
|
else
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BD_REP, n->line, n->pos,
|
2014-11-22 18:08:25 +00:00
|
|
|
"Bd -%s", mdoc_argnames[argv->arg]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DISP__NONE == n->norm->Bd.type) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BD_NOTYPE, n->line, n->pos, "Bd");
|
2012-10-18 09:55:16 +00:00
|
|
|
n->norm->Bd.type = DISP_ragged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Stand-alone line macros.
|
|
|
|
*/
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_an_norm(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2014-11-22 18:08:25 +00:00
|
|
|
struct mdoc_argv *argv;
|
|
|
|
size_t i;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
2014-11-22 18:08:25 +00:00
|
|
|
if (n->args == NULL)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
for (i = 1; i < n->args->argc; i++) {
|
|
|
|
argv = n->args->argv + i;
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_AN_REP, argv->line, argv->pos,
|
2014-11-22 18:08:25 +00:00
|
|
|
"An -%s", mdoc_argnames[argv->arg]);
|
|
|
|
}
|
|
|
|
|
|
|
|
argv = n->args->argv;
|
|
|
|
if (argv->arg == MDOC_Split)
|
2012-10-18 09:55:16 +00:00
|
|
|
n->norm->An.auth = AUTH_split;
|
2014-11-22 18:08:25 +00:00
|
|
|
else if (argv->arg == MDOC_Nosplit)
|
2012-10-18 09:55:16 +00:00
|
|
|
n->norm->An.auth = AUTH_nosplit;
|
|
|
|
else
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static void
|
|
|
|
post_eoln(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
|
2017-06-08 19:29:07 +00:00
|
|
|
post_useless(mdoc);
|
2017-01-21 13:01:39 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
if (n->child != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_SKIP, n->line,
|
2017-06-08 19:29:07 +00:00
|
|
|
n->pos, "%s %s", roff_name[n->tok], n->child->string);
|
2017-01-21 13:01:39 +00:00
|
|
|
|
|
|
|
while (n->child != NULL)
|
|
|
|
roff_node_delete(mdoc, n->child);
|
|
|
|
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, n->tok == MDOC_Bt ?
|
|
|
|
"is currently in beta test." : "currently under development.");
|
|
|
|
mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
build_list(struct roff_man *mdoc, int tok)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
int ic;
|
|
|
|
|
|
|
|
n = mdoc->last->next;
|
|
|
|
for (ic = 1;; ic++) {
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, tok);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
2019-03-29 13:13:30 +00:00
|
|
|
roff_node_relink(mdoc, n);
|
2017-01-21 13:01:39 +00:00
|
|
|
n = mdoc->last = mdoc->last->parent;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
if (n->next == NULL)
|
|
|
|
return ic;
|
|
|
|
if (ic > 1 || n->next->next != NULL) {
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, ",");
|
|
|
|
mdoc->last->flags |= NODE_DELIMC | NODE_NOSRC;
|
|
|
|
}
|
|
|
|
n = mdoc->last->next;
|
|
|
|
if (n->next == NULL) {
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "and");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_ex(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
int ic;
|
|
|
|
|
|
|
|
post_std(mdoc);
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "The");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
|
|
|
|
if (mdoc->last->next != NULL)
|
|
|
|
ic = build_list(mdoc, MDOC_Nm);
|
|
|
|
else if (mdoc->meta.name != NULL) {
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Nm);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = mdoc->last->parent;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
ic = 1;
|
|
|
|
} else {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_EX_NONAME, n->line, n->pos, "Ex");
|
2017-01-21 13:01:39 +00:00
|
|
|
ic = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos,
|
|
|
|
ic > 1 ? "utilities exit\\~0" : "utility exits\\~0");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos,
|
|
|
|
"on success, and\\~>0 if an error occurs.");
|
|
|
|
mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_lb(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
const char *p;
|
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb(mdoc);
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
assert(n->child->type == ROFFT_TEXT);
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
|
|
|
|
if ((p = mdoc_a2lib(n->child->string)) != NULL) {
|
|
|
|
n->child->flags |= NODE_NOPRT;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, p);
|
|
|
|
mdoc->last->flags = NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_LB_BAD, n->child->line,
|
2017-06-08 19:29:07 +00:00
|
|
|
n->child->pos, "Lb %s", n->child->string);
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "library");
|
|
|
|
mdoc->last->flags = NODE_NOSRC;
|
2018-09-20 07:33:14 +00:00
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "\\(lq");
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->flags = NODE_DELIMO | NODE_NOSRC;
|
|
|
|
mdoc->last = mdoc->last->next;
|
2018-09-20 07:33:14 +00:00
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "\\(rq");
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->flags = NODE_DELIMC | NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_rv(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
int ic;
|
|
|
|
|
|
|
|
post_std(mdoc);
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
if (n->child != NULL) {
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "The");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
ic = build_list(mdoc, MDOC_Fn);
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos,
|
|
|
|
ic > 1 ? "functions return" : "function returns");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos,
|
|
|
|
"the value\\~0 if successful;");
|
|
|
|
} else
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "Upon successful "
|
|
|
|
"completion, the value\\~0 is returned;");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "otherwise "
|
|
|
|
"the value\\~\\-1 is returned and the global variable");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Va);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "errno");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = mdoc->last->parent;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos,
|
|
|
|
"is set to indicate the error.");
|
|
|
|
mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_std(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim(mdoc);
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
if (n->args && n->args->argc == 1)
|
|
|
|
if (n->args->argv[0].arg == MDOC_Std)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_STD, n->line, n->pos,
|
|
|
|
"%s", roff_name[n->tok]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static void
|
|
|
|
post_st(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n, *nch;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
nch = n->child;
|
|
|
|
assert(nch->type == ROFFT_TEXT);
|
|
|
|
|
|
|
|
if ((p = mdoc_a2st(nch->string)) == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ST_BAD,
|
2017-01-21 13:01:39 +00:00
|
|
|
nch->line, nch->pos, "St %s", nch->string);
|
|
|
|
roff_node_delete(mdoc, n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nch->flags |= NODE_NOPRT;
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, nch->line, nch->pos, p);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last= n;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_obsolete(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
if (n->type == ROFFT_ELEM || n->type == ROFFT_BLOCK)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MACRO_OBS, n->line, n->pos,
|
|
|
|
"%s", roff_name[n->tok]);
|
2017-06-08 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_useless(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MACRO_USELESS, n->line, n->pos,
|
|
|
|
"%s", roff_name[n->tok]);
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/*
|
|
|
|
* Block macros.
|
|
|
|
*/
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_bf(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *np, *nch;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlike other data pointers, these are "housed" by the HEAD
|
|
|
|
* element, which contains the goods.
|
|
|
|
*/
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
np = mdoc->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->type != ROFFT_HEAD)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
assert(np->parent->type == ROFFT_BLOCK);
|
|
|
|
assert(np->parent->tok == MDOC_Bf);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/* Check the number of arguments. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
nch = np->child;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->parent->args == NULL) {
|
|
|
|
if (nch == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BF_NOFONT,
|
2014-11-22 18:08:25 +00:00
|
|
|
np->line, np->pos, "Bf");
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
|
|
|
nch = nch->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
if (nch != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_EXCESS,
|
2014-11-22 18:08:25 +00:00
|
|
|
nch->line, nch->pos, "Bf ... %s", nch->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Extract argument into data. */
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->parent->args != NULL) {
|
|
|
|
switch (np->parent->args->argv[0].arg) {
|
|
|
|
case MDOC_Emphasis:
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Em;
|
2016-01-15 23:08:59 +00:00
|
|
|
break;
|
|
|
|
case MDOC_Literal:
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Li;
|
2016-01-15 23:08:59 +00:00
|
|
|
break;
|
|
|
|
case MDOC_Symbolic:
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Sy;
|
2016-01-15 23:08:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-18 09:55:16 +00:00
|
|
|
abort();
|
2016-01-15 23:08:59 +00:00
|
|
|
}
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract parameter into data. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if ( ! strcmp(np->child->string, "Em"))
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Em;
|
2016-01-15 23:08:59 +00:00
|
|
|
else if ( ! strcmp(np->child->string, "Li"))
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Li;
|
2016-01-15 23:08:59 +00:00
|
|
|
else if ( ! strcmp(np->child->string, "Sy"))
|
2012-10-18 09:55:16 +00:00
|
|
|
np->norm->Bf.font = FONT_Sy;
|
2014-11-22 18:08:25 +00:00
|
|
|
else
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BF_BADFONT, np->child->line,
|
|
|
|
np->child->pos, "Bf %s", np->child->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
|
|
|
post_fname(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
const struct roff_node *n;
|
2014-12-02 07:34:06 +00:00
|
|
|
const char *cp;
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
n = mdoc->last->child;
|
|
|
|
pos = strcspn(n->string, "()");
|
|
|
|
cp = n->string + pos;
|
|
|
|
if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*')))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos,
|
|
|
|
"%s", n->string);
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_fn(POST_ARGS)
|
|
|
|
{
|
|
|
|
|
|
|
|
post_fname(mdoc);
|
|
|
|
post_fa(mdoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_fo(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
const struct roff_node *n;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->type != ROFFT_HEAD)
|
2015-03-02 16:45:41 +00:00
|
|
|
return;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (n->child == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_FO_NOHEAD, n->line, n->pos, "Fo");
|
2015-03-02 16:45:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (n->child != n->last) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_EXCESS,
|
2015-03-02 16:45:41 +00:00
|
|
|
n->child->next->line, n->child->next->pos,
|
|
|
|
"Fo ... %s", n->child->next->string);
|
|
|
|
while (n->child != n->last)
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, n->last);
|
2017-07-31 19:17:54 +00:00
|
|
|
} else
|
|
|
|
post_delim(mdoc);
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
post_fname(mdoc);
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
|
|
|
post_fa(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
const struct roff_node *n;
|
2014-12-02 07:34:06 +00:00
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
for (n = mdoc->last->child; n != NULL; n = n->next) {
|
|
|
|
for (cp = n->string; *cp != '\0'; cp++) {
|
|
|
|
/* Ignore callbacks and alterations. */
|
|
|
|
if (*cp == '(' || *cp == '{')
|
|
|
|
break;
|
|
|
|
if (*cp != ',')
|
|
|
|
continue;
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_FA_COMMA, n->line,
|
|
|
|
n->pos + (int)(cp - n->string), "%s", n->string);
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb(mdoc);
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_nm(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
|
2017-10-06 11:45:56 +00:00
|
|
|
if (n->sec == SEC_NAME && n->child != NULL &&
|
|
|
|
n->child->type == ROFFT_TEXT && mdoc->meta.msec != NULL)
|
2017-07-31 19:17:54 +00:00
|
|
|
mandoc_xr_add(mdoc->meta.msec, n->child->string, -1, -1);
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
if (n->last != NULL && n->last->tok == MDOC_Pp)
|
|
|
|
roff_node_relink(mdoc, n->last);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->meta.name == NULL)
|
2017-01-21 13:01:39 +00:00
|
|
|
deroff(&mdoc->meta.name, n);
|
|
|
|
|
|
|
|
if (mdoc->meta.name == NULL ||
|
|
|
|
(mdoc->lastsec == SEC_NAME && n->child == NULL))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NM_NONAME, n->line, n->pos, "Nm");
|
2017-02-19 17:41:20 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
switch (n->type) {
|
|
|
|
case ROFFT_ELEM:
|
|
|
|
post_delim_nb(mdoc);
|
|
|
|
break;
|
|
|
|
case ROFFT_HEAD:
|
|
|
|
post_delim(mdoc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((n->child != NULL && n->child->type == ROFFT_TEXT) ||
|
2017-02-19 17:41:20 +00:00
|
|
|
mdoc->meta.name == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_nd(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->type != ROFFT_BODY)
|
2015-03-02 16:45:41 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-08 19:29:07 +00:00
|
|
|
if (n->sec != SEC_NAME)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ND_LATE, n->line, n->pos, "Nd");
|
2017-06-08 19:29:07 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (n->child == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ND_EMPTY, n->line, n->pos, "Nd");
|
2017-07-31 19:17:54 +00:00
|
|
|
else
|
|
|
|
post_delim(mdoc);
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
post_hyph(mdoc);
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_display(POST_ARGS)
|
2014-11-22 18:08:25 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n, *np;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
switch (n->type) {
|
|
|
|
case ROFFT_BODY:
|
2017-01-21 13:01:39 +00:00
|
|
|
if (n->end != ENDBODY_NOT) {
|
|
|
|
if (n->tok == MDOC_Bd &&
|
|
|
|
n->body->parent->args == NULL)
|
|
|
|
roff_node_delete(mdoc, n);
|
|
|
|
} else if (n->child == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY, n->line, n->pos,
|
|
|
|
"%s", roff_name[n->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
else if (n->tok == MDOC_D1)
|
|
|
|
post_hyph(mdoc);
|
|
|
|
break;
|
|
|
|
case ROFFT_BLOCK:
|
|
|
|
if (n->tok == MDOC_Bd) {
|
|
|
|
if (n->args == NULL) {
|
|
|
|
mandoc_msg(MANDOCERR_BD_NOARG,
|
2019-03-29 13:13:30 +00:00
|
|
|
n->line, n->pos, "Bd");
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
while (n->body->child != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
roff_node_relink(mdoc,
|
2016-01-15 23:08:59 +00:00
|
|
|
n->body->child);
|
|
|
|
roff_node_delete(mdoc, n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
post_bd(mdoc);
|
|
|
|
post_prevpar(mdoc);
|
|
|
|
}
|
|
|
|
for (np = n->parent; np != NULL; np = np->parent) {
|
|
|
|
if (np->type == ROFFT_BLOCK && np->tok == MDOC_Bd) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BD_NEST, n->line,
|
|
|
|
n->pos, "%s in Bd", roff_name[n->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_defaults(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nn;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
if (mdoc->last->child != NULL) {
|
|
|
|
post_delim_nb(mdoc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
|
|
|
* The `Ar' defaults to "file ..." if no value is provided as an
|
|
|
|
* argument; the `Mt' and `Pa' macros use "~"; the `Li' just
|
|
|
|
* gets an empty string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nn = mdoc->last;
|
|
|
|
switch (nn->tok) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ar:
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, nn->line, nn->pos, "file");
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_word_alloc(mdoc, nn->line, nn->pos, "...");
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Pa:
|
|
|
|
case MDOC_Mt:
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, nn->line, nn->pos, "~");
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
mdoc->last = nn;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_at(POST_ARGS)
|
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
struct roff_node *n, *nch;
|
|
|
|
const char *att;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
2017-01-21 13:01:39 +00:00
|
|
|
nch = n->child;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a child, look it up in the standard keys. If a
|
|
|
|
* key exist, use that instead of the child; if it doesn't,
|
|
|
|
* prefix "AT&T UNIX " to the existing data.
|
|
|
|
*/
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
att = NULL;
|
|
|
|
if (nch != NULL && ((att = mdoc_a2att(nch->string)) == NULL))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_AT_BAD,
|
2017-01-21 13:01:39 +00:00
|
|
|
nch->line, nch->pos, "At %s", nch->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
if (att != NULL) {
|
|
|
|
roff_word_alloc(mdoc, nch->line, nch->pos, att);
|
|
|
|
nch->flags |= NODE_NOPRT;
|
|
|
|
} else
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_an(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *np, *nch;
|
|
|
|
|
|
|
|
post_an_norm(mdoc);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
np = mdoc->last;
|
2015-03-02 16:45:41 +00:00
|
|
|
nch = np->child;
|
|
|
|
if (np->norm->An.auth == AUTH__NONE) {
|
|
|
|
if (nch == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MACRO_EMPTY,
|
2015-03-02 16:45:41 +00:00
|
|
|
np->line, np->pos, "An");
|
2017-07-31 19:17:54 +00:00
|
|
|
else
|
|
|
|
post_delim_nb(mdoc);
|
2015-03-02 16:45:41 +00:00
|
|
|
} else if (nch != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_EXCESS,
|
2015-03-02 16:45:41 +00:00
|
|
|
nch->line, nch->pos, "An ... %s", nch->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_en(POST_ARGS)
|
|
|
|
{
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
post_obsolete(mdoc);
|
|
|
|
if (mdoc->last->type == ROFFT_BLOCK)
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->last->norm->Es = mdoc->last_es;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_es(POST_ARGS)
|
|
|
|
{
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
post_obsolete(mdoc);
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->last_es = mdoc->last;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static void
|
|
|
|
post_xx(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n;
|
|
|
|
const char *os;
|
2017-07-31 19:17:54 +00:00
|
|
|
char *v;
|
|
|
|
|
|
|
|
post_delim_nb(mdoc);
|
2017-01-21 13:01:39 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
switch (n->tok) {
|
|
|
|
case MDOC_Bsx:
|
|
|
|
os = "BSD/OS";
|
|
|
|
break;
|
|
|
|
case MDOC_Dx:
|
|
|
|
os = "DragonFly";
|
|
|
|
break;
|
|
|
|
case MDOC_Fx:
|
|
|
|
os = "FreeBSD";
|
|
|
|
break;
|
|
|
|
case MDOC_Nx:
|
|
|
|
os = "NetBSD";
|
2017-07-31 19:17:54 +00:00
|
|
|
if (n->child == NULL)
|
|
|
|
break;
|
|
|
|
v = n->child->string;
|
|
|
|
if ((v[0] != '0' && v[0] != '1') || v[1] != '.' ||
|
|
|
|
v[2] < '0' || v[2] > '9' ||
|
|
|
|
v[3] < 'a' || v[3] > 'z' || v[4] != '\0')
|
|
|
|
break;
|
|
|
|
n->child->flags |= NODE_NOPRT;
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, n->child->line, n->child->pos, v);
|
|
|
|
v = mdoc->last->string;
|
|
|
|
v[3] = toupper((unsigned char)v[3]);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
2017-01-21 13:01:39 +00:00
|
|
|
break;
|
|
|
|
case MDOC_Ox:
|
|
|
|
os = "OpenBSD";
|
|
|
|
break;
|
|
|
|
case MDOC_Ux:
|
|
|
|
os = "UNIX";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, os);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_it(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nbl, *nit, *nch;
|
2012-10-18 09:55:16 +00:00
|
|
|
int i, cols;
|
|
|
|
enum mdoc_list lt;
|
2016-01-15 23:08:59 +00:00
|
|
|
|
|
|
|
post_prevpar(mdoc);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
nit = mdoc->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (nit->type != ROFFT_BLOCK)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
nbl = nit->parent->parent;
|
|
|
|
lt = nbl->norm->Bl.type;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
switch (lt) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_tag:
|
|
|
|
case LIST_hang:
|
|
|
|
case LIST_ohang:
|
|
|
|
case LIST_inset:
|
|
|
|
case LIST_diag:
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nit->head->child == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_IT_NOHEAD,
|
|
|
|
nit->line, nit->pos, "Bl -%s It",
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc_argnames[nbl->args->argv[0].arg]);
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_bullet:
|
|
|
|
case LIST_dash:
|
|
|
|
case LIST_enum:
|
|
|
|
case LIST_hyphen:
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nit->body == NULL || nit->body->child == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_IT_NOBODY,
|
|
|
|
nit->line, nit->pos, "Bl -%s It",
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc_argnames[nbl->args->argv[0].arg]);
|
2012-10-18 09:55:16 +00:00
|
|
|
/* FALLTHROUGH */
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_item:
|
2017-01-21 13:01:39 +00:00
|
|
|
if ((nch = nit->head->child) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_SKIP,
|
2017-06-08 19:29:07 +00:00
|
|
|
nit->line, nit->pos, "It %s",
|
|
|
|
nch->string == NULL ? roff_name[nch->tok] :
|
|
|
|
nch->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_column:
|
|
|
|
cols = (int)nbl->norm->Bl.ncols;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
assert(nit->head->child == NULL);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
if (nit->head->next->child == NULL &&
|
|
|
|
nit->head->next->next == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MACRO_EMPTY,
|
2017-07-31 19:17:54 +00:00
|
|
|
nit->line, nit->pos, "It");
|
|
|
|
roff_node_delete(mdoc, nit);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
i = 0;
|
|
|
|
for (nch = nit->child; nch != NULL; nch = nch->next) {
|
|
|
|
if (nch->type != ROFFT_BODY)
|
|
|
|
continue;
|
|
|
|
if (i++ && nch->flags & NODE_LINE)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_TA_LINE,
|
2017-07-31 19:17:54 +00:00
|
|
|
nch->line, nch->pos, "Ta");
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
if (i < cols || i > cols + 1)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_COL, nit->line, nit->pos,
|
2015-03-02 16:45:41 +00:00
|
|
|
"%d columns, %d cells", cols, i);
|
2017-07-31 19:17:54 +00:00
|
|
|
else if (nit->head->next->child != NULL &&
|
2019-03-29 13:13:30 +00:00
|
|
|
nit->head->next->child->flags & NODE_LINE)
|
|
|
|
mandoc_msg(MANDOCERR_IT_NOARG,
|
2017-07-31 19:17:54 +00:00
|
|
|
nit->line, nit->pos, "Bl -column It");
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
default:
|
|
|
|
abort();
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_bl_block(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n, *ni, *nc;
|
|
|
|
|
|
|
|
post_prevpar(mdoc);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
for (ni = n->body->child; ni != NULL; ni = ni->next) {
|
|
|
|
if (ni->body == NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
continue;
|
|
|
|
nc = ni->body->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
while (nc != NULL) {
|
2014-01-31 19:59:03 +00:00
|
|
|
switch (nc->tok) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Pp:
|
2017-06-08 19:29:07 +00:00
|
|
|
case ROFF_br:
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nc = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
if (ni->next == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PAR_MOVE, nc->line,
|
|
|
|
nc->pos, "%s", roff_name[nc->tok]);
|
|
|
|
roff_node_relink(mdoc, nc);
|
2016-01-15 23:08:59 +00:00
|
|
|
} else if (n->norm->Bl.comp == 0 &&
|
|
|
|
n->norm->Bl.type != LIST_column) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PAR_SKIP,
|
|
|
|
nc->line, nc->pos,
|
2017-06-08 19:29:07 +00:00
|
|
|
"%s before It", roff_name[nc->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, nc);
|
2014-01-31 19:59:03 +00:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
nc = ni->body->last;
|
|
|
|
}
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
/*
|
|
|
|
* If the argument of -offset or -width is a macro,
|
|
|
|
* replace it with the associated default width.
|
|
|
|
*/
|
2017-06-08 19:29:07 +00:00
|
|
|
static void
|
|
|
|
rewrite_macro2len(struct roff_man *mdoc, char **arg)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
size_t width;
|
2017-06-08 19:29:07 +00:00
|
|
|
enum roff_tok tok;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
if (*arg == NULL)
|
|
|
|
return;
|
|
|
|
else if ( ! strcmp(*arg, "Ds"))
|
2012-10-18 09:55:16 +00:00
|
|
|
width = 6;
|
2017-06-08 19:29:07 +00:00
|
|
|
else if ((tok = roffhash_find(mdoc->mdocmac, *arg, 0)) == TOKEN_NONE)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2014-11-22 18:08:25 +00:00
|
|
|
else
|
|
|
|
width = macro2len(tok);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
free(*arg);
|
|
|
|
mandoc_asprintf(arg, "%zun", width);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_bl_head(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nbl, *nh, *nch, *nnext;
|
2014-11-22 18:08:25 +00:00
|
|
|
struct mdoc_argv *argv;
|
2012-10-18 09:55:16 +00:00
|
|
|
int i, j;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
post_bl_norm(mdoc);
|
2015-03-02 16:45:41 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
nh = mdoc->last;
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nh->norm->Bl.type != LIST_column) {
|
|
|
|
if ((nch = nh->child) == NULL)
|
|
|
|
return;
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_EXCESS,
|
2015-03-02 16:45:41 +00:00
|
|
|
nch->line, nch->pos, "Bl ... %s", nch->string);
|
|
|
|
while (nch != NULL) {
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, nch);
|
2015-03-02 16:45:41 +00:00
|
|
|
nch = nh->child;
|
|
|
|
}
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
2014-11-22 18:08:25 +00:00
|
|
|
* Append old-style lists, where the column width specifiers
|
2012-10-18 09:55:16 +00:00
|
|
|
* trail as macro parameters, to the new-style ("normal-form")
|
|
|
|
* lists where they're argument values following -column.
|
|
|
|
*/
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nh->child == NULL)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
nbl = nh->parent;
|
|
|
|
for (j = 0; j < (int)nbl->args->argc; j++)
|
|
|
|
if (nbl->args->argv[j].arg == MDOC_Column)
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
assert(j < (int)nbl->args->argc);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Accommodate for new-style groff column syntax. Shuffle the
|
|
|
|
* child nodes, all of which must be TEXT, as arguments for the
|
|
|
|
* column field. Then, delete the head children.
|
|
|
|
*/
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
argv = nbl->args->argv + j;
|
2014-11-22 18:08:25 +00:00
|
|
|
i = argv->sz;
|
2016-01-15 23:08:59 +00:00
|
|
|
for (nch = nh->child; nch != NULL; nch = nch->next)
|
|
|
|
argv->sz++;
|
2014-11-22 18:08:25 +00:00
|
|
|
argv->value = mandoc_reallocarray(argv->value,
|
|
|
|
argv->sz, sizeof(char *));
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
nh->norm->Bl.ncols = argv->sz;
|
|
|
|
nh->norm->Bl.cols = (void *)argv->value;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
for (nch = nh->child; nch != NULL; nch = nnext) {
|
|
|
|
argv->value[i++] = nch->string;
|
|
|
|
nch->string = NULL;
|
|
|
|
nnext = nch->next;
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(NULL, nch);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2015-03-02 16:45:41 +00:00
|
|
|
nh->child = NULL;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_bl(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nparent, *nprev; /* of the Bl block */
|
|
|
|
struct roff_node *nblock, *nbody; /* of the Bl */
|
|
|
|
struct roff_node *nchild, *nnext; /* of the Bl body */
|
2017-06-08 19:29:07 +00:00
|
|
|
const char *prev_Er;
|
|
|
|
int order;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
nbody = mdoc->last;
|
|
|
|
switch (nbody->type) {
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_BLOCK:
|
2014-12-02 07:34:06 +00:00
|
|
|
post_bl_block(mdoc);
|
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_HEAD:
|
2014-12-02 07:34:06 +00:00
|
|
|
post_bl_head(mdoc);
|
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_BODY:
|
2014-01-31 19:59:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2014-01-31 19:59:03 +00:00
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
if (nbody->end != ENDBODY_NOT)
|
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
nchild = nbody->child;
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nchild == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY,
|
2015-03-02 16:45:41 +00:00
|
|
|
nbody->line, nbody->pos, "Bl");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (nchild != NULL) {
|
2017-01-21 13:01:39 +00:00
|
|
|
nnext = nchild->next;
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nchild->tok == MDOC_It ||
|
|
|
|
(nchild->tok == MDOC_Sm &&
|
2017-01-21 13:01:39 +00:00
|
|
|
nnext != NULL && nnext->tok == MDOC_It)) {
|
|
|
|
nchild = nnext;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In .Bl -column, the first rows may be implicit,
|
|
|
|
* that is, they may not start with .It macros.
|
|
|
|
* Such rows may be followed by nodes generated on the
|
|
|
|
* roff level, for example .TS, which cannot be moved
|
|
|
|
* out of the list. In that case, wrap such roff nodes
|
|
|
|
* into an implicit row.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nchild->prev != NULL) {
|
|
|
|
mdoc->last = nchild;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
roff_block_alloc(mdoc, nchild->line,
|
|
|
|
nchild->pos, MDOC_It);
|
|
|
|
roff_head_alloc(mdoc, nchild->line,
|
|
|
|
nchild->pos, MDOC_It);
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
roff_body_alloc(mdoc, nchild->line,
|
|
|
|
nchild->pos, MDOC_It);
|
|
|
|
while (nchild->tok != MDOC_It) {
|
2019-03-29 13:13:30 +00:00
|
|
|
roff_node_relink(mdoc, nchild);
|
2017-01-21 13:01:39 +00:00
|
|
|
if ((nchild = nnext) == NULL)
|
|
|
|
break;
|
|
|
|
nnext = nchild->next;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
}
|
|
|
|
mdoc->last = nbody;
|
2012-10-18 09:55:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_MOVE, nchild->line, nchild->pos,
|
|
|
|
"%s", roff_name[nchild->tok]);
|
2014-01-31 19:59:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the node out of the Bl block.
|
|
|
|
* First, collect all required node pointers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nblock = nbody->parent;
|
|
|
|
nprev = nblock->prev;
|
|
|
|
nparent = nblock->parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink this child.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
nbody->child = nnext;
|
|
|
|
if (nnext == NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
nbody->last = NULL;
|
2016-01-15 23:08:59 +00:00
|
|
|
else
|
2014-01-31 19:59:03 +00:00
|
|
|
nnext->prev = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Relink this child.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nchild->parent = nparent;
|
|
|
|
nchild->prev = nprev;
|
|
|
|
nchild->next = nblock;
|
|
|
|
|
|
|
|
nblock->prev = nchild;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (nprev == NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
nparent->child = nchild;
|
|
|
|
else
|
|
|
|
nprev->next = nchild;
|
|
|
|
|
|
|
|
nchild = nnext;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2017-06-08 19:29:07 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
if (mdoc->meta.os_e != MANDOC_OS_NETBSD)
|
2017-06-08 19:29:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
prev_Er = NULL;
|
|
|
|
for (nchild = nbody->child; nchild != NULL; nchild = nchild->next) {
|
|
|
|
if (nchild->tok != MDOC_It)
|
|
|
|
continue;
|
|
|
|
if ((nnext = nchild->head->child) == NULL)
|
|
|
|
continue;
|
|
|
|
if (nnext->type == ROFFT_BLOCK)
|
|
|
|
nnext = nnext->body->child;
|
|
|
|
if (nnext == NULL || nnext->tok != MDOC_Er)
|
|
|
|
continue;
|
|
|
|
nnext = nnext->child;
|
|
|
|
if (prev_Er != NULL) {
|
|
|
|
order = strcmp(prev_Er, nnext->string);
|
|
|
|
if (order > 0)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ER_ORDER,
|
|
|
|
nnext->line, nnext->pos,
|
2017-07-31 19:17:54 +00:00
|
|
|
"Er %s %s (NetBSD)",
|
|
|
|
prev_Er, nnext->string);
|
2017-06-08 19:29:07 +00:00
|
|
|
else if (order == 0)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ER_REP,
|
|
|
|
nnext->line, nnext->pos,
|
2017-07-31 19:17:54 +00:00
|
|
|
"Er %s (NetBSD)", prev_Er);
|
2017-06-08 19:29:07 +00:00
|
|
|
}
|
|
|
|
prev_Er = nnext->string;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-11-22 18:08:25 +00:00
|
|
|
post_bk(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->type == ROFFT_BLOCK && n->body->child == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY, n->line, n->pos, "Bk");
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, n);
|
2015-03-02 16:45:41 +00:00
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_sm(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nch;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
|
|
|
nch = mdoc->last->child;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
if (nch == NULL) {
|
|
|
|
mdoc->flags ^= MDOC_SMOFF;
|
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
assert(nch->type == ROFFT_TEXT);
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
if ( ! strcmp(nch->string, "on")) {
|
|
|
|
mdoc->flags &= ~MDOC_SMOFF;
|
|
|
|
return;
|
2014-01-31 19:59:03 +00:00
|
|
|
}
|
2014-12-02 07:34:06 +00:00
|
|
|
if ( ! strcmp(nch->string, "off")) {
|
|
|
|
mdoc->flags |= MDOC_SMOFF;
|
|
|
|
return;
|
2014-01-31 19:59:03 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SM_BAD, nch->line, nch->pos,
|
2017-06-08 19:29:07 +00:00
|
|
|
"%s %s", roff_name[mdoc->last->tok], nch->string);
|
2019-03-29 13:13:30 +00:00
|
|
|
roff_node_relink(mdoc, nch);
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_root(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/* Add missing prologue data. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->meta.date == NULL)
|
2019-07-26 09:51:35 +00:00
|
|
|
mdoc->meta.date = mandoc_normdate(mdoc, NULL, 0, 0);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->meta.title == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF");
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.title = mandoc_strdup("UNTITLED");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mdoc->meta.vol == NULL)
|
|
|
|
mdoc->meta.vol = mandoc_strdup("LOCAL");
|
|
|
|
|
|
|
|
if (mdoc->meta.os == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_OS_MISSING, 0, 0, NULL);
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.os = mandoc_strdup("");
|
2017-07-31 19:17:54 +00:00
|
|
|
} else if (mdoc->meta.os_e &&
|
|
|
|
(mdoc->meta.rcsids & (1 << mdoc->meta.os_e)) == 0)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_RCS_MISSING, 0, 0,
|
2017-07-31 19:17:54 +00:00
|
|
|
mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
|
|
|
|
"(OpenBSD)" : "(NetBSD)");
|
|
|
|
|
|
|
|
if (mdoc->meta.arch != NULL &&
|
2019-03-29 13:13:30 +00:00
|
|
|
arch_valid(mdoc->meta.arch, mdoc->meta.os_e) == 0) {
|
|
|
|
n = mdoc->meta.first->child;
|
|
|
|
while (n->tok != MDOC_Dt ||
|
|
|
|
n->child == NULL ||
|
|
|
|
n->child->next == NULL ||
|
|
|
|
n->child->next->next == NULL)
|
|
|
|
n = n->next;
|
|
|
|
n = n->child->next->next;
|
|
|
|
mandoc_msg(MANDOCERR_ARCH_BAD, n->line, n->pos,
|
|
|
|
"Dt ... %s %s", mdoc->meta.arch,
|
|
|
|
mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
|
|
|
|
"(OpenBSD)" : "(NetBSD)");
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that we begin with a proper `Sh'. */
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
n = mdoc->meta.first->child;
|
2018-09-20 07:33:14 +00:00
|
|
|
while (n != NULL &&
|
|
|
|
(n->type == ROFFT_COMMENT ||
|
|
|
|
(n->tok >= MDOC_Dd &&
|
2019-03-29 13:13:30 +00:00
|
|
|
mdoc_macro(n->tok)->flags & MDOC_PROLOGUE)))
|
2014-12-02 07:34:06 +00:00
|
|
|
n = n->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
if (n == NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DOC_EMPTY, 0, 0, NULL);
|
2014-12-02 07:34:06 +00:00
|
|
|
else if (n->tok != MDOC_Sh)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SEC_BEFORE, n->line, n->pos,
|
|
|
|
"%s", roff_name[n->tok]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_rs(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *np, *nch, *next, *prev;
|
2012-10-18 09:55:16 +00:00
|
|
|
int i, j;
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
np = mdoc->last;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->type != ROFFT_BODY)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
if (np->child == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_RS_EMPTY, np->line, np->pos, "Rs");
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The full `Rs' block needs special handling to order the
|
|
|
|
* sub-elements according to `rsord'. Pick through each element
|
2014-11-22 18:08:25 +00:00
|
|
|
* and correctly order it. This is an insertion sort.
|
2012-10-18 09:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
next = NULL;
|
2015-03-02 16:45:41 +00:00
|
|
|
for (nch = np->child->next; nch != NULL; nch = next) {
|
|
|
|
/* Determine order number of this child. */
|
2012-10-18 09:55:16 +00:00
|
|
|
for (i = 0; i < RSORD_MAX; i++)
|
2015-03-02 16:45:41 +00:00
|
|
|
if (rsord[i] == nch->tok)
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (i == RSORD_MAX) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_RS_BAD, nch->line, nch->pos,
|
|
|
|
"%s", roff_name[nch->tok]);
|
2014-11-22 18:08:25 +00:00
|
|
|
i = -1;
|
2015-03-02 16:45:41 +00:00
|
|
|
} else if (nch->tok == MDOC__J || nch->tok == MDOC__B)
|
|
|
|
np->norm->Rs.quote_T++;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
|
|
|
/*
|
2015-03-02 16:45:41 +00:00
|
|
|
* Remove this child from the chain. This somewhat
|
2016-01-15 23:08:59 +00:00
|
|
|
* repeats roff_node_unlink(), but since we're
|
2012-10-18 09:55:16 +00:00
|
|
|
* just re-ordering, there's no need for the
|
|
|
|
* full unlink process.
|
|
|
|
*/
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if ((next = nch->next) != NULL)
|
|
|
|
next->prev = nch->prev;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if ((prev = nch->prev) != NULL)
|
|
|
|
prev->next = nch->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
nch->prev = nch->next = NULL;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/*
|
2012-10-18 09:55:16 +00:00
|
|
|
* Scan back until we reach a node that's
|
2015-03-02 16:45:41 +00:00
|
|
|
* to be ordered before this child.
|
2012-10-18 09:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
for ( ; prev ; prev = prev->prev) {
|
|
|
|
/* Determine order of `prev'. */
|
|
|
|
for (j = 0; j < RSORD_MAX; j++)
|
|
|
|
if (rsord[j] == prev->tok)
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
if (j == RSORD_MAX)
|
|
|
|
j = -1;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if (j <= i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-02 16:45:41 +00:00
|
|
|
* Set this child back into its correct place
|
|
|
|
* in front of the `prev' node.
|
2012-10-18 09:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
nch->prev = prev;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (prev == NULL) {
|
|
|
|
np->child->prev = nch;
|
|
|
|
nch->next = np->child;
|
|
|
|
np->child = nch;
|
2012-10-18 09:55:16 +00:00
|
|
|
} else {
|
2015-03-02 16:45:41 +00:00
|
|
|
if (prev->next)
|
|
|
|
prev->next->prev = nch;
|
|
|
|
nch->next = prev->next;
|
|
|
|
prev->next = nch;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
/*
|
|
|
|
* For some arguments of some macros,
|
|
|
|
* convert all breakable hyphens into ASCII_HYPH.
|
|
|
|
*/
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-01-31 19:59:03 +00:00
|
|
|
post_hyph(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nch;
|
2014-01-31 19:59:03 +00:00
|
|
|
char *cp;
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
for (nch = mdoc->last->child; nch != NULL; nch = nch->next) {
|
2016-01-15 23:08:59 +00:00
|
|
|
if (nch->type != ROFFT_TEXT)
|
2014-01-31 19:59:03 +00:00
|
|
|
continue;
|
|
|
|
cp = nch->string;
|
2015-03-02 16:45:41 +00:00
|
|
|
if (*cp == '\0')
|
2014-01-31 19:59:03 +00:00
|
|
|
continue;
|
2015-03-02 16:45:41 +00:00
|
|
|
while (*(++cp) != '\0')
|
|
|
|
if (*cp == '-' &&
|
2014-01-31 19:59:03 +00:00
|
|
|
isalpha((unsigned char)cp[-1]) &&
|
|
|
|
isalpha((unsigned char)cp[1]))
|
|
|
|
*cp = ASCII_HYPH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_ns(POST_ARGS)
|
|
|
|
{
|
2017-07-31 19:17:54 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
if (n->flags & NODE_LINE ||
|
|
|
|
(n->next != NULL && n->next->flags & NODE_DELIMC))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NS_SKIP, n->line, n->pos, NULL);
|
2017-07-31 19:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_sx(POST_ARGS)
|
|
|
|
{
|
|
|
|
post_delim(mdoc);
|
|
|
|
post_hyph(mdoc);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_sh(POST_ARGS)
|
|
|
|
{
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
post_ignpar(mdoc);
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
switch (mdoc->last->type) {
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_HEAD:
|
2014-12-02 07:34:06 +00:00
|
|
|
post_sh_head(mdoc);
|
|
|
|
break;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_BODY:
|
2014-12-02 07:34:06 +00:00
|
|
|
switch (mdoc->lastsec) {
|
|
|
|
case SEC_NAME:
|
|
|
|
post_sh_name(mdoc);
|
|
|
|
break;
|
|
|
|
case SEC_SEE_ALSO:
|
|
|
|
post_sh_see_also(mdoc);
|
|
|
|
break;
|
|
|
|
case SEC_AUTHORS:
|
|
|
|
post_sh_authors(mdoc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
|
|
|
post_sh_name(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2015-03-02 16:45:41 +00:00
|
|
|
int hasnm, hasnd;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
hasnm = hasnd = 0;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
for (n = mdoc->last->child; n != NULL; n = n->next) {
|
|
|
|
switch (n->tok) {
|
|
|
|
case MDOC_Nm:
|
2017-01-21 13:01:39 +00:00
|
|
|
if (hasnm && n->child != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_PUNCT,
|
|
|
|
n->line, n->pos,
|
2017-01-21 13:01:39 +00:00
|
|
|
"Nm %s", n->child->string);
|
2015-03-02 16:45:41 +00:00
|
|
|
hasnm = 1;
|
2017-01-21 13:01:39 +00:00
|
|
|
continue;
|
2015-03-02 16:45:41 +00:00
|
|
|
case MDOC_Nd:
|
|
|
|
hasnd = 1;
|
|
|
|
if (n->next != NULL)
|
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_ND,
|
2019-03-29 13:13:30 +00:00
|
|
|
n->line, n->pos, NULL);
|
2015-03-02 16:45:41 +00:00
|
|
|
break;
|
2016-01-15 23:08:59 +00:00
|
|
|
case TOKEN_NONE:
|
2017-01-21 13:01:39 +00:00
|
|
|
if (n->type == ROFFT_TEXT &&
|
|
|
|
n->string[0] == ',' && n->string[1] == '\0' &&
|
|
|
|
n->next != NULL && n->next->tok == MDOC_Nm) {
|
|
|
|
n = n->next;
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-02 16:45:41 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_BAD,
|
|
|
|
n->line, n->pos, "%s", roff_name[n->tok]);
|
2017-01-21 13:01:39 +00:00
|
|
|
continue;
|
2015-03-02 16:45:41 +00:00
|
|
|
}
|
2017-01-21 13:01:39 +00:00
|
|
|
break;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if ( ! hasnm)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_NONM,
|
2015-03-02 16:45:41 +00:00
|
|
|
mdoc->last->line, mdoc->last->pos, NULL);
|
|
|
|
if ( ! hasnd)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_NOND,
|
2015-03-02 16:45:41 +00:00
|
|
|
mdoc->last->line, mdoc->last->pos, NULL);
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_sh_see_also(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
const struct roff_node *n;
|
2015-03-02 16:45:41 +00:00
|
|
|
const char *name, *sec;
|
2014-12-02 07:34:06 +00:00
|
|
|
const char *lastname, *lastsec, *lastpunct;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
n = mdoc->last->child;
|
|
|
|
lastname = lastsec = lastpunct = NULL;
|
|
|
|
while (n != NULL) {
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->tok != MDOC_Xr ||
|
|
|
|
n->child == NULL ||
|
|
|
|
n->child->next == NULL)
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Process one .Xr node. */
|
|
|
|
|
|
|
|
name = n->child->string;
|
|
|
|
sec = n->child->next->string;
|
|
|
|
if (lastsec != NULL) {
|
|
|
|
if (lastpunct[0] != ',' || lastpunct[1] != '\0')
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_PUNCT, n->line,
|
|
|
|
n->pos, "%s before %s(%s)",
|
|
|
|
lastpunct, name, sec);
|
2014-12-02 07:34:06 +00:00
|
|
|
cmp = strcmp(lastsec, sec);
|
|
|
|
if (cmp > 0)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_ORDER, n->line,
|
|
|
|
n->pos, "%s(%s) after %s(%s)",
|
|
|
|
name, sec, lastname, lastsec);
|
2014-12-02 07:34:06 +00:00
|
|
|
else if (cmp == 0 &&
|
|
|
|
strcasecmp(lastname, name) > 0)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_ORDER, n->line,
|
|
|
|
n->pos, "%s after %s", name, lastname);
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
lastname = name;
|
|
|
|
lastsec = sec;
|
|
|
|
|
|
|
|
/* Process the following node. */
|
|
|
|
|
|
|
|
n = n->next;
|
|
|
|
if (n == NULL)
|
|
|
|
break;
|
|
|
|
if (n->tok == MDOC_Xr) {
|
|
|
|
lastpunct = "none";
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->type != ROFFT_TEXT)
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
for (name = n->string; *name != '\0'; name++)
|
|
|
|
if (isalpha((const unsigned char)*name))
|
|
|
|
return;
|
|
|
|
lastpunct = n->string;
|
2017-06-08 19:29:07 +00:00
|
|
|
if (n->next == NULL || n->next->tok == MDOC_Rs)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_PUNCT, n->line,
|
|
|
|
n->pos, "%s after %s(%s)",
|
2014-12-02 07:34:06 +00:00
|
|
|
lastpunct, lastname, lastsec);
|
|
|
|
n = n->next;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-01-15 23:08:59 +00:00
|
|
|
child_an(const struct roff_node *n)
|
2014-12-02 07:34:06 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
for (n = n->child; n != NULL; n = n->next)
|
2016-01-15 23:08:59 +00:00
|
|
|
if ((n->tok == MDOC_An && n->child != NULL) || child_an(n))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_sh_authors(POST_ARGS)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( ! child_an(mdoc->last))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_AN_MISSING,
|
2014-12-02 07:34:06 +00:00
|
|
|
mdoc->last->line, mdoc->last->pos, NULL);
|
|
|
|
}
|
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
/*
|
|
|
|
* Return an upper bound for the string distance (allowing
|
|
|
|
* transpositions). Not a full Levenshtein implementation
|
|
|
|
* because Levenshtein is quadratic in the string length
|
|
|
|
* and this function is called for every standard name,
|
|
|
|
* so the check for each custom name would be cubic.
|
|
|
|
* The following crude heuristics is linear, resulting
|
|
|
|
* in quadratic behaviour for checking one custom name,
|
|
|
|
* which does not cause measurable slowdown.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
similar(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
const int maxdist = 3;
|
|
|
|
int dist = 0;
|
|
|
|
|
|
|
|
while (s1[0] != '\0' && s2[0] != '\0') {
|
|
|
|
if (s1[0] == s2[0]) {
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (++dist > maxdist)
|
|
|
|
return INT_MAX;
|
|
|
|
if (s1[1] == s2[1]) { /* replacement */
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
} else if (s1[0] == s2[1] && s1[1] == s2[0]) {
|
|
|
|
s1 += 2; /* transposition */
|
|
|
|
s2 += 2;
|
|
|
|
} else if (s1[0] == s2[1]) /* insertion */
|
|
|
|
s2++;
|
|
|
|
else if (s1[1] == s2[0]) /* deletion */
|
|
|
|
s1++;
|
|
|
|
else
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
dist += strlen(s1) + strlen(s2);
|
|
|
|
return dist > maxdist ? INT_MAX : dist;
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_sh_head(POST_ARGS)
|
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
struct roff_node *nch;
|
|
|
|
const char *goodsec;
|
2017-07-31 19:17:54 +00:00
|
|
|
const char *const *testsec;
|
|
|
|
int dist, mindist;
|
2017-01-21 13:01:39 +00:00
|
|
|
enum roff_sec sec;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a new section. Sections are either "named" or
|
|
|
|
* "custom". Custom sections are user-defined, while named ones
|
|
|
|
* follow a conventional order and may only appear in certain
|
|
|
|
* manual sections.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
sec = mdoc->last->sec;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* The NAME should be first. */
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
if (sec != SEC_NAME && mdoc->lastnamed == SEC_NONE)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_FIRST,
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last->line, mdoc->last->pos, "Sh %s",
|
|
|
|
sec != SEC_CUSTOM ? secnames[sec] :
|
|
|
|
(nch = mdoc->last->child) == NULL ? "" :
|
|
|
|
nch->type == ROFFT_TEXT ? nch->string :
|
2017-06-08 19:29:07 +00:00
|
|
|
roff_name[nch->tok]);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* The SYNOPSIS gets special attention in other areas. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (sec == SEC_SYNOPSIS) {
|
2014-01-31 19:59:03 +00:00
|
|
|
roff_setreg(mdoc->roff, "nS", 1, '=');
|
2012-10-18 09:55:16 +00:00
|
|
|
mdoc->flags |= MDOC_SYNOPSIS;
|
2014-01-31 19:59:03 +00:00
|
|
|
} else {
|
|
|
|
roff_setreg(mdoc->roff, "nS", 0, '=');
|
2012-10-18 09:55:16 +00:00
|
|
|
mdoc->flags &= ~MDOC_SYNOPSIS;
|
2014-01-31 19:59:03 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Mark our last section. */
|
|
|
|
|
|
|
|
mdoc->lastsec = sec;
|
|
|
|
|
|
|
|
/* We don't care about custom sections after this. */
|
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
if (sec == SEC_CUSTOM) {
|
|
|
|
if ((nch = mdoc->last->child) == NULL ||
|
|
|
|
nch->type != ROFFT_TEXT || nch->next != NULL)
|
|
|
|
return;
|
|
|
|
goodsec = NULL;
|
|
|
|
mindist = INT_MAX;
|
|
|
|
for (testsec = secnames + 1; *testsec != NULL; testsec++) {
|
|
|
|
dist = similar(nch->string, *testsec);
|
|
|
|
if (dist < mindist) {
|
|
|
|
goodsec = *testsec;
|
|
|
|
mindist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (goodsec != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SEC_TYPO, nch->line, nch->pos,
|
|
|
|
"Sh %s instead of %s", nch->string, goodsec);
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2017-07-31 19:17:54 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether our non-custom section is being repeated or is
|
|
|
|
* out of order.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sec == mdoc->lastnamed)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SEC_REP, mdoc->last->line,
|
|
|
|
mdoc->last->pos, "Sh %s", secnames[sec]);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if (sec < mdoc->lastnamed)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SEC_ORDER, mdoc->last->line,
|
|
|
|
mdoc->last->pos, "Sh %s", secnames[sec]);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Mark the last named section. */
|
|
|
|
|
|
|
|
mdoc->lastnamed = sec;
|
|
|
|
|
|
|
|
/* Check particular section/manual conventions. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->meta.msec == NULL)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
goodsec = NULL;
|
2012-10-18 09:55:16 +00:00
|
|
|
switch (sec) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case SEC_ERRORS:
|
|
|
|
if (*mdoc->meta.msec == '4')
|
|
|
|
break;
|
|
|
|
goodsec = "2, 3, 4, 9";
|
2012-10-18 09:55:16 +00:00
|
|
|
/* FALLTHROUGH */
|
2014-11-22 18:08:25 +00:00
|
|
|
case SEC_RETURN_VALUES:
|
|
|
|
case SEC_LIBRARY:
|
2012-10-18 09:55:16 +00:00
|
|
|
if (*mdoc->meta.msec == '2')
|
|
|
|
break;
|
|
|
|
if (*mdoc->meta.msec == '3')
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
if (NULL == goodsec)
|
|
|
|
goodsec = "2, 3, 9";
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case SEC_CONTEXT:
|
2012-10-18 09:55:16 +00:00
|
|
|
if (*mdoc->meta.msec == '9')
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
if (NULL == goodsec)
|
|
|
|
goodsec = "9";
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_SEC_MSEC,
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->last->line, mdoc->last->pos,
|
2016-01-15 23:08:59 +00:00
|
|
|
"Sh %s for %s only", secnames[sec], goodsec);
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
static void
|
|
|
|
post_xr(POST_ARGS)
|
|
|
|
{
|
|
|
|
struct roff_node *n, *nch;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
nch = n->child;
|
|
|
|
if (nch->next == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_NOSEC,
|
2017-01-21 13:01:39 +00:00
|
|
|
n->line, n->pos, "Xr %s", nch->string);
|
2017-07-31 19:17:54 +00:00
|
|
|
} else {
|
|
|
|
assert(nch->next == n->last);
|
|
|
|
if(mandoc_xr_add(nch->next->string, nch->string,
|
|
|
|
nch->line, nch->pos))
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_XR_SELF,
|
2017-07-31 19:17:54 +00:00
|
|
|
nch->line, nch->pos, "Xr %s %s",
|
|
|
|
nch->string, nch->next->string);
|
2017-01-21 13:01:39 +00:00
|
|
|
}
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb(mdoc);
|
2017-01-21 13:01:39 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_ignpar(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *np;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
switch (mdoc->last->type) {
|
2017-06-08 19:29:07 +00:00
|
|
|
case ROFFT_BLOCK:
|
|
|
|
post_prevpar(mdoc);
|
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_HEAD:
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim(mdoc);
|
2015-03-02 16:45:41 +00:00
|
|
|
post_hyph(mdoc);
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_BODY:
|
2015-03-02 16:45:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if ((np = mdoc->last->child) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
if (np->tok == MDOC_Pp ||
|
|
|
|
np->tok == ROFF_br || np->tok == ROFF_sp) {
|
|
|
|
mandoc_msg(MANDOCERR_PAR_SKIP, np->line, np->pos,
|
2017-06-08 19:29:07 +00:00
|
|
|
"%s after %s", roff_name[np->tok],
|
|
|
|
roff_name[mdoc->last->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, np);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if ((np = mdoc->last->last) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
if (np->tok == MDOC_Pp || np->tok == ROFF_br) {
|
|
|
|
mandoc_msg(MANDOCERR_PAR_SKIP, np->line, np->pos,
|
|
|
|
"%s at the end of %s", roff_name[np->tok],
|
2017-06-08 19:29:07 +00:00
|
|
|
roff_name[mdoc->last->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, np);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2016-01-15 23:08:59 +00:00
|
|
|
post_prevpar(POST_ARGS)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
if (NULL == n->prev)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->type != ROFFT_ELEM && n->type != ROFFT_BLOCK)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/*
|
2019-03-29 13:13:30 +00:00
|
|
|
* Don't allow `Pp' prior to a paragraph-type
|
|
|
|
* block: `Pp' or non-compact `Bd' or `Bl'.
|
2012-10-18 09:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
if (n->prev->tok != MDOC_Pp && n->prev->tok != ROFF_br)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->tok == MDOC_Bl && n->norm->Bl.comp)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->tok == MDOC_Bd && n->norm->Bd.comp)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->tok == MDOC_It && n->parent->norm->Bl.comp)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PAR_SKIP, n->prev->line, n->prev->pos,
|
|
|
|
"%s before %s", roff_name[n->prev->tok], roff_name[n->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, n->prev);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2014-01-31 19:59:03 +00:00
|
|
|
post_par(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *np;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
post_prevpar(mdoc);
|
2014-01-31 19:59:03 +00:00
|
|
|
|
2019-03-29 13:13:30 +00:00
|
|
|
np = mdoc->last;
|
|
|
|
if (np->child != NULL)
|
|
|
|
mandoc_msg(MANDOCERR_ARG_SKIP, np->line, np->pos,
|
|
|
|
"%s %s", roff_name[np->tok], np->child->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_dd(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2014-11-22 18:08:25 +00:00
|
|
|
char *datestr;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
2017-01-21 13:01:39 +00:00
|
|
|
n->flags |= NODE_NOPRT;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->meta.date != NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, n->line, n->pos, "Dd");
|
2012-10-18 09:55:16 +00:00
|
|
|
free(mdoc->meta.date);
|
2016-01-15 23:08:59 +00:00
|
|
|
} else if (mdoc->flags & MDOC_PBODY)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_LATE, n->line, n->pos, "Dd");
|
2016-01-15 23:08:59 +00:00
|
|
|
else if (mdoc->meta.title != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER,
|
2016-01-15 23:08:59 +00:00
|
|
|
n->line, n->pos, "Dd after Dt");
|
|
|
|
else if (mdoc->meta.os != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER,
|
2016-01-15 23:08:59 +00:00
|
|
|
n->line, n->pos, "Dd after Os");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
datestr = NULL;
|
2016-01-15 23:08:59 +00:00
|
|
|
deroff(&datestr, n);
|
2019-07-26 09:51:35 +00:00
|
|
|
mdoc->meta.date = mandoc_normdate(mdoc, datestr, n->line, n->pos);
|
|
|
|
free(datestr);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_dt(POST_ARGS)
|
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *nn, *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
const char *cp;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
2017-01-21 13:01:39 +00:00
|
|
|
n->flags |= NODE_NOPRT;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->flags & MDOC_PBODY) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DT_LATE, n->line, n->pos, "Dt");
|
2017-01-21 13:01:39 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mdoc->meta.title != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, n->line, n->pos, "Dt");
|
2016-01-15 23:08:59 +00:00
|
|
|
else if (mdoc->meta.os != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER,
|
2016-01-15 23:08:59 +00:00
|
|
|
n->line, n->pos, "Dt after Os");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
free(mdoc->meta.title);
|
|
|
|
free(mdoc->meta.msec);
|
|
|
|
free(mdoc->meta.vol);
|
|
|
|
free(mdoc->meta.arch);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.title = NULL;
|
|
|
|
mdoc->meta.msec = NULL;
|
|
|
|
mdoc->meta.vol = NULL;
|
|
|
|
mdoc->meta.arch = NULL;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
/* Mandatory first argument: title. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
nn = n->child;
|
|
|
|
if (nn == NULL || *nn->string == '\0') {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_DT_NOTITLE, n->line, n->pos, "Dt");
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.title = mandoc_strdup("UNTITLED");
|
2015-03-02 16:45:41 +00:00
|
|
|
} else {
|
|
|
|
mdoc->meta.title = mandoc_strdup(nn->string);
|
|
|
|
|
|
|
|
/* Check that all characters are uppercase. */
|
|
|
|
|
|
|
|
for (p = nn->string; *p != '\0'; p++)
|
|
|
|
if (islower((unsigned char)*p)) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_TITLE_CASE, nn->line,
|
|
|
|
nn->pos + (int)(p - nn->string),
|
2015-03-02 16:45:41 +00:00
|
|
|
"Dt %s", nn->string);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
/* Mandatory second argument: section. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nn != NULL)
|
|
|
|
nn = nn->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (nn == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MSEC_MISSING, n->line, n->pos,
|
2014-11-22 18:08:25 +00:00
|
|
|
"Dt %s", mdoc->meta.title);
|
2012-10-18 09:55:16 +00:00
|
|
|
mdoc->meta.vol = mandoc_strdup("LOCAL");
|
2017-01-21 13:01:39 +00:00
|
|
|
return; /* msec and arch remain NULL. */
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
mdoc->meta.msec = mandoc_strdup(nn->string);
|
|
|
|
|
|
|
|
/* Infer volume title from section number. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
cp = mandoc_a2msec(nn->string);
|
2015-03-02 16:45:41 +00:00
|
|
|
if (cp == NULL) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MSEC_BAD,
|
2014-11-22 18:08:25 +00:00
|
|
|
nn->line, nn->pos, "Dt ... %s", nn->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
mdoc->meta.vol = mandoc_strdup(nn->string);
|
2015-03-02 16:45:41 +00:00
|
|
|
} else
|
|
|
|
mdoc->meta.vol = mandoc_strdup(cp);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
/* Optional third argument: architecture. */
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if ((nn = nn->next) == NULL)
|
2017-01-21 13:01:39 +00:00
|
|
|
return;
|
2015-03-02 16:45:41 +00:00
|
|
|
|
|
|
|
for (p = nn->string; *p != '\0'; p++)
|
|
|
|
*p = tolower((unsigned char)*p);
|
|
|
|
mdoc->meta.arch = mandoc_strdup(nn->string);
|
|
|
|
|
|
|
|
/* Ignore fourth and later arguments. */
|
|
|
|
|
|
|
|
if ((nn = nn->next) != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_EXCESS,
|
2015-03-02 16:45:41 +00:00
|
|
|
nn->line, nn->pos, "Dt ... %s", nn->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_bx(POST_ARGS)
|
|
|
|
{
|
2017-01-21 13:01:39 +00:00
|
|
|
struct roff_node *n, *nch;
|
2017-06-08 19:29:07 +00:00
|
|
|
const char *macro;
|
2017-01-21 13:01:39 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim_nb(mdoc);
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
nch = n->child;
|
|
|
|
|
|
|
|
if (nch != NULL) {
|
2017-06-08 19:29:07 +00:00
|
|
|
macro = !strcmp(nch->string, "Open") ? "Ox" :
|
|
|
|
!strcmp(nch->string, "Net") ? "Nx" :
|
|
|
|
!strcmp(nch->string, "Free") ? "Fx" :
|
|
|
|
!strcmp(nch->string, "DragonFly") ? "Dx" : NULL;
|
|
|
|
if (macro != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_BX,
|
|
|
|
n->line, n->pos, "%s", macro);
|
2017-01-21 13:01:39 +00:00
|
|
|
mdoc->last = nch;
|
|
|
|
nch = nch->next;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
} else
|
|
|
|
mdoc->next = ROFF_NEXT_CHILD;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "BSD");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
|
|
|
|
if (nch == NULL) {
|
|
|
|
mdoc->last = n;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "-");
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
|
|
|
|
mdoc->last->flags |= NODE_NOSRC;
|
|
|
|
mdoc->last = n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
/*
|
2012-10-18 09:55:16 +00:00
|
|
|
* Make `Bx's second argument always start with an uppercase
|
|
|
|
* letter. Groff checks if it's an "accepted" term, but we just
|
|
|
|
* uppercase blindly.
|
|
|
|
*/
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
*nch->string = (char)toupper((unsigned char)*nch->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
2012-10-18 09:55:16 +00:00
|
|
|
post_os(POST_ARGS)
|
|
|
|
{
|
|
|
|
#ifndef OSNAME
|
|
|
|
struct utsname utsname;
|
2014-11-22 18:08:25 +00:00
|
|
|
static char *defbuf;
|
2012-10-18 09:55:16 +00:00
|
|
|
#endif
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
n = mdoc->last;
|
2017-01-21 13:01:39 +00:00
|
|
|
n->flags |= NODE_NOPRT;
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->meta.os != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, n->line, n->pos, "Os");
|
2016-01-15 23:08:59 +00:00
|
|
|
else if (mdoc->flags & MDOC_PBODY)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_PROLOG_LATE, n->line, n->pos, "Os");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
post_delim(mdoc);
|
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
2014-01-31 19:59:03 +00:00
|
|
|
* Set the operating system by way of the `Os' macro.
|
|
|
|
* The order of precedence is:
|
|
|
|
* 1. the argument of the `Os' macro, unless empty
|
|
|
|
* 2. the -Ios=foo command line argument, if provided
|
|
|
|
* 3. -DOSNAME="\"foo\"", if provided during compilation
|
|
|
|
* 4. "sysname release" from uname(3)
|
2014-11-22 18:08:25 +00:00
|
|
|
*/
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
free(mdoc->meta.os);
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.os = NULL;
|
2016-01-15 23:08:59 +00:00
|
|
|
deroff(&mdoc->meta.os, n);
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->meta.os)
|
2017-06-08 19:29:07 +00:00
|
|
|
goto out;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
if (mdoc->os_s != NULL) {
|
|
|
|
mdoc->meta.os = mandoc_strdup(mdoc->os_s);
|
2017-06-08 19:29:07 +00:00
|
|
|
goto out;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OSNAME
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.os = mandoc_strdup(OSNAME);
|
2012-10-18 09:55:16 +00:00
|
|
|
#else /*!OSNAME */
|
2016-01-15 23:08:59 +00:00
|
|
|
if (defbuf == NULL) {
|
|
|
|
if (uname(&utsname) == -1) {
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_OS_UNAME, n->line, n->pos, "Os");
|
2014-11-22 18:08:25 +00:00
|
|
|
defbuf = mandoc_strdup("UNKNOWN");
|
|
|
|
} else
|
|
|
|
mandoc_asprintf(&defbuf, "%s %s",
|
|
|
|
utsname.sysname, utsname.release);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.os = mandoc_strdup(defbuf);
|
|
|
|
#endif /*!OSNAME*/
|
2017-06-08 19:29:07 +00:00
|
|
|
|
2017-07-31 19:17:54 +00:00
|
|
|
out:
|
|
|
|
if (mdoc->meta.os_e == MANDOC_OS_OTHER) {
|
|
|
|
if (strstr(mdoc->meta.os, "OpenBSD") != NULL)
|
|
|
|
mdoc->meta.os_e = MANDOC_OS_OPENBSD;
|
|
|
|
else if (strstr(mdoc->meta.os, "NetBSD") != NULL)
|
|
|
|
mdoc->meta.os_e = MANDOC_OS_NETBSD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the earliest point where we can check
|
|
|
|
* Mdocdate conventions because we don't know
|
|
|
|
* the operating system earlier.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (n->child != NULL)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_OS_ARG, n->child->line, n->child->pos,
|
2017-07-31 19:17:54 +00:00
|
|
|
"Os %s (%s)", n->child->string,
|
|
|
|
mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
|
|
|
|
"OpenBSD" : "NetBSD");
|
|
|
|
|
|
|
|
while (n->tok != MDOC_Dd)
|
|
|
|
if ((n = n->prev) == NULL)
|
|
|
|
return;
|
|
|
|
if ((n = n->child) == NULL)
|
|
|
|
return;
|
|
|
|
if (strncmp(n->string, "$" "Mdocdate", 9)) {
|
|
|
|
if (mdoc->meta.os_e == MANDOC_OS_OPENBSD)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MDOCDATE_MISSING, n->line,
|
|
|
|
n->pos, "Dd %s (OpenBSD)", n->string);
|
2017-07-31 19:17:54 +00:00
|
|
|
} else {
|
|
|
|
if (mdoc->meta.os_e == MANDOC_OS_NETBSD)
|
2019-03-29 13:13:30 +00:00
|
|
|
mandoc_msg(MANDOCERR_MDOCDATE, n->line,
|
|
|
|
n->pos, "Dd %s (NetBSD)", n->string);
|
2017-07-31 19:17:54 +00:00
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
enum roff_sec
|
|
|
|
mdoc_a2sec(const char *p)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
for (i = 0; i < (int)SEC__MAX; i++)
|
2012-10-18 09:55:16 +00:00
|
|
|
if (secnames[i] && 0 == strcmp(p, secnames[i]))
|
2016-01-15 23:08:59 +00:00
|
|
|
return (enum roff_sec)i;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return SEC_CUSTOM;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2017-06-08 19:29:07 +00:00
|
|
|
macro2len(enum roff_tok macro)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (macro) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ad:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ao:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_An:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Aq:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ar:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Bo:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Bq:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Cd:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Cm:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Do:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Dq:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Dv:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Eo:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Em:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Er:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 17;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ev:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 15;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Fa:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Fl:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Fo:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 16;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Fn:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 16;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ic:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Li:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 16;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ms:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 6;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Nm:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_No:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Oo:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Op:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 14;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Pa:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 32;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Pf:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Po:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Pq:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Ql:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 16;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Qo:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_So:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Sq:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Sy:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 6;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Sx:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 16;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Tn:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Va:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Vt:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 12;
|
2014-11-22 18:08:25 +00:00
|
|
|
case MDOC_Xr:
|
2016-01-15 23:08:59 +00:00
|
|
|
return 10;
|
2012-10-18 09:55:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
2016-01-15 23:08:59 +00:00
|
|
|
return 0;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|