Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 May 2017 22:28:28 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r318600 - head/usr.bin/catman
Message-ID:  <201705212228.v4LMSSJV047765@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Sun May 21 22:28:28 2017
New Revision: 318600
URL: https://svnweb.freebsd.org/changeset/base/318600

Log:
  Make catman(1) use mandoc(1) by default
  
  catman(1) checks if mandoc(1) do support the manpage before trying to generate
  the catpage and falls back on nroff, using the same mechanism as man(1).

Modified:
  head/usr.bin/catman/catman.1
  head/usr.bin/catman/catman.c

Modified: head/usr.bin/catman/catman.1
==============================================================================
--- head/usr.bin/catman/catman.1	Sun May 21 22:10:08 2017	(r318599)
+++ head/usr.bin/catman/catman.1	Sun May 21 22:28:28 2017	(r318600)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 3, 2005
+.Dd May 22, 2017
 .Dt CATMAN 1
 .Os
 .Sh NAME
@@ -40,6 +40,8 @@ The
 utility preformats all the man pages in
 .Ar directories
 using the
+.Nm mandoc
+command when supported, falling back on the
 .Nm nroff Fl man
 command.
 Directories may be separated by colons instead of spaces.
@@ -99,6 +101,7 @@ environment variable is not set.
 .Sh SEE ALSO
 .Xr makewhatis 1 ,
 .Xr man 1 ,
+.Xr mandoc 1 ,
 .Xr nroff 1
 .Sh HISTORY
 A previous version of the

Modified: head/usr.bin/catman/catman.c
==============================================================================
--- head/usr.bin/catman/catman.c	Sun May 21 22:10:08 2017	(r318599)
+++ head/usr.bin/catman/catman.c	Sun May 21 22:28:28 2017	(r318600)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include <locale.h>
 #include <langinfo.h>
 #include <libgen.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -70,6 +71,8 @@ static char *lang_locale;	/* short form 
 static const char *machine, *machine_arch;
 static int exit_code;		/* exit code to use when finished */
 
+extern char **environ;
+
 /*
  * -T argument for nroff
  */
@@ -93,6 +96,7 @@ static const char *locale_device[] = {
 #define	GZCAT_CMD	"z"
 enum Ziptype {NONE, BZIP, GZIP};
 
+static bool mandoc_locales = false;
 static uid_t uid;
 static int starting_dir;
 static char tmp_file[MAXPATHLEN];
@@ -438,11 +442,24 @@ process_page(char *mandir, char *src, ch
 	}
 	snprintf(tmp_file, sizeof tmp_file, "%s.tmp", cat);
 	snprintf(cmd, sizeof cmd,
-	    "%scat %s | tbl | nroff -c -T%s -man | %s > %s.tmp",
+	    "%scat %s | mandoc -Tlint -Wunsupp 2>/dev/null",
 	    zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "",
-	    src, nroff_device,
-	    zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat",
-	    cat);
+	    src);
+	if (system(cmd) == 0) {
+		snprintf(cmd, sizeof cmd,
+		    "%scat %s | mandoc -T%s | %s > %s.tmp",
+		    zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "",
+		    src, mandoc_locales ? "locale" : "ascii",
+		    zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat",
+		    cat);
+	} else {
+		snprintf(cmd, sizeof cmd,
+		    "%scat %s | tbl | nroff -c -T%s -man | %s > %s.tmp",
+		    zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "",
+		    src, nroff_device,
+		    zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat",
+		    cat);
+	}
 	if (system(cmd) != 0)
 		err(1, "formatting pipeline");
 	if (rename(tmp_file, cat) < 0)
@@ -771,6 +788,7 @@ main(int argc, char **argv)
 			break;
 		case 'L':
 			determine_locale();
+			mandoc_locales = true;
 			break;
 		case 'n':
 			pretend++;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705212228.v4LMSSJV047765>