| 1 | #!/bin/sh |
| 2 | |
| 3 | print_if_not_rst() |
| 4 | { |
| 5 | test $in_rst -eq 0 && printf "%s\n" "$str" |
| 6 | } |
| 7 | |
| 8 | hxtoh() |
| 9 | { |
| 10 | in_rst=0 |
| 11 | # .name for HMP |
| 12 | seen_name=0 |
| 13 | while read -r str; do |
| 14 | case $str in |
| 15 | HXCOMM*) |
| 16 | ;; |
| 17 | SRST*) |
| 18 | if [ $in_rst -eq 1 ] |
| 19 | then |
| 20 | echo "Error: SRST inside another RST" >&2 |
| 21 | exit 1 |
| 22 | fi |
| 23 | # consume the name |
| 24 | seen_name=0 |
| 25 | in_rst=1 |
| 26 | ;; |
| 27 | ERST*) |
| 28 | if [ $in_rst -eq 0 ] |
| 29 | then |
| 30 | echo "Error: ERST already outside RST" >&2 |
| 31 | exit 1 |
| 32 | fi |
| 33 | in_rst=0 |
| 34 | ;; |
| 35 | # Note the space at the start - we need to exclude something.name |
| 36 | ( .name*) |
| 37 | if [ $seen_name -eq 1 ] |
| 38 | then |
| 39 | echo "Error: Seen another .name, maybe missing docs?" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | seen_name=1 |
| 43 | print_if_not_rst |
| 44 | ;; |
| 45 | *) |
| 46 | print_if_not_rst |
| 47 | ;; |
| 48 | esac |
| 49 | done |
| 50 | } |
| 51 | |
| 52 | case "$1" in |
| 53 | "-h") hxtoh ;; |
| 54 | *) exit 1 ;; |
| 55 | esac < "$2" |
| 56 | |
| 57 | exit 0 |