set filter_name "filter.exe"
set oanda_name  "oanda.txt"
set debug 0
frame .config
frame .includes
frame .excludes
frame .actions
pack .config .includes .excludes .actions -side top 
button .exe -textvariable filter_name -command {
 set filter_name [tk_getOpenFile -filetypes {
      {{Executable files} {.exe}}
      {{All files} {""}}
      }]
}

button .target -textvariable oanda_name -command {
 set oanda_name [tk_getOpenFile -filetypes {
      {{Text files} {.txt}}
      {{All files} {""}}
      }]
}
pack .exe .target -side top -in .config -fill x
frame .inc1 
label .findlabel1 -text "Search for:" -width 15
entry .search1    -width 20 -relief sunken -textvariable search1term
checkbutton .case1inc -variable inc1yes -text "Case Sensitive" 
pack .findlabel1 .search1 .case1inc -side left -padx 1m -pady 2m -in .inc1
pack .inc1 -in .includes

frame .inc2
label .findlabel2 -text "Or:" -width 15
entry .search2    -width 20 -relief sunken -textvariable search2term
checkbutton .case2inc -variable inc2yes -text "Case Sensitive" 
pack .findlabel2 .search2 .case2inc -side left -padx 1m -pady 2m -in .inc2
pack .inc2 -in .includes

frame .ex1
label .excludelabel1 -text "But not:" -width 15
entry .exclude1    -width 20 -relief sunken -textvariable x1term
checkbutton .excl1inc -variable exc1yes -text "Case Sensitive" 
pack .excludelabel1 .exclude1 .excl1inc -side left -padx 1m -pady 2m \
  -in .actions -in .ex1
pack .ex1 -in .excludes
button .go -text "Find It" -command {
    set cmd ""
    append cmd "\"$filter_name\" \"$oanda_name\" " 
    if $inc1yes {
      append cmd " \"="
      } else {
      append cmd " \"+" } 
    append cmd [string trim $search1term] "\""
    if [string length [string trim $search2term]]>0 then {
      if $inc2yes {
        append cmd " \"="
        } else {
        append cmd " \"+" } 
      append cmd [string trim $search2term] "\""
    }
    if [string length [string trim $x1term]]>0 then {
      if $exc1yes {
        append cmp " \"_"
        } else {
        append cmd " \"-" } 
      append cmd [string trim $x1term] "\""
    }
    if $debug {tk_messageBox -message $cmd}
    eval exec $cmd > results.txt
    showFile results.txt
}

button .exit -text "EXIT"  -command {exit}

pack .go .exit -side left -fill x -in .actions
proc showFile {thefile} {
     set w .text
     catch {destroy $w}
     toplevel $w
     wm title $w "$thefile"
     wm iconname $w "text"

     frame $w.buttons
     pack $w.buttons -side bottom -fill x -pady 2m
     button $w.buttons.dismiss -text Dismiss -command "destroy $w"
     pack $w.buttons.dismiss  -side bottom -expand 1

     text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" \
        -setgrid 1 -height 30
     scrollbar $w.scroll -command "$w.text yview"
     pack $w.scroll -side right -fill y
     pack $w.text -expand yes -fill both
     textLoadFile $w.text $thefile
     $w.text mark set insert 0.0 } 

proc textLoadFile {w file} {
    if [file exists $file] {
      set f [open $file]
      $w delete 1.0 end
      while {![eof $f]} {
         $w insert end [read $f 10000]
      }
      close $f
  }
}