summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2017-01-10 12:54:29 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2017-01-10 12:54:29 +0000
commitc53de85976eb23ce439737adc25a952aece3db20 (patch)
tree669698d57cd7d637acfd0a83d40fa96714799193 /usr.bin/mandoc/mdoc_validate.c
parent0761931691e27db6d4e2cbd44442279635d029f3 (diff)
Introduce flags NODE_NOSRC and NODE_NOPRT for AST nodes.
Use them to mark generated nodes and nodes that shall not produce output. Let -Ttree output mode display these new flags. Use NODE_NOSRC for .Ar, .Mt, and .Pa default arguments. Use NODE_NOPRT for .Dd, .Dt, and .Os. These will help to make handling of text production macros more rigorous.
Diffstat (limited to 'usr.bin/mandoc/mdoc_validate.c')
-rw-r--r--usr.bin/mandoc/mdoc_validate.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 47900442c91..ff52063c8fd 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.228 2017/01/08 02:01:14 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.229 2017/01/10 12:54:28 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -936,12 +936,15 @@ post_defaults(POST_ARGS)
case MDOC_Ar:
mdoc->next = ROFF_NEXT_CHILD;
roff_word_alloc(mdoc, nn->line, nn->pos, "file");
+ mdoc->last->flags |= NODE_NOSRC;
roff_word_alloc(mdoc, nn->line, nn->pos, "...");
+ mdoc->last->flags |= NODE_NOSRC;
break;
case MDOC_Pa:
case MDOC_Mt:
mdoc->next = ROFF_NEXT_CHILD;
roff_word_alloc(mdoc, nn->line, nn->pos, "~");
+ mdoc->last->flags |= NODE_NOSRC;
break;
default:
abort();
@@ -1932,6 +1935,8 @@ post_dd(POST_ARGS)
char *datestr;
n = mdoc->last;
+ n->flags |= NODE_NOPRT;
+
if (mdoc->meta.date != NULL) {
mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
n->line, n->pos, "Dd");
@@ -1949,7 +1954,7 @@ post_dd(POST_ARGS)
if (n->child == NULL || n->child->string[0] == '\0') {
mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
mandoc_normdate(mdoc->parse, NULL, n->line, n->pos);
- goto out;
+ return;
}
datestr = NULL;
@@ -1961,8 +1966,6 @@ post_dd(POST_ARGS)
datestr, n->line, n->pos);
free(datestr);
}
-out:
- roff_node_delete(mdoc, n);
}
static void
@@ -1973,10 +1976,12 @@ post_dt(POST_ARGS)
char *p;
n = mdoc->last;
+ n->flags |= NODE_NOPRT;
+
if (mdoc->flags & MDOC_PBODY) {
mandoc_msg(MANDOCERR_DT_LATE, mdoc->parse,
n->line, n->pos, "Dt");
- goto out;
+ return;
}
if (mdoc->meta.title != NULL)
@@ -2028,7 +2033,7 @@ post_dt(POST_ARGS)
mdoc->parse, n->line, n->pos,
"Dt %s", mdoc->meta.title);
mdoc->meta.vol = mandoc_strdup("LOCAL");
- goto out; /* msec and arch remain NULL. */
+ return; /* msec and arch remain NULL. */
}
mdoc->meta.msec = mandoc_strdup(nn->string);
@@ -2046,7 +2051,7 @@ post_dt(POST_ARGS)
/* Optional third argument: architecture. */
if ((nn = nn->next) == NULL)
- goto out;
+ return;
for (p = nn->string; *p != '\0'; p++)
*p = tolower((unsigned char)*p);
@@ -2057,9 +2062,6 @@ post_dt(POST_ARGS)
if ((nn = nn->next) != NULL)
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
nn->line, nn->pos, "Dt ... %s", nn->string);
-
-out:
- roff_node_delete(mdoc, n);
}
static void
@@ -2087,6 +2089,8 @@ post_os(POST_ARGS)
struct roff_node *n;
n = mdoc->last;
+ n->flags |= NODE_NOPRT;
+
if (mdoc->meta.os != NULL)
mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
n->line, n->pos, "Os");
@@ -2107,11 +2111,11 @@ post_os(POST_ARGS)
mdoc->meta.os = NULL;
deroff(&mdoc->meta.os, n);
if (mdoc->meta.os)
- goto out;
+ return;
if (mdoc->defos) {
mdoc->meta.os = mandoc_strdup(mdoc->defos);
- goto out;
+ return;
}
#ifdef OSNAME
@@ -2128,9 +2132,6 @@ post_os(POST_ARGS)
}
mdoc->meta.os = mandoc_strdup(defbuf);
#endif /*!OSNAME*/
-
-out:
- roff_node_delete(mdoc, n);
}
/*