2
0

hxtool 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ARCHHEADING*)
  49. echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
  50. ;;
  51. *)
  52. test $flag -eq 1 && echo "$str"
  53. ;;
  54. esac
  55. line=$((line+1))
  56. done
  57. }
  58. hxtoqmp()
  59. {
  60. IFS=
  61. flag=0
  62. line=1
  63. while read -r str; do
  64. case "$str" in
  65. HXCOMM*)
  66. ;;
  67. SQMP*)
  68. if test $flag -eq 1 ; then
  69. echo "line $line: syntax error: expected EQMP, found $str" >&2
  70. exit 1
  71. fi
  72. flag=1
  73. ;;
  74. EQMP*)
  75. if test $flag -ne 1 ; then
  76. echo "line $line: syntax error: expected SQMP, found $str" >&2
  77. exit 1
  78. fi
  79. flag=0
  80. ;;
  81. STEXI*|ETEXI*)
  82. if test $flag -eq 1 ; then
  83. echo "line $line: syntax error: expected EQMP, found $str" >&2
  84. exit 1
  85. fi
  86. ;;
  87. *)
  88. test $flag -eq 1 && echo "$str"
  89. ;;
  90. esac
  91. line=$((line+1))
  92. done
  93. }
  94. case "$1" in
  95. "-h") hxtoh ;;
  96. "-t") hxtotexi ;;
  97. "-q") hxtoqmp ;;
  98. *) exit 1 ;;
  99. esac
  100. exit 0