summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-01-10 23:36:34 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-01-10 23:36:34 +0000
commitf1073511b0d42c759d7f3aac33e0f567c69e7dfe (patch)
treee0811e4923917dea3b3276a6d352752f5747109c
parent88adc8bfc4d6844007b7f059956fa0ce17eeee04 (diff)
downloadmandoc-f1073511b0d42c759d7f3aac33e0f567c69e7dfe.tar.gz
Use new NODE_NOSRC and NODE_NOPRT flags for .Bx and .At.
More rigorous AST and 40 lines less code.
-rw-r--r--mandocdb.c4
-rw-r--r--mdoc_html.c30
-rw-r--r--mdoc_man.c23
-rw-r--r--mdoc_term.c26
-rw-r--r--mdoc_validate.c66
5 files changed, 50 insertions, 99 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 57c1e3ec..ff41e134 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -239,13 +239,13 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
{ NULL, 0, 0 }, /* Ac */
{ NULL, 0, 0 }, /* Ao */
{ NULL, 0, 0 }, /* Aq */
- { NULL, TYPE_At, 0 }, /* At */
+ { NULL, TYPE_At, NODE_NOSRC }, /* At */
{ NULL, 0, 0 }, /* Bc */
{ NULL, 0, 0 }, /* Bf */
{ NULL, 0, 0 }, /* Bo */
{ NULL, 0, 0 }, /* Bq */
{ NULL, TYPE_Bsx, NODE_NOSRC }, /* Bsx */
- { NULL, TYPE_Bx, 0 }, /* Bx */
+ { NULL, TYPE_Bx, NODE_NOSRC }, /* Bx */
{ NULL, 0, 0 }, /* Db */
{ NULL, 0, 0 }, /* Dc */
{ NULL, 0, 0 }, /* Do */
diff --git a/mdoc_html.c b/mdoc_html.c
index 4409964d..7e11f8fc 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -71,7 +71,6 @@ static void mdoc_bk_post(MDOC_ARGS);
static int mdoc_bk_pre(MDOC_ARGS);
static int mdoc_bl_pre(MDOC_ARGS);
static int mdoc_bt_pre(MDOC_ARGS);
-static int mdoc_bx_pre(MDOC_ARGS);
static int mdoc_cd_pre(MDOC_ARGS);
static int mdoc_d1_pre(MDOC_ARGS);
static int mdoc_dv_pre(MDOC_ARGS);
@@ -183,7 +182,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_quote_pre, mdoc_quote_post}, /* Bo */
{mdoc_quote_pre, mdoc_quote_post}, /* Bq */
{mdoc_xx_pre, NULL}, /* Bsx */
- {mdoc_bx_pre, NULL}, /* Bx */
+ {mdoc_xx_pre, NULL}, /* Bx */
{mdoc_skip_pre, NULL}, /* Db */
{NULL, NULL}, /* Dc */
{mdoc_quote_pre, mdoc_quote_post}, /* Do */
@@ -740,33 +739,6 @@ mdoc_xx_pre(MDOC_ARGS)
}
static int
-mdoc_bx_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- PAIR_CLASS_INIT(&tag, "unix");
- print_otag(h, TAG_SPAN, 1, &tag);
-
- if (NULL != (n = n->child)) {
- print_text(h, n->string);
- h->flags |= HTML_NOSPACE;
- print_text(h, "BSD");
- } else {
- print_text(h, "BSD");
- return 0;
- }
-
- if (NULL != (n = n->next)) {
- h->flags |= HTML_NOSPACE;
- print_text(h, "-");
- h->flags |= HTML_NOSPACE;
- print_text(h, n->string);
- }
-
- return 0;
-}
-
-static int
mdoc_it_pre(MDOC_ARGS)
{
struct roffsu su;
diff --git a/mdoc_man.c b/mdoc_man.c
index 176cbd10..393d362c 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -79,7 +79,6 @@ static int pre_bf(DECL_ARGS);
static int pre_bk(DECL_ARGS);
static int pre_bl(DECL_ARGS);
static int pre_br(DECL_ARGS);
-static int pre_bx(DECL_ARGS);
static int pre_dl(DECL_ARGS);
static int pre_en(DECL_ARGS);
static int pre_enc(DECL_ARGS);
@@ -183,7 +182,7 @@ static const struct manact manacts[MDOC_MAX + 1] = {
{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
{ NULL, NULL, NULL, NULL, NULL }, /* Bsx */
- { NULL, pre_bx, NULL, NULL, NULL }, /* Bx */
+ { NULL, NULL, NULL, NULL, NULL }, /* Bx */
{ NULL, pre_skip, NULL, NULL, NULL }, /* Db */
{ NULL, NULL, NULL, NULL, NULL }, /* Dc */
{ cond_body, pre_enc, post_enc, "\\(Lq", "\\(Rq" }, /* Do */
@@ -1054,26 +1053,6 @@ pre_br(DECL_ARGS)
}
static int
-pre_bx(DECL_ARGS)
-{
-
- n = n->child;
- if (n) {
- print_word(n->string);
- outflags &= ~MMAN_spc;
- n = n->next;
- }
- print_word("BSD");
- if (NULL == n)
- return 0;
- outflags &= ~MMAN_spc;
- print_word("-");
- outflags &= ~MMAN_spc;
- print_word(n->string);
- return 0;
-}
-
-static int
pre_dl(DECL_ARGS)
{
diff --git a/mdoc_term.c b/mdoc_term.c
index 183d5224..0a420442 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -92,7 +92,6 @@ static int termp_bk_pre(DECL_ARGS);
static int termp_bl_pre(DECL_ARGS);
static int termp_bold_pre(DECL_ARGS);
static int termp_bt_pre(DECL_ARGS);
-static int termp_bx_pre(DECL_ARGS);
static int termp_cd_pre(DECL_ARGS);
static int termp_d1_pre(DECL_ARGS);
static int termp_eo_pre(DECL_ARGS);
@@ -191,7 +190,7 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_quote_pre, termp_quote_post }, /* Bo */
{ termp_quote_pre, termp_quote_post }, /* Bq */
{ termp_xx_pre, termp_xx_post }, /* Bsx */
- { termp_bx_pre, NULL }, /* Bx */
+ { NULL, NULL }, /* Bx */
{ termp_skip_pre, NULL }, /* Db */
{ NULL, NULL }, /* Dc */
{ termp_quote_pre, termp_quote_post }, /* Do */
@@ -1653,29 +1652,6 @@ termp_bd_post(DECL_ARGS)
}
static int
-termp_bx_pre(DECL_ARGS)
-{
-
- if (NULL != (n = n->child)) {
- term_word(p, n->string);
- p->flags |= TERMP_NOSPACE;
- term_word(p, "BSD");
- } else {
- term_word(p, "BSD");
- return 0;
- }
-
- if (NULL != (n = n->next)) {
- p->flags |= TERMP_NOSPACE;
- term_word(p, "-");
- p->flags |= TERMP_NOSPACE;
- term_word(p, n->string);
- }
-
- return 0;
-}
-
-static int
termp_xx_pre(DECL_ARGS)
{
if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 3e1afb0b..ed717511 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -965,17 +965,11 @@ post_defaults(POST_ARGS)
static void
post_at(POST_ARGS)
{
- struct roff_node *n;
- const char *std_att;
- char *att;
+ struct roff_node *n, *nch;
+ const char *att;
n = mdoc->last;
- if (n->child == NULL) {
- mdoc->next = ROFF_NEXT_CHILD;
- roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
- mdoc->last = n;
- return;
- }
+ nch = n->child;
/*
* If we have a child, look it up in the standard keys. If a
@@ -983,17 +977,19 @@ post_at(POST_ARGS)
* prefix "AT&T UNIX " to the existing data.
*/
- n = n->child;
- assert(n->type == ROFFT_TEXT);
- if ((std_att = mdoc_a2att(n->string)) == NULL) {
+ att = NULL;
+ if (nch != NULL && ((att = mdoc_a2att(nch->string)) == NULL))
mandoc_vmsg(MANDOCERR_AT_BAD, mdoc->parse,
- n->line, n->pos, "At %s", n->string);
- mandoc_asprintf(&att, "AT&T UNIX %s", n->string);
- } else
- att = mandoc_strdup(std_att);
+ nch->line, nch->pos, "At %s", nch->string);
- free(n->string);
- n->string = att;
+ 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;
}
static void
@@ -2112,7 +2108,36 @@ post_dt(POST_ARGS)
static void
post_bx(POST_ARGS)
{
- struct roff_node *n;
+ 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;
/*
* Make `Bx's second argument always start with an uppercase
@@ -2120,8 +2145,7 @@ post_bx(POST_ARGS)
* uppercase blindly.
*/
- if ((n = mdoc->last->child) != NULL && (n = n->next) != NULL)
- *n->string = (char)toupper((unsigned char)*n->string);
+ *nch->string = (char)toupper((unsigned char)*nch->string);
}
static void