# call of the letter program
#
# Copyright (C) 2000  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University

proc letter {f austext} {

  upvar 1 $austext a

  global  vv Wle main_file sub pid dirprefix letter letoptions letback

  set a ""

  if {$letback==1} {set back "&"} else {set back ""}

  if {$dirprefix==""} {set mainfile $main_file} else {set mainfile ""} 
  if {"[file tail $letter]"=="addressbook"} {set mainfile ""}

  TestPut 4 "<$letter><$back> <$letoptions> <$mainfile>"

  writescr $f "[datime] $vv(le1) $letter $letoptions $mainfile\n"
  if {"[file tail $letter]"=="xtem_letter"} {

    xtem_letter $letoptions
 
  } elseif {("[file tail $letter]"=="tk_Brief")||("[file tail $letter]"=="addressbook")} {

    writescr $f "[datime] $vv(le1) $letter $letoptions $mainfile\n"
    if {$letback==0} {
     mkCmd_wait $f $letter "$letoptions $mainfile"
     set pid ""
    } else {
     eval set r [catch "exec $letter $letoptions $mainfile &" m]
     set pid "$m";  set a "${a}$pid\n";  if {$r!=0} {set a "${a}$vv(pr8)=$r\n"}
    }

 } else {# letter program not found!

   set a "${a}\n***** $vv(aprog)  $letter  $vv(anf)\n"
   mybell 2

  }

}
