Skip to contentSkip to conversation

hxtool: Add syntax error detection

PATCH Applied Jan Kiszka 2 participants 2 messages May 20, 2010 – May 22, 2010 1 message not in the archive

lore
Share & tools
lore

Jan Kiszka

author
#1 lore raw

PATCH 2/2 hxtool: Add syntax error detection

In reply to a message not in the archive

From: Jan Kiszka <[email protected]>

Add basic imbalance detection for STEXT/ETEXI.

---
 hxtool |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
hxtool +15 -1
index 0fdbc64..8f65532 100644
@@ -19,11 +19,24 @@ hxtoh()
 hxtotexi()
 {
     flag=0
+    line=1
     while read -r str; do
         case "$str" in
             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*)
             echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
@@ -32,6 +45,7 @@ hxtotexi()
             test $flag -eq 1 && echo "$str"
             ;;
         esac
+        line=$((line+1))
     done
 }
 
Signature · 1 line
1.6.0.2
Applied
#2 lore raw

Thanks, applied.

Quoted 51 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Add basic imbalance detection for STEXT/ETEXI.

---
 hxtool |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
hxtool +0 -0
index 0fdbc64..8f65532 100644
@@ -19,11 +19,24 @@ hxtoh()
  hxtotexi()
  {

    flag=0
+    line=1
    while read -r str; do
        case "$str" in
            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*)
            echo "$(expr "$str" : "DEFHEADING(\(.*\))")"

hxtool +0 -0
@@ -32,6 +45,7 @@ hxtotexi()

            test $flag -eq 1 && echo "$str"
            ;;
        esac
+        line=$((line+1))
    done
 }

--
1.6.0.2