summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2019-03-04 13:01:53 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2019-03-04 13:01:53 +0000
commit3d0ae15b738b91538f9b5b8ab024a3c8c0598a99 (patch)
treed389d7073e228160965c747e765532716c5fbfa7
parent4c84aa76ac41e6a49ebe3e7c66cf37475c40e604 (diff)
When the -S option is given to man(1) and the requested manual page
name is not found and the requested architecture is unknown, complain about the architecture rather than about the manual page name: $ man -S vax cpu man: Unknown architecture "vax". $ man -S sparc64 foobar man: No entry for foobar in the manual. Friendlier error message suggested by jmc@, who also OK'ed the patch.
-rw-r--r--usr.bin/mandoc/Makefile4
-rw-r--r--usr.bin/mandoc/arch.c52
-rw-r--r--usr.bin/mandoc/main.c8
-rw-r--r--usr.bin/mandoc/mdoc_validate.c54
-rw-r--r--usr.bin/mandoc/roff.h5
5 files changed, 77 insertions, 46 deletions
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile
index d470321b438..3740006423d 100644
--- a/usr.bin/mandoc/Makefile
+++ b/usr.bin/mandoc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.115 2019/02/24 12:57:14 kn Exp $
+# $OpenBSD: Makefile,v 1.116 2019/03/04 13:01:52 schwarze Exp $
.include <bsd.own.mk>
@@ -7,7 +7,7 @@ DPADD += ${LIBUTIL}
LDADD += -lutil -lz
SRCS= mandoc_aux.c mandoc_ohash.c mandoc.c mandoc_msg.c mandoc_xr.c \
- chars.c preconv.c read.c \
+ arch.c chars.c preconv.c read.c \
roff.c roff_validate.c tbl.c tbl_opts.c tbl_layout.c tbl_data.c eqn.c
SRCS+= mdoc_macro.c mdoc.c \
mdoc_argv.c mdoc_state.c mdoc_validate.c att.c msec.c st.c
diff --git a/usr.bin/mandoc/arch.c b/usr.bin/mandoc/arch.c
new file mode 100644
index 00000000000..18970285ef3
--- /dev/null
+++ b/usr.bin/mandoc/arch.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: arch.c,v 1.10 2019/03/04 13:01:52 schwarze Exp $ */
+/*
+ * Copyright (c) 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <string.h>
+
+#include "roff.h"
+
+int
+arch_valid(const char *arch, enum mandoc_os os)
+{
+ 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 };
+ const char **arch_p;
+
+ if ((arch_p = arches[os]) == NULL)
+ return 1;
+ for (; *arch_p != NULL; arch_p++)
+ if (strcmp(*arch_p, arch) == 0)
+ return 1;
+ return 0;
+}
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 2db236a256e..6eb8a620f01 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.222 2019/03/03 13:01:47 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.223 2019/03/04 13:01:52 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -767,7 +767,11 @@ fs_search(const struct mansearch *cfg, const struct manpaths *paths,
}
if (res != NULL && *ressz == lastsz &&
strchr(*argv, '/') == NULL) {
- if (cfg->sec == NULL)
+ if (cfg->arch != NULL &&
+ arch_valid(cfg->arch, MANDOC_OS_OPENBSD) == 0)
+ warnx("Unknown architecture \"%s\".",
+ cfg->arch);
+ else if (cfg->sec == NULL)
warnx("No entry for %s in the manual.",
*argv);
else
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 916c7dda071..53b03a6119e 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: mdoc_validate.c,v 1.285 2019/03/04 11:40:03 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.286 2019/03/04 13:01:52 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
@@ -1883,29 +1883,7 @@ 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. */
@@ -1931,22 +1909,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'. */
diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h
index 89588219341..037759af400 100644
--- a/usr.bin/mandoc/roff.h
+++ b/usr.bin/mandoc/roff.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: roff.h,v 1.50 2018/12/31 08:17:58 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.51 2019/03/04 13:01:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -548,4 +548,5 @@ struct roff_meta {
extern const char *const *roff_name;
+int arch_valid(const char *, enum mandoc_os);
void deroff(char **, const struct roff_node *);