
#
# This bit of code is mainly to overcome the need for TclX which is not
# in the freewrap code.  This for those who use the fr.exe version of fr.
#
# The missing piece is a function to kill a process by pid. With no function
# we must use a program. Over the years MS has shipped various kill
# programs.  Hopefully we have yours in the list.
#
# We will use the TclX call:
#
#   kill ?signal? idlist    (note we do NOT handle -pgroup, or rather we
#                            ignor it.)
#
# The first thing one should do is call the killInit routine below.
# It will set up the proper kill call

proc killInit {} {
  set killProcs [list \
		     {kill.exe /f %s} \
		     {kill -s 9 %s} \
		     {pskill.exe -t %s}\
		     {tskill.exe %s } \
		     {taskkill.exe /f /pid %s /t}\
		]
	       

  # the prefered way...
  if {[info command kill] != {}} {return}
  set r [catch {package require Tclx}]
  if {$r == 0} {return {}}
  
  # Ok, we don't have the kill command.
  foreach p $killProcs {
    set full [auto_execok [lindex $p 0]]
    if {$full != {}} {
      frputs "building with $full "
      set body [format {
	foreach pid $args {
	  if { [string index $pid 0] == "-"} {continue}
	  exec %s 
	}
      } [format [lreplace $p 0 0 $full] \$pid]]
      # puts "body is $body"
      proc kill args $body
      return {}
    }
  }
  puts "no kill program found"
  proc kill args {error "No kill function or program found."}
  return $killProcs
}
