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