man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH v5] man(1): Do not roff pages w/o macros


From: Mihail Konev
Subject: [Man-db-devel] [PATCH v5] man(1): Do not roff pages w/o macros
Date: Mon, 31 Oct 2016 05:16:49 +0500

This fixes display of manpages that really are catpages.
---
v5:
  - add license
  - fix awk regexp for no_tbl_input

 configure.ac       |  1 +
 man/replace.sin.in |  1 +
 src/Makefile.am    |  2 ++
 src/man.c          | 22 +++++++++++++++++++--
 src/roff_maybe     | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 81 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..b40bfcab77dc
--- /dev/null
+++ b/src/roff_maybe
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# roff_maybe: Workaround for catpages-installed-as-manpages
+#
+# Copyright (C) 2016 Mihail Konev.
+#
+# This file is part of man-db.
+#
+# man-db is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# man-db is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with man-db; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+# Run nroff (or whatever is passed as "$@"),
+# but only if stdin has troff macros.
+# If it is not, remove troff macros prepended by GNU tbl.
+#
+# This is to fix any possible alterations roff
+# could introduce, such as inserting additional
+# newlines.
+#
+# 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]