summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-02-16 19:02:48 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-02-16 19:02:48 +0000
commitd051fb46374527510c8eca76499a77e487090a22 (patch)
tree6227561ebd3b797b013f3d9e03ac12315dcafb4a
parenta8aad8b14d8c6c974b71e5ab88a00d3abe7f285d (diff)
downloadmandoc-d051fb46374527510c8eca76499a77e487090a22.tar.gz
clean up post_dt() validation function;
improved diagnostics, minus six lines of code
-rw-r--r--mandoc.13
-rw-r--r--mdoc_validate.c82
2 files changed, 43 insertions, 42 deletions
diff --git a/mandoc.1 b/mandoc.1
index 306827b0..0acd752e 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1687,6 +1687,9 @@ or a request of the
.Ic \&de
family with more than two arguments
.It
+.Ic \&Dt
+with more than three arguments
+.It
.Ic \&TH
with more than five arguments
.It
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 3471b58c..0310da83 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -2156,70 +2156,68 @@ post_dt(POST_ARGS)
mdoc->meta.vol = NULL;
mdoc->meta.arch = NULL;
- /* First check that all characters are uppercase. */
+ /* Mandatory first argument: title. */
- if (NULL != (nn = n->child))
- for (p = nn->string; *p; p++) {
- if (toupper((unsigned char)*p) == *p)
- continue;
- mandoc_vmsg(MANDOCERR_TITLE_CASE,
- mdoc->parse, nn->line,
- nn->pos + (p - nn->string),
- "Dt %s", nn->string);
- break;
- }
-
- /* No argument: msec and arch remain NULL. */
-
- if (NULL == (nn = n->child)) {
+ nn = n->child;
+ if (nn == NULL || *nn->string == '\0') {
mandoc_msg(MANDOCERR_DT_NOTITLE,
mdoc->parse, n->line, n->pos, "Dt");
mdoc->meta.title = mandoc_strdup("UNTITLED");
- mdoc->meta.vol = mandoc_strdup("LOCAL");
- goto out;
+ } else {
+ mdoc->meta.title = mandoc_strdup(nn->string);
+
+ /* Check that all characters are uppercase. */
+
+ for (p = nn->string; *p != '\0'; p++)
+ if (islower((unsigned char)*p)) {
+ mandoc_vmsg(MANDOCERR_TITLE_CASE,
+ mdoc->parse, nn->line,
+ nn->pos + (p - nn->string),
+ "Dt %s", nn->string);
+ break;
+ }
}
- /* One argument: msec and arch remain NULL. */
+ /* Mandatory second argument: section. */
- mdoc->meta.title = mandoc_strdup(
- '\0' == nn->string[0] ? "UNTITLED" : nn->string);
+ if (nn != NULL)
+ nn = nn->next;
- if (NULL == (nn = nn->next)) {
+ if (nn == NULL) {
mandoc_vmsg(MANDOCERR_MSEC_MISSING,
mdoc->parse, n->line, n->pos,
"Dt %s", mdoc->meta.title);
mdoc->meta.vol = mandoc_strdup("LOCAL");
- goto out;
+ goto out; /* msec and arch remain NULL. */
}
- /* Handles: `.Dt TITLE SEC'
- * title = TITLE,
- * volume = SEC is msec ? format(msec) : SEC,
- * msec = SEC is msec ? atoi(msec) : 0,
- * arch = NULL
- */
+ mdoc->meta.msec = mandoc_strdup(nn->string);
+
+ /* Infer volume title from section number. */
cp = mandoc_a2msec(nn->string);
- if (cp) {
- mdoc->meta.vol = mandoc_strdup(cp);
- mdoc->meta.msec = mandoc_strdup(nn->string);
- } else {
+ if (cp == NULL) {
mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse,
nn->line, nn->pos, "Dt ... %s", nn->string);
mdoc->meta.vol = mandoc_strdup(nn->string);
- mdoc->meta.msec = mandoc_strdup(nn->string);
- }
+ } else
+ mdoc->meta.vol = mandoc_strdup(cp);
- /* Handle an optional architecture */
+ /* Optional third argument: architecture. */
- if ((nn = nn->next) != NULL) {
- for (p = nn->string; *p; p++)
- *p = tolower((unsigned char)*p);
- mdoc->meta.arch = mandoc_strdup(nn->string);
- }
+ if ((nn = nn->next) == NULL)
+ goto out;
+
+ for (p = nn->string; *p != '\0'; p++)
+ *p = tolower((unsigned char)*p);
+ mdoc->meta.arch = mandoc_strdup(nn->string);
+
+ /* Ignore fourth and later arguments. */
+
+ if ((nn = nn->next) != NULL)
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
+ nn->line, nn->pos, "Dt ... %s", nn->string);
- /* Ignore any subsequent parameters... */
- /* FIXME: warn about subsequent parameters. */
out:
mdoc_node_delete(mdoc, n);
}