4.3BSD/usr/contrib/B/src/b/b.sh.gen

: 'Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984, 1985.'
: '$Header: b.sh.gen,v 1.1 85/08/22 14:33:39 timo Exp $'
:
: 'Shell script to start B'
:

IFS=
PATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/new
export PATH

: 'Most variables use the construct ${var=default}, meaning that they'
: 'are set to "default" only when they do not have a value initially.'
: 'The user can override by setting these variables in the environment'

: 'B_LIB is the directory where b finds auxiliary binaries and data files.'
: 'Filled in by make.'
B_LIB=
: 'BINT determines whether bint or bsmall will be used as interpreter.'
: 'Filled in by ../../Setup.'
BINT=

: 'B_INTERPRETER is the binary of the interpreter (passed to the editor)'
: ${B_INTERPRETER=$B_LIB/$BINT}
export B_INTERPRETER

: 'B_MESSAGES is where the interpreter finds its error messages'
: ${B_MESSAGES=$B_LIB/Messages}
export B_MESSAGES

: 'BEDITOR is the B editor to be used (must be a B editor, not vi etc.)'
: ${BEDITOR=$B_LIB/bed}
export BEDITOR

: 'BED_LIB is used by the B editor to find various files'
: ${BED_LIB=$B_LIB}
export BED_LIB

: 'BED_HELP is where the B editor finds its help file'
: ${BED_HELP=$BED_LIB/Bed_help}
export BED_HELP

: 'LPR is the lineprinter spooler'
LPR=lpr

: 'MKSUGG makes the suggestion file for the editor'
MKSUGG=$B_LIB/mksugg

: 'CONV creates a .b_perm with all B-units and targets found in it'
CONV=$B_LIB/convert

: 'Test for TERMCAP.  Give default only if there is no /etc/termcap'
case $TERMCAP in
'')	if test -f /etc/termcap
	then	: 'No need to set termcap'
	else
		TERMCAP=$B_LIB/termcap
		export TERMCAP
	fi;;
esac

: 'Subroutine to print an error message for b -i/-o and exit'
IO_ERR='echo \
"*** There is something I don'\''t quite get in your call of $0
    $0 $1
    `echo $0 $1|sed s/./\ /g`^
*** The problem is: no target where expected"
exit 1'

: 'Convert old workspace format to new'
if test ! -f .b_perm -a -f [\"\'\<\>=]?*
then
	if test -f .prmnv
	then
		echo '
*** Just a moment!  It seems you have never used this version of B before in
*** this workspace.  While you are reading this message, I will convert it
*** to one with which the new B interpreter is more happy.
***
*** One warning: the converted workspace is no longer compatible with the
*** old version of B.  If you want to use that version in this workspace
*** lateron, you will have to move the file ".prmnv_save" back to ".prmnv".
*** The shell command "mv .prmnv_save .prmnv" will accomplish this.
*** However, if you do this, you will loose any permanent targets created
*** or modified while using the new version, so please make up your mind.
'
	else
		echo '*** [Recovering lost permanent environment information]'
	fi
	if test -f =????????????*
	then
		echo '*** [Warning -- long target names may be truncated]'
	fi
	$CONV [\"\'\<\>=]?*
fi

case $1 in
'')	if test -t 0 -a -t 1 # -a -t 2
	then
		$MKSUGG
		exec $BEDITOR
	else
		exec $B_INTERPRETER
	fi;;
-e)	BEDITOR=${EDITOR-/usr/ucb/vi}; export BEDITOR; exec $B_INTERPRETER;;
-v)	BEDITOR=/usr/ucb/vi; export BEDITOR; exec $B_INTERPRETER;;
-i)	case $2 in
	'')	eval "$IO_ERR";;
	*)	{
		echo "PUT {} IN $2"
		echo "WHILE 1=1: READ $2[#$2 + 1] RAW"
	  	cat $3
		} | $B_INTERPRETER >/dev/null 2>&1
		: '(No output because there is always a complaint about EOF)'
		;;
	esac
	;;
-o)	case $2 in
	'')	eval "$IO_ERR";;
	*)	{
		echo "FOR l'i'n'e\" IN $2:"
		echo "    WRITE l'i'n'e\" /"
		echo "DELETE l'i'n'e\""
		} | $B_INTERPRETER >$3
		;;
	esac
	;;
-p)	$B_LIB/b_p|$LPR;;
-l)	exec $B_LIB/b_p;;
*)	if	test -f "$1"
	then	exec $B_INTERPRETER "$@" -q
	else
		case $SHELL in
		*/csh) B=`basename $0`;;
		*) B="$0";;
		esac
		echo 'To enter '$B' type "'$B'"
to enter '$B' with the '`basename "${EDITOR-vi}"`' editor, type "'$B' -e"'
		case $EDITOR in
		''|vi|*/vi) ;;
		*) echo 'to enter '$B' with the vi editor, type "'$B' -v"';;
		esac
		echo 'to execute commands from a file, type "'$B' file"
to input lines from a file to a text-table, type "'$B' -i table-name file"
to output lines from a text-table to a file, type "'$B' -o table-name file"
to print units on the line printer, type "'$B' -p"
to print units on the terminal, type "'$B' -l"' >&2
		exit 1
	fi;;
esac