Print this page
-T on the wrong command!
Latest round of fixes per RM and AL. Fix bugs found in man.c.
@@ -21,10 +21,11 @@
/*
* Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2014 Garrett D'Amore <garrett@damore.org>
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T. */
/* All rights reserved. */
@@ -80,11 +81,12 @@
{ "3r", "3rt" },
{ "3s", "3c" },
{ "3t", "3thr" },
{ "3x", "3curses" },
{ "3xc", "3xcurses" },
- { "3xn", "3xnet" }
+ { "3xn", "3xnet" },
+ { NULL, NULL }
};
struct suffix {
char *ds;
char *fs;
@@ -156,15 +158,16 @@
static int list = 0;
static int makewhatis = 0;
static int printmp = 0;
static int sargs = 0;
static int psoutput = 0;
+static int lintout = 0;
static int whatis = 0;
static int makewhatishere = 0;
static char *mansec;
-static char *pager;
+static char *pager = NULL;
static char *addlocale(char *);
static struct man_node *build_manpath(char **, int);
static void do_makewhatis(struct man_node *);
static char *check_config(char *);
@@ -236,19 +239,23 @@
whatis++;
opts = "M:ds:";
} else if (strcmp(__progname, "catman") == 0) {
catman++;
makewhatis++;
- opts = "M:w";
+ opts = "P:M:w";
} else if (strcmp(__progname, "makewhatis") == 0) {
makewhatis++;
makewhatishere++;
manpath = ".";
opts = "";
} else {
- opts = "M:adfklps:tw";
+ opts = "FM:P:T:adfklprs:tw";
+ if (argc > 1 && strcmp(argv[1], "-") == 0) {
+ pager = "cat";
+ optind++;
}
+ }
opterr = 0;
while ((c = getopt(argc, argv, opts)) != -1) {
switch (c) {
case 'M': /* Respecify path for man pages */
@@ -266,21 +273,30 @@
case 'k':
apropos++;
break;
case 'l':
list++;
- /*FALLTHROUGH*/
+ all++;
+ break;
case 'p':
printmp++;
break;
case 's':
mansec = optarg;
sargs++;
break;
+ case 'r':
+ lintout++;
+ break;
case 't':
psoutput++;
break;
+ case 'T':
+ case 'P':
+ case 'F':
+ /* legacy options, compatibility only and ignored */
+ break;
case 'w':
makewhatis++;
break;
case '?':
default:
@@ -349,12 +365,14 @@
}
if (manwidth != 0) {
DPRINTF("-- Using non-standard page width: %d\n", manwidth);
}
+ if (pager == NULL) {
if ((pager = getenv("PAGER")) == NULL || *pager == '\0')
pager = PAGER;
+ }
DPRINTF("-- Using pager: %s\n", pager);
for (i = 0; i < argc; i++) {
char *cmd;
static struct man_node *mp;
@@ -1144,25 +1162,19 @@
*/
static char *
map_section(char *section, char *path)
{
int i;
- int len;
char fullpath[MAXPATHLEN];
if (list) /* -l option fall through */
return (NULL);
- for (i = 0; i <= ((sizeof (map)/sizeof (map[0]) - 1)); i++) {
- if (strlen(section) > strlen(map[i].new_name)) {
- len = strlen(section);
- } else {
- len = strlen(map[i].new_name);
- }
- if (strncmp(section, map[i].old_name, len) == 0) {
+ for (i = 0; map[i].new_name != NULL; i++) {
+ if (strcmp(section, map[i].old_name) == 0) {
(void) snprintf(fullpath, sizeof (fullpath),
- "%s/sman%s", path, map[i].new_name);
+ "%s/man%s", path, map[i].new_name);
if (!access(fullpath, R_OK | X_OK)) {
return (map[i].new_name);
} else {
return (NULL);
}
@@ -1195,11 +1207,11 @@
dir + 3, pg);
(void) snprintf(catpname, sizeof (catpname), "%s/cat%s/%s", path,
dir + 3, pg);
/* Can't do PS output if manpage doesn't exist */
- if (stat(manpname, &sbman) != 0 && psoutput)
+ if (stat(manpname, &sbman) != 0 && (psoutput|lintout))
return (-1);
/*
* If both manpage and catpage do not exist, manpname is
* broken symlink, most likely.
@@ -1211,11 +1223,11 @@
if (fnmatch("*.gz", manpname, 0) == 0)
cattool = "gzcat";
else if (fnmatch("*.bz2", manpname, 0) == 0)
cattool = "bzcat";
else
- cattool = "gzcat -f";
+ cattool = "cat";
/* Preprocess UTF-8 input with preconv (could be smarter) */
if (strstr(path, "UTF-8") != NULL)
utf8 = 1;
@@ -1224,10 +1236,17 @@
"cd %s; %s %s%s | mandoc -Tps | lp -Tpostscript",
path, cattool, manpname,
utf8 ? " | " PRECONV " -e UTF-8" : "");
DPRINTF("-- Using manpage: %s\n", manpname);
goto cmd;
+ } else if (lintout) {
+ (void) snprintf(cmdbuf, BUFSIZ,
+ "cd %s; %s %s%s | mandoc -Tlint",
+ path, cattool, manpname,
+ utf8 ? " | " PRECONV " -e UTF-8" : "");
+ DPRINTF("-- Linting manpage: %s\n", manpname);
+ goto cmd;
}
/*
* Output catpage if:
* - manpage doesn't exist
@@ -1566,12 +1585,12 @@
usage_man(void)
{
(void) fprintf(stderr, gettext(
"usage: man [-alptw] [-M path] [-s section] name ...\n"
-" man [-M path] [-s section] -k keyword -- emulate apropos\n"
-" man [-M path] [-s section] -f keyword -- emulate whatis\n"));
+" man [-M path] [-s section] -k keyword ...\n"
+" man [-M path] [-s section] -f keyword ...\n"));
exit(1);
}
static void