#! /bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#
# Copyright  (c) 1986 AT&T
#	All Rights Reserved
#
#ident	"$Header: setenv.sh 1.4 89/10/10 $@(#)vm:xx/setenv.sh	1.1"
#

# usage: setenv [-f file] [-r variable] [variable=value] ...
# sets variables in files

file=$HOME/pref/.environ
var=
while [ "$#" -gt 0 ]
do
	case "$1" in
	-f)
		file="$2"
		shift
		;;
	-f*)
		file="`expr \"$1\" : '-f\(.*\)'`"
		;;
	-r)
		var="$2"
		echo "`grep \"^$var=\" \"$file\" 2>/dev/null`" | sed -e "s/^$var=//"
		shift
		;;
	-r*)
		var="`expr \"$1\" : '-r\(.*\)'`"
		echo "`grep \"^$var=\" \"$file\" 2>/dev/null`" | sed -e "s/^$var=//"
		;;
	*)
		var="`expr \"$1\" : '\([^=]*\)=.*'`"
		(expr "$1" : '\(.*\)' | sed -e 's/\\[ncrbft0]/\\&/g' -e 's/$/\\n/' | tr -d '\012'; echo) | sed -e 's/\\n$//' > /tmp/setenv$$
		grep -v "^$var=" "$file" >> /tmp/setenv$$ 2>/dev/null
		cp /tmp/setenv$$ "$file"
		rm -f /tmp/setenv$$
		;;
	esac
	shift
done
