+static int
+check_head1(CHKARGS)
+{
+
+ if (MAN_HEAD == n->type && 1 != n->nchild)
+ mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
+ n->pos, "line arguments eq 1 (have %d)", n->nchild);
+
+ return(1);
+}
+
+static int
+post_ft(CHKARGS)
+{
+ char *cp;
+ int ok;
+
+ if (0 == n->nchild)
+ return(1);
+
+ ok = 0;
+ cp = n->child->string;
+ switch (*cp) {
+ case ('1'):
+ /* FALLTHROUGH */
+ case ('2'):
+ /* FALLTHROUGH */
+ case ('3'):
+ /* FALLTHROUGH */
+ case ('4'):
+ /* FALLTHROUGH */
+ case ('I'):
+ /* FALLTHROUGH */
+ case ('P'):
+ /* FALLTHROUGH */
+ case ('R'):
+ if ('\0' == cp[1])
+ ok = 1;
+ break;
+ case ('B'):
+ if ('\0' == cp[1] || ('I' == cp[1] && '\0' == cp[2]))
+ ok = 1;
+ break;
+ case ('C'):
+ if ('W' == cp[1] && '\0' == cp[2])
+ ok = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (0 == ok) {
+ mandoc_vmsg
+ (MANDOCERR_BADFONT, man->parse,
+ n->line, n->pos, "%s", cp);
+ *cp = '\0';
+ }
+
+ if (1 < n->nchild)
+ mandoc_vmsg
+ (MANDOCERR_ARGCOUNT, man->parse, n->line,
+ n->pos, "want one child (have %d)",
+ n->nchild);
+
+ return(1);
+}
+
+static int
+pre_sec(CHKARGS)
+{
+
+ if (MAN_BLOCK == n->type)
+ man->flags &= ~MAN_LITERAL;
+ return(1);
+}
+
+static int
+post_sec(CHKARGS)
+{
+
+ if ( ! (MAN_HEAD == n->type && 0 == n->nchild))
+ return(1);
+
+ man_nmsg(man, n, MANDOCERR_SYNTARGCOUNT);
+ return(0);
+}
+
+static int
+check_part(CHKARGS)
+{
+
+ if (MAN_BODY == n->type && 0 == n->nchild)
+ mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line,
+ n->pos, "want children (have none)");
+
+ return(1);
+}
+
+
+static int
+check_par(CHKARGS)
+{
+
+ switch (n->type) {
+ case (MAN_BLOCK):
+ if (0 == n->body->nchild)
+ man_node_delete(man, n);
+ break;
+ case (MAN_BODY):
+ if (0 == n->nchild)
+ man_nmsg(man, n, MANDOCERR_IGNPAR);
+ break;
+ case (MAN_HEAD):
+ if (n->nchild)
+ man_nmsg(man, n, MANDOCERR_ARGSLOST);
+ break;
+ default:
+ break;
+ }
+
+ return(1);
+}
+
+static int
+post_IP(CHKARGS)
+{
+
+ switch (n->type) {
+ case (MAN_BLOCK):
+ if (0 == n->head->nchild && 0 == n->body->nchild)
+ man_node_delete(man, n);
+ break;
+ case (MAN_BODY):
+ if (0 == n->parent->head->nchild && 0 == n->nchild)
+ man_nmsg(man, n, MANDOCERR_IGNPAR);
+ break;
+ default:
+ break;
+ }
+ return(1);
+}
+
+static int
+post_TH(CHKARGS)
+{
+ const char *p;
+
+ free(man->meta.title);
+ free(man->meta.vol);
+ free(man->meta.source);
+ free(man->meta.msec);
+ free(man->meta.date);
+
+ man->meta.title = man->meta.vol = man->meta.date =
+ man->meta.msec = man->meta.source = NULL;
+
+ /* ->TITLE<- MSEC DATE SOURCE VOL */
+
+ n = n->child;
+ if (n && n->string) {
+ for (p = n->string; '\0' != *p; p++) {
+ /* Only warn about this once... */
+ if (isalpha((unsigned char)*p) &&
+ ! isupper((unsigned char)*p)) {
+ man_nmsg(man, n, MANDOCERR_UPPERCASE);
+ break;
+ }
+ }
+ man->meta.title = mandoc_strdup(n->string);
+ } else
+ man->meta.title = mandoc_strdup("");
+
+ /* TITLE ->MSEC<- DATE SOURCE VOL */
+
+ if (n)
+ n = n->next;
+ if (n && n->string)
+ man->meta.msec = mandoc_strdup(n->string);
+ else
+ man->meta.msec = mandoc_strdup("");
+
+ /* TITLE MSEC ->DATE<- SOURCE VOL */
+
+ if (n)
+ n = n->next;
+ if (n && n->string && '\0' != n->string[0]) {
+ man->meta.date = man->quick ?
+ mandoc_strdup(n->string) :
+ mandoc_normdate(man->parse, n->string,
+ n->line, n->pos);
+ } else
+ man->meta.date = mandoc_strdup("");
+
+ /* TITLE MSEC DATE ->SOURCE<- VOL */
+
+ if (n && (n = n->next))
+ man->meta.source = mandoc_strdup(n->string);
+
+ /* TITLE MSEC DATE SOURCE ->VOL<- */
+ /* If missing, use the default VOL name for MSEC. */
+
+ if (n && (n = n->next))
+ man->meta.vol = mandoc_strdup(n->string);
+ else if ('\0' != man->meta.msec[0] &&
+ (NULL != (p = mandoc_a2msec(man->meta.msec))))
+ man->meta.vol = mandoc_strdup(p);
+
+ /*
+ * Remove the `TH' node after we've processed it for our
+ * meta-data.
+ */
+ man_node_delete(man, man->last);
+ return(1);
+}
+
+static int
+post_nf(CHKARGS)
+{
+
+ if (MAN_LITERAL & man->flags)
+ man_nmsg(man, n, MANDOCERR_SCOPEREP);
+
+ man->flags |= MAN_LITERAL;
+ return(1);
+}
+
+static int
+post_fi(CHKARGS)
+{
+
+ if ( ! (MAN_LITERAL & man->flags))
+ man_nmsg(man, n, MANDOCERR_WNOSCOPE);
+
+ man->flags &= ~MAN_LITERAL;
+ return(1);
+}
+
+static int
+post_UC(CHKARGS)
+{
+ static const char * const bsd_versions[] = {
+ "3rd Berkeley Distribution",
+ "4th Berkeley Distribution",
+ "4.2 Berkeley Distribution",
+ "4.3 Berkeley Distribution",
+ "4.4 Berkeley Distribution",
+ };
+
+ const char *p, *s;
+
+ n = n->child;
+
+ if (NULL == n || MAN_TEXT != n->type)
+ p = bsd_versions[0];
+ else {
+ s = n->string;
+ if (0 == strcmp(s, "3"))
+ p = bsd_versions[0];
+ else if (0 == strcmp(s, "4"))
+ p = bsd_versions[1];
+ else if (0 == strcmp(s, "5"))
+ p = bsd_versions[2];
+ else if (0 == strcmp(s, "6"))
+ p = bsd_versions[3];
+ else if (0 == strcmp(s, "7"))
+ p = bsd_versions[4];
+ else
+ p = bsd_versions[0];
+ }
+
+ free(man->meta.source);
+ man->meta.source = mandoc_strdup(p);
+ return(1);
+}
+
+static int
+post_AT(CHKARGS)
+{
+ static const char * const unix_versions[] = {
+ "7th Edition",
+ "System III",
+ "System V",
+ "System V Release 2",
+ };
+
+ const char *p, *s;
+ struct man_node *nn;
+
+ n = n->child;
+
+ if (NULL == n || MAN_TEXT != n->type)
+ p = unix_versions[0];
+ else {
+ s = n->string;
+ if (0 == strcmp(s, "3"))
+ p = unix_versions[0];
+ else if (0 == strcmp(s, "4"))
+ p = unix_versions[1];
+ else if (0 == strcmp(s, "5")) {
+ nn = n->next;
+ if (nn && MAN_TEXT == nn->type && nn->string[0])
+ p = unix_versions[3];
+ else
+ p = unix_versions[2];
+ } else
+ p = unix_versions[0];
+ }
+
+ free(man->meta.source);
+ man->meta.source = mandoc_strdup(p);
+ return(1);
+}
+
+static int
+post_vs(CHKARGS)
+{
+
+ if (NULL != n->prev)
+ return(1);
+
+ switch (n->parent->tok) {
+ case (MAN_SH):
+ /* FALLTHROUGH */
+ case (MAN_SS):
+ man_nmsg(man, n, MANDOCERR_IGNPAR);
+ /* FALLTHROUGH */
+ case (MAN_MAX):
+ /*
+ * Don't warn about this because it occurs in pod2man
+ * and would cause considerable (unfixable) warnage.
+ */
+ man_node_delete(man, n);
+ break;
+ default:
+ break;
+ }
+
+ return(1);
+}