#!/bin/sh

# Test FL routines
#
# $Id: tFLroutines,v 1.7 1996/10/23 libtsp-V2R7a $

PATH=${PATH}:bin
export PATH

echo ""
echo "========== tFLbackup"
fname=/usr/tmp/temporaryfile
fnameb=${fname}~
touch $fname
tFLbackup $fname 2>&1
ls ${fname}*
rm -f $fname $fnameb

fname=/usr/tmp/temporaryfile.xxxx
fnameb=${fname}~
touch $fname
touch $fnameb
chmod u-w $fnameb
tFLbackup $fname 2>&1	# move on top of existing readonly file
ls ${fname}*
rm -f $fname $fnameb

fname=/usr/tmp/tempf
fnameb=${fname}~
touch $fname
ln -s $fname $fnameb
tFLbackup $fname 2>&1		# backup link (should kill link)
ls ${fname}*
rm -f $fname $fnameb

tFLbackup /bin 2>&1		# directory
tFLbackup /bin/sh 2>&1		# no permission
tFLbackup /dev/tty00 2>&1	# device
tFLbackup XxXxYx		# file does not exist

echo ""
echo "========== tFLdefName"
tFLdefName abc/def xxx/yyy
tFLdefName def xxx/yyy
tFLdefName abc/ xxx/yyy
tFLdefName abc /

echo ""
echo "========== tFLexist"
tFLexist XxXxXx		# file does not exist
tFLexist /dev		# directory
tFLexist /dev/tty	# device
tFLexist Makefile
fname=/usr/tmp/tempf
fnamel=${fname}l
fnamell=${fnamel}l
touch $fname
ln -s $fname $fnamel
ln -s $fnamel $fnamell
tFLexist $fname
tFLexist $fnamel		# link to regular file
tFLexist $fnamell
rm -f $fname $fnamel $fnamell

echo ""
echo "========== tFLexpHome"
tFLexpHome ""
tFLexpHome abc/def
tFLexpHome ~junk
tFLexpHome ~junk/abc/def
tFLexpHome ~root
tFLexpHome ~root/abc/def

echo ""
echo "========== tFLfReadData"
cat << EoF > test.dat
! data values
0.5
1.0 1.5 ! xxxx

2.0
EoF
tFLfReadData test.dat		# test ignore comments and blank lines
rm -rf test.dat

cat << EoF > test.dat
! data values
0.5
1.0 1.5 xxxx

2.0
EoF
tFLfReadData test.dat 2>&1	# test bad data value
rm -rf test.dat

cat << EoF > test.dat
0.5 1.0 1.5 2.0 2.5 3.0
EoF
tFLfReadData test.dat 2>&1	# test too many data items
rm -rf test.dat

cat << EoF > test.dat
0.5 1.0 1.5 2.0 2.5
xx
EoF
tFLfReadData test.dat 2>&1	# test too many lines
rm -rf test.dat

echo ""
echo "========== tFLfWriteData"
tFLfWriteData test.dat 1.1 2.2 3.3 4.4 5.5
cat test.dat
rm -rf test.dat
cat > test.dat << EoF
abc !xxxx
abd\\
def\\
abc #xxxx
EoF

echo ""
echo "========== tFLgetRec"
tFLgetRec test.dat "!#" "\\" 2
echo ""
tFLgetRec test.dat "!#" "\\" 1
echo ""
tFLgetRec test.dat "!#" "\\" 0
rm -f test.dat

echo ""
echo "========== tFLfullName"
tFLfullName ""
tFLfullName /xx
tFLfullName /xx/yy
tFLfullName /usr/users/u2/kabal/edit/../xx

echo ""
echo "========== tFLhomeDir"
tFLhomeDir junk
tFLhomeDir root

echo ""
echo "========== tFLpathList"
PLIST=".:/bin"
export PLIST
tFLpathList xxx/yyy ""
tFLpathList xxx/yyy "$PLIST"
tFLpathList ls ""
tFLpathList ls "xxx:zzz"
tFLpathList ls "./ :: /bin"
tFLpathList ls '$PLIST'

echo ""
echo "========== tFLreadLine"
tFLreadLine "Prompt > " << EoF
line 1
line 2
EoF

echo ""
echo "========== tFLxxxDate (expect time zone differences)"
tFLxxxDate tFLxxxDate.c

echo ""
echo "========== tFLxxxName"
tFLxxxName ""
tFLxxxName xx
tFLxxxName ./xx
tFLxxxName xx/yy/
tFLxxxName /xx/yy/
tFLxxxName xx/yy.ex
tFLxxxName xx/yy/zz
tFLxxxName /
tFLxxxName /xx
tFLxxxName /xx/yy.ex
tFLxxxName /xx/yy/zz

echo ""
echo "========== tFLjoinNames"
tFLjoinNames "" xxx/yyy
tFLjoinNames abc/def ""
tFLjoinNames abc/def xxx/yyy
tFLjoinNames abc/def/ xxx/yyy
tFLjoinNames / xxx/yyy
tFLjoinNames abc/def /xxx/yyy
tFLjoinNames abc/def/ /xxx/yyy

echo ""
echo "========== tFLexpHome (expect system dependencies)"
tFLexpHome ~
tFLexpHome ~${USER}
tFLexpHome ~${USER}/abc/def
tFLexpHome ~/abc/def

echo ""
echo "========== tFLfullName (expect system dependencies)"
tFLfullName xx
tFLfullName xx/yy
tFLfullName ~${USER}/edit/..//xx	# should leave ~ part intact

echo ""
echo "========== tFLhomeDir (expect system dependencies)"
tFLhomeDir ""
tFLhomeDir root
tFLhomeDir ${USER}

echo ""
echo "========== tFLpathList (expect system dependencies)"
tFLpathList ~/.cshrc ""
tFLpathList .cshrc '~'
tFLpathList ~${USER}/.cshrc ""
tFLpathList .cshrc ~${USER}
