commit a16cd1428e351c7bd1468e49ee65e860796a7959
parent b9143afb333ff62611a6ebe20661a64fb29bde1b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 22 Aug 2025 17:17:25 +0200
Solstice: add a hook to convert its manp to HTML
The convert_man.sh script is rewritten according to the new build
procedure.
Diffstat:
2 files changed, 103 insertions(+), 67 deletions(-)
diff --git a/convert_man.sh b/convert_man.sh
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh
# Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com)
#
@@ -15,69 +15,36 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. meso-menu.sh
-
-if [ $# -lt 4 ]; then
- echo "Usage: $0 <section> <input> <output> <version>" >&2
- exit 1
-fi
-
-section="$1"
-input="$2"
-output="$3"
-version="$4"
-
-man_name=${input##*/}
-man_name=${man_name%.*}
-man_section=$(echo "${input}" \
- | sed 's/.*man\([[:digit:]]\{1\}[[:alpha:]]\{0,1\}\)\/.*/\1/g')
-
-{
- print_header -s "${section}" -n "${man_name}" -r ../../../
- echo "<header>"
- echo " <h1>${man_name}(${man_section})</h1>";
- echo "</header>"
-
- # First, we fix the input man to avoid unexpected html conversions. For
- # example, the .P macros are not handled by man2html and the .PP macro followed
- # by a .RE macro is badly converted while the reverse works, i.e. the .RE macro
- # followed by the .PP macro.
- #
- # After html conversion, the output file is modified to remove its header and
- # its footer (that are replaced by ours), and to fix some html patterns that
- # are not correctly handled by tidy (see below)
- sed 's/^\.P$/.PP/' "${input}" \
- | sed '/^\.PP$/{$!{N;s/\.PP\n\.RE/.RE\n.PP/;t sub;P;D;:sub}}' \
- | man2html -r \
- | tail -n +10 \
- | sed '/^<HR>$/,$d' \
- | sed 's/\(\ \)\{1,\}/\ /g' \
- | sed 's/^<A NAME="[[:alpha:]]\{0,\}">\ <\/A>//g' \
- | sed 's/<TT>//g' \
- | sed 's/<\/TT>//g' \
- | sed 's/<DL COMPACT>/<DL>/g' \
- | sed '/^<PRE>$/{$!{N;s/<PRE>\n<DL><DT><DD>/<DL><DT><DD><PRE>/;t sub;P;D;:sub}}'
- print_footer
-} > "${output}"
-
-# Remove hyperlink on csplit, feh, gnuplot, sed, mmap and mpirun commands
-# Fix the hyperlink toward the GPLv3+ license
-# Remove unexpected link on sqrt(2)
-# Fix the man2html issues that translates the ' char in cq
-tmp=$(mktemp)
-chmod 644 "${tmp}"
-sed\
- -e 's/<B><A HREF="\.\.\/man1\/csplit\.1\.html">csplit<\/A><\/B>/csplit/g'\
- -e 's/<B><A HREF="\.\.\/man1\/feh\.1\.html">feh<\/A><\/B>/feh/g'\
- -e 's/<B><A HREF="\.\.\/man1\/gnuplot\.1\.html">gnuplot<\/A><\/B>/gnuplot/g'\
- -e 's/<B><A HREF="\.\.\/man1\/sed\.1\.html">sed<\/A><\/B>/sed/g'\
- -e 's/<B><A HREF="\.\.\/man1\/mpirun\.1\.html">mpirun<\/A><\/B>/mpirun/g'\
- -e 's/<B><A HREF="\.\.\/man2\/mmap\.2\.html">mmap<\/A><\/B>/mmap/g'\
- -e 's/gpl\.html\.">\(.*\).<\/A>/gpl.html">\1<\/A>./g'\
- -e 's/<A HREF="\.\.\/man2\/sqrt\.2\.html">sqrt<\/A>/sqrt/g'\
- -e "s/cq\([a-z]\)\>/'\1/g" "${output}" > "${tmp}"
-
-mv "${tmp}" "${output}"
-
-# Clean the html file generated by man2html and lint it if necessary
-tidy --show-info no -m "${output}" > /dev/null 2>&1 || sh lint_html.sh "${output}"
+# The following line can be translated as follows:
+# - Convert the nroff file submitted on stdin to HTML
+# - Remove the page header
+# - Remove the footer
+# - Remove invalid links (they are used as section tags)
+# - Replace multiple non-breaking spaces with a single one
+# - Remove the opening HTML tag tt, which is no longer supported
+# - Remove the closing HTML tag tt, which is no longer supported
+# - Remove the compact attribute from the HTML tag dl, which is no
+# longer supported
+# - Remove links on csplit, feh, gnuplot, sed, mmap, and mpirun
+# - Correct the link to the GPLv3+ license
+# - Remove the unexpected link on sqrt(2)
+# - Fix man2html issues that translate the ' character to cq
+# - Use tidy to further clean up the HTML code
+ man2html -r \
+| tail -n +10 \
+| sed '/^<HR>$/,$d' \
+| sed 's/\(\ \)\{1,\}/\ /g' \
+| sed 's/^<A NAME="[[:alpha:]]\{0,\}">\ <\/A>//g' \
+| sed 's/<TT>//g' \
+| sed 's/<\/TT>//g' \
+| sed 's/<DL COMPACT>/<DL>/g' \
+| sed -e 's/<B><A HREF="\.\.\/man1\/csplit\.1\.html">csplit<\/A><\/B>/csplit/g' \
+ -e 's/<B><A HREF="\.\.\/man1\/feh\.1\.html">feh<\/A><\/B>/feh/g' \
+ -e 's/<B><A HREF="\.\.\/man1\/gnuplot\.1\.html">gnuplot<\/A><\/B>/gnuplot/g' \
+ -e 's/<B><A HREF="\.\.\/man1\/sed\.1\.html">sed<\/A><\/B>/sed/g' \
+ -e 's/<B><A HREF="\.\.\/man1\/mpirun\.1\.html">mpirun<\/A><\/B>/mpirun/g' \
+ -e 's/<B><A HREF="\.\.\/man2\/mmap\.2\.html">mmap<\/A><\/B>/mmap/g' \
+ -e 's/gpl\.html\.">\(.*\).<\/A>/gpl.html">\1<\/A>./g' \
+ -e 's/<A HREF="\.\.\/man2\/sqrt\.2\.html">sqrt<\/A>/sqrt/g' \
+ -e "s/cq\([a-z]\)\>/'\1/g" \
+| tidy --show-info no -m --show-body-only yes 2>/dev/null || true
diff --git a/solstice/hooks/01-generate-man.sh b/solstice/hooks/01-generate-man.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com)
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+. "./config.in"
+
+########################################################################
+# Helper function
+########################################################################
+man_pages()
+{
+ find "${directory}/share/man" -name "*.[1-9]"
+}
+
+# Man to convert is submitted on stdin
+man2html() # output_filename
+{
+ {
+ cd ..
+ sh ./generate_header.sh "${OLDPWD##*/}/$1"
+ sh ./convert_man.sh
+ cat ./footer.html
+ cd "${OLDPWD}"
+ } > "$1"
+}
+
+########################################################################
+# The script
+########################################################################
+if [ "$1" = "targets" ]; then
+ targets
+ exit 0
+fi
+
+man_pages | while read -r i; do
+ filename="$(basename "${i}")"
+ prefix="${filename%.*}"
+ section="${filename##*.}"
+
+ if ! [ -d "./man/man${section}" ]; then
+ mkdir -p "./man/man${section}";
+ fi
+
+ dst="man/man${section}/${filename}.html"
+ man2html "${dst}" < "${i}"
+
+ # Check the result of the HTML conversion
+ if ! tidy --show-info no --show-filename yes -qe "${dst}"; then
+ >2 printf '%s: error converting %s\n' "${0##*/}" "${i}"
+ exit 1
+ fi
+
+ printf '%s/%s\n' "${PWD##*/}" "${dst}"
+done