blob: 7d7c4289e32926ccc026bcb0ecd63c64cfedd87a [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 ;;
Paolo Bonzini44d619b2017-07-07 17:46:46 +020010 STEXI*|ETEXI*) 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
Paolo Bonzini43f187a2017-01-04 13:50:37 +010019print_texi_heading()
20{
21 if test "$*" != ""; then
Markus Armbrusterde6b4f92017-10-02 16:03:00 +020022 title="$*"
23 printf "@subsection %s\n" "${title%:}"
Paolo Bonzini43f187a2017-01-04 13:50:37 +010024 fi
25}
26
blueswir15824d652009-03-28 06:44:27 +000027hxtotexi()
28{
29 flag=0
Jan Kiszka6c913ba2010-05-20 09:16:33 +020030 line=1
blueswir1fb21ced2009-03-29 09:06:43 +000031 while read -r str; do
blueswir15824d652009-03-28 06:44:27 +000032 case "$str" in
33 HXCOMM*)
34 ;;
Jan Kiszka6c913ba2010-05-20 09:16:33 +020035 STEXI*)
36 if test $flag -eq 1 ; then
Daniel Shahaf5a1de0b2016-10-16 17:28:18 +030037 printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
Jan Kiszka6c913ba2010-05-20 09:16:33 +020038 exit 1
39 fi
40 flag=1
41 ;;
42 ETEXI*)
43 if test $flag -ne 1 ; then
Daniel Shahaf5a1de0b2016-10-16 17:28:18 +030044 printf "line %d: syntax error: expected STEXI, found '%s'\n" "$line" "$str" >&2
Jan Kiszka6c913ba2010-05-20 09:16:33 +020045 exit 1
46 fi
47 flag=0
blueswir15824d652009-03-28 06:44:27 +000048 ;;
49 DEFHEADING*)
Paolo Bonzini43f187a2017-01-04 13:50:37 +010050 print_texi_heading "$(expr "$str" : "DEFHEADING(\(.*\))")"
blueswir15824d652009-03-28 06:44:27 +000051 ;;
Michael Ellermana3adb7a2011-12-19 17:19:31 +110052 ARCHHEADING*)
Paolo Bonzini43f187a2017-01-04 13:50:37 +010053 print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
Michael Ellermana3adb7a2011-12-19 17:19:31 +110054 ;;
blueswir15824d652009-03-28 06:44:27 +000055 *)
Daniel Shahaf5a1de0b2016-10-16 17:28:18 +030056 test $flag -eq 1 && printf '%s\n' "$str"
blueswir15824d652009-03-28 06:44:27 +000057 ;;
58 esac
Jan Kiszka6c913ba2010-05-20 09:16:33 +020059 line=$((line+1))
blueswir15824d652009-03-28 06:44:27 +000060 done
61}
62
63case "$1" in
64"-h") hxtoh ;;
65"-t") hxtotexi ;;
66*) exit 1 ;;
67esac
blueswir15c2f8d22009-03-28 08:13:56 +000068
69exit 0