#! /bin/sh

# Convert a binary OpenFST file into an efsm textual file.

syms=symbols.txt
trans=transitions.fsm
fstprint --acceptor --save_isymbols=$syms "$@" > $trans

# Sort symbols per number, not per value.
cat <<EOF
#! /bin/sh

cat >symbols.txt <<\EOFSM
$(sort -n -k2 $syms)
EOFSM

cat >transitions.fsm <<\EOFSM
$(cat $trans)
EOFSM

fstcompile --acceptor \\
  --keep_isymbols --isymbols=symbols.txt \\
  --keep_osymbols --osymbols=symbols.txt \\
  transitions.fsm "\$@"
EOF
