]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
command_util: replace dump_xxx() by make_xxx().
authorAndre Noll <maan@systemlinux.org>
Wed, 27 Jun 2012 23:18:23 +0000 (01:18 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 29 Jun 2012 19:36:30 +0000 (21:36 +0200)
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

index a66b56bbdb51940a5aabb50f3e98daeae5d561cd..563ab1a25ebe80e6e7bd837fa5e613d8ba3e880c 100755 (executable)
@@ -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
 }