#!/bin/sh

ver=3.3
dvips=dvipsj
LINKOPT=-h
EWBDIR=/usr/share/ewblib
GSEWB=/usr/share/ghostscript/ewb
TMDIR=/usr/share/texmf
EWBTM=/usr/share/ewb/$ver/texmf

if [ $# -gt 0 ] ; then
  if [ X"$1" = "Xgs-ja" -o X"$1" = "Xgs-alad-vf" ] ; then
# update kanji fonts setting files of ghostscript
    GSNAME="$1"
    if [ -x /usr/bin/$GSNAME ] ; then
    for d in `$GSNAME -help | awk '/^Search path/ { while(getline) { if (/^ /) { gsub(/\:/, "\n"); print }}}'`
      do
      if test -f $d/CIDFnmap ; then
	cat $d/CIDFnmap $EWBDIR/CIDFnmap.in > $GSEWB/CIDFnmap
      fi
      if test -f $d/pcf.ps ; then
	cp -f $EWBDIR/pcf.ps.in $GSEWB/pcf.ps
      fi
      if test -f $d/vflib.ps ; then
	cp -f $EWBDIR/vflib.ps.in $GSEWB/vflib.ps
      fi
      if test -f $d/kconfig.ps ; then
# "test ! $LINKOPT $d/kconfig.ps" is not appropriate for gs-ja (>= 7.07)
	if grep VFlibkanji $d/kconfig.ps > /dev/null ; then
	    cp -f $EWBDIR/vflib.ps.in $GSEWB/kconfig.ps
	elif grep pcfkanji $d/kconfig.ps > /dev/null ; then
	    cp -f $EWBDIR/pcf.ps.in $GSEWB/kconfig.ps
	fi
      fi
      done
    else
    echo "Not found $GSNAME! Please check it first."
    exit 1
    fi
  elif [ X"$1" = Xdvips -o X"$1" = Xdvipsk-ja ] ; then
# update dvipsk config and program files
    cd $EWBTM/dvips-ewb/base
    rm -f *.pro
    cat $TMDIR/$dvips/base/texc.pro $TMDIR/$dvips/base/texps.pro > tmp.pro
    mv -f tmp.pro texc.pro ; touch texps.pro
  else
echo "$0 : wrong usage"
echo "$0 takes options only 'gs-ja', 'gs-alad-vf' or 'dvips'"
  exit 1
  fi
else
echo "$0 : wrong usage"
echo "$0 takes options only 'gs-ja', 'gs-alad-vf' or 'dvips'"
exit 1
fi
