--- old/usr/src/cmd/man/man.c	Sat Jul 19 14:19:57 2014
+++ new/usr/src/cmd/man/man.c	Sat Jul 19 14:19:57 2014
@@ -23,6 +23,7 @@
  * 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.	*/
@@ -82,7 +83,8 @@
 	{ "3t",		"3thr"		},
 	{ "3x",		"3curses"	},
 	{ "3xc",	"3xcurses"	},
-	{ "3xn",	"3xnet"		}
+	{ "3xn",	"3xnet"		},
+	{ NULL,		NULL		}
 };
 
 struct suffix {
@@ -158,11 +160,12 @@
 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);
@@ -238,7 +241,7 @@
 	} else if (strcmp(__progname, "catman") == 0) {
 		catman++;
 		makewhatis++;
-		opts = "M:w";
+		opts = "P:M:w";
 	} else if (strcmp(__progname, "makewhatis") == 0) {
 		makewhatis++;
 		makewhatishere++;
@@ -245,7 +248,11 @@
 		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;
@@ -268,7 +275,8 @@
 			break;
 		case 'l':
 			list++;
-			/*FALLTHROUGH*/
+			all++;
+			break;
 		case 'p':
 			printmp++;
 			break;
@@ -276,9 +284,17 @@
 			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;
@@ -351,8 +367,10 @@
 		DPRINTF("-- Using non-standard page width: %d\n", manwidth);
 	}
 
-	if ((pager = getenv("PAGER")) == NULL || *pager == '\0')
-		pager = PAGER;
+	if (pager == NULL) {
+		if ((pager = getenv("PAGER")) == NULL || *pager == '\0')
+			pager = PAGER;
+	}
 	DPRINTF("-- Using pager: %s\n", pager);
 
 	for (i = 0; i < argc; i++) {
@@ -1146,21 +1164,15 @@
 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 {
@@ -1197,7 +1209,7 @@
 	    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);
 
 	/*
@@ -1213,7 +1225,7 @@
 	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)
@@ -1226,6 +1238,13 @@
 		    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;
 	}
 
 	/*
@@ -1568,8 +1587,8 @@
 
 	(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);
 }
