# call of the editor $editor for editing the file $efile$esuff   
#
# Copyright (C) 2000  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"

  TestPut 4 "<$editor><$edxterm><$edBack>"
  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>"
    set res [catch "exec $call" message]
    set a "${a}[datime] gnudoit-xemacs call: $call\n"
    set pid ""

  } else {

    if {$edxterm==""} {
      if {$edBack==""} {
	eval set res [catch "exec $editor $edoptions $ed_file" pid]
      } else {
	set res [eval mkCmd_back $f  $editor $edoptions $ed_file]
      }
    } else {
      if {$edBack==""} {
	eval set res [catch "exec $edxterm $editor $edoptions $ed_file" pid]
      } else {
	regsub -all {\"} $edxterm "\\\"" EDXTERM
	TestPut 4 "edxterm background <$edxterm><$EDXTERM><$editor><$edoptions><$ed_file>"
	set res [eval mkCmd_back $f $EDXTERM $editor $edoptions $ed_file]
      }
    }

  }

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

}
