]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - command_util.sh
command_util: Output array members with backslashes.
[paraslash.git] / command_util.sh
index a66b56bbdb51940a5aabb50f3e98daeae5d561cd..875b5e6957f7509a15352cdfc6a9c7239402a448 100755 (executable)
@@ -186,56 +186,51 @@ 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 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' \
-               -e "s/$TAB/\\\t/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"
 }
 
-dump_completion()
+make_completion()
 {
-       echo "  {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\"
+       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"
@@ -254,8 +249,9 @@ template_loop()
                help_txt=$(printf "%s\n" "$t_help" | $sed_cmd)
                prototype=$(echo "$template_prototype" | $sed_cmd)
                $1
+               loop_result="$loop_result$result"
        done
-
+       result="$loop_result"
 }
 
 com_c_file()
@@ -272,10 +268,12 @@ com_c_file()
                        break
                fi
                if test $template -eq 0; then
-                       dump_array_member
+                       make_array_member
+                       printf "%s" "$result"
                        continue
                fi
-               template_loop dump_array_member
+               template_loop make_array_member
+               printf "%s" "$result"
        done
        echo '{.name = NULL}};'
 }
@@ -292,10 +290,12 @@ com_header()
                        break
                fi
                if test $template -eq 0; then
-                       dump_proto
+                       make_proto
+                       printf "%s" "$result"
                        continue
                fi
-               template_loop dump_proto
+               template_loop make_proto
+               printf "%s" "$result"
        done
 }
 
@@ -312,10 +312,12 @@ com_completion()
                        break
                fi
                if test $template -eq 0; then
-                       dump_completion
+                       make_completion
+                       printf "%s" "$result"
                        continue
                fi
-               template_loop dump_completion
+               template_loop make_completion
+               printf "%s" "$result"
        done
        echo
 }