3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2020 Gavin D. Howard and contributors.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
31 printf "usage: %s manpage\n" "$0" 1>&2
37 _print_manpage_md="$1"
40 _print_manpage_out="$1"
43 cat "$manualsdir/header.txt" > "$_print_manpage_out"
44 cat "$manualsdir/header_${manpage}.txt" >> "$_print_manpage_out"
46 pandoc -f markdown -t man "$_print_manpage_md" >> "$_print_manpage_out"
52 _gen_manpage_args="$1"
55 _gen_manpage_status="$ALL"
56 _gen_manpage_out="$manualsdir/$manpage/$_gen_manpage_args.1"
57 _gen_manpage_md="$manualsdir/$manpage/$_gen_manpage_args.1.md"
58 _gen_manpage_temp="$manualsdir/temp.1.md"
59 _gen_manpage_ifs="$IFS"
61 rm -rf "$_gen_manpage_out" "$_gen_manpage_md"
63 while IFS= read -r line; do
65 if [ "$line" = "{{ end }}" ]; then
67 if [ "$_gen_manpage_status" -eq "$ALL" ]; then
68 err_exit "{{ end }} tag without corresponding start tag" 2
71 _gen_manpage_status="$ALL"
73 elif [ "${line#\{\{* $_gen_manpage_args *\}\}}" != "$line" ]; then
75 if [ "$_gen_manpage_status" -ne "$ALL" ]; then
76 err_exit "start tag nested in start tag" 3
79 _gen_manpage_status="$NOSKIP"
81 elif [ "${line#\{\{*\}\}}" != "$line" ]; then
83 if [ "$_gen_manpage_status" -ne "$ALL" ]; then
84 err_exit "start tag nested in start tag" 3
87 _gen_manpage_status="$SKIP"
90 if [ "$_gen_manpage_status" -ne "$SKIP" ]; then
91 printf '%s\n' "$line" >> "$_gen_manpage_temp"
95 done < "$manualsdir/${manpage}.1.md.in"
97 uniq "$_gen_manpage_temp" "$_gen_manpage_md"
98 rm -rf "$_gen_manpage_temp"
100 IFS="$_gen_manpage_ifs"
102 print_manpage "$_gen_manpage_md" "$_gen_manpage_out"
108 scriptdir=$(dirname "$script")
109 manualsdir="$scriptdir/manuals"
111 . "$scriptdir/functions.sh"
113 ARGS="A E H N P EH EN EP HN HP NP EHN EHP ENP HNP EHNP"
118 test "$#" -eq 1 || usage
123 if [ "$manpage" != "bcl" ]; then
130 print_manpage "$manualsdir/${manpage}.3.md" "$manualsdir/${manpage}.3"