hxtool 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. hxtoh()
  3. {
  4. flag=1
  5. while read -r str; do
  6. case $str in
  7. HXCOMM*)
  8. ;;
  9. STEXI*|ETEXI*|SQMP*|EQMP*) flag=$(($flag^1))
  10. ;;
  11. *)
  12. test $flag -eq 1 && printf "%s\n" "$str"
  13. ;;
  14. esac
  15. done
  16. }
  17. hxtotexi()
  18. {
  19. flag=0
  20. line=1
  21. while read -r str; do
  22. case "$str" in
  23. HXCOMM*)
  24. ;;
  25. STEXI*)
  26. if test $flag -eq 1 ; then
  27. echo "line $line: syntax error: expected ETEXI, found $str" >&2
  28. exit 1
  29. fi
  30. flag=1
  31. ;;
  32. ETEXI*)
  33. if test $flag -ne 1 ; then
  34. echo "line $line: syntax error: expected STEXI, found $str" >&2
  35. exit 1
  36. fi
  37. flag=0
  38. ;;
  39. SQMP*|EQMP*)
  40. if test $flag -eq 1 ; then
  41. echo "line $line: syntax error: expected ETEXI, found $str" >&2
  42. exit 1
  43. fi
  44. ;;
  45. DEFHEADING*)
  46. echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
  47. ;;
  48. *)
  49. test $flag -eq 1 && echo "$str"
  50. ;;
  51. esac
  52. line=$((line+1))
  53. done
  54. }
  55. hxtoqmp()
  56. {
  57. IFS=
  58. flag=0
  59. line=1
  60. while read -r str; do
  61. case "$str" in
  62. HXCOMM*)
  63. ;;
  64. SQMP*)
  65. if test $flag -eq 1 ; then
  66. echo "line $line: syntax error: expected EQMP, found $str" >&2
  67. exit 1
  68. fi
  69. flag=1
  70. ;;
  71. EQMP*)
  72. if test $flag -ne 1 ; then
  73. echo "line $line: syntax error: expected SQMP, found $str" >&2
  74. exit 1
  75. fi
  76. flag=0
  77. ;;
  78. STEXI*|ETEXI*)
  79. if test $flag -eq 1 ; then
  80. echo "line $line: syntax error: expected EQMP, found $str" >&2
  81. exit 1
  82. fi
  83. ;;
  84. *)
  85. test $flag -eq 1 && echo "$str"
  86. ;;
  87. esac
  88. line=$((line+1))
  89. done
  90. }
  91. case "$1" in
  92. "-h") hxtoh ;;
  93. "-t") hxtotexi ;;
  94. "-q") hxtoqmp ;;
  95. *) exit 1 ;;
  96. esac
  97. exit 0