2017-01-21 13:01:39 +00:00
|
|
|
/* $Id: mdoc_validate.c,v 1.317 2017/01/11 17:39:53 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>
|
2017-01-21 13:01:39 +00:00
|
|
|
* Copyright (c) 2010-2017 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"
|
|
|
|
#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_text(struct roff_man *, int, int, char *);
|
|
|
|
static void check_argv(struct roff_man *,
|
|
|
|
struct roff_node *, struct mdoc_argv *);
|
|
|
|
static void check_args(struct roff_man *, struct roff_node *);
|
|
|
|
static int child_an(const struct roff_node *);
|
|
|
|
static size_t macro2len(int);
|
2014-12-02 07:34:06 +00:00
|
|
|
static void rewrite_macro2len(char **);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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-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
|
|
|
|
|
|
|
static v_post mdoc_valids[MDOC_MAX] = {
|
|
|
|
NULL, /* Ap */
|
|
|
|
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 */
|
|
|
|
NULL, /* Ad */
|
|
|
|
post_an, /* An */
|
|
|
|
post_defaults, /* Ar */
|
|
|
|
NULL, /* Cd */
|
|
|
|
NULL, /* Cm */
|
|
|
|
NULL, /* Dv */
|
|
|
|
NULL, /* Er */
|
|
|
|
NULL, /* Ev */
|
|
|
|
post_ex, /* Ex */
|
|
|
|
post_fa, /* Fa */
|
|
|
|
NULL, /* Fd */
|
|
|
|
NULL, /* Fl */
|
|
|
|
post_fn, /* Fn */
|
|
|
|
NULL, /* Ft */
|
|
|
|
NULL, /* Ic */
|
|
|
|
NULL, /* In */
|
|
|
|
post_defaults, /* Li */
|
|
|
|
post_nd, /* Nd */
|
|
|
|
post_nm, /* Nm */
|
|
|
|
NULL, /* Op */
|
|
|
|
post_obsolete, /* Ot */
|
|
|
|
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 */
|
|
|
|
NULL, /* Va */
|
|
|
|
NULL, /* 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 */
|
|
|
|
NULL, /* Ao */
|
|
|
|
NULL, /* Aq */
|
|
|
|
post_at, /* At */
|
|
|
|
NULL, /* Bc */
|
|
|
|
post_bf, /* Bf */
|
|
|
|
NULL, /* Bo */
|
|
|
|
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 */
|
|
|
|
NULL, /* Em */
|
|
|
|
NULL, /* Eo */
|
2017-01-21 13:01:39 +00:00
|
|
|
post_xx, /* Fx */
|
2016-01-15 23:08:59 +00:00
|
|
|
NULL, /* Ms */
|
|
|
|
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 */
|
|
|
|
NULL, /* Po */
|
|
|
|
NULL, /* Pq */
|
|
|
|
NULL, /* Qc */
|
|
|
|
NULL, /* Ql */
|
|
|
|
NULL, /* Qo */
|
|
|
|
NULL, /* Qq */
|
|
|
|
NULL, /* Re */
|
|
|
|
post_rs, /* Rs */
|
|
|
|
NULL, /* Sc */
|
|
|
|
NULL, /* So */
|
|
|
|
NULL, /* Sq */
|
|
|
|
post_sm, /* Sm */
|
|
|
|
post_hyph, /* Sx */
|
|
|
|
NULL, /* Sy */
|
|
|
|
NULL, /* 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 */
|
|
|
|
NULL, /* Oo */
|
|
|
|
NULL, /* Oc */
|
|
|
|
post_bk, /* Bk */
|
|
|
|
NULL, /* Ek */
|
|
|
|
post_eoln, /* Bt */
|
|
|
|
NULL, /* Hf */
|
|
|
|
post_obsolete, /* Fr */
|
|
|
|
post_eoln, /* Ud */
|
|
|
|
post_lb, /* Lb */
|
|
|
|
post_par, /* Lp */
|
|
|
|
NULL, /* Lk */
|
|
|
|
post_defaults, /* Mt */
|
|
|
|
NULL, /* Brq */
|
|
|
|
NULL, /* Bro */
|
|
|
|
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 */
|
|
|
|
post_par, /* br */
|
|
|
|
post_par, /* sp */
|
|
|
|
NULL, /* %U */
|
|
|
|
NULL, /* Ta */
|
|
|
|
NULL, /* ll */
|
2012-10-18 09:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define RSORD_MAX 14 /* Number of `Rs' blocks. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
static const int 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
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
void
|
2016-01-15 23:08:59 +00:00
|
|
|
mdoc_node_validate(struct roff_man *mdoc)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
2016-01-15 23:08:59 +00:00
|
|
|
struct roff_node *n;
|
|
|
|
v_post *p;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
n = mdoc->last;
|
|
|
|
mdoc->last = mdoc->last->child;
|
|
|
|
while (mdoc->last != NULL) {
|
|
|
|
mdoc_node_validate(mdoc);
|
|
|
|
if (mdoc->last == n)
|
|
|
|
mdoc->last = mdoc->last->child;
|
|
|
|
else
|
|
|
|
mdoc->last = mdoc->last->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2017-01-21 13:01:39 +00:00
|
|
|
if (n->sec != SEC_SYNOPSIS ||
|
|
|
|
(n->parent->tok != MDOC_Cd && n->parent->tok != MDOC_Fd))
|
2015-03-02 16:45:41 +00:00
|
|
|
check_text(mdoc, n->line, n->pos, n->string);
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
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. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
p = mdoc_valids + n->tok;
|
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;
|
|
|
|
|
2014-01-31 19:59:03 +00:00
|
|
|
if (MDOC_LITERAL & mdoc->flags)
|
2012-10-18 09:55:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (cp = p; NULL != (p = strchr(p, '\t')); p++)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_FI_TAB, mdoc->parse,
|
|
|
|
ln, pos + (int)(p - cp), NULL);
|
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_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,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bl -compact");
|
|
|
|
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,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bl -width");
|
|
|
|
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)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_REP,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bl -width %s",
|
|
|
|
argv->value[0]);
|
2014-12-02 07:34:06 +00:00
|
|
|
rewrite_macro2len(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,
|
|
|
|
mdoc->parse, 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)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_REP,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bl -offset %s",
|
|
|
|
argv->value[0]);
|
2014-12-02 07:34:06 +00:00
|
|
|
rewrite_macro2len(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) {
|
|
|
|
mandoc_vmsg(MANDOCERR_BL_REP,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"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)
|
|
|
|
mandoc_vmsg(MANDOCERR_BL_LATETYPE,
|
|
|
|
mdoc->parse, n->line, n->pos, "Bl -%s",
|
|
|
|
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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_NOTYPE, mdoc->parse,
|
|
|
|
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:
|
2014-01-31 19:59:03 +00:00
|
|
|
if (NULL == n->norm->Bl.width)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_NOWIDTH, mdoc->parse,
|
|
|
|
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:
|
2012-10-18 09:55:16 +00:00
|
|
|
if (n->norm->Bl.width)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_BL_SKIPW, mdoc->parse,
|
|
|
|
wa->line, wa->pos, "Bl -%s",
|
|
|
|
mdoc_argnames[mdoclt]);
|
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:
|
2014-01-31 19:59:03 +00:00
|
|
|
if (NULL == n->norm->Bl.width)
|
|
|
|
n->norm->Bl.width = "2n";
|
|
|
|
break;
|
2014-11-22 18:08:25 +00:00
|
|
|
case LIST_enum:
|
2014-01-31 19:59:03 +00:00
|
|
|
if (NULL == n->norm->Bl.width)
|
|
|
|
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:
|
|
|
|
mandoc_msg(MANDOCERR_BD_FILE, mdoc->parse,
|
|
|
|
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,
|
|
|
|
mdoc->parse, 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)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_REP,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bd -offset %s",
|
|
|
|
argv->value[0]);
|
2014-12-02 07:34:06 +00:00
|
|
|
rewrite_macro2len(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,
|
|
|
|
mdoc->parse, argv->line,
|
|
|
|
argv->pos, "Bd -compact");
|
|
|
|
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
|
|
|
|
mandoc_vmsg(MANDOCERR_BD_REP,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"Bd -%s", mdoc_argnames[argv->arg]);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DISP__NONE == n->norm->Bd.type) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_BD_NOTYPE, mdoc->parse,
|
|
|
|
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;
|
|
|
|
mandoc_vmsg(MANDOCERR_AN_REP,
|
|
|
|
mdoc->parse, argv->line, argv->pos,
|
|
|
|
"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;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
if (n->child != NULL)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
|
|
|
|
n->line, n->pos, "%s %s",
|
|
|
|
mdoc_macronames[n->tok], n->child->string);
|
|
|
|
|
|
|
|
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;
|
|
|
|
mdoc_node_relink(mdoc, n);
|
|
|
|
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 {
|
|
|
|
mandoc_msg(MANDOCERR_EX_NONAME, mdoc->parse,
|
|
|
|
n->line, n->pos, "Ex");
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "library");
|
|
|
|
mdoc->last->flags = NODE_NOSRC;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "\\(Lq");
|
|
|
|
mdoc->last->flags = NODE_DELIMO | NODE_NOSRC;
|
|
|
|
mdoc->last = mdoc->last->next;
|
|
|
|
roff_word_alloc(mdoc, n->line, n->pos, "\\(Rq");
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_ARG_STD, mdoc->parse,
|
|
|
|
n->line, n->pos, mdoc_macronames[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) {
|
|
|
|
mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse,
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_MACRO_OBS, mdoc->parse,
|
|
|
|
n->line, n->pos, mdoc_macronames[n->tok]);
|
|
|
|
}
|
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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_BF_NOFONT, mdoc->parse,
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
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
|
|
|
|
mandoc_vmsg(MANDOCERR_BF_BADFONT, mdoc->parse,
|
|
|
|
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] == '*')))
|
|
|
|
mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse,
|
|
|
|
n->line, n->pos + pos, n->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
mandoc_msg(MANDOCERR_FO_NOHEAD, mdoc->parse,
|
|
|
|
n->line, n->pos, "Fo");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (n->child != n->last) {
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
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);
|
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;
|
|
|
|
mandoc_msg(MANDOCERR_FA_COMMA, mdoc->parse,
|
|
|
|
n->line, n->pos + (cp - n->string),
|
|
|
|
n->string);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (n->last != NULL &&
|
|
|
|
(n->last->tok == MDOC_Pp ||
|
|
|
|
n->last->tok == MDOC_Lp))
|
|
|
|
mdoc_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))
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse,
|
2015-03-02 16:45:41 +00:00
|
|
|
n->line, n->pos, "Nm");
|
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;
|
|
|
|
|
|
|
|
if (n->child == NULL)
|
|
|
|
mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse,
|
|
|
|
n->line, n->pos, "Nd");
|
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)
|
2016-01-15 23:08:59 +00:00
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
|
|
|
|
n->line, n->pos, mdoc_macronames[n->tok]);
|
|
|
|
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,
|
|
|
|
mdoc->parse, n->line, n->pos, "Bd");
|
|
|
|
mdoc->next = ROFF_NEXT_SIBLING;
|
|
|
|
while (n->body->child != NULL)
|
|
|
|
mdoc_node_relink(mdoc,
|
|
|
|
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) {
|
|
|
|
mandoc_vmsg(MANDOCERR_BD_NEST,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"%s in Bd", mdoc_macronames[n->tok]);
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (mdoc->last->child != NULL)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
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))
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_AT_BAD, mdoc->parse,
|
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)
|
|
|
|
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
|
|
|
|
np->line, np->pos, "An");
|
|
|
|
} else if (nch != NULL)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
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;
|
|
|
|
|
|
|
|
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";
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_IT_NOHEAD,
|
|
|
|
mdoc->parse, nit->line, nit->pos,
|
|
|
|
"Bl -%s It",
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_IT_NOBODY,
|
|
|
|
mdoc->parse, nit->line, nit->pos,
|
|
|
|
"Bl -%s It",
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_ARG_SKIP,
|
|
|
|
mdoc->parse, nit->line, nit->pos,
|
2017-01-21 13:01:39 +00:00
|
|
|
"It %s", nch->string == NULL ?
|
|
|
|
mdoc_macronames[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
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
i = 0;
|
|
|
|
for (nch = nit->child; nch != NULL; nch = nch->next)
|
|
|
|
if (nch->type == ROFFT_BODY)
|
2012-10-18 09:55:16 +00:00
|
|
|
i++;
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (i < cols || i > cols + 1)
|
2015-03-02 16:45:41 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_BL_COL,
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->parse, nit->line, nit->pos,
|
2015-03-02 16:45:41 +00:00
|
|
|
"%d columns, %d cells", cols, i);
|
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:
|
|
|
|
case MDOC_Lp:
|
|
|
|
case MDOC_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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_PAR_MOVE,
|
|
|
|
mdoc->parse, nc->line, nc->pos,
|
|
|
|
mdoc_macronames[nc->tok]);
|
2014-12-02 07:34:06 +00:00
|
|
|
mdoc_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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_PAR_SKIP,
|
|
|
|
mdoc->parse, nc->line, nc->pos,
|
|
|
|
"%s before It",
|
|
|
|
mdoc_macronames[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.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rewrite_macro2len(char **arg)
|
2012-10-18 09:55:16 +00:00
|
|
|
{
|
|
|
|
size_t width;
|
2016-01-15 23:08:59 +00:00
|
|
|
int 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;
|
2016-01-15 23:08:59 +00:00
|
|
|
else if ((tok = mdoc_hash_find(*arg)) == 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;
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
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 */
|
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) {
|
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
|
|
|
|
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) {
|
|
|
|
mdoc_node_relink(mdoc, nchild);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_BL_MOVE, mdoc->parse,
|
|
|
|
nchild->line, nchild->pos,
|
|
|
|
mdoc_macronames[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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-03-02 16:45:41 +00:00
|
|
|
mandoc_msg(MANDOCERR_BLK_EMPTY,
|
|
|
|
mdoc->parse, 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
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_SM_BAD,
|
|
|
|
mdoc->parse, nch->line, nch->pos,
|
2014-12-02 07:34:06 +00:00
|
|
|
"%s %s", mdoc_macronames[mdoc->last->tok], nch->string);
|
|
|
|
mdoc_node_relink(mdoc, nch);
|
|
|
|
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)
|
|
|
|
mdoc->meta.date = mdoc->quick ?
|
|
|
|
mandoc_strdup("") :
|
|
|
|
mandoc_normdate(mdoc->parse, NULL, 0, 0);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->meta.title == NULL) {
|
|
|
|
mandoc_msg(MANDOCERR_DT_NOTITLE,
|
|
|
|
mdoc->parse, 0, 0, "EOF");
|
|
|
|
mdoc->meta.title = mandoc_strdup("UNTITLED");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mdoc->meta.vol == NULL)
|
|
|
|
mdoc->meta.vol = mandoc_strdup("LOCAL");
|
|
|
|
|
|
|
|
if (mdoc->meta.os == NULL) {
|
|
|
|
mandoc_msg(MANDOCERR_OS_MISSING,
|
|
|
|
mdoc->parse, 0, 0, NULL);
|
|
|
|
mdoc->meta.os = mandoc_strdup("");
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that we begin with a proper `Sh'. */
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
n = mdoc->first->child;
|
2016-01-15 23:08:59 +00:00
|
|
|
while (n != NULL && n->tok != TOKEN_NONE &&
|
|
|
|
mdoc_macros[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)
|
|
|
|
mandoc_msg(MANDOCERR_DOC_EMPTY, mdoc->parse, 0, 0, NULL);
|
|
|
|
else if (n->tok != MDOC_Sh)
|
|
|
|
mandoc_msg(MANDOCERR_SEC_BEFORE, mdoc->parse,
|
|
|
|
n->line, n->pos, mdoc_macronames[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) {
|
|
|
|
mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse,
|
|
|
|
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) {
|
|
|
|
mandoc_msg(MANDOCERR_RS_BAD,
|
2015-03-02 16:45:41 +00:00
|
|
|
mdoc->parse, nch->line, nch->pos,
|
|
|
|
mdoc_macronames[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-01-21 13:01:39 +00:00
|
|
|
if (mdoc->last->flags & NODE_LINE)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_NS_SKIP, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos, 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_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)
|
|
|
|
mandoc_vmsg(MANDOCERR_NAMESEC_PUNCT,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"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,
|
|
|
|
mdoc->parse, n->line, n->pos, NULL);
|
|
|
|
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:
|
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
|
|
|
|
n->line, n->pos, mdoc_macronames[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)
|
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_NONM, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos, NULL);
|
|
|
|
if ( ! hasnd)
|
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_NOND, mdoc->parse,
|
|
|
|
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')
|
|
|
|
mandoc_vmsg(MANDOCERR_XR_PUNCT,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"%s before %s(%s)", lastpunct,
|
|
|
|
name, sec);
|
|
|
|
cmp = strcmp(lastsec, sec);
|
|
|
|
if (cmp > 0)
|
|
|
|
mandoc_vmsg(MANDOCERR_XR_ORDER,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"%s(%s) after %s(%s)", name,
|
|
|
|
sec, lastname, lastsec);
|
|
|
|
else if (cmp == 0 &&
|
|
|
|
strcasecmp(lastname, name) > 0)
|
|
|
|
mandoc_vmsg(MANDOCERR_XR_ORDER,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"%s after %s", name, lastname);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (n->next == NULL)
|
|
|
|
mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse,
|
|
|
|
n->line, n->pos, "%s after %s(%s)",
|
|
|
|
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))
|
|
|
|
mandoc_msg(MANDOCERR_AN_MISSING, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_NAMESEC_FIRST, mdoc->parse,
|
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 :
|
|
|
|
mdoc_macronames[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. */
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (sec == SEC_CUSTOM)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
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)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_SEC_REP, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos,
|
2016-01-15 23:08:59 +00:00
|
|
|
"Sh %s", secnames[sec]);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
if (sec < mdoc->lastnamed)
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_SEC_ORDER, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos,
|
2016-01-15 23:08:59 +00:00
|
|
|
"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";
|
|
|
|
mandoc_vmsg(MANDOCERR_SEC_MSEC, mdoc->parse,
|
|
|
|
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) {
|
|
|
|
mandoc_vmsg(MANDOCERR_XR_NOSEC, mdoc->parse,
|
|
|
|
n->line, n->pos, "Xr %s", nch->string);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(nch->next == n->last);
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-01-15 23:08:59 +00:00
|
|
|
case ROFFT_HEAD:
|
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)
|
|
|
|
if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_PAR_SKIP,
|
|
|
|
mdoc->parse, np->line, np->pos,
|
|
|
|
"%s after %s", mdoc_macronames[np->tok],
|
|
|
|
mdoc_macronames[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)
|
|
|
|
if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
|
|
|
|
np->line, np->pos, "%s at the end of %s",
|
|
|
|
mdoc_macronames[np->tok],
|
|
|
|
mdoc_macronames[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
|
|
|
/*
|
2012-10-18 09:55:16 +00:00
|
|
|
* Don't allow prior `Lp' or `Pp' prior to a paragraph-type
|
|
|
|
* block: `Lp', `Pp', or non-compact `Bd' or `Bl'.
|
|
|
|
*/
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->prev->tok != MDOC_Pp &&
|
|
|
|
n->prev->tok != MDOC_Lp &&
|
|
|
|
n->prev->tok != MDOC_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
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
|
2016-01-15 23:08:59 +00:00
|
|
|
n->prev->line, n->prev->pos,
|
|
|
|
"%s before %s", mdoc_macronames[n->prev->tok],
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc_macronames[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
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
np = mdoc->last;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->tok != MDOC_br && np->tok != MDOC_sp)
|
|
|
|
post_prevpar(mdoc);
|
2014-01-31 19:59:03 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (np->tok == MDOC_sp) {
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->child != NULL && np->child->next != NULL)
|
2015-03-02 16:45:41 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
np->child->next->line, np->child->next->pos,
|
|
|
|
"sp ... %s", np->child->next->string);
|
|
|
|
} else if (np->child != NULL)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_SKIP,
|
|
|
|
mdoc->parse, np->line, np->pos, "%s %s",
|
|
|
|
mdoc_macronames[np->tok], np->child->string);
|
2014-01-31 19:59:03 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if ((np = mdoc->last->prev) == NULL) {
|
2014-11-22 18:08:25 +00:00
|
|
|
np = mdoc->last->parent;
|
2016-01-15 23:08:59 +00:00
|
|
|
if (np->tok != MDOC_Sh && np->tok != MDOC_Ss)
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2016-01-15 23:08:59 +00:00
|
|
|
} else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp &&
|
|
|
|
(mdoc->last->tok != MDOC_br ||
|
|
|
|
(np->tok != MDOC_sp && np->tok != MDOC_br)))
|
2014-12-02 07:34:06 +00:00
|
|
|
return;
|
2014-01-31 19:59:03 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
|
|
|
|
mdoc->last->line, mdoc->last->pos,
|
|
|
|
"%s after %s", mdoc_macronames[mdoc->last->tok],
|
|
|
|
mdoc_macronames[np->tok]);
|
2016-01-15 23:08:59 +00:00
|
|
|
roff_node_delete(mdoc, mdoc->last);
|
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) {
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
|
|
|
|
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)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_LATE, mdoc->parse,
|
|
|
|
n->line, n->pos, "Dd");
|
|
|
|
else if (mdoc->meta.title != NULL)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
|
|
|
|
n->line, n->pos, "Dd after Dt");
|
|
|
|
else if (mdoc->meta.os != NULL)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
|
|
|
|
n->line, n->pos, "Dd after Os");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
if (n->child == NULL || n->child->string[0] == '\0') {
|
2014-11-22 18:08:25 +00:00
|
|
|
mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
|
|
|
|
mandoc_normdate(mdoc->parse, NULL, n->line, n->pos);
|
2017-01-21 13:01:39 +00:00
|
|
|
return;
|
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);
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->quick)
|
|
|
|
mdoc->meta.date = datestr;
|
|
|
|
else {
|
|
|
|
mdoc->meta.date = mandoc_normdate(mdoc->parse,
|
|
|
|
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) {
|
|
|
|
mandoc_msg(MANDOCERR_DT_LATE, mdoc->parse,
|
|
|
|
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)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
|
|
|
|
n->line, n->pos, "Dt");
|
|
|
|
else if (mdoc->meta.os != NULL)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
|
|
|
|
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') {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_DT_NOTITLE,
|
|
|
|
mdoc->parse, n->line, n->pos, "Dt");
|
|
|
|
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)) {
|
|
|
|
mandoc_vmsg(MANDOCERR_TITLE_CASE,
|
|
|
|
mdoc->parse, nn->line,
|
|
|
|
nn->pos + (p - nn->string),
|
|
|
|
"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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_MSEC_MISSING,
|
|
|
|
mdoc->parse, n->line, n->pos,
|
|
|
|
"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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse,
|
|
|
|
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)
|
|
|
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
|
|
|
|
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;
|
|
|
|
|
|
|
|
n = mdoc->last;
|
|
|
|
nch = n->child;
|
|
|
|
|
|
|
|
if (nch != NULL) {
|
|
|
|
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)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
|
|
|
|
n->line, n->pos, "Os");
|
|
|
|
else if (mdoc->flags & MDOC_PBODY)
|
|
|
|
mandoc_msg(MANDOCERR_PROLOG_LATE, mdoc->parse,
|
|
|
|
n->line, n->pos, "Os");
|
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-01-21 13:01:39 +00:00
|
|
|
return;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
if (mdoc->defos) {
|
|
|
|
mdoc->meta.os = mandoc_strdup(mdoc->defos);
|
2017-01-21 13:01:39 +00:00
|
|
|
return;
|
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) {
|
2014-11-22 18:08:25 +00:00
|
|
|
mandoc_msg(MANDOCERR_OS_UNAME, mdoc->parse,
|
|
|
|
n->line, n->pos, "Os");
|
|
|
|
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*/
|
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
|
2016-01-15 23:08:59 +00:00
|
|
|
macro2len(int 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
|
|
|
}
|