aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-02 22:48:17 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-02 22:48:17 +0000
commit8a1e7c36cb8b9ca64c677d1ff9d786c9e46fd7b0 (patch)
tree8875174fa99d2fb62fe97ec308a53905416a4e4f /mdoc_validate.c
parent483afc5a7a52b601da9e854d5645cd4b0a140184 (diff)
downloadmandoc-8a1e7c36cb8b9ca64c677d1ff9d786c9e46fd7b0.tar.gz
mandoc-8a1e7c36cb8b9ca64c677d1ff9d786c9e46fd7b0.tar.zst
mandoc-8a1e7c36cb8b9ca64c677d1ff9d786c9e46fd7b0.zip
Second step towards parser unification:
Replace struct mdoc_node and struct man_node by a unified struct roff_node. To be able to use the tok member for both mdoc(7) and man(7) without defining all the macros in roff.h, sacrifice a tiny bit of type safety and make tok an int rather than an enum. Almost mechanical, no functional change. Written on the Eurostar from Bruxelles to London on the way to p2k15.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c112
1 files changed, 56 insertions, 56 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 6b89abc9..d090ff7a 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.284 2015/04/02 21:36:50 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.285 2015/04/02 22:48:17 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -40,7 +40,7 @@
/* FIXME: .Bl -diag can't have non-text children in HEAD. */
-#define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n
+#define PRE_ARGS struct mdoc *mdoc, struct roff_node *n
#define POST_ARGS struct mdoc *mdoc
enum check_ineq {
@@ -59,11 +59,11 @@ struct valids {
static void check_text(struct mdoc *, int, int, char *);
static void check_argv(struct mdoc *,
- struct mdoc_node *, struct mdoc_argv *);
-static void check_args(struct mdoc *, struct mdoc_node *);
-static int child_an(const struct mdoc_node *);
-static enum mdoc_sec a2sec(const char *);
-static size_t macro2len(enum mdoct);
+ struct roff_node *, struct mdoc_argv *);
+static void check_args(struct mdoc *, struct roff_node *);
+static int child_an(const struct roff_node *);
+static enum roff_sec a2sec(const char *);
+static size_t macro2len(int);
static void rewrite_macro2len(char **);
static void post_an(POST_ARGS);
@@ -248,7 +248,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
#define RSORD_MAX 14 /* Number of `Rs' blocks. */
-static const enum mdoct rsord[RSORD_MAX] = {
+static const int rsord[RSORD_MAX] = {
MDOC__A,
MDOC__T,
MDOC__B,
@@ -293,7 +293,7 @@ static const char * const secnames[SEC__MAX] = {
void
-mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
+mdoc_valid_pre(struct mdoc *mdoc, struct roff_node *n)
{
v_pre p;
@@ -321,7 +321,7 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
void
mdoc_valid_post(struct mdoc *mdoc)
{
- struct mdoc_node *n;
+ struct roff_node *n;
v_post p;
n = mdoc->last;
@@ -362,7 +362,7 @@ mdoc_valid_post(struct mdoc *mdoc)
}
static void
-check_args(struct mdoc *mdoc, struct mdoc_node *n)
+check_args(struct mdoc *mdoc, struct roff_node *n)
{
int i;
@@ -375,7 +375,7 @@ check_args(struct mdoc *mdoc, struct mdoc_node *n)
}
static void
-check_argv(struct mdoc *mdoc, struct mdoc_node *n, struct mdoc_argv *v)
+check_argv(struct mdoc *mdoc, struct roff_node *n, struct mdoc_argv *v)
{
int i;
@@ -399,7 +399,7 @@ check_text(struct mdoc *mdoc, int ln, int pos, char *p)
static void
pre_display(PRE_ARGS)
{
- struct mdoc_node *node;
+ struct roff_node *node;
if (n->type != ROFFT_BLOCK)
return;
@@ -769,7 +769,7 @@ pre_dd(PRE_ARGS)
static void
post_bf(POST_ARGS)
{
- struct mdoc_node *np, *nch;
+ struct roff_node *np, *nch;
enum mdocargt arg;
/*
@@ -831,7 +831,7 @@ post_bf(POST_ARGS)
static void
post_lb(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
const char *stdlibname;
char *libname;
@@ -851,7 +851,7 @@ post_lb(POST_ARGS)
static void
post_eoln(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
n = mdoc->last;
if (n->child)
@@ -864,7 +864,7 @@ post_eoln(POST_ARGS)
static void
post_fname(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
const char *cp;
size_t pos;
@@ -887,7 +887,7 @@ post_fn(POST_ARGS)
static void
post_fo(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
n = mdoc->last;
@@ -913,7 +913,7 @@ post_fo(POST_ARGS)
static void
post_fa(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
const char *cp;
for (n = mdoc->last->child; n != NULL; n = n->next) {
@@ -934,7 +934,7 @@ post_fa(POST_ARGS)
static void
post_vt(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
/*
* The Vt macro comes in both ELEM and BLOCK form, both of which
@@ -956,7 +956,7 @@ post_vt(POST_ARGS)
static void
post_nm(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -978,7 +978,7 @@ post_nm(POST_ARGS)
static void
post_nd(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -995,7 +995,7 @@ post_nd(POST_ARGS)
static void
post_d1(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -1012,7 +1012,7 @@ post_d1(POST_ARGS)
static void
post_literal(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -1034,7 +1034,7 @@ post_literal(POST_ARGS)
static void
post_defaults(POST_ARGS)
{
- struct mdoc_node *nn;
+ struct roff_node *nn;
/*
* The `Ar' defaults to "file ..." if no value is provided as an
@@ -1068,7 +1068,7 @@ post_defaults(POST_ARGS)
static void
post_at(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
const char *std_att;
char *att;
@@ -1102,7 +1102,7 @@ post_at(POST_ARGS)
static void
post_an(POST_ARGS)
{
- struct mdoc_node *np, *nch;
+ struct roff_node *np, *nch;
np = mdoc->last;
nch = np->child;
@@ -1133,9 +1133,9 @@ post_es(POST_ARGS)
static void
post_it(POST_ARGS)
{
+ struct roff_node *nbl, *nit, *nch;
int i, cols;
enum mdoc_list lt;
- struct mdoc_node *nbl, *nit, *nch;
nit = mdoc->last;
if (nit->type != ROFFT_BLOCK)
@@ -1201,7 +1201,7 @@ post_it(POST_ARGS)
static void
post_bl_block(POST_ARGS)
{
- struct mdoc_node *n, *ni, *nc;
+ struct roff_node *n, *ni, *nc;
/*
* These are fairly complicated, so we've broken them into two
@@ -1262,7 +1262,7 @@ void
rewrite_macro2len(char **arg)
{
size_t width;
- enum mdoct tok;
+ int tok;
if (*arg == NULL)
return;
@@ -1280,7 +1280,7 @@ rewrite_macro2len(char **arg)
static void
post_bl_block_tag(POST_ARGS)
{
- struct mdoc_node *n, *nn;
+ struct roff_node *n, *nn;
size_t sz, ssz;
int i;
char buf[24];
@@ -1345,7 +1345,7 @@ post_bl_block_tag(POST_ARGS)
static void
post_bl_head(POST_ARGS)
{
- struct mdoc_node *nbl, *nh, *nch, *nnext;
+ struct roff_node *nbl, *nh, *nch, *nnext;
struct mdoc_argv *argv;
int i, j;
@@ -1407,9 +1407,9 @@ post_bl_head(POST_ARGS)
static void
post_bl(POST_ARGS)
{
- struct mdoc_node *nparent, *nprev; /* of the Bl block */
- struct mdoc_node *nblock, *nbody; /* of the Bl */
- struct mdoc_node *nchild, *nnext; /* of the Bl body */
+ 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 */
nbody = mdoc->last;
switch (nbody->type) {
@@ -1490,7 +1490,7 @@ post_bl(POST_ARGS)
static void
post_bk(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -1504,7 +1504,7 @@ post_bk(POST_ARGS)
static void
post_sm(struct mdoc *mdoc)
{
- struct mdoc_node *nch;
+ struct roff_node *nch;
nch = mdoc->last->child;
@@ -1534,7 +1534,7 @@ post_sm(struct mdoc *mdoc)
static void
post_root(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
/* Add missing prologue data. */
@@ -1574,7 +1574,7 @@ post_root(POST_ARGS)
static void
post_st(POST_ARGS)
{
- struct mdoc_node *n, *nch;
+ struct roff_node *n, *nch;
const char *p;
n = mdoc->last;
@@ -1595,7 +1595,7 @@ post_st(POST_ARGS)
static void
post_rs(POST_ARGS)
{
- struct mdoc_node *np, *nch, *next, *prev;
+ struct roff_node *np, *nch, *next, *prev;
int i, j;
np = mdoc->last;
@@ -1689,7 +1689,7 @@ post_rs(POST_ARGS)
static void
post_hyph(POST_ARGS)
{
- struct mdoc_node *nch;
+ struct roff_node *nch;
char *cp;
for (nch = mdoc->last->child; nch != NULL; nch = nch->next) {
@@ -1748,7 +1748,7 @@ post_sh(POST_ARGS)
static void
post_sh_name(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
int hasnm, hasnd;
hasnm = hasnd = 0;
@@ -1786,7 +1786,7 @@ post_sh_name(POST_ARGS)
static void
post_sh_see_also(POST_ARGS)
{
- const struct mdoc_node *n;
+ const struct roff_node *n;
const char *name, *sec;
const char *lastname, *lastsec, *lastpunct;
int cmp;
@@ -1846,7 +1846,7 @@ post_sh_see_also(POST_ARGS)
}
static int
-child_an(const struct mdoc_node *n)
+child_an(const struct roff_node *n)
{
for (n = n->child; n != NULL; n = n->next)
@@ -1867,10 +1867,10 @@ post_sh_authors(POST_ARGS)
static void
post_sh_head(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
const char *goodsec;
char *secname;
- enum mdoc_sec sec;
+ enum roff_sec sec;
/*
* Process a new section. Sections are either "named" or
@@ -1987,7 +1987,7 @@ post_sh_head(POST_ARGS)
static void
post_ignpar(POST_ARGS)
{
- struct mdoc_node *np;
+ struct roff_node *np;
switch (mdoc->last->type) {
case ROFFT_HEAD:
@@ -2053,7 +2053,7 @@ pre_par(PRE_ARGS)
static void
post_par(POST_ARGS)
{
- struct mdoc_node *np;
+ struct roff_node *np;
np = mdoc->last;
@@ -2116,7 +2116,7 @@ pre_literal(PRE_ARGS)
static void
post_dd(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
char *datestr;
if (mdoc->meta.date)
@@ -2145,7 +2145,7 @@ out:
static void
post_dt(POST_ARGS)
{
- struct mdoc_node *nn, *n;
+ struct roff_node *nn, *n;
const char *cp;
char *p;
@@ -2230,7 +2230,7 @@ out:
static void
post_bx(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
/*
* Make `Bx's second argument always start with an uppercase
@@ -2250,7 +2250,7 @@ post_os(POST_ARGS)
struct utsname utsname;
static char *defbuf;
#endif
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -2300,7 +2300,7 @@ out:
static void
post_ex(POST_ARGS)
{
- struct mdoc_node *n;
+ struct roff_node *n;
n = mdoc->last;
@@ -2318,20 +2318,20 @@ post_ex(POST_ARGS)
mdoc->last = n;
}
-static enum mdoc_sec
+static enum roff_sec
a2sec(const char *p)
{
int i;
for (i = 0; i < (int)SEC__MAX; i++)
if (secnames[i] && 0 == strcmp(p, secnames[i]))
- return((enum mdoc_sec)i);
+ return((enum roff_sec)i);
return(SEC_CUSTOM);
}
static size_t
-macro2len(enum mdoct macro)
+macro2len(int macro)
{
switch (macro) {