From a5158610b0a44f7b0d26c603dc1063dec15d5eb5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 28 Jun 2012 01:18:23 +0200 Subject: [PATCH] command_util: replace dump_xxx() by make_xxx(). This replace dump_array_member(), dump_completion() and dump_proto() by their make_xxx counterpart. This allows to iterate over all commands twice. --- command_util.sh | 67 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/command_util.sh b/command_util.sh index a66b56bb..563ab1a2 100755 --- a/command_util.sh +++ b/command_util.sh @@ -186,52 +186,50 @@ com_man() done } -dump_proto() +make_proto() { - local source_file match="" - - echo '/**' - echo " * $desc_txt" - 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() { local TAB=' ' - echo '{' - echo ".name = \"$name_txt\"," - echo ".handler = com_$name_txt," + 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' \ - -e "s/$TAB/\\\t/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 }," } -dump_completion() +make_completion() { - echo " {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\" + result=" {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\" } template_loop() @@ -253,7 +251,9 @@ 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 + echo "$result" done } @@ -272,10 +272,11 @@ com_c_file() break fi if test $template -eq 0; then - dump_array_member + make_array_member + echo "$result" continue fi - template_loop dump_array_member + template_loop make_array_member done echo '{.name = NULL}};' } @@ -292,10 +293,11 @@ com_header() break fi if test $template -eq 0; then - dump_proto + make_proto + echo "$result" continue fi - template_loop dump_proto + template_loop make_proto done } @@ -312,10 +314,11 @@ com_completion() break fi if test $template -eq 0; then - dump_completion + make_completion + echo "$result" continue fi - template_loop dump_completion + template_loop make_completion done echo } -- 2.39.5