# call of the editor $editor for editing the file $efile$esuff   
#
# Copyright (C) 1999  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University

proc editor {f austext} {

  upvar 1 $austext a

  global  vv editor edback edxterm edoptions efile esuff pid tlaOutLstAct leEditCFN edBack

  set a ""; set message ""; set res 0


  if {$f=="letter-edit"} {# editor call for editing letter block (proc leEditBlockSelected)

    set f ""; set edBack ""; set ed_file $leEditCFN

  } else {# normal editor call

    if {$tlaOutLstAct==0} {writescr0 $f ""}
    if {[fileName $efile]==""} {set a "${a}***** $vv(ea1)\n"; mybell 3; return}
    set edBack "$edback"; set ed_file $efile$esuff
    writescr $f "[datime] $vv(eda1): $edxterm $editor $edoptions $ed_file $edBack\n"

  }


  # the editor builds its own window (e.g. emacs) or the editor is called
  # in an xterm window (e.g. vi), depending on variable "edxterm"

  if {$editor=="gnudoit"} {#####@@@@@ special call for gnudoit

    set call "$editor $edoptions";		TestPut 4 "call before evaluation: <$call>"
    regsub -all {\$ed_file} "$call" "[pwd]/$ed_file" call
						TestPut 4 "call after  evaluation: <$call>"
    SigChldB; set res [catch "exec $call" message]; SigChldU
    set a "${a}[datime] gnudoit-xemacs call: $call\n"
    set pid ""

  } else {

    if {$edxterm==""} {
	SigChldB; eval set r [catch "exec $editor $edoptions $ed_file $edBack" m]; SigChldU
    } else {# no SigChld... with xterm!
	eval set r [catch "exec $edxterm $editor $edoptions $ed_file $edBack" m]
    }
    set pid "$m"

  }

  if {$pid != ""} {set a "${a}[datime] $vv(eda1): $vv(pid)=$pid\n"}
  if {$r != 0} {set a "${a}\n$vv(eda5)=$r\n"}

}
