#!/bin/sh

#    File: xd_edit
# Purpose: Shell script wrapper to run an editor in a window.  Returns
#          with the PID of the eiditor (or its terminal window if 
#          applicable) or -1 for error.
#
#  Arguments: Uses $1 as filename, $2 as line number to start editing
#
# Evironment: $EDITOR and $VISUAL are examined (in that order) and
#             are used if set.  If neither is set, vi is used.
#             XD_TERM specifies a terminal emulator (default is xterm,
#               or hpterm under HP-UX)
#                      
#
# Giles P.J. Thomas
# Imperial Software Technology (IST),
# 95 London Street,
# Reading RG1 4QA
# United Kingdom
#
# Telephone: +44 734 597055
# Fax:       +44 734 589005
# Email:     giles@ist.co.uk

editor="${EDITOR:-"${VISUAL:-vi}"}"
ed_name=`basename $editor`

title="$ed_name $1"

case $ed_name in
   xemacs | emacs)
	# the current versions detect an X server and put themselves in
	# their own window.  xemacs, of course, does the same
	$editor +$2 $1 ;;

   dtpad | vuepad)
	# vuepad and dtpad are Motif applications so obviously no window needed.
	# unfortunately no way of setting line number.
	$editor $1 ;;

   *)
	# for vi or any other editor, we just  bring up a window.  If
	# the editor is not vi, we have to hope it takes vi-style
	# command-line syntax...
	if [ -n "$XD_TERM" ];
	then $XD_TERM -title "$title" -e $editor +$2 $1
	elif [ "`uname -s`" = "HP-UX" ];
	then hpterm -title "$title" -e $editor +$2 $1
	else xterm -title "$title" -e $editor +$2 $1
	fi ;;
esac
