X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command_util.sh;h=1530aee7333ea03a1b2748d85d60ce68c2eae2dd;hp=f388b2cfb152db7cf34e0b2f84313ba26a209903;hb=ad386453c0a3153783cb8f506f668118e58d0a32;hpb=eecc102ad0abeb0335fe994bb72031a15b9090d7 diff --git a/command_util.sh b/command_util.sh index f388b2cf..1530aee7 100755 --- a/command_util.sh +++ b/command_util.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash - read_header() { local key value i @@ -10,36 +9,12 @@ read_header() ---) break ;; - HC:) - header_comment="$value" - ;; - CC:) - c_file_comment="$value" - ;; - OF:) - output_file="$value" - array_name=${value%command_list}cmds + BN:) + base_name="$value" ;; SF:) source_files="$value" ;; - AT:) - array_type="$value" - ;; - SI:) - for i in $value; do - system_includes="$system_includes -#include <$i.h>" - done - ;; - IN:) - for i in $value; do - includes="$includes -#include \"$i.h\"" - done - includes="$includes -#include \"$output_file.h\"" - ;; SN:) section_name="$value" ;; @@ -47,11 +22,6 @@ read_header() template_members="$value" esac done - if test -z "$header_comment" -o -z "$c_file_comment" \ - -o -z "$output_file"; then - echo "header error" 1&>2 - exit 1 - fi } read_one_command() @@ -193,58 +163,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,24 +218,32 @@ 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() +com_header() { - echo "/** \file $output_file.c $c_file_comment */" - echo "$system_includes" - echo "$includes" - echo "struct $array_type $array_name[] = {" + local array_members CR=' +' + while : ; do read_one_command if test $ret -lt 0; then @@ -282,19 +253,25 @@ com_c_file() break fi if test $template -eq 0; then - dump_array_member + make_proto + printf "%s" "$result" + make_array_member + array_members="$array_members$result" continue fi - template_loop dump_array_member + template_loop make_proto + printf "%s" "$result" + template_loop make_array_member + array_members="$array_members$result" done - echo '{.name = NULL}};' + array_members="$array_members{.name = NULL} \\$CR" + echo "#define DEFINE_$(tr 'a-z' 'A-Z' <<< "$base_name")_CMD_ARRAY $array_members" } -com_header() +com_completion() { - echo "/** \file $output_file.h $header_comment */" - echo - echo "extern struct $array_type $array_name[];" + + echo "#define $1 \\" while : ; do read_one_command if test $ret -lt 0; then @@ -304,24 +281,27 @@ com_header() break fi if test $template -eq 0; then - dump_proto + make_completion + printf "%s" "$result" continue fi - template_loop dump_proto + template_loop make_completion + printf "%s" "$result" done + echo } read_header arg="$1" shift case "$arg" in - "c") - com_c_file - ;; "h") com_header ;; "man") com_man $* ;; + "compl") + com_completion $* + ;; esac