hxtool 2.3 KB
Newer Older
1 2 3 4 5
#!/bin/sh

hxtoh()
{
    flag=1
6
    while read -r str; do
7 8 9
        case $str in
            HXCOMM*)
            ;;
10
            STEXI*|ETEXI*|SQMP*|EQMP*) flag=$(($flag^1))
11 12
            ;;
            *)
13
            test $flag -eq 1 && printf "%s\n" "$str"
14 15 16 17 18 19 20 21
            ;;
        esac
    done
}

hxtotexi()
{
    flag=0
J
Jan Kiszka 已提交
22
    line=1
23
    while read -r str; do
24 25 26
        case "$str" in
            HXCOMM*)
            ;;
J
Jan Kiszka 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39
            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
40
            ;;
41 42 43 44 45 46
            SQMP*|EQMP*)
            if test $flag -eq 1 ; then
                echo "line $line: syntax error: expected ETEXI, found $str" >&2
                exit 1
            fi
            ;;
47
            DEFHEADING*)
S
Stefan Weil 已提交
48
            echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
49
            ;;
50 51 52
            ARCHHEADING*)
            echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
            ;;
53
            *)
S
Stefan Weil 已提交
54
            test $flag -eq 1 && echo "$str"
55 56
            ;;
        esac
J
Jan Kiszka 已提交
57
        line=$((line+1))
58 59 60
    done
}

61 62 63 64
hxtoqmp()
{
    IFS=
    flag=0
65
    line=1
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    while read -r str; do
        case "$str" in
            HXCOMM*)
            ;;
            SQMP*)
            if test $flag -eq 1 ; then
                echo "line $line: syntax error: expected EQMP, found $str" >&2
                exit 1
            fi
            flag=1
            ;;
            EQMP*)
            if test $flag -ne 1 ; then
                echo "line $line: syntax error: expected SQMP, found $str" >&2
                exit 1
            fi
            flag=0
            ;;
            STEXI*|ETEXI*)
            if test $flag -eq 1 ; then
                echo "line $line: syntax error: expected EQMP, found $str" >&2
                exit 1
            fi
            ;;
            *)
            test $flag -eq 1 && echo "$str"
            ;;
        esac
94
        line=$((line+1))
95 96 97
    done
}

98 99 100
case "$1" in
"-h") hxtoh ;;
"-t") hxtotexi ;;
101
"-q") hxtoqmp ;;
102 103
*) exit 1 ;;
esac
B
blueswir1 已提交
104 105

exit 0