---)
break
;;
- HC:)
- header_comment="$value"
- ;;
- CC:)
- c_file_comment="$value"
- ;;
OF:)
output_file="$value"
array_name=${value%command_list}cmds
template_members="$value"
esac
done
- if test -z "$header_comment" -o -z "$c_file_comment" \
- -o -z "$output_file"; then
+ if test -z "$output_file"; then
echo "header error" 1&>2
exit 1
fi
done
}
-dump_proto()
+make_proto()
{
- local source_file match=""
-
- echo '/**'
- echo " * $desc_txt"
- echo ' *'
- if [[ "$system_includes" =~ openssl/rc4.h ]]; then
- echo ' * \param rc4c The rc4 crypt context.'
- else
- echo ' * \param fd The file descriptor to send output to.'
- fi
- echo ' * \param argc The number of arguments.'
- echo ' * \param argv The argument vector.'
- echo ' * '
- echo " * Usage: $usage_txt"
- echo ' * '
- echo "$help_txt" | sed -e 's/^/ * /g'
- echo ' */'
+ local source_file match="" CR='
+'
if test -n "$prototype"; then
- echo "$prototype"
- echo
+ result="$prototype$CR"
return
fi
+ result=
for source_file in $source_files; do
match=$(grep "^\(__noreturn \)*int com_$name_txt(" $source_file | head -n 1 | sed -e 's/$/;/1')
if test -n "$match"; then
- echo "$match"
+ result="$result$match$CR"
break
fi
done
- echo
}
-dump_array_member()
+make_array_member()
{
- echo '{'
- echo ".name = \"$name_txt\","
- echo ".handler = com_$name_txt,"
+ local TAB=' '
+ local tmp
+
+ result="
+ {
+ .name = \"$name_txt\",
+ .handler = com_$name_txt,
+ "
if test -n "$perms_txt"; then
- echo ".perms = $perms_txt,"
+ result="$result .perms = $perms_txt,"
fi
- echo ".description = \"$desc_txt\","
- echo ".usage = \"$usage_txt\","
- echo ".help = "
- printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g'
- echo '},'
+ result="$result
+ .description = \"$desc_txt\",
+ .usage = \"$usage_txt\",
+ .help = "
+ tmp="$(printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g' \
+ -e "s/$TAB/\\\t/g")"
+ result="$result $tmp },"
}
+make_completion()
+{
+ local CR='
+'
+ result=" {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\$CR"
+}
template_loop()
{
+ local loop_result=
+
local t_name="$name_txt"
local t_perms="$perms_txt"
local t_desc="$desc_txt"
for member in $template_members; do
local sed_cmd="sed -e s/@member@/$member/g"
#echo "sed_cmd: $sed_cmd"
- name_txt=$(echo $t_name | $sed_cmd)
+ name_txt=$(echo "$t_name" | $sed_cmd)
#name_txt="$tname"
- perms_txt=$(echo $t_perms | $sed_cmd)
- desc_txt=$(echo $t_desc | $sed_cmd)
- usage_txt=$(echo $t_usage | $sed_cmd)
+ perms_txt=$(echo "$t_perms" | $sed_cmd)
+ desc_txt=$(echo "$t_desc" | $sed_cmd)
+ usage_txt=$(echo "$t_usage" | $sed_cmd)
help_txt=$(printf "%s\n" "$t_help" | $sed_cmd)
prototype=$(echo "$template_prototype" | $sed_cmd)
$1
+ loop_result="$loop_result$result"
done
-
+ result="$loop_result"
}
com_c_file()
{
- echo "/** \file $output_file.c $c_file_comment */"
echo "$system_includes"
echo "$includes"
echo "struct $array_type $array_name[] = {"
break
fi
if test $template -eq 0; then
- dump_array_member
+ make_array_member
+ printf "%s" "$result"
continue
fi
- template_loop dump_array_member
+ template_loop make_array_member
+ printf "%s" "$result"
done
echo '{.name = NULL}};'
}
com_header()
{
- echo "/** \file $output_file.h $header_comment */"
- echo
echo "extern struct $array_type $array_name[];"
while : ; do
read_one_command
break
fi
if test $template -eq 0; then
- dump_proto
+ make_proto
+ printf "%s" "$result"
continue
fi
- template_loop dump_proto
+ template_loop make_proto
+ printf "%s" "$result"
done
}
+com_completion()
+{
+
+ echo "#define $1 \\"
+ while : ; do
+ read_one_command
+ if test $ret -lt 0; then
+ exit 1
+ fi
+ if test $ret -eq 0; then
+ break
+ fi
+ if test $template -eq 0; then
+ make_completion
+ printf "%s" "$result"
+ continue
+ fi
+ template_loop make_completion
+ printf "%s" "$result"
+ done
+ echo
+}
+
read_header
arg="$1"
shift
"man")
com_man $*
;;
+ "compl")
+ com_completion $*
+ ;;
esac