X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command_util.sh;h=1530aee7333ea03a1b2748d85d60ce68c2eae2dd;hp=b3b8804c28f4bce50398ebdde5d4c32809a05bc4;hb=ad386453c0a3153783cb8f506f668118e58d0a32;hpb=3792a24ac9bb2ee3ea1505c18b3b9ff27db47287 diff --git a/command_util.sh b/command_util.sh index b3b8804c..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,30 +9,12 @@ read_header() ---) break ;; - 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" ;; @@ -41,10 +22,6 @@ read_header() template_members="$value" esac done - if test -z "$output_file"; then - echo "header error" 1&>2 - exit 1 - fi } read_one_command() @@ -206,24 +183,18 @@ make_proto() make_array_member() { - local TAB=' ' + local TAB=' ' CR=' +' local tmp - result=" - { - .name = \"$name_txt\", - .handler = com_$name_txt, - " + result="{.name = \"$name_txt\", .handler = com_$name_txt, " if test -n "$perms_txt"; then result="$result .perms = $perms_txt," fi - result="$result - .description = \"$desc_txt\", - .usage = \"$usage_txt\", - .help = " + 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")" - result="$result $tmp }," + -e "s/$TAB/\\\t/g" -e's/$/\\/g')" + result="$result$tmp$CR}, \\$CR" } make_completion() @@ -254,39 +225,25 @@ template_loop() 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" -} - -com_c_file() -{ - echo "$system_includes" - echo "$includes" - echo "struct $array_type $array_name[] = {" - 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_array_member - printf "%s" "$result" - continue - fi - template_loop make_array_member - printf "%s" "$result" - done - echo '{.name = NULL}};' + # 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_header() { - echo "extern struct $array_type $array_name[];" + local array_members CR=' +' + while : ; do read_one_command if test $ret -lt 0; then @@ -298,11 +255,17 @@ com_header() if test $template -eq 0; then make_proto printf "%s" "$result" + make_array_member + array_members="$array_members$result" continue fi 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() @@ -332,9 +295,6 @@ read_header arg="$1" shift case "$arg" in - "c") - com_c_file - ;; "h") com_header ;;