From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: better handle empty .Bd .Bl .D1 .Dl blocks
Date: Thu, 5 Feb 2015 21:05:25 -0500 (EST) [thread overview]
Message-ID: <505695354739049094.enqueue@fantadrom.bsd.lv> (raw)
Log Message:
-----------
better handle empty .Bd .Bl .D1 .Dl blocks
Modified Files:
--------------
mdocml:
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v
retrieving revision 1.272
retrieving revision 1.273
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.272 -r1.273
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -1072,26 +1072,40 @@ post_nd(POST_ARGS)
static void
post_d1(POST_ARGS)
{
+ struct mdoc_node *n;
+
+ n = mdoc->last;
+
+ if (n->type != MDOC_BODY)
+ return;
+
+ if (n->child == NULL)
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ n->line, n->pos, "D1");
- bwarn_ge1(mdoc);
post_hyph(mdoc);
}
static void
post_literal(POST_ARGS)
{
+ struct mdoc_node *n;
- bwarn_ge1(mdoc);
+ n = mdoc->last;
- /*
- * The `Dl' (note "el" not "one") and `Bd' macros unset the
- * MDOC_LITERAL flag as they leave. Note that `Bd' only sets
- * this in literal mode, but it doesn't hurt to just switch it
- * off in general since displays can't be nested.
- */
+ if (n->type != MDOC_BODY)
+ return;
+
+ if (n->child == NULL)
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ n->line, n->pos, mdoc_macronames[n->tok]);
+
+ if (n->tok == MDOC_Bd &&
+ n->norm->Bd.type != DISP_literal &&
+ n->norm->Bd.type != DISP_unfilled)
+ return;
- if (MDOC_BODY == mdoc->last->type)
- mdoc->flags &= ~MDOC_LITERAL;
+ mdoc->flags &= ~MDOC_LITERAL;
}
static void
@@ -1488,10 +1502,13 @@ post_bl(POST_ARGS)
return;
}
- bwarn_ge1(mdoc);
-
nchild = nbody->child;
- while (NULL != nchild) {
+ if (nchild == NULL) {
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ nbody->line, nbody->pos, "Bl");
+ return;
+ }
+ while (nchild != NULL) {
if (nchild->tok == MDOC_It ||
(nchild->tok == MDOC_Sm &&
nchild->next != NULL &&
@@ -1749,33 +1766,17 @@ post_rs(POST_ARGS)
static void
post_hyph(POST_ARGS)
{
- struct mdoc_node *n, *nch;
+ struct mdoc_node *nch;
char *cp;
- n = mdoc->last;
- switch (n->type) {
- case MDOC_HEAD:
- if (MDOC_Sh == n->tok || MDOC_Ss == n->tok)
- break;
- return;
- case MDOC_BODY:
- if (MDOC_D1 == n->tok || MDOC_Nd == n->tok)
- break;
- return;
- case MDOC_ELEM:
- break;
- default:
- return;
- }
-
- for (nch = n->child; nch; nch = nch->next) {
- if (MDOC_TEXT != nch->type)
+ for (nch = mdoc->last->child; nch != NULL; nch = nch->next) {
+ if (nch->type != MDOC_TEXT)
continue;
cp = nch->string;
- if ('\0' == *cp)
+ if (*cp == '\0')
continue;
- while ('\0' != *(++cp))
- if ('-' == *cp &&
+ while (*(++cp) != '\0')
+ if (*cp == '-' &&
isalpha((unsigned char)cp[-1]) &&
isalpha((unsigned char)cp[1]))
*cp = ASCII_HYPH;
@@ -2069,10 +2070,15 @@ post_ignpar(POST_ARGS)
{
struct mdoc_node *np;
- post_hyph(mdoc);
-
- if (MDOC_BODY != mdoc->last->type)
+ switch (mdoc->last->type) {
+ case MDOC_HEAD:
+ post_hyph(mdoc);
return;
+ case MDOC_BODY:
+ break;
+ default:
+ return;
+ }
if (NULL != (np = mdoc->last->child))
if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2015-02-06 2:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=505695354739049094.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).