xref: /openbmc/qemu/scripts/hxtool (revision d901eff3)
1#!/bin/sh
2
3hxtoh()
4{
5    flag=1
6    while read -r str; do
7        case $str in
8            HXCOMM*)
9            ;;
10            STEXI*|ETEXI*|SQMP*|EQMP*) flag=$(($flag^1))
11            ;;
12            *)
13            test $flag -eq 1 && printf "%s\n" "$str"
14            ;;
15        esac
16    done
17}
18
19hxtotexi()
20{
21    flag=0
22    line=1
23    while read -r str; do
24        case "$str" in
25            HXCOMM*)
26            ;;
27            STEXI*)
28            if test $flag -eq 1 ; then
29                echo "line $line: syntax error: expected ETEXI, found $str" >&2
30                exit 1
31            fi
32            flag=1
33            ;;
34            ETEXI*)
35            if test $flag -ne 1 ; then
36                echo "line $line: syntax error: expected STEXI, found $str" >&2
37                exit 1
38            fi
39            flag=0
40            ;;
41            SQMP*|EQMP*)
42            if test $flag -eq 1 ; then
43                echo "line $line: syntax error: expected ETEXI, found $str" >&2
44                exit 1
45            fi
46            ;;
47            DEFHEADING*)
48            echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
49            ;;
50            ARCHHEADING*)
51            echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
52            ;;
53            *)
54            test $flag -eq 1 && echo "$str"
55            ;;
56        esac
57        line=$((line+1))
58    done
59}
60
61hxtoqmp()
62{
63    IFS=
64    flag=0
65    line=1
66    while read -r str; do
67        case "$str" in
68            HXCOMM*)
69            ;;
70            SQMP*)
71            if test $flag -eq 1 ; then
72                echo "line $line: syntax error: expected EQMP, found $str" >&2
73                exit 1
74            fi
75            flag=1
76            ;;
77            EQMP*)
78            if test $flag -ne 1 ; then
79                echo "line $line: syntax error: expected SQMP, found $str" >&2
80                exit 1
81            fi
82            flag=0
83            ;;
84            STEXI*|ETEXI*)
85            if test $flag -eq 1 ; then
86                echo "line $line: syntax error: expected EQMP, found $str" >&2
87                exit 1
88            fi
89            ;;
90            *)
91            test $flag -eq 1 && echo "$str"
92            ;;
93        esac
94        line=$((line+1))
95    done
96}
97
98case "$1" in
99"-h") hxtoh ;;
100"-t") hxtotexi ;;
101"-q") hxtoqmp ;;
102*) exit 1 ;;
103esac
104
105exit 0
106