#!/bin/sh

rm -f runno@

gawkloc=`which gawk|grep ":"`
if test "$gawkloc" = ""; then
   gawkloc=`which gawk|grep "no gawk"`
fi
if test "$gawkloc" != ""; then
   gawkbin="awk"
else
   gawkbin="gawk"
fi

searchtexmf="y"
if test "$searchtexmf" = "y"; then
TEXMF=`kpsexpand '$TEXMF'|cut -d! -f 3 `
VARTEXFONTS=`kpsexpand '$VARTEXFONTS' `
if test "$VARTEXFONTS" = ""; then
   VARTEXFONTS=`kpsexpand '$VARFONTS' `
   export VARFONTS
   export VARTEXFONTS
else
   export VARTEXFONTS
fi

echo "yes" > tmp@
texmfcnffile=`kpsexpand -w cnf texmf.cnf`
TEXMFCNF=`
$gawkbin  '
{texmfcnfloc=index(texmfcnffile,"/texmf.cnf")
 print substr(texmfcnffile,1,texmfcnfloc-1)
}' texmfcnffile=$texmfcnffile tmp@ `

echo $TEXMFCNF > tmp@
TEXMF=`
$gawkbin '
{
  inline=$0
  gsub(/web2c/,"",inline)
  inline=substr(inline,1,length(inline)-1)
  print inline
}' tmp@ `

fi


TEXPKS=.:$TEXMF/fonts//:$VARTEXFONTS//
#TEXMFCNF=$TEXMF/web2c
TTFONTS=.:$TEXMF/fonts/chinese/ttf//
TTF2PKINPUTS=.:$TEXMF
TTF2TFMINPUTS=.:$TEXMF
TFMFONTS=.:$TEXMF/fonts/tfm//:$VARTEXFONTS/tfm//
TEXMFDBS=$TEXMF:$VARTEXFONTS

export TEXMF
export VARTEXFONTS
export TEXMFCNF
export TTF2PKINPUTS
export TTFONTS
export TTF2TFMINPUTS
export TFMFONTS
export TEXMFDBS
export TEXPKS

rm -f tmp@

# This is the xdvi wrapper script for teTeX, version 0.2.
# Copyright Thomas Esser, 1998. Permission to distribute under the terms
# of the GNU general public license version 2 or later.

# This script sets some environment variables to make sure that xdvi's
# ressource file in $XDVIINPUTS/xdvi is read by xdvi.bin.
# Special care was taken to make this work for old R3, too. Therefore,
# we need to modify XAPPLRESDIR. If you are running R4 or later, you
# can set XUSERFILESEARCHPATH for user specific application default
# files. You cannot use XAPPLRESDIR for user specific application default
# files.

test -f /bin/sh5 && test -z "$RUNNING_SH5" \
  && test x"`(uname -s) 2>&1`" = xULTRIX \
  && { RUNNING_SH5=true; export RUNNING_SH5; exec /bin/sh5 $0 ${1+"$@"}; }
RUNNING_SH5=

test -f /bin/bsh && test -z "$RUNNING_BSH" \
  && test x"`(uname -s) 2>&1`" = xAIX \
  && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; }
RUNNING_BSH=

# -help and -version only work if they are the only options. Therefore,
# we cannot give the "-name xdvi" parameter in that case.
# SU: Actually, with current xdvik, they should work in any position; but
# we may keep this for compatibility with older versions and non-k xdvi.
case "$#:$1" in
  1:-help|1:-version)
    NAMEOPT=;;
  *)
    NAMEOPT='-name xdvi';;
esac

XDVIINPUTS="$XDVIINPUTS":'$TEXMF/{xdvi,web2c}'; export XDVIINPUTS
xdviappfile=`kpsewhich -progname=xdvi --format='other text files' XDvi`
if test -n "$xdviappfile"; then
  xdviappdir=`dirname "$xdviappfile"`
  xdviapppath="${xdviappdir}%N"

  # For R3, we have to set XAPPLRESDIR.
  XAPPLRESDIR="$xdviappdir"; export XAPPLRESDIR

  # For R4 or later, we have to set XFILESEARCHPATH, since XAPPLRESDIR might
  # be ignored (if XUSERFILESEARCHPATH is set)
  XFILESEARCHPATH="$xdviapppath:${XFILESEARCHPATH-%D}"; export XFILESEARCHPATH
fi

if test -s /usr/bin/xdvi-motif.bin; then
   exec xdvi-motif.bin $NAMEOPT ${1+"$@"}
else
   exec xdvi.bin $NAMEOPT ${1+"$@"}
fi   
