diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-02-04 18:03:29 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-02-04 18:03:29 +0000 |
commit | 2abdea8dd24252d6e41ca4a6954edff1fe8d3454 (patch) | |
tree | 587ff7f575889219da675474554719336b204a9e /usr.bin/mandoc | |
parent | 203bd5d9c4f0078a07e5c626d95626aaeb40d522 (diff) |
discard .Rs head arguments and improve .Rs diagnostics
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 13 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 70 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 3 |
4 files changed, 47 insertions, 42 deletions
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index cd752d11127..a34095a48a2 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.137 2015/02/04 16:38:31 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.138 2015/02/04 18:03:28 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -103,6 +103,7 @@ enum mandocerr { MANDOCERR_BF_NOFONT, /* missing font type, using \fR: Bf */ MANDOCERR_BF_BADFONT, /* unknown font type, using \fR: Bf font */ MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */ + MANDOCERR_RS_EMPTY, /* empty reference block: Rs */ MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */ MANDOCERR_EQN_NOBOX, /* missing eqn box, using "": op */ diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index 3d91845b321..b4e81d68608 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.128 2015/02/03 18:19:27 schwarze Exp $ */ +/* $OpenBSD: mdoc_macro.c,v 1.129 2015/02/04 18:03:28 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -1025,8 +1025,6 @@ blk_full(MACRO_PROT_ARGS) la = *pos; lac = ac; ac = mdoc_args(mdoc, line, pos, buf, tok, &p); - if (ac == ARGS_PUNCT) - break; if (ac == ARGS_EOLN) { if (lac != ARGS_PPHRASE && lac != ARGS_PHRASE) break; @@ -1042,6 +1040,13 @@ blk_full(MACRO_PROT_ARGS) body = mdoc_body_alloc(mdoc, line, ppos, tok); break; } + if (tok == MDOC_Rs) { + mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse, + line, la, "Rs %s", buf + la); + break; + } + if (ac == ARGS_PUNCT) + break; /* * Emit leading punctuation (i.e., punctuation before @@ -1098,7 +1103,7 @@ blk_full(MACRO_PROT_ARGS) return; if (head == NULL) head = mdoc_head_alloc(mdoc, line, ppos, tok); - if (nl) + if (nl && tok != MDOC_Rs) append_delims(mdoc, line, pos, buf); if (body != NULL) goto out; diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 772969ce183..6873ab49870 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.183 2015/02/04 16:38:31 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.184 2015/02/04 18:03:28 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -1649,19 +1649,17 @@ post_st(POST_ARGS) static void post_rs(POST_ARGS) { - struct mdoc_node *nn, *next, *prev; + struct mdoc_node *np, *nch, *next, *prev; int i, j; - switch (mdoc->last->type) { - case MDOC_HEAD: - check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0); - return; - case MDOC_BODY: - if (mdoc->last->child) - break; - check_count(mdoc, MDOC_BODY, CHECK_GT, 0); + np = mdoc->last; + + if (np->type != MDOC_BODY) return; - default: + + if (np->child == NULL) { + mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse, + np->line, np->pos, "Rs"); return; } @@ -1672,38 +1670,38 @@ post_rs(POST_ARGS) */ next = NULL; - for (nn = mdoc->last->child->next; nn; nn = next) { - /* Determine order of `nn'. */ + for (nch = np->child->next; nch != NULL; nch = next) { + /* Determine order number of this child. */ for (i = 0; i < RSORD_MAX; i++) - if (rsord[i] == nn->tok) + if (rsord[i] == nch->tok) break; if (i == RSORD_MAX) { mandoc_msg(MANDOCERR_RS_BAD, - mdoc->parse, nn->line, nn->pos, - mdoc_macronames[nn->tok]); + mdoc->parse, nch->line, nch->pos, + mdoc_macronames[nch->tok]); i = -1; - } else if (MDOC__J == nn->tok || MDOC__B == nn->tok) - mdoc->last->norm->Rs.quote_T++; + } else if (nch->tok == MDOC__J || nch->tok == MDOC__B) + np->norm->Rs.quote_T++; /* - * Remove `nn' from the chain. This somewhat + * Remove this child from the chain. This somewhat * repeats mdoc_node_unlink(), but since we're * just re-ordering, there's no need for the * full unlink process. */ - if (NULL != (next = nn->next)) - next->prev = nn->prev; + if ((next = nch->next) != NULL) + next->prev = nch->prev; - if (NULL != (prev = nn->prev)) - prev->next = nn->next; + if ((prev = nch->prev) != NULL) + prev->next = nch->next; - nn->prev = nn->next = NULL; + nch->prev = nch->next = NULL; /* * Scan back until we reach a node that's - * ordered before `nn'. + * to be ordered before this child. */ for ( ; prev ; prev = prev->prev) { @@ -1719,21 +1717,21 @@ post_rs(POST_ARGS) } /* - * Set `nn' back into its correct place in front - * of the `prev' node. + * Set this child back into its correct place + * in front of the `prev' node. */ - nn->prev = prev; + nch->prev = prev; - if (prev) { - if (prev->next) - prev->next->prev = nn; - nn->next = prev->next; - prev->next = nn; + if (prev == NULL) { + np->child->prev = nch; + nch->next = np->child; + np->child = nch; } else { - mdoc->last->child->prev = nn; - nn->next = mdoc->last->child; - mdoc->last->child = nn; + if (prev->next) + prev->next->prev = nch; + nch->next = prev->next; + prev->next = nch; } } } diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 9282797b95e..d70803bebd2 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.96 2015/02/04 16:38:31 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.97 2015/02/04 18:03:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -142,6 +142,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "missing font type, using \\fR", "unknown font type, using \\fR", "nothing follows prefix", + "empty reference block", "missing -std argument, adding it", "missing eqn box, using \"\"", |