X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command_util.sh;h=e33e0769d9cbc2230bf02b70813d5435f2447430;hp=f388b2cfb152db7cf34e0b2f84313ba26a209903;hb=1526296ab4088bba659787e83553a605cbda09bd;hpb=684ea7f70948c9ce5077a8a6460946ff86fefe46 diff --git a/command_util.sh b/command_util.sh index f388b2cf..e33e0769 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() @@ -66,7 +36,6 @@ read_one_command() template=0 template_name="" template_prototype="" - mkdir -p man/man1 while read key value; do case "$key" in ---) @@ -193,58 +162,53 @@ 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 regex='\(__noreturn \)*\(static \)*int com_' + local source_file match="" all_commands CR=' +' if test -n "$prototype"; then - echo "$prototype" - echo + result="$prototype$CR" return fi + all_commands="$(cat $source_files | grep "$regex")" + result= for source_file in $source_files; do - match=$(grep "^\(__noreturn \)*int com_$name_txt(" $source_file | head -n 1 | sed -e 's/$/;/1') + match=$(grep "$regex$name_txt(" <<< "$all_commands" | 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" @@ -253,26 +217,31 @@ template_loop() local t_source_files="$source_files" local member 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="$tname" - 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) + name_txt="${t_name//@member@/$member}" + perms_txt="${t_perms//@member@/$member}" + desc_txt="${t_desc//@member@/$member}" + usage_txt="${t_usage//@member@/$member}" + help_txt="${t_help//@member@/$member}" + prototype="${template_prototype//@member@/$member}" + 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 +251,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 +279,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