Patchwork [2/2] hxtool: Add syntax error detection

login
register
mail settings
Submitter Jan Kiszka
Date May 20, 2010, 7:16 a.m.
Message ID <4BF4E1D1.1010507@web.de>
Download mbox | patch
Permalink /patch/53051/
State New
Headers show

Comments

Jan Kiszka - May 20, 2010, 7:16 a.m.
From: Jan Kiszka <jan.kiszka@siemens.com>

Add basic imbalance detection for STEXT/ETEXI.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hxtool |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
Blue Swirl - May 22, 2010, 9:27 a.m.
Thanks, applied.

On Thu, May 20, 2010 at 7:16 AM, Jan Kiszka <jan.kiszka@web.de> wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> Add basic imbalance detection for STEXT/ETEXI.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  hxtool |   16 +++++++++++++++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/hxtool b/hxtool
> index 0fdbc64..8f65532 100644
> --- a/hxtool
> +++ b/hxtool
> @@ -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
>  }
>
> --
> 1.6.0.2
>
>

Patch

diff --git a/hxtool b/hxtool
index 0fdbc64..8f65532 100644
--- a/hxtool
+++ b/hxtool
@@ -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
 }