#!/bin/sh

# append_db
# Written by Thomas Esser <te@informatik.uni-hannover.de>, Nov., 1994

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; chmod 666 $db_file)

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

ed -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
