From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 3befc739 for ; Mon, 4 Mar 2019 08:02:28 -0500 (EST) Date: Mon, 4 Mar 2019 08:02:28 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: When the -S option is given to man(1) and the requested manual X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: Log Message: ----------- 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. Modified Files: -------------- mandoc: Makefile TODO configure configure.local.example main.c mdoc_validate.c roff.h Added Files: ----------- mandoc: arch.c Revision Data ------------- Index: configure =================================================================== RCS file: /home/cvs/mandoc/mandoc/configure,v retrieving revision 1.67 retrieving revision 1.68 diff -Lconfigure -Lconfigure -u -p -r1.67 -r1.68 --- configure +++ configure @@ -2,7 +2,7 @@ # # $Id$ # -# Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze +# Copyright (c) 2014-2019 Ingo Schwarze # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -37,6 +37,7 @@ SOURCEDIR=`dirname "$0"` MANPATH_BASE="/usr/share/man:/usr/X11R6/man" MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man" +OSENUM= OSNAME= UTF8_LOCALE= @@ -219,6 +220,26 @@ get_locale() { return 0; } +# --- operating system ------------------------------------------------- + +if [ -n "${OSENUM}" ]; then + echo "OSENUM specified manually: ${OSENUM}" 1>&2 + echo "OSENUM specified manually: ${OSENUM}" 1>&3 +else + OSDETECT=$(uname) + if [ "X${OSDETECT}" = "XNetBSD" ]; then + OSENUM=MANDOC_OS_NETBSD + elif [ "X${OSDETECT}" = "XOpenBSD" ]; then + OSENUM=MANDOC_OS_OPENBSD + else + OSENUM=MANDOC_OS_OTHER + fi + echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&2 + echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&3 + unset OSDETECT +fi +echo 1>&3 + # --- compiler options ------------------------------------------------- DEFCFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter" @@ -419,6 +440,7 @@ echo echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\"" echo "#define MANPATH_BASE \"${MANPATH_BASE}\"" echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\"" +echo "#define OSENUM ${OSENUM}" [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\"" [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\"" [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\"" Index: arch.c =================================================================== RCS file: arch.c diff -N arch.c --- arch.c +++ arch.c @@ -0,0 +1,54 @@ +/* $Id$ */ +/* + * Copyright (c) 2017, 2019 Ingo Schwarze + * + * 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 "config.h" + +#include + +#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; +} Index: configure.local.example =================================================================== RCS file: /home/cvs/mandoc/mandoc/configure.local.example,v retrieving revision 1.34 retrieving revision 1.35 diff -Lconfigure.local.example -Lconfigure.local.example -u -p -r1.34 -r1.35 --- configure.local.example +++ configure.local.example @@ -1,6 +1,6 @@ # $Id$ # -# Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze +# Copyright (c) 2014-2019 Ingo Schwarze # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -67,6 +67,17 @@ MANPATH_DEFAULT="/usr/share/man:/usr/X11 MANPATH_BASE="/usr/share/man:/usr/X11R6/man" +# When man(1) is called with the -S option and no manual page is +# found matching the requested name and the requested architecture, +# it tries to figure out whether the requested architecture is valid +# for the present operating system. Normally, ./configure detects +# the operating system using uname(1). If that fails or is not +# desired, either of the following lines can be used: + +OSENUM=MANDOC_OS_NETBSD +OSENUM=MANDOC_OS_OPENBSD +OSENUM=MANDOC_OS_OTHER + # In manual pages written in the mdoc(7) language, the operating system # version is displayed in the page footer line. If an operating system # is specified as an argument to the .Os macro, that is always used. @@ -77,7 +88,7 @@ MANPATH_BASE="/usr/share/man:/usr/X11R6/ # If you do not want uname(3) to be called but instead want a fixed # string to be used, use the following line: -OSNAME="OpenBSD 6.3" +OSNAME="OpenBSD 6.5" # The following installation directories are used. # It is possible to set only one or a few of these variables, Index: main.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/main.c,v retrieving revision 1.319 retrieving revision 1.320 diff -Lmain.c -Lmain.c -u -p -r1.319 -r1.320 --- main.c +++ main.c @@ -797,7 +797,11 @@ fs_search(const struct mansearch *cfg, c } if (res != NULL && *ressz == lastsz && strchr(*argv, '/') == NULL) { - if (cfg->sec == NULL) + if (cfg->arch != NULL && + arch_valid(cfg->arch, OSENUM) == 0) + warnx("Unknown architecture \"%s\".", + cfg->arch); + else if (cfg->sec == NULL) warnx("No entry for %s in the manual.", *argv); else Index: mdoc_validate.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v retrieving revision 1.370 retrieving revision 1.371 diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.370 -r1.371 --- mdoc_validate.c +++ mdoc_validate.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2018 Ingo Schwarze + * Copyright (c) 2010-2019 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -1898,29 +1898,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. */ @@ -1946,22 +1924,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'. */ Index: TODO =================================================================== RCS file: /home/cvs/mandoc/mandoc/TODO,v retrieving revision 1.288 retrieving revision 1.289 diff -LTODO -LTODO -u -p -r1.288 -r1.289 --- TODO +++ TODO @@ -446,15 +446,6 @@ are mere guesses, and some may be wrong. * warning issues ************************************************************************ -- When a man(1) command returns no result and there was an -S - argument, check the -S argument against the list of valid - architectures and say "Unknown architecture AAA" rather than - "No entry for NNN in the manual" if there is no match. - Requires moving the lists of valid architectures out of - mdoc_validate.c such that they can be used by main.c. - Discussed with jmc@ 10 Aug 2018 19:20:12 +0100. - loc ** exist * algo * size * imp ** - - warn about duplicate .Sh/.Ss heads gre(4): Rename duplicate sections 20 Apr 2018 15:27:33 +0200 loc * exist * algo * size * imp ** Index: roff.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/roff.h,v retrieving revision 1.68 retrieving revision 1.69 diff -Lroff.h -Lroff.h -u -p -r1.68 -r1.69 --- roff.h +++ roff.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze + * Copyright (c) 2013-2015, 2017-2019 Ingo Schwarze * * 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 *); Index: Makefile =================================================================== RCS file: /home/cvs/mandoc/mandoc/Makefile,v retrieving revision 1.527 retrieving revision 1.528 diff -LMakefile -LMakefile -u -p -r1.527 -r1.528 --- Makefile +++ Makefile @@ -1,7 +1,7 @@ # $Id$ # # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons -# Copyright (c) 2011, 2013-2018 Ingo Schwarze +# Copyright (c) 2011, 2013-2019 Ingo Schwarze # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -54,7 +54,8 @@ TESTSRCS = test-be32toh.c \ test-vasprintf.c \ test-wchar.c -SRCS = att.c \ +SRCS = arch.c \ + att.c \ catman.c \ cgi.c \ chars.c \ @@ -235,6 +236,7 @@ LIBROFF_OBJS = eqn.o \ LIBMANDOC_OBJS = $(LIBMAN_OBJS) \ $(LIBMDOC_OBJS) \ $(LIBROFF_OBJS) \ + arch.o \ chars.o \ mandoc.o \ mandoc_aux.o \ -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv