hxtool: Add syntax error detection

Add basic imbalance detection for STEXT/ETEXI.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Jan Kiszka 2010-05-20 09:16:33 +02:00 committed by Blue Swirl
parent 3c4c32101b
commit 6c913ba5f3
1 changed files with 15 additions and 1 deletions

16
hxtool
View File

@ -19,11 +19,24 @@ hxtoh()
hxtotexi() hxtotexi()
{ {
flag=0 flag=0
line=1
while read -r str; do while read -r str; do
case "$str" in case "$str" in
HXCOMM*) HXCOMM*)
;; ;;
STEXI*|ETEXI*) flag=$(($flag^1)) STEXI*)
if test $flag -eq 1 ; then
echo "line $line: syntax error: expected ETEXI, found $str" >&2
exit 1
fi
flag=1
;;
ETEXI*)
if test $flag -ne 1 ; then
echo "line $line: syntax error: expected STEXI, found $str" >&2
exit 1
fi
flag=0
;; ;;
DEFHEADING*) DEFHEADING*)
echo "$(expr "$str" : "DEFHEADING(\(.*\))")" echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
@ -32,6 +45,7 @@ hxtotexi()
test $flag -eq 1 && echo "$str" test $flag -eq 1 && echo "$str"
;; ;;
esac esac
line=$((line+1))
done done
} }