#!/bin/sh
# this script is invoked by the spad )edit command
# can be replaced by users favorite editor
# optional second argument should be character offset in file

thefile=$1
if [ ! -f $1 ] ; then 
  thefile=$AXIOM/../../src/algebra/$1
else
  thefile=$1
fi


if [ $# = 2 ] ; then
	START=`grep -n \^$2\( $thefile | awk -F: '{print $1}'`
else
	START=1
fi

if [ ! "$EDITOR" ] ; then
	EDITOR=vi
fi

if [ "$DISPLAY" ] ; then
	if [ "$EDITOR" = "emacs" ] ; then
		emacs  +$START $thefile &
	elif [ "$EDITOR" = "vi" ] ; then
		xterm -e vi +$START $thefile &
        else
		xterm -e $EDITOR $thefile &
	fi
else
	$EDITOR $thefile
fi
