#!/bin/csh -f
#
# csh script for l2h wrapper
# 04/05 2002
# 08/24 2002
# 09/25 2004
# shige
# mkwrapper
#
# 08/24 2002
# remove GIF/PNG
# 09/25 2004
# for JIS/SJIS/EUC output
#
set install = install
#set install = /usr/ucb/install

if ( $#argv < 1 ) then
usage:
    echo "Usage: ./mkwrapper [prefix]"
    echo " [prefix] = install directory of latex2html (must be absolute path)"
    echo " Note: Run me in latex2html-2002-2-1/."
    exit
endif

##
## directory & file check
##
set prefix = $argv[1]
if ( ! -d $prefix || ! -d $prefix/bin || ! -x $prefix/bin/latex2html ) goto usage
#echo $prefix | grep -i -q '^/'
#if ( $status ) set prefix = `pwd`/$prefix

set bindir = $prefix/bin
set libdir = $prefix/lib/latex2html
echo $prefix | grep -i -q l2h
if ( ! $status ) set libdir = $prefix
echo $prefix | grep -i -q latex2html
if ( ! $status ) set libdir = $prefix

if ( ! -f $libdir/l2hconf.pm ) goto usage
if ( ! -f ./l2hconf.pm || ! -f ./l2h-wrapper-temp ) goto usage


#if ( $#argv >= 2 ) then
#    switch ( $argv[2] )
#    case install:
#	goto install
#    case clean:
#	goto clean
#    default:
#	goto usage
#    endsw
#endif

make:
##
## make several l2hconf.pm and wrapper
##
sed -e 's/"jarticle"/"article"/' -e 's/japanese/english/' \
    -e 's/UNUSEACCENT = 1/UNUSEACCENT = 0/' \
    -e 's/texexpand/texexpand-en/' \
    l2hconf.pm > l2hconf_en.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -j";/' \
    -e 's/#$charset/$charset = "iso-2022-jp";/' \
    l2hconf.pm > l2hconf_jis.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -s";/' \
    -e 's/#$charset/$charset = "Shift_JIS";/' \
    l2hconf.pm > l2hconf_sjis.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -e";/' \
    -e 's/#$charset/$charset = "EUC-JP";/' \
    l2hconf.pm > l2hconf_euc.pm

sed -e 's/${FROMNATIVE} $infile |/<$infile/' texexpand > texexpand-en
sed -e "s@LIBDIR@$libdir@" -e "s@BINDIR@$bindir@" l2h-wrapper-temp > l2h-wrapper
goto install

install:
##
## install
##
if ( ! -f l2hconf_en.pm ) then
    echo 'l2hconf_en.pm does not found in the current directory.'
    exit
endif
cp l2hconf_{en,jis,sjis,euc}.pm $libdir
$install -c -m 0755 l2h-wrapper $bindir/l2h
$install -c -m 0755 texexpand-en $bindir/texexpand-en
goto quit

clean:
##
## clean
##
if ( -f l2hconf_en.pm ) then
    rm -f l2hconf_{en,jis,sjis,euc}.pm l2h-wrapper texexpand-en
endif
goto quit

quit:
