hxtool 1.4 KB

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