meso-web

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

01-generate-man.sh (3194B)


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