[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Man-db-devel] [PATCH v4] man(1): Do not roff pages w/o macros
From: |
Mihail Konev |
Subject: |
[Man-db-devel] [PATCH v4] man(1): Do not roff pages w/o macros |
Date: |
Mon, 31 Oct 2016 05:06:41 +0500 |
This fixes display of manpages that really are catpages.
---
v4: correct the description
configure.ac | 1 +
man/replace.sin.in | 1 +
src/Makefile.am | 2 ++
src/man.c | 22 ++++++++++++++++++++--
src/roff_maybe | 39 +++++++++++++++++++++++++++++++++++++++
5 files changed, 63 insertions(+), 2 deletions(-)
create mode 100755 src/roff_maybe
diff --git a/configure.ac b/configure.ac
index c8339f378a4a..1e30c4777be7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -440,6 +440,7 @@ MAN_TRANS_SUBST([man])
MAN_TRANS_SUBST([manconv])
MAN_TRANS_SUBST([mandb])
MAN_TRANS_SUBST([manpath])
+MAN_TRANS_SUBST([roff_maybe])
MAN_TRANS_SUBST([whatis])
MAN_TRANS_SUBST([zsoelim])
diff --git a/man/replace.sin.in b/man/replace.sin.in
index 72a7e09835f9..5da9f275bd29 100644
--- a/man/replace.sin.in
+++ b/man/replace.sin.in
@@ -11,6 +11,7 @@ s,%catman%,@TRANS_CATMAN@,g
s,%apropos%,@TRANS_APROPOS@,g
s,%whatis%,@TRANS_WHATIS@,g
s,%manconv%,@TRANS_MANCONV@,g
+s,%roff_maybe%,@TRANS_ROFF_MAYBE@,g
s,%thzsoelim%,@TRANS_ZSOELIM_UPPER@,g
s,%thman%,@TRANS_MAN_UPPER@,g
s,%thmandb%,@TRANS_MANDB_UPPER@,g
diff --git a/src/Makefile.am b/src/Makefile.am
index d485ef42a72f..86072f377aeb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ bin_PROGRAMS = \
whatis
sbin_PROGRAMS = accessdb
pkglibexec_PROGRAMS = globbing manconv zsoelim
+pkglibexec_SCRIPTS = roff_maybe
noinst_DATA = man_db.conf
EXTRA_DIST = lexgrog.c zsoelim.c
@@ -49,6 +50,7 @@ AM_CPPFLAGS = \
-DMAN=\"$(bindir)/$(TRANS_MAN)\" \
-DMANCONV=\"$(pkglibexecdir)/$(TRANS_MANCONV)\" \
-DMANDB=\"$(bindir)/$(TRANS_MANDB)\" \
+ -DROFF_MAYBE=\"$(pkglibexecdir)/$(TRANS_ROFF_MAYBE)\" \
-DWHATIS=\"$(bindir)/$(TRANS_WHATIS)\" \
-DZSOELIM=\"$(pkglibexecdir)/$(TRANS_ZSOELIM)\"
AM_CFLAGS = \
diff --git a/src/man.c b/src/man.c
index ebb97dab4bad..8e3458f86a29 100644
--- a/src/man.c
+++ b/src/man.c
@@ -1065,6 +1065,24 @@ static void add_col (pipeline *p, const char
*locale_charset, ...)
pipeline_command (p, cmd);
}
+/* Return pipecmd invoking the command through roff_maybe. */
+static pipecmd *roff_maybe_argstr (const char *command)
+{
+ const char command_prefix[] = ROFF_MAYBE " ";
+ char *full_command;
+ pipecmd *ret;
+
+ full_command = malloc(strlen(command_prefix) +
+ strlen(command) + 1);
+ sprintf(full_command, "%s%s",
+ command_prefix, command);
+
+ ret = pipecmd_new_argstr(full_command);
+
+ free(full_command);
+ return ret;
+}
+
/* Return pipeline to format file to stdout. */
static pipeline *make_roff_command (const char *dir, const char *file,
pipeline *decomp, const char *dbfilters,
@@ -1297,11 +1315,11 @@ static pipeline *make_roff_command (const char *dir,
const char *file,
case 0:
/* done with preprocessors, now add roff */
if (troff) {
- cmd = pipecmd_new_argstr
+ cmd = roff_maybe_argstr
(get_def ("troff", TROFF));
save_cat = 0;
} else
- cmd = pipecmd_new_argstr
+ cmd = roff_maybe_argstr
(get_def ("nroff", NROFF));
#ifdef TROFF_IS_GROFF
diff --git a/src/roff_maybe b/src/roff_maybe
new file mode 100755
index 000000000000..f12721b062ed
--- /dev/null
+++ b/src/roff_maybe
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# Run nroff (or whatever is passed as "$@"),
+# but only if stdin has (g)roff macros.
+# If it is not, remove macros prepended by GNU tbl.
+#
+# This is to fix any possible alterations roff
+# could introduce, such as inserting additional
+# newlines.
+#
+# Note that it is much slower that a specialized
+# C wrapper (as it also has to run grep and awk).
+#
+# Caveat: stdout would always be terminated with
+# a single newline, no matter how many (if any)
+# were on stdin.
+
+input=$(cat)
+
+no_tbl_input=$(
+ echo "$input" | awk '
+ BEGIN { after_tbl = 0; }
+ ! /^.[il]f / { after_tbl = 1; }
+
+ {
+ if (after_tbl)
+ print;
+ }
+ '
+)
+
+match=$(echo "$no_tbl_input" | grep -i '^[.][a-z]')
+
+if test ! -z "$match" ; then
+ echo "$input" | "$@"
+else
+ echo "$no_tbl_input"
+fi
+
--
2.9.2
Re: [Man-db-devel] [PATCH v3] man(1): Do not roff non-mandoc pages, Mihail Konev, 2016/10/28