]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_validate.c
Improve validation of function names:
[mandoc.git] / mdoc_validate.c
index 448cc7ca2218c0cbad8fdc9b48c8baaccf275fab..c14d4008cb88fea65571d4baa09427bcf87935c2 100644 (file)
@@ -1,7 +1,7 @@
-/*     $Id: mdoc_validate.c,v 1.370 2019/03/04 11:40:09 schwarze Exp $ */
+/*     $Id: mdoc_validate.c,v 1.375 2019/09/13 19:26:46 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -64,7 +64,7 @@ static        size_t          macro2len(enum roff_tok);
 static void     rewrite_macro2len(struct roff_man *, char **);
 static int      similar(const char *, const char *);
 
-static void     post_abort(POST_ARGS);
+static void     post_abort(POST_ARGS) __attribute__((__noreturn__));
 static void     post_an(POST_ARGS);
 static void     post_an_norm(POST_ARGS);
 static void     post_at(POST_ARGS);
@@ -1186,11 +1186,17 @@ post_fname(POST_ARGS)
        size_t                   pos;
 
        n = mdoc->last->child;
-       pos = strcspn(n->string, "()");
-       cp = n->string + pos;
-       if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*')))
-               mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos,
-                   "%s", n->string);
+       cp = n->string;
+       if (*cp == '(') {
+               if (cp[strlen(cp + 1)] == ')')
+                       return;
+               pos = 0;
+       } else {
+               pos = strcspn(cp, "()");
+               if (cp[pos] == '\0')
+                       return;
+       }
+       mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos, "%s", cp);
 }
 
 static void
@@ -1898,35 +1904,12 @@ post_sm(POST_ARGS)
 static void
 post_root(POST_ARGS)
 {
-       const char *openbsd_arch[] = {
-               "alpha", "amd64", "arm64", "armv7", "hppa", "i386",
-               "landisk", "loongson", "luna88k", "macppc", "mips64",
-               "octeon", "sgi", "socppc", "sparc64", NULL
-       };
-       const char *netbsd_arch[] = {
-               "acorn26", "acorn32", "algor", "alpha", "amiga",
-               "arc", "atari",
-               "bebox", "cats", "cesfic", "cobalt", "dreamcast",
-               "emips", "evbarm", "evbmips", "evbppc", "evbsh3", "evbsh5",
-               "hp300", "hpcarm", "hpcmips", "hpcsh", "hppa",
-               "i386", "ibmnws", "luna68k",
-               "mac68k", "macppc", "mipsco", "mmeye", "mvme68k", "mvmeppc",
-               "netwinder", "news68k", "newsmips", "next68k",
-               "pc532", "playstation2", "pmax", "pmppc", "prep",
-               "sandpoint", "sbmips", "sgimips", "shark",
-               "sparc", "sparc64", "sun2", "sun3",
-               "vax", "walnut", "x68k", "x86", "x86_64", "xen", NULL
-        };
-       const char **arches[] = { NULL, netbsd_arch, openbsd_arch };
-
        struct roff_node *n;
-       const char **arch;
 
        /* Add missing prologue data. */
 
        if (mdoc->meta.date == NULL)
-               mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
-                   mandoc_normdate(mdoc, NULL, 0, 0);
+               mdoc->meta.date = mandoc_normdate(mdoc, NULL, 0, 0);
 
        if (mdoc->meta.title == NULL) {
                mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF");
@@ -1946,22 +1929,18 @@ post_root(POST_ARGS)
                    "(OpenBSD)" : "(NetBSD)");
 
        if (mdoc->meta.arch != NULL &&
-           (arch = arches[mdoc->meta.os_e]) != NULL) {
-               while (*arch != NULL && strcmp(*arch, mdoc->meta.arch))
-                       arch++;
-               if (*arch == NULL) {
-                       n = mdoc->meta.first->child;
-                       while (n->tok != MDOC_Dt ||
-                           n->child == NULL ||
-                           n->child->next == NULL ||
-                           n->child->next->next == NULL)
-                               n = n->next;
-                       n = n->child->next->next;
-                       mandoc_msg(MANDOCERR_ARCH_BAD, n->line, n->pos,
-                           "Dt ... %s %s", mdoc->meta.arch,
-                           mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
-                           "(OpenBSD)" : "(NetBSD)");
-               }
+           arch_valid(mdoc->meta.arch, mdoc->meta.os_e) == 0) {
+               n = mdoc->meta.first->child;
+               while (n->tok != MDOC_Dt ||
+                   n->child == NULL ||
+                   n->child->next == NULL ||
+                   n->child->next->next == NULL)
+                       n = n->next;
+               n = n->child->next->next;
+               mandoc_msg(MANDOCERR_ARCH_BAD, n->line, n->pos,
+                   "Dt ... %s %s", mdoc->meta.arch,
+                   mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
+                   "(OpenBSD)" : "(NetBSD)");
        }
 
        /* Check that we begin with a proper `Sh'. */
@@ -2545,21 +2524,10 @@ post_dd(POST_ARGS)
                mandoc_msg(MANDOCERR_PROLOG_ORDER,
                    n->line, n->pos, "Dd after Os");
 
-       if (n->child == NULL || n->child->string[0] == '\0') {
-               mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
-                   mandoc_normdate(mdoc, NULL, n->line, n->pos);
-               return;
-       }
-
        datestr = NULL;
        deroff(&datestr, n);
-       if (mdoc->quick)
-               mdoc->meta.date = datestr;
-       else {
-               mdoc->meta.date = mandoc_normdate(mdoc,
-                   datestr, n->line, n->pos);
-               free(datestr);
-       }
+       mdoc->meta.date = mandoc_normdate(mdoc, datestr, n->line, n->pos);
+       free(datestr);
 }
 
 static void