#!/usr/local/bin/wish8.4
#!/usr/local/bin/wish8.4
#!/usr/local/bin/wish8.4
#!/usr/local/bin/wish8.4
#!/usr/local/bin/wish8.4
#!/usr/local/bin/wish8.3
#!/usr/local/bin/wish8.3

# This is a Windows front-end to JStrack's filter script.  Its purpose
# is to make life a bit easier for those who can't just let procmail
# do all of the work for them (like we Unix users do).

if {$tcl_platform(platform) != "windows"} {
   tk_messageBox -type ok \
      -message "This script is written specifically for Windows...."
}

# rfcdir is the directory where JStrack's filter program is located.
# If, for example, it is located in d:/jdg/src/ht/filt, it would be
# defined as:
#    set rfcdir d:/jdg/src/ht/filt
# Note the use of '/' and not a backslash.
#
# If this is not defined (or is defined as UNDEFINED, as below), the
# script will attempt to find the correct location on its own.  If it
# fails, it will ask the user for the location.

set rfcdir UNDEFINED

# Simple proc to return the name of a tmpfile

proc mk_tmpfile {} {
   global rfcdir

   set dir $rfcdir/tmp
   if {[file exists $rfcdir/tmp]} {
      if {![file isdirectory $rfcdir/tmp]} { set dir $rfcdir }
   } else {
      file mkdir $rfcdir/tmp
   }

   return $dir/[pid]
}


# If rfcdir is undefined, try to find out where the filter is located.

if {![info exists rfcdir] || [string compare $rfcdir UNDEFINED] == 0} {
   set rfctest [file dirname $argv0]
   if {[file exists $rfctest/filt.tcl]} { set rfcdir $rfctest }
}

# If rfcdir is STILL undefined, ask the user for help....

if {![info exists rfcdir] || [string compare $rfcdir UNDEFINED] == 0} {
   set rfcpath [tk_getOpenFile -title "Where is JStrack's filt.tcl?"]
   set rfcdir [file dirname $rfcpath]
}


# Grab the path/name of tclsh
regsub -nocase wish [info nameofexecutable] tclsh tclshpath

# Make sure we know where tclsh is...and while we're at it, fix the
# path to use the full name instead of the dos 8.3 name (if needed).

if {![regexp tclsh $tclshpath]} {
   set tclshpath [tk_getOpenFile -title "Where is tclsh8x.exe?" \
      -initialdir "c:/Program Files/Tcl/bin"]
} else {
   regsub "C:/PROGRA~1/" $tclshpath "C:/Program Files/" tclshpath2
   set tclshpath $tclshpath2
}


label .l0 -text "Tclsh is $tclshpath"
label .l0a -text "JStrack's filter is in $rfcdir"
label .l0b -text ""
label .l1 -text "For each e-mail/web page with an NHC advisory:"
label .l2 -text "    Open the e-mail/web page, select the entire message    "
label .l2b -text "text, copy it into the buffer (see below) and then"
label .l2c -text "click on the button below to process the data."
label .l3 -text ""
pack .l0 .l0a .l0b .l1 .l2 .l2b .l2c .l3 -side top
foreach i [list .l0 .l0a .l0b .l1 .l2 .l2b .l2c .l3] {
   $i configure -font "Helvetica 14 bold"
}


set w .f1 ; pack [frame $w] -side top

label $w.l4a -text "Using the keyboard:" -font "Helvetica 14 bold"
label $w.l4b -text "CTRL-A CTRL-C" -font "Helvetica 14 bold"
grid $w.l4a -row 1 -column 1 -sticky w
grid $w.l4b -row 1 -column 2 -sticky w

label $w.l5a -text "Using the mouse:" -font "Helvetica 14 bold"
label $w.l5b -text "Edit--->Select All" -font "Helvetica 14 bold"
label $w.l5c -text "Edit--->Copy" -font "Helvetica 14 bold"
grid $w.l5a -row 2 -column 1 -sticky w
grid $w.l5b -row 2 -column 2 -sticky w
grid $w.l5c -row 3 -column 2 -sticky w

# spacer....
pack [label .l5 -text "" -font "Helvetica 14 bold"] -side top

set w .f2 ; pack [frame $w] -side top

button $w.b1 -text "Grab buffer and run filter" -command {
   # Grab the selection buffer
   set flist [split [selection get -selection CLIPBOARD] \n\r]

   set tmpfile [mk_tmpfile]

   set f [open $tmpfile w]
   foreach line $flist { puts $f $line }
   close $f
   exec $tclshpath $rfcdir/filt.tcl < $tmpfile
   file delete $tmpfile
}

button $w.b2 -text "Done" -command { exit }

$w.b1 configure -font "Helvetica 14 bold"
$w.b2 configure -font "Helvetica 14 bold"

pack $w.b1 $w.b2 -side left















