scripts/hxtool: fix undefined behavour of echo

Avoid undefined behaviour of echo(1) with backslashes in arguments
The behaviour is implementation-defined, different /bin/sh's behave
differently.

Signed-off-by: Daniel Shahaf <danielsh@apache.org>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Daniel Shahaf 2016-10-16 17:28:18 +03:00 committed by Michael Tokarev
parent e1f3b974f4
commit 5a1de0b325

View File

@ -26,32 +26,32 @@ hxtotexi()
;; ;;
STEXI*) STEXI*)
if test $flag -eq 1 ; then if test $flag -eq 1 ; then
echo "line $line: syntax error: expected ETEXI, found $str" >&2 printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
flag=1 flag=1
;; ;;
ETEXI*) ETEXI*)
if test $flag -ne 1 ; then if test $flag -ne 1 ; then
echo "line $line: syntax error: expected STEXI, found $str" >&2 printf "line %d: syntax error: expected STEXI, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
flag=0 flag=0
;; ;;
SQMP*|EQMP*) SQMP*|EQMP*)
if test $flag -eq 1 ; then if test $flag -eq 1 ; then
echo "line $line: syntax error: expected ETEXI, found $str" >&2 printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
;; ;;
DEFHEADING*) DEFHEADING*)
echo "$(expr "$str" : "DEFHEADING(\(.*\))")" printf '%s\n' "$(expr "$str" : "DEFHEADING(\(.*\))")"
;; ;;
ARCHHEADING*) ARCHHEADING*)
echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")" printf '%s\n' "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
;; ;;
*) *)
test $flag -eq 1 && echo "$str" test $flag -eq 1 && printf '%s\n' "$str"
;; ;;
esac esac
line=$((line+1)) line=$((line+1))
@ -69,26 +69,26 @@ hxtoqmp()
;; ;;
SQMP*) SQMP*)
if test $flag -eq 1 ; then if test $flag -eq 1 ; then
echo "line $line: syntax error: expected EQMP, found $str" >&2 printf "line %d: syntax error: expected EQMP, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
flag=1 flag=1
;; ;;
EQMP*) EQMP*)
if test $flag -ne 1 ; then if test $flag -ne 1 ; then
echo "line $line: syntax error: expected SQMP, found $str" >&2 printf "line %d: syntax error: expected SQMP, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
flag=0 flag=0
;; ;;
STEXI*|ETEXI*) STEXI*|ETEXI*)
if test $flag -eq 1 ; then if test $flag -eq 1 ; then
echo "line $line: syntax error: expected EQMP, found $str" >&2 printf "line %d: syntax error: expected EQMP, found '%s'\n" "$line" "$str" >&2
exit 1 exit 1
fi fi
;; ;;
*) *)
test $flag -eq 1 && echo "$str" test $flag -eq 1 && printf '%s\n' "$str"
;; ;;
esac esac
line=$((line+1)) line=$((line+1))