]> git.tuebingen.mpg.de Git - paraslash.git/blob - command_util.sh
ea952e5b1283589d16bff19717ba39b20964648c
[paraslash.git] / command_util.sh
1 #!/bin/bash
2
3
4 dump_array_member()
5 {
6         echo '{'
7         echo ".name = \"$name_txt\","
8         if test $line_handler -eq 0; then
9                 echo ".handler = com_$name_txt,"
10         else
11                 echo ".line_handler = com_$name_txt,"
12         fi
13         if test -n "$perms_txt"; then
14                 echo ".perms = $perms_txt,"
15         fi
16         echo ".description = \"$desc_txt\","
17         echo ".synopsis = \"$syn_txt\","
18         echo ".help = "
19         echo "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g'
20         echo '},'
21 }
22
23
24 read_one_command()
25 {
26         local line
27
28         name_txt=""
29         desc_txt=""
30         syn_txt=""
31         help_txt=""
32         perms_txt=""
33         line_handler=0
34         mkdir -p man/man1
35         while read key value; do
36                 case "$key" in
37                 ---)
38                         break
39                         ;;
40                 N:)
41                         name_txt="$value"
42                         ;;
43                 P:)
44                         perms_txt="$value"
45                         ;;
46                 D:)
47                         desc_txt="$value"
48                         ;;
49                 L:)
50                         line_handler=1
51                         ;;
52                 S:)
53                         syn_txt="$value"
54                         ;;
55                 H:)
56                         help_txt="${value}"
57                         while read line; do
58                                 if test "$line" = "---"; then
59                                         break;
60                                 fi
61                                 line=${line#H:}
62                                 help_txt="$help_txt
63 ${line# }"
64                         done
65                         break
66                         ;;
67                 esac
68         done
69         if test -n "$name_txt" -a -n "$desc_txt" -a -n "$syn_txt" \
70                         -a -n "$help_txt"; then
71                 ret=1
72                 return
73         fi
74         if test -z "$name_txt" -a -z "$desc_txt" -a -z "$syn_txt" \
75                         -a -z "$help_txt"; then
76                 ret=0
77                 return
78         fi
79         ret=-1
80         return
81         echo "!ERROR!"
82         echo "N: $name_txt"
83         echo "D: $desc_txt"
84         echo "S: $syn_txt"
85         echo "P: $perms_txt"
86         echo "H: $help_txt"
87 }
88
89 dump_man()
90 {
91         echo "NAME"
92         printf "\t$name_txt - $desc_txt\n"
93         echo "SYNOPSIS"
94         printf "\t$syn_txt\n"
95         echo "DESCRIPTION"
96         echo "$help_txt"
97         if test -n "$perms_txt"; then
98                 echo "PERMISSIONS"
99                 if test "$perms_txt" = "0"; then
100                         printf "\t(none)\n"
101                 else
102                         printf "\t$perms_txt\n"
103                 fi
104         fi
105
106 }
107
108
109 com_man()
110 {
111         local cn="$(grep ^codename Makefile.in)"
112         local ver="$(grep ^AC_INIT configure.ac \
113                 | cut -f 2 -d ',')"
114         cn=${cn#*=}
115         ver=${ver# *[}
116         ver=${ver%]}
117         echo "r=paraslash-$ver (cn: $cn)"
118         local n
119         local txtdir=txt
120         local mandir=man/man1
121         local htmldir=html
122         local pfx="$1"
123         mkdir -p $txtdir $mandir $htmldir || exit 1
124         while : ; do
125                 read_one_command
126                 if test $ret -lt 0; then
127                         exit 1
128                 fi
129                 if test $ret -eq 0; then
130                         break
131                 fi
132                 n=$pfx-$name_txt
133                 echo "pfx: $pfx, name: $n"
134                 dump_man > $txtdir/$n.txt
135                 txt2man -t "$n" -r "$r"  < $txtdir/$n.txt \
136                         | sed -e 1d > $mandir/$n.1
137                 man2html $mandir/$n.1 > $htmldir/$n.html
138         done
139 }
140
141 com_array()
142 {
143         while : ; do
144                 read_one_command
145                 if test $ret -lt 0; then
146                         exit 1
147                 fi
148                 if test $ret -eq 0; then
149                         break
150                 fi
151                 dump_array_member
152         done
153 }
154
155 dump_proto()
156 {
157         if test $line_handler -eq 0; then
158                 echo "int com_$name_txt(int, int, char **);"
159         else
160                 echo "int com_$name_txt(int, char *);"
161         fi
162 }
163
164 com_proto()
165 {
166         while : ; do
167                 read_one_command
168                 if test $ret -lt 0; then
169                         exit 1
170                 fi
171                 if test $ret -eq 0; then
172                         break
173                 fi
174                 dump_proto
175         done
176 }
177
178 arg="$1"
179 shift
180 case "$arg" in
181         "array")
182                 com_array
183                 ;;
184         "proto")
185                 com_proto
186                 ;;
187         "man")
188                 com_man $*
189                 ;;
190 esac