summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2017-05-04 17:48:25 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2017-05-04 17:48:25 +0000
commit8bef1bbb61ad14d5d32efdc5d06c918b519b3e9d (patch)
tree80caa6efed944253c415a8fe32f2f9c14dad56b8 /usr.bin/mandoc
parent8f30999a489969e5c15663adf9d1c3f83f7ae21c (diff)
Parser reorg:
Generate the first node on the roff level: .br Fix some column numbers in diagnostic messages while here.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/man_html.c15
-rw-r--r--usr.bin/mandoc/man_macro.c6
-rw-r--r--usr.bin/mandoc/man_term.c17
-rw-r--r--usr.bin/mandoc/man_validate.c14
-rw-r--r--usr.bin/mandoc/mandocdb.c8
-rw-r--r--usr.bin/mandoc/mdoc_argv.c3
-rw-r--r--usr.bin/mandoc/mdoc_html.c19
-rw-r--r--usr.bin/mandoc/mdoc_macro.c13
-rw-r--r--usr.bin/mandoc/mdoc_man.c13
-rw-r--r--usr.bin/mandoc/mdoc_markdown.c20
-rw-r--r--usr.bin/mandoc/mdoc_state.c7
-rw-r--r--usr.bin/mandoc/mdoc_term.c22
-rw-r--r--usr.bin/mandoc/mdoc_validate.c25
-rw-r--r--usr.bin/mandoc/roff.c33
-rw-r--r--usr.bin/mandoc/roff.h9
15 files changed, 157 insertions, 67 deletions
diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c
index a3fa4b95dc6..30f90693618 100644
--- a/usr.bin/mandoc/man_html.c
+++ b/usr.bin/mandoc/man_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_html.c,v 1.89 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: man_html.c,v 1.90 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -90,7 +90,6 @@ static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
{ man_I_pre, NULL }, /* I */
{ man_alt_pre, NULL }, /* IR */
{ man_alt_pre, NULL }, /* RI */
- { man_br_pre, NULL }, /* br */
{ man_br_pre, NULL }, /* sp */
{ NULL, NULL }, /* nf */
{ NULL, NULL }, /* fi */
@@ -303,6 +302,18 @@ print_man_node(MAN_ARGS)
print_tblclose(h);
t = h->tag;
+ if (n->tok < ROFF_MAX) {
+ switch(n->tok) {
+ case ROFF_br:
+ man_br_pre(man, n, h);
+ break;
+ default:
+ abort();
+ }
+ break;
+ }
+
+ assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
if (mans[n->tok].pre)
child = (*mans[n->tok].pre)(man, n, h);
diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c
index 4fd0e90a3ac..780ae8a417e 100644
--- a/usr.bin/mandoc/man_macro.c
+++ b/usr.bin/mandoc/man_macro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_macro.c,v 1.78 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: man_macro.c,v 1.79 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -59,7 +59,6 @@ const struct man_macro __man_macros[MAN_MAX - MAN_TH] = {
{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* I */
{ in_line_eoln, 0 }, /* IR */
{ in_line_eoln, 0 }, /* RI */
- { in_line_eoln, MAN_NSCOPED }, /* br */
{ in_line_eoln, MAN_NSCOPED }, /* sp */
{ in_line_eoln, MAN_NSCOPED }, /* nf */
{ in_line_eoln, MAN_NSCOPED }, /* fi */
@@ -326,8 +325,7 @@ in_line_eoln(MACRO_PROT_ARGS)
n = man->last;
for (;;) {
- if (buf[*pos] != '\0' && (tok == MAN_br ||
- tok == MAN_fi || tok == MAN_nf)) {
+ if (buf[*pos] != '\0' && (tok == MAN_fi || tok == MAN_nf)) {
mandoc_vmsg(MANDOCERR_ARG_SKIP,
man->parse, line, *pos, "%s %s",
roff_name[tok], buf + *pos);
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index de01a1a5b31..526606aacba 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_term.c,v 1.145 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: man_term.c,v 1.146 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -114,7 +114,6 @@ static const struct termact __termacts[MAN_MAX - MAN_TH] = {
{ pre_I, NULL, 0 }, /* I */
{ pre_alternate, NULL, 0 }, /* IR */
{ pre_alternate, NULL, 0 }, /* RI */
- { pre_sp, NULL, MAN_NOTEXT }, /* br */
{ pre_sp, NULL, MAN_NOTEXT }, /* sp */
{ pre_literal, NULL, 0 }, /* nf */
{ pre_literal, NULL, 0 }, /* fi */
@@ -456,7 +455,7 @@ pre_sp(DECL_ARGS)
}
}
- if (n->tok == MAN_br)
+ if (n->tok == ROFF_br)
len = 0;
else if (n->child == NULL)
len = 1;
@@ -985,6 +984,18 @@ print_man_node(DECL_ARGS)
break;
}
+ if (n->tok < ROFF_MAX) {
+ switch (n->tok) {
+ case ROFF_br:
+ pre_sp(p, mt, n, meta);
+ break;
+ default:
+ abort();
+ }
+ return;
+ }
+
+ assert(n->tok >= MAN_TH && n->tok <= MAN_MAX);
if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
term_fontrepl(p, TERMFONT_NONE);
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index 3ece06f6dc3..b7d9a71addb 100644
--- a/usr.bin/mandoc/man_validate.c
+++ b/usr.bin/mandoc/man_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_validate.c,v 1.94 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: man_validate.c,v 1.95 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -73,7 +73,6 @@ static const v_check __man_valids[MAN_MAX - MAN_TH] = {
NULL, /* I */
NULL, /* IR */
NULL, /* RI */
- post_vs, /* br */
post_vs, /* sp */
NULL, /* nf */
NULL, /* fi */
@@ -124,6 +123,17 @@ man_node_validate(struct roff_man *man)
case ROFFT_TBL:
break;
default:
+ if (n->tok < ROFF_MAX) {
+ switch (n->tok) {
+ case ROFF_br:
+ post_vs(man, n);
+ break;
+ default:
+ abort();
+ }
+ break;
+ }
+ assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
cp = man_valids + n->tok;
if (*cp)
(*cp)(man, n);
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index 011f50dc274..deb42744948 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandocdb.c,v 1.195 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mandocdb.c,v 1.196 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -287,7 +287,6 @@ static const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = {
{ NULL, 0, 0 }, /* En */
{ NULL, TYPE_Dx, NODE_NOSRC }, /* Dx */
{ NULL, 0, 0 }, /* %Q */
- { NULL, 0, 0 }, /* br */
{ NULL, 0, 0 }, /* sp */
{ NULL, 0, 0 }, /* %U */
{ NULL, 0, 0 }, /* Ta */
@@ -1507,8 +1506,11 @@ parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,
{
for (n = n->child; n != NULL; n = n->next) {
- if (n->tok == TOKEN_NONE || n->flags & mdocs[n->tok].taboo)
+ if (n->tok == TOKEN_NONE ||
+ n->tok < ROFF_MAX ||
+ n->flags & mdocs[n->tok].taboo)
continue;
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
switch (n->type) {
case ROFFT_ELEM:
case ROFFT_BLOCK:
diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c
index f4db31a5232..9e6ef9c43d3 100644
--- a/usr.bin/mandoc/mdoc_argv.c
+++ b/usr.bin/mandoc/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_argv.c,v 1.67 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_argv.c,v 1.68 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -261,7 +261,6 @@ static const struct mdocarg __mdocargs[MDOC_MAX - MDOC_Dd] = {
{ ARGSFL_DELIM, NULL }, /* En */
{ ARGSFL_DELIM, NULL }, /* Dx */
{ ARGSFL_NONE, NULL }, /* %Q */
- { ARGSFL_NONE, NULL }, /* br */
{ ARGSFL_NONE, NULL }, /* sp */
{ ARGSFL_NONE, NULL }, /* %U */
{ ARGSFL_NONE, NULL }, /* Ta */
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index 5258584e77b..72afef4cf03 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_html.c,v 1.155 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.156 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -235,7 +235,6 @@ static const struct htmlmdoc __mdocs[MDOC_MAX - MDOC_Dd] = {
{mdoc_quote_pre, mdoc_quote_post}, /* En */
{mdoc_xx_pre, NULL}, /* Dx */
{mdoc__x_pre, mdoc__x_post}, /* %Q */
- {mdoc_sp_pre, NULL}, /* br */
{mdoc_sp_pre, NULL}, /* sp */
{mdoc__x_pre, mdoc__x_post}, /* %U */
{NULL, NULL}, /* Ta */
@@ -392,6 +391,16 @@ print_mdoc_node(MDOC_ARGS)
t = h->tag;
}
assert(h->tblt == NULL);
+ if (n->tok < ROFF_MAX) {
+ switch(n->tok) {
+ case ROFF_br:
+ mdoc_sp_pre(meta, n, h);
+ break;
+ default:
+ abort();
+ }
+ break;
+ }
assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
if (mdocs[n->tok].pre != NULL &&
(n->end == ENDBODY_NOT || n->child != NULL))
@@ -413,7 +422,9 @@ print_mdoc_node(MDOC_ARGS)
case ROFFT_EQN:
break;
default:
- if (mdocs[n->tok].post == NULL || n->flags & NODE_ENDED)
+ if (n->tok < ROFF_MAX ||
+ mdocs[n->tok].post == NULL ||
+ n->flags & NODE_ENDED)
break;
(*mdocs[n->tok].post)(meta, n, h);
if (n->end != ENDBODY_NOT)
@@ -1003,7 +1014,7 @@ mdoc_bd_pre(MDOC_ARGS)
*/
switch (nn->tok) {
case MDOC_Sm:
- case MDOC_br:
+ case ROFF_br:
case MDOC_sp:
case MDOC_Bl:
case MDOC_D1:
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 9a9c777f53a..c3ee37d4d2c 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_macro.c,v 1.177 2017/04/29 12:43:55 schwarze Exp $ */
+/* $OpenBSD: mdoc_macro.c,v 1.178 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -195,7 +195,6 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX - MDOC_Dd] = {
{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* En */
{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Dx */
{ in_line_eoln, MDOC_JOIN }, /* %Q */
- { in_line_eoln, 0 }, /* br */
{ in_line_eoln, 0 }, /* sp */
{ in_line_eoln, 0 }, /* %U */
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */
@@ -249,7 +248,7 @@ lookup(struct roff_man *mdoc, int from, int line, int ppos, const char *p)
if (res != TOKEN_NONE) {
if (mdoc_macros[res].flags & MDOC_CALLABLE)
return res;
- if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll)
+ if (res != MDOC_sp && res != MDOC_ll)
mandoc_msg(MANDOCERR_MACRO_CALL,
mdoc->parse, line, ppos, p);
}
@@ -680,8 +679,8 @@ blk_exp_close(MACRO_PROT_ARGS)
* Stray .Ec without previous .Eo:
* Break the output line, keep the arguments.
*/
- roff_elem_alloc(mdoc, line, ppos, MDOC_br);
- rew_elem(mdoc, MDOC_br);
+ roff_elem_alloc(mdoc, line, ppos, ROFF_br);
+ rew_elem(mdoc, ROFF_br);
}
} else if (endbody == NULL) {
rew_last(mdoc, body);
@@ -1021,8 +1020,8 @@ blk_full(MACRO_PROT_ARGS)
if (tok == MDOC_It && (n == NULL || n->tok != MDOC_Bl)) {
mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse,
line, ppos, "It %s", buf + *pos);
- roff_elem_alloc(mdoc, line, ppos, MDOC_br);
- rew_elem(mdoc, MDOC_br);
+ roff_elem_alloc(mdoc, line, ppos, ROFF_br);
+ rew_elem(mdoc, ROFF_br);
return;
}
}
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index 141b2b356b2..bbd12ee8959 100644
--- a/usr.bin/mandoc/mdoc_man.c
+++ b/usr.bin/mandoc/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_man.c,v 1.107 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.108 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -18,6 +18,7 @@
#include <assert.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "mandoc_aux.h"
@@ -236,7 +237,6 @@ static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = {
{ cond_body, pre_en, post_en, NULL, NULL }, /* En */
{ NULL, NULL, NULL, NULL, NULL }, /* Dx */
{ NULL, NULL, post_percent, NULL, NULL }, /* %Q */
- { NULL, pre_br, NULL, NULL, NULL }, /* br */
{ NULL, pre_sp, post_sp, NULL, NULL }, /* sp */
{ NULL, NULL, post_percent, NULL, NULL }, /* %U */
{ NULL, NULL, NULL, NULL, NULL }, /* Ta */
@@ -649,7 +649,16 @@ print_node(DECL_ARGS)
outflags &= ~(MMAN_spc | MMAN_spc_force);
else if (outflags & MMAN_Sm)
outflags |= MMAN_spc;
+ } else if (n->tok < ROFF_MAX) {
+ switch (n->tok) {
+ case ROFF_br:
+ pre_br(meta, n);
+ break;
+ default:
+ abort();
+ }
} else {
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
/*
* Conditionally run the pre-node action handler for a
* node.
diff --git a/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c
index b3f6c2a7e6c..0f5bd5836de 100644
--- a/usr.bin/mandoc/mdoc_markdown.c
+++ b/usr.bin/mandoc/mdoc_markdown.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_markdown.c,v 1.17 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_markdown.c,v 1.18 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -19,6 +19,7 @@
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "mandoc_aux.h"
@@ -222,7 +223,6 @@ static const struct md_act __md_acts[MDOC_MAX - MDOC_Dd] = {
{ md_cond_body, md_pre_En, md_post_En, NULL, NULL }, /* En */
{ NULL, NULL, NULL, NULL, NULL }, /* Dx */
{ NULL, NULL, md_post_pc, NULL, NULL }, /* %Q */
- { NULL, md_pre_br, NULL, NULL, NULL }, /* br */
{ NULL, md_pre_Pp, NULL, NULL, NULL }, /* sp */
{ NULL, md_pre_Lk, md_post_pc, NULL, NULL }, /* %U */
{ NULL, NULL, NULL, NULL, NULL }, /* Ta */
@@ -310,8 +310,7 @@ md_node(struct roff_node *n)
process_children = 1;
n->flags &= ~NODE_ENDED;
- switch (n->type) {
- case ROFFT_TEXT:
+ if (n->type == ROFFT_TEXT) {
if (n->flags & NODE_DELIMC)
outflags &= ~(MD_spc | MD_spc_force);
else if (outflags & MD_Sm)
@@ -321,14 +320,21 @@ md_node(struct roff_node *n)
outflags &= ~(MD_spc | MD_spc_force);
else if (outflags & MD_Sm)
outflags |= MD_spc;
- break;
- default:
+ } else if (n->tok < ROFF_MAX) {
+ switch (n->tok) {
+ case ROFF_br:
+ md_pre_br(n);
+ break;
+ default:
+ abort();
+ }
+ } else {
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
act = md_acts + n->tok;
cond = act->cond == NULL || (*act->cond)(n);
if (cond && act->pre != NULL &&
(n->end == ENDBODY_NOT || n->child != NULL))
process_children = (*act->pre)(n);
- break;
}
if (process_children && n->child != NULL)
diff --git a/usr.bin/mandoc/mdoc_state.c b/usr.bin/mandoc/mdoc_state.c
index e81f743884f..9a9ff17394a 100644
--- a/usr.bin/mandoc/mdoc_state.c
+++ b/usr.bin/mandoc/mdoc_state.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_state.c,v 1.5 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_state.c,v 1.6 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -16,6 +16,7 @@
*/
#include <sys/types.h>
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -154,7 +155,6 @@ static const state_handler __state_handlers[MDOC_MAX - MDOC_Dd] = {
NULL, /* En */
NULL, /* Dx */
NULL, /* %Q */
- NULL, /* br */
NULL, /* sp */
NULL, /* %U */
NULL, /* Ta */
@@ -168,9 +168,10 @@ mdoc_state(struct roff_man *mdoc, struct roff_node *n)
{
state_handler handler;
- if (n->tok == TOKEN_NONE)
+ if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX)
return;
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
if ( ! (mdoc_macros[n->tok].flags & MDOC_PROLOGUE))
mdoc->flags |= MDOC_PBODY;
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index c1b01ad3dc5..7dd2f7e2447 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_term.c,v 1.249 2017/04/24 23:06:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.250 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -242,7 +242,6 @@ static const struct termact __termacts[MDOC_MAX - MDOC_Dd] = {
{ termp_quote_pre, termp_quote_post }, /* En */
{ termp_xx_pre, termp_xx_post }, /* Dx */
{ NULL, termp____post }, /* %Q */
- { termp_sp_pre, NULL }, /* br */
{ termp_sp_pre, NULL }, /* sp */
{ NULL, termp____post }, /* %U */
{ NULL, NULL }, /* Ta */
@@ -363,6 +362,17 @@ print_mdoc_node(DECL_ARGS)
term_tbl(p, n->span);
break;
default:
+ if (n->tok < ROFF_MAX) {
+ switch (n->tok) {
+ case ROFF_br:
+ termp_sp_pre(p, &npair, meta, n);
+ break;
+ default:
+ abort();
+ }
+ break;
+ }
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
if (termacts[n->tok].pre != NULL &&
(n->end == ENDBODY_NOT || n->child != NULL))
chld = (*termacts[n->tok].pre)
@@ -384,7 +394,9 @@ print_mdoc_node(DECL_ARGS)
case ROFFT_EQN:
break;
default:
- if (termacts[n->tok].post == NULL || n->flags & NODE_ENDED)
+ if (n->tok < ROFF_MAX ||
+ termacts[n->tok].post == NULL ||
+ n->flags & NODE_ENDED)
break;
(void)(*termacts[n->tok].post)(p, &npair, meta, n);
@@ -1502,7 +1514,7 @@ termp_bd_pre(DECL_ARGS)
*/
switch (nn->tok) {
case MDOC_Sm:
- case MDOC_br:
+ case ROFF_br:
case MDOC_sp:
case MDOC_Bl:
case MDOC_D1:
@@ -1664,7 +1676,7 @@ termp_sp_pre(DECL_ARGS)
} else
len = 1;
break;
- case MDOC_br:
+ case ROFF_br:
len = 0;
break;
default:
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 2450bfb10be..b73c93416e3 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_validate.c,v 1.238 2017/04/29 12:43:55 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.239 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -225,7 +225,6 @@ static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] = {
post_en, /* En */
post_xx, /* Dx */
NULL, /* %Q */
- post_par, /* br */
post_par, /* sp */
NULL, /* %U */
NULL, /* Ta */
@@ -325,6 +324,18 @@ mdoc_node_validate(struct roff_man *mdoc)
/* Call the macro's postprocessor. */
+ if (n->tok < ROFF_MAX) {
+ switch(n->tok) {
+ case ROFF_br:
+ post_par(mdoc);
+ break;
+ default:
+ abort();
+ }
+ break;
+ }
+
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
p = mdoc_valids + n->tok;
if (*p)
(*p)(mdoc);
@@ -1298,7 +1309,7 @@ post_bl_block(POST_ARGS)
switch (nc->tok) {
case MDOC_Pp:
case MDOC_Lp:
- case MDOC_br:
+ case ROFF_br:
break;
default:
nc = NULL;
@@ -2052,7 +2063,7 @@ post_prevpar(POST_ARGS)
if (n->prev->tok != MDOC_Pp &&
n->prev->tok != MDOC_Lp &&
- n->prev->tok != MDOC_br)
+ n->prev->tok != ROFF_br)
return;
if (n->tok == MDOC_Bl && n->norm->Bl.comp)
return;
@@ -2073,7 +2084,7 @@ post_par(POST_ARGS)
struct roff_node *np;
np = mdoc->last;
- if (np->tok != MDOC_br && np->tok != MDOC_sp)
+ if (np->tok != ROFF_br && np->tok != MDOC_sp)
post_prevpar(mdoc);
if (np->tok == MDOC_sp) {
@@ -2091,8 +2102,8 @@ post_par(POST_ARGS)
if (np->tok != MDOC_Sh && np->tok != MDOC_Ss)
return;
} else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp &&
- (mdoc->last->tok != MDOC_br ||
- (np->tok != MDOC_sp && np->tok != MDOC_br)))
+ (mdoc->last->tok != ROFF_br ||
+ (np->tok != MDOC_sp && np->tok != ROFF_br)))
return;
mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 5ca2cbf9e28..3960f47e943 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.167 2017/04/29 12:43:55 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.168 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -75,6 +75,7 @@ struct roffreq {
struct roff {
struct mparse *parse; /* parse point */
+ struct roff_man *man; /* mdoc or man parser */
struct roffnode *last; /* leaf of stack */
int *rstack; /* stack of inverted `ie' values */
struct ohash *reqtab; /* request lookup table */
@@ -144,7 +145,7 @@ static void roffnode_push(struct roff *, enum roff_tok,
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
static enum rofferr roff_block_sub(ROFF_ARGS);
-static enum rofferr roff_brp(ROFF_ARGS);
+static enum rofferr roff_br(ROFF_ARGS);
static enum rofferr roff_cblock(ROFF_ARGS);
static enum rofferr roff_cc(ROFF_ARGS);
static void roff_ccond(struct roff *, int, int);
@@ -207,6 +208,7 @@ static enum rofferr roff_userdef(ROFF_ARGS);
#define ROFFNUM_WHITE (1 << 1) /* Skip whitespace in roff_evalnum(). */
const char *__roff_name[MAN_MAX + 1] = {
+ "br", NULL,
"ab", "ad", "af", "aln",
"als", "am", "am1", "ami",
"ami1", "as", "as1", "asciify",
@@ -296,14 +298,14 @@ const char *__roff_name[MAN_MAX + 1] = {
"Fr", "Ud", "Lb", "Lp",
"Lk", "Mt", "Brq", "Bro",
"Brc", "%C", "Es", "En",
- "Dx", "%Q", "br", "sp",
+ "Dx", "%Q", "sp",
"%U", "Ta", "ll", NULL,
"TH", "SH", "SS", "TP",
"LP", "PP", "P", "IP",
"HP", "SM", "SB", "BI",
"IB", "BR", "RB", "R",
"B", "I", "IR", "RI",
- "br", "sp", "nf", "fi",
+ "sp", "nf", "fi",
"RE", "RS", "DT", "UC",
"PD", "AT", "in", "ft",
"OP", "EX", "EE", "UR",
@@ -312,6 +314,8 @@ const char *__roff_name[MAN_MAX + 1] = {
const char *const *roff_name = __roff_name;
static struct roffmac roffs[TOKEN_NONE] = {
+ { roff_br, NULL, NULL, 0 }, /* br */
+ { NULL, NULL, NULL, 0 }, /* ROFF_MAX */
{ roff_unsupp, NULL, NULL, 0 }, /* ab */
{ roff_line_ignore, NULL, NULL, 0 }, /* ad */
{ roff_line_ignore, NULL, NULL, 0 }, /* af */
@@ -335,7 +339,7 @@ static struct roffmac roffs[TOKEN_NONE] = {
{ roff_unsupp, NULL, NULL, 0 }, /* break */
{ roff_line_ignore, NULL, NULL, 0 }, /* breakchar */
{ roff_line_ignore, NULL, NULL, 0 }, /* brnl */
- { roff_brp, NULL, NULL, 0 }, /* brp */
+ { roff_br, NULL, NULL, 0 }, /* brp */
{ roff_line_ignore, NULL, NULL, 0 }, /* brpnl */
{ roff_unsupp, NULL, NULL, 0 }, /* c2 */
{ roff_cc, NULL, NULL, 0 }, /* cc */
@@ -608,6 +612,8 @@ roffhash_alloc(enum roff_tok mintok, enum roff_tok maxtok)
mandoc_ohash_init(htab, 8, offsetof(struct roffreq, name));
for (tok = mintok; tok < maxtok; tok++) {
+ if (roff_name[tok] == NULL)
+ continue;
sz = strlen(roff_name[tok]);
req = mandoc_malloc(sizeof(*req) + sz + 1);
req->tok = tok;
@@ -822,6 +828,7 @@ roff_man_alloc(struct roff *roff, struct mparse *parse,
man->defos = defos;
man->quick = quick;
roff_man_alloc1(man);
+ roff->man = man;
return man;
}
@@ -1471,7 +1478,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
/* Execute a roff request or a user defined macro. */
- return (*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs);
+ return (*roffs[t].proc)(r, t, buf, ln, spos, pos, offs);
}
void
@@ -2631,7 +2638,7 @@ roff_T_(ROFF_ARGS)
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
ln, ppos, "T&");
else
- tbl_restart(ppos, ln, r->tbl);
+ tbl_restart(ln, ppos, r->tbl);
return ROFF_IGN;
}
@@ -2758,11 +2765,15 @@ roff_TS(ROFF_ARGS)
}
static enum rofferr
-roff_brp(ROFF_ARGS)
+roff_br(ROFF_ARGS)
{
-
- buf->buf[pos - 1] = '\0';
- return ROFF_CONT;
+ roff_elem_alloc(r->man, ln, ppos, ROFF_br);
+ if (buf->buf[pos] != '\0')
+ mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ "%s %s", roff_name[tok], buf->buf + pos);
+ r->man->last->flags |= NODE_LINE | NODE_VALID | NODE_ENDED;
+ r->man->next = ROFF_NEXT_SIBLING;
+ return ROFF_IGN;
}
static enum rofferr
diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h
index 5d560e074d8..772e53a6677 100644
--- a/usr.bin/mandoc/roff.h
+++ b/usr.bin/mandoc/roff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.h,v 1.24 2017/04/29 12:43:55 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.25 2017/05/04 17:48:24 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -66,7 +66,9 @@ enum roff_type {
};
enum roff_tok {
- ROFF_ab = 0,
+ ROFF_br = 0,
+ ROFF_MAX,
+ ROFF_ab,
ROFF_ad,
ROFF_af,
ROFF_aln,
@@ -86,7 +88,6 @@ enum roff_tok {
ROFF_boxa,
ROFF_bp,
ROFF_BP,
- /* MAN_br, MDOC_br */
ROFF_break,
ROFF_breakchar,
ROFF_brnl,
@@ -428,7 +429,6 @@ enum roff_tok {
MDOC_En,
MDOC_Dx,
MDOC__Q,
- MDOC_br,
MDOC_sp,
MDOC__U,
MDOC_Ta,
@@ -454,7 +454,6 @@ enum roff_tok {
MAN_I,
MAN_IR,
MAN_RI,
- MAN_br,
MAN_sp,
MAN_nf,
MAN_fi,