8 while read key value; do
18 array_name=${value%command_list}cmds
28 system_includes="$system_includes
38 #include \"$output_file.h\""
44 template_members="$value"
47 if test -z "$output_file"; then
48 echo "header error" 1&>2
66 while read key value; do
75 template_name="$value"
79 template_prototype="$value"
94 if test "$line" = "---"; then
105 if test $template -eq 0; then
106 if test -n "$name_txt" -a -n "$desc_txt" -a -n "$usage_txt" \
107 -a -n "$help_txt"; then
112 if test -n "$template_name" -a -n "$template_prototype" \
113 -a -n "$name_txt " -a -n "$template_members" \
114 -a -n "$desc_txt" -a -n "$usage_txt" \
115 -a -n "$help_txt"; then
120 if test -z "$name_txt" -a -z "$desc_txt" -a -z "$usage_txt" \
121 -a -z "$help_txt"; then
133 echo "O: $template_prototype"
138 if test $template -eq 0; then
139 echo ".SS \"$name_txt\""
142 echo "\\fBUsage: \\fP$usage_txt"
144 for member in $template_members; do
145 local sed_cmd="sed -e s/@member@/$member/g"
146 local t_name_txt=$(echo $name_txt | $sed_cmd)
147 echo ".SS \"$t_name_txt\""
149 echo "$desc_txt" | sed -e "s/@member@/{$(echo $template_members | sed -e 's/ / | /g')}/g"
151 echo "\\fBUsage: \\fP"
154 for member in $template_members; do
155 local sed_cmd="sed -e s/@member@/$member/g"
156 local t_usage_txt=$(echo $usage_txt | $sed_cmd)
157 printf "\t$t_usage_txt\n"
162 echo "$help_txt" | sed -e 's/^ //'
164 if test -n "$perms_txt"; then
165 echo -n "\\fBpermissions:\\fP "
166 if test "$perms_txt" = "0"; then
178 echo "[$section_name]"
182 if test $ret -lt 0; then
185 if test $ret -eq 0; then
194 local source_file match="" CR='
196 if test -n "$prototype"; then
197 result="$prototype$CR"
201 for source_file in $source_files; do
202 match=$(grep "^\(__noreturn \)*int com_$name_txt(" $source_file | head -n 1 | sed -e 's/$/;/1')
203 if test -n "$match"; then
204 result="$result$match$CR"
216 result="{.name = \"$name_txt\", .handler = com_$name_txt, "
217 if test -n "$perms_txt"; then
218 result="$result .perms = $perms_txt,"
220 result="$result.description = \"$desc_txt\", .usage = \"$usage_txt\", \\$CR .help = "
221 tmp="$(printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g' \
222 -e "s/$TAB/\\\t/g" -e's/$/\\/g')"
223 result="$result$tmp$CR}, \\$CR"
230 result=" {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\$CR"
237 local t_name="$name_txt"
238 local t_perms="$perms_txt"
239 local t_desc="$desc_txt"
240 local t_usage="$usage_txt"
241 local t_help="$help_txt"
242 local t_source_files="$source_files"
244 for member in $template_members; do
245 local sed_cmd="sed -e s/@member@/$member/g"
246 #echo "sed_cmd: $sed_cmd"
247 name_txt=$(echo "$t_name" | $sed_cmd)
249 perms_txt=$(echo "$t_perms" | $sed_cmd)
250 desc_txt=$(echo "$t_desc" | $sed_cmd)
251 usage_txt=$(echo "$t_usage" | $sed_cmd)
252 help_txt=$(printf "%s\n" "$t_help" | $sed_cmd)
253 prototype=$(echo "$template_prototype" | $sed_cmd)
256 loop_result="$loop_result$result"
258 result="$loop_result"
259 # reset global variables
265 source_files="$t_source_files"
270 echo "$system_includes"
272 echo "struct $array_type $array_name[] = {"
275 if test $ret -lt 0; then
278 if test $ret -eq 0; then
281 if test $template -eq 0; then
283 printf "%s" "$result"
286 template_loop make_array_member
287 printf "%s" "$result"
289 echo '{.name = NULL}};'
294 local array_members CR='
297 echo "extern struct $array_type $array_name[];"
300 if test $ret -lt 0; then
303 if test $ret -eq 0; then
306 if test $template -eq 0; then
308 printf "%s" "$result"
310 array_members="$array_members$result"
313 template_loop make_proto
314 printf "%s" "$result"
315 template_loop make_array_member
316 array_members="$array_members$result"
318 array_members="$array_members{.name = NULL} \\$CR"
319 echo "#define DEFINE_$(tr 'a-z' 'A-Z' <<< "$base_name")_CMD_ARRAY $array_members"
328 if test $ret -lt 0; then
331 if test $ret -eq 0; then
334 if test $template -eq 0; then
336 printf "%s" "$result"
339 template_loop make_completion
340 printf "%s" "$result"