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