#!/bin/bash

if [ "$1" == "" ]; then
  echo
  echo Usage:
  echo "      " "$0" \[filename\]
  echo
  echo Example:
  echo "        " "$0" LIU5.CIN
  echo
  exit
fi

if [ ! -f "$1" ]; then
  echo "$0": No such file
  exit
fi

echo
echo Generating noseeing.gtab ...

iconv -f CP950 -t UTF-8 -c "$1" | \
sed -e 's/^%prompt 無蝦米/%prompt 嘸蝦米/' \
    -e 's/^%dupsel 9/%space_style 1/' \
    -e 's/^\] 〔/\] 〕/' | \
grep -v '^%quick ' | \
grep -v '^%sel1st ' > noseeing.cin
rm -fr noseeing.gtab
gcin2tab noseeing.cin > /dev/null 2>&1

if [ -f noseeing.gtab ]; then
  echo
  echo Done.
  echo
  echo Please copy noseeing.gtab to $HOME/.gcin or /usr/share/gcin/table
  echo
  exit
fi
