blob: 995bb7f08c2b7632e019ff273990ce308527aaeb [file] [log] [blame]
blueswir15824d652009-03-28 06:44:27 +00001#!/bin/sh
2
3hxtoh()
4{
5 flag=1
blueswir1fb21ced2009-03-29 09:06:43 +00006 while read -r str; do
blueswir15824d652009-03-28 06:44:27 +00007 case $str in
8 HXCOMM*)
9 ;;
Jan Kiszkab40292e2010-05-31 14:43:31 -030010 STEXI*|ETEXI*|SQMP*|EQMP*) flag=$(($flag^1))
blueswir15824d652009-03-28 06:44:27 +000011 ;;
12 *)
blueswir1004efc92009-03-29 10:50:43 +000013 test $flag -eq 1 && printf "%s\n" "$str"
blueswir15824d652009-03-28 06:44:27 +000014 ;;
15 esac
16 done
17}
18
19hxtotexi()
20{
21 flag=0
Jan Kiszka6c913ba2010-05-20 09:16:33 +020022 line=1
blueswir1fb21ced2009-03-29 09:06:43 +000023 while read -r str; do
blueswir15824d652009-03-28 06:44:27 +000024 case "$str" in
25 HXCOMM*)
26 ;;
Jan Kiszka6c913ba2010-05-20 09:16:33 +020027 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
blueswir15824d652009-03-28 06:44:27 +000040 ;;
Jan Kiszkab40292e2010-05-31 14:43:31 -030041 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 ;;
blueswir15824d652009-03-28 06:44:27 +000047 DEFHEADING*)
Stefan Weil7d69c522009-07-01 23:13:34 +020048 echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
blueswir15824d652009-03-28 06:44:27 +000049 ;;
Michael Ellermana3adb7a2011-12-19 17:19:31 +110050 ARCHHEADING*)
51 echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
52 ;;
blueswir15824d652009-03-28 06:44:27 +000053 *)
Stefan Weil7d69c522009-07-01 23:13:34 +020054 test $flag -eq 1 && echo "$str"
blueswir15824d652009-03-28 06:44:27 +000055 ;;
56 esac
Jan Kiszka6c913ba2010-05-20 09:16:33 +020057 line=$((line+1))
blueswir15824d652009-03-28 06:44:27 +000058 done
59}
60
Jan Kiszkab40292e2010-05-31 14:43:31 -030061hxtoqmp()
62{
63 IFS=
64 flag=0
Jan Kiszka02e95912010-06-02 09:06:03 +020065 line=1
Jan Kiszkab40292e2010-05-31 14:43:31 -030066 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
Jan Kiszka02e95912010-06-02 09:06:03 +020094 line=$((line+1))
Jan Kiszkab40292e2010-05-31 14:43:31 -030095 done
96}
97
blueswir15824d652009-03-28 06:44:27 +000098case "$1" in
99"-h") hxtoh ;;
100"-t") hxtotexi ;;
Jan Kiszkab40292e2010-05-31 14:43:31 -0300101"-q") hxtoqmp ;;
blueswir15824d652009-03-28 06:44:27 +0000102*) exit 1 ;;
103esac
blueswir15c2f8d22009-03-28 08:13:56 +0000104
105exit 0