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