diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-01-10 23:36:25 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-01-10 23:36:25 +0000 |
commit | a5cecdd2d2f8ff8ef483f43bf533efee1e898a4b (patch) | |
tree | 263ae5f8f8a65b528b22b3bac6bb761abd96f4be /usr.bin | |
parent | 13cd29f0a09be6241a49f99b2542ae78cc847c26 (diff) |
Use new NODE_NOSRC and NODE_NOPRT flags for .Bx and .At.
More rigorous AST and 40 lines less code.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 32 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_man.c | 25 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 28 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 68 |
5 files changed, 55 insertions, 104 deletions
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 0a3b809f6b6..f17d6febd64 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.184 2017/01/10 21:54:34 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.185 2017/01/10 23:36:24 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -224,13 +224,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/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index c1bab9d133d..a848cb0a5c6 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.120 2017/01/10 21:54:34 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.121 2017/01/10 23:36:24 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -69,7 +69,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); @@ -181,7 +180,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 */ @@ -738,33 +737,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/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 9aef7020577..8919e8f8c43 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.97 2017/01/10 21:54:34 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.98 2017/01/10 23:36:24 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org> * @@ -77,7 +77,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); @@ -181,7 +180,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 */ @@ -1052,26 +1051,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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 5bcb9620206..05b956437b8 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.238 2017/01/10 21:54:34 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.239 2017/01/10 23:36:24 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -90,7 +90,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); @@ -189,7 +188,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 */ @@ -1651,29 +1650,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/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index b41aba41201..af87f2b0399 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.231 2017/01/10 21:54:34 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.232 2017/01/10 23:36:24 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -956,17 +956,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 @@ -974,17 +968,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 @@ -2103,7 +2099,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 @@ -2111,8 +2136,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 |