#!/bin/sh 
#  Copyright 1995, Richard M. Troth, all rights reserved.   <plaintext> 
# 
#	  Name: rcv (shell script) 
#		receive files from "receive pool" to current dir 
#	  Date: 1995-Jan-14, Apr-29, Nov-09 
# 
 
# 
# user must indicate which UFT file to receive: 
if [ -z "$1" ]; then 
	echo "usage: $0 nnnn" 
	exit 24 
	fi 
 
# 
# set some variables: 
D=/usr/spool/uft/$LOGNAME 
if [ -n "$UFT_SPOOLDIR" ]; then D="$UFT_SPOOLDIR"; fi 
MAKETEXT=/usr/local/lib/maketext 
 
# 
# make sure we have a UFT spool directory: 
if [ ! -d "$D" ]; then 
	mkdir "$D" 
	chmod 700 "$D" 
	fi 
if [ ! -d "$D" ]; then 
	echo "UFT configuration problem: no spool dir" 
	exit 1 
	fi 
 
# 
# sequence file must exist for auto-sequence receive: 
if [ ! -f $D/.seq ]; then 
	echo "0000" > $D/.seq 
	fi 
 
# 
# now ... what file did you say you wanted? 
if [ "$1" = "-" ]; then 
	F=`cat $D/.seq` 
	else 
		F=`echo "$1" | awk '{printf "%04d",$1}'` 
		if [ "$?" != 0 ]; then exit 24; fi 
	fi 
 
# 
# be sure this file exists: 
if [ ! -f $D/$F.cf -o ! -f $D/$F.df ]; then 
	echo "file $F not found" 
	exit 28 
	fi 
 
# 
# extract some meta info from the control file: 
touch /tmp/$$.env; chmod 600 /tmp/$$.env 
cat $D/$F.cf | egrep "TYPE=|NAME=" | grep -v "#" \
	| sed "s/;/ /g" | sed "s/'//g" | sed 's/"//g' \
	| awk '{print $1}' > /tmp/$$.env 
. /tmp/$$.env 
rm /tmp/$$.env 
 
# 
# clean-up the filename: 
NAME=`basename $NAME | awk '{print tolower($1)}'` 
if [ -n "$2" ]; then NAME="$2"; fi 
 
# 
# clean-up the canonicalization type: 
if [ -z "$TYPE" ]; then TYPE=text/plain; fi 
TYPE=`echo $TYPE | awk -F/ '{print toupper($1)}'` 
FILT="cat" 
if [ "$TYPE" = "A" ]; then FILT="$MAKETEXT local"; fi 
if [ "$TYPE" = "T" ]; then FILT="$MAKETEXT local"; fi 
if [ "$TYPE" = "TEXT" ]; then FILT="$MAKETEXT local"; fi 
 
# 
# file may have been sent unnamed: 
if [ -z "$NAME" ]; then 
	echo "file $F has no name" 
	exit 24 
	fi 
 
# 
# be careful to not clobber existing files: 
if [ -f "$NAME" ]; then 
	echo "file $NAME already exists" 
	exit 28 
	fi 
 
# 
# after all that, receive the file ... 
if [ "$2" = "-" ] 
	then cat $D/$F.df | $FILT 
	else cat $D/$F.df | $FILT > "$NAME" 
	fi 
if [ "$?" != 0 ]; then exit $?; fi 
 
# 
# and remove it from "spool": 
chmod 600 $D/$F.cf $D/$F.df $D/$F.ef $D/$F.lf 
rm -f $D/$F.cf $D/$F.df $D/$F.ef $D/$F.lf 
 
exit 
 

