meso-web

Sources of the |Méso|Star> website
git clone git://git.meso-star.com/meso-web.git
Log | Files | Refs | README | LICENSE

01-generate-man.sh (3166B)


      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 set -e
     21 
     22 . "./config.sh.in"
     23 
     24 ########################################################################
     25 # Helper function
     26 ########################################################################
     27 man_pages()
     28 {
     29   find "${htrdr_dir}/share/man" -type f -name "*.[1-9]"
     30 }
     31 
     32 # Man to convert is submitted on stdin
     33 man2html() # output_filename
     34 {
     35   {
     36     cd ..
     37     sty-genhead "${OLDPWD##*/}/$1"
     38     mandoc -O man=../man%S/%N.%S.html,fragment -I os=UNIX -T html
     39     cat ./templates/footer.html
     40     cd "${OLDPWD}"
     41   } \
     42   | sed \
     43     -e 's/"Nm">htrdr-atmosphere/"Nm">htrdr\&#8209;atmosphere/g' \
     44     -e 's/"Nm">htrdr-combustion/"Nm">htrdr\&#8209;combustion/g' \
     45     -e 's/"Nm">htrdr-image/"Nm">htrdr\&#8209;image/g' \
     46     -e 's/"Nm">htrdr-materials/"Nm">htrdr\&#8209;materials/g' \
     47     -e 's/"Nm">htrdr-planets/"Nm">htrdr\&#8209;planets/g' \
     48     -e 's/<a class="Xr"[^>]\{0,\}>csplit(1)<\/a>/<a class "Xr">csplit(1)<\/a>/g' \
     49     -e 's/<a class="Xr"[^>]\{0,\}>gnuplot(1)<\/a>/<a class "Xr">gnuplot(1)<\/a>/g' \
     50     -e 's/<a class="Xr"[^>]\{0,\}>mmap(2)<\/a>/<a class "Xr">mmap(2)<\/a>/g' \
     51     -e 's/<a class="Xr"[^>]\{0,\}>mpirun(1)<\/a>/<a class "Xr">mpirun(1)<\/a>/g' \
     52     -e 's/<a class="Xr"[^>]\{0,\}>ppm(5)<\/a>/<a class "Xr">ppm(5)<\/a>/g' \
     53     -e 's/<a class="Xr"[^>]\{0,\}>sysconf(3)<\/a>/<a class "Xr">sysconf(3)<\/a>/g' \
     54     -e 's/<a class="Xr"[^>]\{0,\}>wordexp(3)<\/a>/<a class "Xr">wordexp(3)<\/a>/g' \
     55   > "$1"
     56 }
     57 
     58 ########################################################################
     59 # The script
     60 ########################################################################
     61 man_pages | while read -r i; do
     62   filename="$(basename "${i}")"
     63   section="${filename##*.}"
     64 
     65   if ! [ -d "./man/man${section}" ]; then
     66     mkdir -p "./man/man${section}";
     67   fi
     68 
     69   dst="man/man${section}/${filename}.html"
     70   man2html "${dst}" < "${i}"
     71 
     72   # Check the result of the HTML conversion. Do this operation from the
     73   # parent directory so that tidy displays the file name relative to the
     74   # location where the make command is invoked. This makes the message
     75   # clearer for the user.
     76   cd ..
     77   if ! tidy --show-info no --show-filename yes -qe "${OLDPWD##*/}/${dst}"; then
     78     >&2 printf '%s: error converting %s\n' "${0##*/}" "${i}"
     79     exit 1
     80   fi
     81   cd "${OLDPWD}"
     82 
     83   # Write the generated files to standard output to inform the build
     84   # system which files it needs to handle during installation.
     85   printf '%s/%s\n' "${PWD##*/}" "${dst}"
     86 done