X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command_util.sh;h=abae4ec2b74c84e925c0297900c01c3dfb3c553a;hp=f388b2cfb152db7cf34e0b2f84313ba26a209903;hb=c9df5dfaa915915e0717c1992bc8498f6432dba8;hpb=ec354cf583bc2838ecfac64c428d3f992681c5fc diff --git a/command_util.sh b/command_util.sh index f388b2cf..abae4ec2 100755 --- a/command_util.sh +++ b/command_util.sh @@ -10,11 +10,8 @@ read_header() ---) break ;; - HC:) - header_comment="$value" - ;; - CC:) - c_file_comment="$value" + BN:) + base_name="$value" ;; OF:) output_file="$value" @@ -47,8 +44,7 @@ read_header() 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 @@ -193,58 +189,51 @@ com_man() 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=' ' CR=' +' + 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\", \\$CR .help = " + tmp="$(printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g' \ + -e "s/$TAB/\\\t/g" -e's/$/\\/g')" + result="$result$tmp$CR}, \\$CR" } +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" @@ -255,21 +244,29 @@ template_loop() 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) + result= $1 + loop_result="$loop_result$result" done - + result="$loop_result" + # reset global variables + name_txt="$t_name" + perms_txt="$t_perms" + desc_txt="$t_desc" + usage_txt="$t_usage" + help_txt="$t_help" + source_files="$t_source_files" } com_c_file() { - echo "/** \file $output_file.c $c_file_comment */" echo "$system_includes" echo "$includes" echo "struct $array_type $array_name[] = {" @@ -282,18 +279,21 @@ com_c_file() 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 + local array_members CR=' +' + echo "extern struct $array_type $array_name[];" while : ; do read_one_command @@ -304,11 +304,42 @@ com_header() break fi if test $template -eq 0; then - dump_proto + make_proto + printf "%s" "$result" + make_array_member + array_members="$array_members$result" continue fi - template_loop dump_proto + template_loop make_proto + printf "%s" "$result" + template_loop make_array_member + array_members="$array_members$result" done + array_members="$array_members{.name = NULL} \\$CR" + echo "#define DEFINE_$(tr 'a-z' 'A-Z' <<< "$base_name")_CMD_ARRAY $array_members" +} + +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 @@ -324,4 +355,7 @@ case "$arg" in "man") com_man $* ;; + "compl") + com_completion $* + ;; esac