xref: /openbmc/qemu/scripts/hxtool (revision ba632924)
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*) 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    line=1
31    while read -r str; do
32        case "$str" in
33            HXCOMM*)
34            ;;
35            STEXI*)
36            if test $flag -eq 1 ; then
37                printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
38                exit 1
39            fi
40            flag=1
41            ;;
42            ETEXI*)
43            if test $flag -ne 1 ; then
44                printf "line %d: syntax error: expected STEXI, found '%s'\n" "$line" "$str" >&2
45                exit 1
46            fi
47            flag=0
48            ;;
49            DEFHEADING*)
50            print_texi_heading "$(expr "$str" : "DEFHEADING(\(.*\))")"
51            ;;
52            ARCHHEADING*)
53            print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
54            ;;
55            *)
56            test $flag -eq 1 && printf '%s\n' "$str"
57            ;;
58        esac
59        line=$((line+1))
60    done
61}
62
63case "$1" in
64"-h") hxtoh ;;
65"-t") hxtotexi ;;
66*) exit 1 ;;
67esac
68
69exit 0
70