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