From 4d16f068f299d6051b1ed364884765046c93b024 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 21 May 2017 22:28:28 +0000 Subject: 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). --- usr.bin/catman/catman.1 | 5 ++++- usr.bin/catman/catman.c | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/usr.bin/catman/catman.1 b/usr.bin/catman/catman.1 index fe855872fd54..3b387c312750 100644 --- a/usr.bin/catman/catman.1 +++ b/usr.bin/catman/catman.1 @@ -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 diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c index 47906f5c35f3..c3897e1a715f 100644 --- a/usr.bin/catman/catman.c +++ b/usr.bin/catman/catman.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -70,6 +71,8 @@ static char *lang_locale; /* short form of locale */ 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, char *cat, enum Ziptype zipped) } 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++; -- cgit v1.2.3