01-generate-man.sh (3139B)
1 #!/bin/sh 2 3 # Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com) 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 set -e 19 20 . "./config.sh.in" 21 22 ######################################################################## 23 # Helper function 24 ######################################################################## 25 man_pages() 26 { 27 find "${htrdr_dir}/share/man" -type f -name "*.[1-9]" 28 } 29 30 # Man to convert is submitted on stdin 31 man2html() # output_filename 32 { 33 { 34 cd .. 35 sty-genhead "${OLDPWD##*/}/$1" 36 mandoc -O man=../man%S/%N.%S.html,fragment -I os=UNIX -T html 37 cat ./templates/footer.html 38 cd "${OLDPWD}" 39 } \ 40 | sed \ 41 -e 's/"Nm">htrdr-atmosphere/"Nm">htrdr\‑atmosphere/g' \ 42 -e 's/"Nm">htrdr-combustion/"Nm">htrdr\‑combustion/g' \ 43 -e 's/"Nm">htrdr-image/"Nm">htrdr\‑image/g' \ 44 -e 's/"Nm">htrdr-materials/"Nm">htrdr\‑materials/g' \ 45 -e 's/"Nm">htrdr-planets/"Nm">htrdr\‑planets/g' \ 46 -e 's/<a class="Xr"[^>]\{0,\}>csplit(1)<\/a>/<a class "Xr">csplit(1)<\/a>/g' \ 47 -e 's/<a class="Xr"[^>]\{0,\}>gnuplot(1)<\/a>/<a class "Xr">gnuplot(1)<\/a>/g' \ 48 -e 's/<a class="Xr"[^>]\{0,\}>mmap(2)<\/a>/<a class "Xr">mmap(2)<\/a>/g' \ 49 -e 's/<a class="Xr"[^>]\{0,\}>mpirun(1)<\/a>/<a class "Xr">mpirun(1)<\/a>/g' \ 50 -e 's/<a class="Xr"[^>]\{0,\}>ppm(5)<\/a>/<a class "Xr">ppm(5)<\/a>/g' \ 51 -e 's/<a class="Xr"[^>]\{0,\}>sysconf(3)<\/a>/<a class "Xr">sysconf(3)<\/a>/g' \ 52 -e 's/<a class="Xr"[^>]\{0,\}>wordexp(3)<\/a>/<a class "Xr">wordexp(3)<\/a>/g' \ 53 > "$1" 54 } 55 56 ######################################################################## 57 # The script 58 ######################################################################## 59 man_pages | while read -r i; do 60 filename="$(basename "${i}")" 61 section="${filename##*.}" 62 63 if ! [ -d "./man/man${section}" ]; then 64 mkdir -p "./man/man${section}"; 65 fi 66 67 dst="man/man${section}/${filename}.html" 68 man2html "${dst}" < "${i}" 69 70 # Check the result of the HTML conversion. Do this operation from the 71 # parent directory so that tidy displays the file name relative to the 72 # location where the make command is invoked. This makes the message 73 # clearer for the user. 74 cd .. 75 if ! tidy --show-info no --show-filename yes -qe "${OLDPWD##*/}/${dst}"; then 76 >&2 printf '%s: error converting %s\n' "${0##*/}" "${i}" 77 exit 1 78 fi 79 cd "${OLDPWD}" 80 81 # Write the generated files to standard output to inform the build 82 # system which files it needs to handle during installation. 83 printf '%s/%s\n' "${PWD##*/}" "${dst}" 84 done