#!/bin/sh

# append_db
# Written by Thomas Esser <[email protected]>, Nov., 1994

TOOLS="/usr/local/tex/kpsetools-0.2/bin"
KPSEXPAND="$TOOLS/kpsexpand"
SED="/usr/bin/sed"
CAT="/bin/cat"
EDT="/bin/ed"
CHM="/bin/chmod 666"


progname=`basename $0`
db_file=`$KPSEXPAND '$TEXMF'`/ls-R
control_string='% This is file ls-R. Maintained by texhash and append_db.'

case $# in
2)      ;;
*)      echo "Usage: append_db dir file"
       exit
       ;;
esac

test -f $db_file || (echo "$control_string" > $db_file; $CHM $db_file)

if [ ! -w "$db_file" ] ; then
       echo "$progname: error: cannot write to file $db_file."
       exit
fi >&2

$EDT -s $db_file >& /dev/null <<-eof
       /`echo $1 | $SED 's@/@\\\\/@g'`/a
       $2
       .
       wq
eof

if [ $? != 0 ]; then
       $CAT >> $db_file <<-eof
               $1:
               $2
       eof
fi