Debian Codegraph @

mitm/m4man

raw
1 #!/usr/bin/env bash
2 # generate a man page or html man page from m4 source
3 function usage()
4 {
5 echo >&2 "usage: $0 -t html|man -p product -n name [-o outfile] [-v version.txt] [-w] source"
6 exit 1
7 }
8
9 unset windows
10 version_txt=./version.txt
11
12 while [ $# -gt 0 ]
13 do case $1 in
14 -t)
15 shift
16 case $1 in
17 html|man)
18 type=$1
19 shift
20 ;;
21 *)
22 usage
23 esac
24 ;;
25 -p)
26 shift
27 product=$1
28 shift
29 ;;
30 -n)
31 shift
32 name=$1
33 shift
34 ;;
35 -o)
36 shift
37 outfile=$1
38 shift
39 ;;
40 -v)
41 shift
42 version_txt=$1
43 shift
44 ;;
45 -w)
46 shift
47 platform=windows
48 ;;
49 -*)
50 usage
51 ;;
52 *)
53 if [ -n "$source" ]
54 then usage
55 fi
56 source=$1
57 shift
58 esac
59 done
60 if [ -z "$type" -o -z "$product" -o -z "$name" -o -z "$source" ]
61 then usage
62 fi
63
64 . $version_txt
65 date=`date "+%d %B %Y"`
66 # platform
67 if [ x"$platform" != xwindows ]
68 then case $product in
69 w*)
70 platform=windows
71 ;;
72 *)
73 platform=unix
74 esac
75 fi
76 if [ $platform = unix ]
77 then
78 c3270=c3270
79 s3270=s3270
80 pr3287=pr3287
81 x3270=x3270
82 b3270=b3270
83 else
84 c3270=wc3270
85 s3270=ws3270
86 pr3287=wpr3287
87 x3270=wc3270
88 b3270=wb3270
89 fi
90 # mode
91 case $product in
92 c3270|wc3270)
93 mode=console
94 ;;
95 s3270|ws3270|b3270)
96 mode=script
97 ;;
98 *)
99 mode=$product
100 ;;
101 esac
102 # interactive
103 case $product in
104 x3270|c3270|wc3270)
105 interactive=yes
106 ;;
107 *)
108 interactive=no
109 ;;
110 esac
111
112 # set up output file, and make sure it will be deleted
113 if [ -n "$outfile" ]
114 then tf=/tmp/m4man$$
115 rm -f $tf
116 trap "rm -f $tf" exit
117 trap "exit" INT QUIT HUP TERM
118 fi
119
120 /usr/bin/m4 -DXX_PRODUCT=$product -DXX_PAGENAME=$name \
121 -DXX_PLATFORM=$platform -DXX_MODE=$mode -DXX_INTERACTIVE=$interactive \
122 -DXX_C3270=$c3270 -DXX_S3270=$s3270 -DXX_PR3287=$pr3287 -DXX_X3270=$x3270 \
123 -DXX_B3270=$b3270 -DXX_DATE="$date" -DXX_VERSION_NUMBER=$version \
124 -DXX_CYEAR=$cyear $type.m4 $source |
125 if [ -n "$outfile" ]
126 then cat >$tf
127 else cat
128 fi
129 rc=$?
130
131 if [ -n "$outfile" -a $rc -eq 0 ]
132 then mv $tf $outfile
133 rc=$?
134 fi
135
136 exit $rc