#!/bin/sh
#ReadBatch  -*- TCL -*- Created: ramsan Jun-1997, Modified: ramsan Jun-1997


#----------------------ReadBatch ALONE---------------------------
# the next line restarts using wish \
	exec wish4.2 "$0" "$@"

set ReadBatchRunningAlone 0
catch {
    if {$argv0 == [info script] } {
	set ReadBatchRunningAlone 1
	set tcl_interactive 0
	set tk_strictMotif 1
	if { [catch { set GIDDEFAULT $env(GIDDEFAULT)}]!=1 } {
	    set GIDDEFAULTTCL $GIDDEFAULT
	    catch { set GIDDEFAULTTCL $env(GIDDEFAULTTCL) }
	    set auto_path "$GIDDEFAULTTCL"
	    source $GIDDEFAULTTCL/init.tcl
	    source $GIDDEFAULTTCL/tk.tcl
	}
	wm withdraw .
    }
}

#  LOOK AT THE END OF THE FILE !!!
#-------------------------------------------------------------------


proc SeeFileInBatch { w } {

    if { [$w.b1 cget -text] == "See file" } {
	if { [FileReadBatchWin $w] == "error" } { return }
	$w.b1 conf -text [_ "Hide file"]
	grid $w.f6
    } else {
	$w.b1 conf -text [_ "See file"]
	grid remove $w.f6
    }
}

proc FileReadBatchWin { w } {

    global GIDDEFAULT ReadbPriv

    set text $w.fr.t
    set file [string trim $ReadbPriv(filename) " "]

    if { $file == "" } {
	tk_dialogRAM $w.dd [_ "error"] \
	    [_ "One correct batch file name is needed"] \
	    error 0 [_ "OK"]
	return error
    }
    if { $ReadbPriv(CurrentFileName) == $file } {
	if { [file mtime $file] != $ReadbPriv(CurrentFileNameMTime) } {
	    set res [tk_dialogRAM $w.tempwin [_ "information window"] \
			 [_ "File is more recent than last time read. Reread it?"] \
			 gidquestionhead 0 [_ "Yes"] [_ "No"] [_ "Cancel"]]
	    if { $res == 1 } {
		return
	    } elseif { $res == 2 } { return error }
	} else { return }
    }
    if { ![file readable $file] } {
	tk_dialogRAM $w.dd [_ "error"] [_ "File name is not correct"] \
	    error 0 [_ "OK"]
	$w.file select from 0 
	$w.file select to end
	return error
    }

    $w conf -cursor watch
    update idletasks

    $text conf -state normal
    $text del 1.0 end
    $text ins end "  "

    set fileid [open $file r]

    set inum 0
    set iline 1
    while { ![eof $fileid] } {
	set input [gets $fileid]
	if { [regexp {^\*\*\*\*\*} $input] } { 
	    if { [string range $input 5 8] == "STOP" || \
		    [string range $input 5 9] == "PAUSE" } {
		$text del "end -3 c" end-1c 
		$text ins end "S " tagbegin
	    }
	    continue 
	}
	if { $ReadbPriv(AreLineNumbers) } {
	    $text ins end [format "%-5i " $iline]
	}
	foreach i [regexp -inline -all {\s*\S+\s*} $input] {
	    if { ![regexp {\s*escape\s*} $i] } {
		$text ins end "$i"
	    } else {
		regexp {([^.]*)} [$text index end] trash line
		incr line -1
		label $text.$inum -bitmap @$GIDDEFAULT/bitmaps/arrow-l -text $line
		set list [concat escapetagRB [bindtags $text.$inum]]
		bindtags $text.$inum $list
		
		regexp {(\s*)escape(\s*)} $i {} before after
		$text ins end $before
		$text window create end -padx 5 -window $text.$inum
		$text ins end $after
		incr inum
	    }
	}
	$text ins end "\n  "
	incr iline
    }
    close $fileid
    regexp {([^.]*)} [$text index end] trash line
    $text del [expr $line-2].0 end

    $text conf -state disabled

    set ReadbPriv(CurrentFileName) $file
    set ReadbPriv(CurrentFileNameMTime) [file mtime $file]
    set ReadbPriv(CurrentLine) 1
    regexp {^[^.]*} [$text index end] ReadbPriv(LastLine) 

    RBatchSetCurrentLine $w
    RBatchProgressBar $w

    $w conf -cursor ""
}

proc FileWriteBatchWin { w } {
    global ReadbPriv

    if { $ReadbPriv(filename) == "" } {
	tk_dialogRAM $w.dd [_ "error"] [_ "There is no batch file read"] \
	    error 0 [_ "OK"]
	return
    }

    if { [FileReadBatchWin $w] == "error" } { return }
    

    set file [Browser-ramR file write $w [_ "write batch"]]
    if { $file == "" } { return }
    FileWriteBatch $w $file
}

proc FileWriteBatch { w file  } {

    global GIDDEFAULT ReadbPriv

    set text $w.fr.t

    if { $file == "" } {
	tk_dialogRAM $w.dd [_ "error"] [_ "One correct batch file name is needed"] \
	    error 0 [_ "OK"]
	return error
    }

    if { [catch {
	set fileid [open $file w]
    }] } {
	tk_dialogRAM $w.dd [_ "error"] [_ "File cannot be written"] \
	    error 0 [_ "OK"]
	return error
    }

    $w conf -cursor watch
    update idletasks

    if { $ReadbPriv(AreLineNumbers) } { set ichar 8 } else { set ichar 2 }
    for {set i 1} {$i < $ReadbPriv(LastLine)} {incr i} {
	foreach {key value index} [$text dump -text -window \
		$i.$ichar "$i.0 lineend"] {
	    switch $key {
		text {
		    puts -nonewline $fileid $value
		}
		window {
		    puts -nonewline $fileid "escape "
		}
	    }
	}
	puts $fileid ""
	set cc [$text get [expr $i+1].0]
	if { $cc == "S" || $cc == "B" } { 
	    puts $fileid "*****STOP"
	}
    }

    close $fileid
    $w conf -cursor ""
}

proc RBatchGo { w } {
    global ReadbPriv

    if { [FileReadBatchWin $w] == "error" } { return }

    if { $ReadbPriv(delay) && ![regexp {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
	    $ReadbPriv(delayMseconds)] } {
	tk_dialogRAM $w.dd [_ "error"] [_ "Time delay must be a positive integer"] \
	    error 0 [_ "OK"]
	$w.f4.e1 select from 0 
	$w.f4.e1 select to end
	return 
    }
    if { $ReadbPriv(stopdelay) && ![regexp {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
	    $ReadbPriv(stopdelayMseconds)] } {
	tk_dialogRAM $w.dd [_ "error"] [_ "Time stop delay must be a positive integer"] \
	    error 0 [_ "OK"]
	$w.f5.e1 select from 0 
	$w.f5.e1 select to end
	return 
    }

    switch $ReadbPriv(stop) {
	end {
	    set lineend $ReadbPriv(LastLine) 
	}
	infloop {
	    set lineend $ReadbPriv(LastLine) 
	}
	Lnumber {
	    if { ![regexp {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
		    $ReadbPriv(stopLineNumber)] } {
		tk_dialogRAM $w.dd [_ "error"] [_ "Line number must be a positive integer"] \
		    error 0 [_ "OK"]
		$w.f3.e1 select from 0 
		$w.f3.e1 select to end
		return 
	    }
	    set lineend $ReadbPriv(stopLineNumber)
	}
	after {
	    if { ![regexp {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
		    $ReadbPriv(stopAfter)] } {
		tk_dialogRAM $w.dd [_ "error"] [_ "Line increment must be a positive integer"] \
		    error 0 [_ "OK"]
		$w.f3.e2 select from 0 
		$w.f3.e2 select to end
		return 
	    }
	    set lineend [expr $ReadbPriv(stopAfter)+$ReadbPriv(CurrentLine)]
	}
	Istop {
	    set lineend $ReadbPriv(LastLine) 
	}
    }

    set text $w.fr.t

    grab $w.stop
    $w conf -cursor watch
    .central.s waitstate 1
    .central.s disable windows 1
    .central.s disable graphinput 1
    if { $ReadbPriv(showinfo) == 0 } { .central.s disable warnline 1 }
    set oldfocus [focus -lastfor $w]
    if { $oldfocus == "" } { set oldfocus $w.file }
    focus $w.stop
    update idletasks
 
    set ReadbPriv(MustBeStopped) 0
    if { $ReadbPriv(AreLineNumbers) } { set ichar 8 } else { set ichar 2 }
    while 1 {
	for {set i $ReadbPriv(CurrentLine)} {$i < $lineend} {incr i} {
	
	    foreach {key value index} [$text dump -text -window \
		    $i.$ichar "$i.0 lineend"] {
		switch $key {
		    text {
			set value [string trimright $value \n]
			.central.s process $value
# 			set len [llength $value]
# 			set ini 0
# 			set end 99
# 			while 1 {
# 			    if { $end >= $len } {
# 				set end [expr $len-1]
# 			    }
# 			    .central.s process [lrange $value $ini $end]
# 			    if { $end == [expr $len-1] } { break }
# 			    set ini [expr $end+1]
# 			    incr end 100
# 			}
		    }
		    window {
			.central.s process escape
		    }
		}
	    }
	    set ReadbPriv(CurrentLine) [expr $i+1]
	    if { $ReadbPriv(stopdelay) } {
		set cc [$text get $ReadbPriv(CurrentLine).0]
		if { $cc == "S" || $cc == "B" } { 
		    after $ReadbPriv(stopdelayMseconds)
		}
	    }
	    if { $ReadbPriv(delay) } {
		after $ReadbPriv(delayMseconds)
	    }
	    
	    RBatchSetCurrentLine $w
	    RBatchProgressBar $w
	    update
	    if { $ReadbPriv(MustBeStopped) } { break }
	        
	    if { $ReadbPriv(stop) == "Istop" } {
		set cc [$text get $ReadbPriv(CurrentLine).0]
		if { $cc == "S" || $cc == "B" } { break }
	    }
	}
	if { $ReadbPriv(CurrentLine) == $ReadbPriv(LastLine) } {
	    set ReadbPriv(CurrentLine) 1
	    RBatchSetCurrentLine $w
	    RBatchProgressBar $w
	}
	if { $ReadbPriv(stop) != "infloop" || $ReadbPriv(MustBeStopped) } { break }
    }

    after idle " \
	    .central.s disable windows 0 ; \
	    .central.s disable graphinput 0 ; \
	    .central.s waitstate 0 ; \
	    grab release $w.stop ; \
	    $w conf -cursor {} ; \
	    focus $oldfocus"
    if { $ReadbPriv(showinfo) == 0 } { after idle .central.s disable warnline 0 }
}

proc RBatchStop { w } {
    global ReadbPriv
    set ReadbPriv(MustBeStopped) 1
}

proc RBatchRewind { w } {
    global ReadbPriv
    FileReadBatchWin $w
    set ReadbPriv(CurrentLine) 1
    RBatchSetCurrentLine $w
    RBatchProgressBar $w
}

proc RBatchFileWindow { w } {
    global ReadbPriv
    set ReadbPriv(filename) [Browser-ramR file read $w [_ "read batch"]] 
    if { $ReadbPriv(filename) == "" } { return }
    FileReadBatchWin $w
}

proc RBatchProgressBar { w } {
    global ReadbPriv

    set rwidth [expr ($ReadbPriv(CurrentLine)-1.0)/($ReadbPriv(LastLine)-1.0)]

    place $w.f25.f -x 0 -y 0 -relheight 1 \
	    -relwidth $rwidth
}

proc RBatchSetNumbers { w } {
    global ReadbPriv

    set text $w.fr.t
    $text conf -state normal
    if { !$ReadbPriv(AreLineNumbers) } {
	$w.f6.num conf -text [_ "No numbers"]
	set ReadbPriv(AreLineNumbers) 1
	if { [info exists ReadbPriv(LastLine)] } { 
	    for {set i 1} {$i < $ReadbPriv(LastLine)} {incr i} {
		$text insert $i.2 [format "%-5i " $i]
	    }
	}
    } else {
	$w.f6.num conf -text [_ "Numbers"]
	set ReadbPriv(AreLineNumbers) 0
	if { [info exists ReadbPriv(LastLine)] } { 
	    for {set i 1} {$i < $ReadbPriv(LastLine)} {incr i} {
		$text delete $i.2 $i.8
	    }
	}
    }
    $text conf -state disabled
}

proc RBatchSetCurrentLine { w } {
    global ReadbPriv
    set text $w.fr.t
    $text conf -state normal
    
    set trange [$text tag ranges tagcurrent]
    if { $trange != "" } { 
	$text del [lindex $trange 0]
	$text ins [lindex $trange 0] " "
    }
    for {set i 0} {$i < 2} {incr i} {
	if { [$text get $ReadbPriv(CurrentLine).$i] == " " } {
	    $text del $ReadbPriv(CurrentLine).$i
	    $text insert $ReadbPriv(CurrentLine).$i C tagcurrent
	    break
	}
    }
    $text see $ReadbPriv(CurrentLine).0
    $text conf -state disabled
}

proc RBatchMarkbreakSet { w x y { sel yes } { win "" } } {

    if { $sel == "yes" } {
	set text $w.fr.t
	if { $win == "" } {
	    set y [expr $y-[winfo rooty $text]]
	    regexp {([^.]*)} [$text index @$x,$y] trash line
	} else {
	    set line [$win cget -text]
	}
	$text conf -state normal
	
	if { [$text get $line.0] == " " } {
	    $text del $line.0
	    $text insert $line.0 B tagbreak
	} elseif { [$text get $line.0] == "C" } {
	    $text del $line.0 $line.2
	    $text insert $line.0 B tagbreak
	    $text insert $line.1 C tagcurrent
	} else {
	    $text conf -state disabled
	    return
	}
	$text conf -state disabled
    }
    grab release $w.fr
    bind $w.fr.t <1> ""
    bind $w.fr.t <B1-Motion> ""
    bind $w.fr.t <Key> ""
    bind escapetagRB <1>  ""
    $w.fr.t conf -cursor ""
    $w.fr conf -cursor ""
    $w.fr.vscr conf -cursor ""
    $w.fr.hscr conf -cursor ""
    focus $w.file
}

proc RBatchMarkbreak { w } {

    grab $w.fr
    bind $w.fr.t <1> "RBatchMarkbreakSet $w %X %Y ; break"
    bind $w.fr.t <B1-Motion> "break"
    bind $w.fr.t <Key> "RBatchMarkbreakSet $w 0 0 no ; break"
    bind escapetagRB <1>  "RBatchMarkbreakSet $w 0 0 yes %W ; break"
    $w.fr.t conf -cursor hand2
    $w.fr conf -cursor pirate
    $w.fr.vscr conf -cursor arrow
    $w.fr.hscr conf -cursor arrow
    focus $w.fr.t

    catch { destroy $w.warn }
    label $w.warn -text [_ "Pick a line in the code to set a mark there"] -relief ridge -bd 2
    place $w.warn -in $w -relx 0 -rely 1 -anchor sw
    after 1000 [list catch "destroy $w.warn"]
}

proc RBatchClearbreakSet { w x y { sel yes }  { win "" } } {

    if { $sel == "yes" } {
	set text $w.fr.t
	if { $win == "" } {
	    set y [expr $y-[winfo rooty $text]]
	    regexp {([^.]*)} [$text index @$x,$y] trash line
	} else {
	    set line [$win cget -text]
	}
	
	$text conf -state normal

	set trange [$text tag nextrange tagbreak $line.0 "$line.0 lineend"]
	if { $trange != "" } {
	    $text del [lindex $trange 0]
	    $text ins [lindex $trange 0] " "
	}
	$text conf -state disabled
	if { $trange == "" } { return }
    }
    grab release $w.fr
    bind $w.fr.t <1> ""
    bind $w.fr.t <B1-Motion> ""
    bind $w.fr.t <Key> ""
    $w.fr.t conf -cursor ""
    $w.fr conf -cursor ""
    $w.fr.vscr conf -cursor ""
    $w.fr.hscr conf -cursor ""
    focus $w.file
}
 
proc RBatchClearbreak { w } {
    set text $w.fr.t

    set res [tk_dialogRAM $w.tempwin [_ "information window"] [_ "Clear one break or all?"] \
		 gidquestionhead 0 [_ "One"] [_ "All"] [_ "Cancel"]]
    
    if { $res == 1 } {
	$text conf -state normal
	foreach "i1 i2" [$text tag ranges tagbreak] {
	    $text del $i1
	    $text ins $i1 " "
	}
	$text conf -state disabled
    } elseif { $res == 0 } {
	grab $w.fr
	bind $w.fr.t <1> "RBatchClearbreakSet $w %X %Y ; break"
	bind $w.fr.t <B1-Motion> "break"
	bind $w.fr.t <Key> "RBatchClearbreakSet $w 0 0 no ; break"
	bind escapetagRB <1>  "RBatchClearbreakSet $w 0 0 yes %W ; break"
	$w.fr.t conf -cursor hand2
	$w.fr conf -cursor pirate
	$w.fr.vscr conf -cursor arrow
	$w.fr.hscr conf -cursor arrow
	focus $w.fr.t
	catch { destroy $w.warn }
	label $w.warn -text [_ "Pick a line in the code to delete its mark"] -relief ridge -bd 2
	place $w.warn -in $w -relx 0 -rely 1 -anchor sw
	after 1000 [list catch "destroy $w.warn"]
    }
}

proc ReadBatch { { w .wReadBatch } } {
    global GIDDEFAULT ReadbPriv
    InitWindow $w [_ "Read batch"] ReadBatchWindowGeom ReadBatch

    frame $w.f1
    label $w.l -text [_ "File:"] 
    entry $w.file -relief sunken -textvariable ReadbPriv(filename)

    bind $w.file <Return> "FileReadBatchWin $w"

    button $w.fileb -bitmap @$GIDDEFAULT/bitmaps/openfile \
	    -command "RBatchFileWindow $w"
    grid columnconf $w.f1 1 -weight 1 
    grid  $w.l $w.file $w.fileb -in $w.f1 -sticky ew


    if { ![info exists ReadbPriv(Goimg)] } {
	set ReadbPriv(Goimg) [image create bitmap -file $GIDDEFAULT/bitmaps/go.xbm \
		-maskfile $GIDDEFAULT/bitmaps/go-msk.xbm \
		-background yellow -foreground black]
    }

    if { ![info exists ReadbPriv(Stopimg)] } {
	set ReadbPriv(Stopimg) [image create bitmap -file $GIDDEFAULT/bitmaps/stop.xbm \
		-maskfile $GIDDEFAULT/bitmaps/stop-msk.xbm \
		-background yellow -foreground black]
    }
    if { ![info exists ReadbPriv(Rewimg)] } {
	set ReadbPriv(Rewimg) [image create bitmap \
		-file $GIDDEFAULT/bitmaps/rewind.xbm \
		-maskfile $GIDDEFAULT/bitmaps/rewind-msk.xbm \
		-background yellow -foreground black]
    }

    frame $w.f2
    button $w.play -image $ReadbPriv(Goimg) -command "RBatchGo $w"
    button $w.stop -image $ReadbPriv(Stopimg) -command "RBatchStop $w"
    button $w.rewind -image $ReadbPriv(Rewimg) -command "RBatchRewind $w"
    grid  $w.play $w.stop $w.rewind -in $w.f2 -pady 5 -padx 5 -ipadx 2 -ipady 2

    frame $w.f25 -relief sunken -bd 2 -height 20
    frame $w.f25.f -bg blue
    
    place $w.f25.f -x 0 -y 0 -relheight 1 -relwidth 0




    frame $w.f3 -relief ridge -bd 2
    label $w.f3.l1 -text [_ "Stop at:"]
    radiobutton $w.f3.r1 -text [_ "End"] -variable ReadbPriv(stop) -value end
    radiobutton $w.f3.r2 -text [_ "Infinite loop"] -variable ReadbPriv(stop) -value infloop
    radiobutton $w.f3.r3 -text [_ "Line number:"] -variable ReadbPriv(stop) -value Lnumber
    entry $w.f3.e1 -relief sunken -width 4 -textvariable ReadbPriv(stopLineNumber)
    radiobutton $w.f3.r4 -text [_ "After:"] -variable ReadbPriv(stop) -value after
    entry $w.f3.e2 -relief sunken -width 4 -textvariable ReadbPriv(stopAfter)
    label $w.f3.l2 -text [_ "lines"]
    radiobutton $w.f3.r5 -text [_ "Internal stop"] -variable ReadbPriv(stop) -value Istop
    grid $w.f3.l1
    grid $w.f3.r1 - $w.f3.r2 -sticky w
    grid $w.f3.r3 -sticky w
    grid $w.f3.e1  -sticky ew -column 1 -row 2
    grid $w.f3.r5 -sticky w -column 2 -row 2
    grid $w.f3.r4  -sticky w
    grid $w.f3.e2 -sticky ew -column 1 -row 3
    grid $w.f3.l2 -sticky w -column 2 -row 3
    grid columnconf $w.f3 1 -weight 1 

    frame $w.f4
    checkbutton $w.f4.c1 -text [_ "Per command delay:"] -variable ReadbPriv(delay)
    entry $w.f4.e1 -relief sunken -width 5 -textvariable ReadbPriv(delayMseconds)
    label $w.f4.l1 -text [_ "miliseconds"]
    grid $w.f4.c1 $w.f4.e1 $w.f4.l1 -sticky ew
    grid columnconf $w.f4 1 -weight 1 

    frame $w.f5
    checkbutton $w.f5.c1 -text [_ "Per stop delay:"] -variable ReadbPriv(stopdelay)
    entry $w.f5.e1 -relief sunken -width 5 -textvariable ReadbPriv(stopdelayMseconds)
    label $w.f5.l1 -text [_ "miliseconds"]
    grid $w.f5.c1 $w.f5.e1 $w.f5.l1 -sticky ew
    grid columnconf $w.f5 1 -weight 1 
    
    checkbutton $w.f55 -text [_ "Show info"] -variable ReadbPriv(showinfo)

    button $w.b1 -text [_ "See file"] -command "SeeFileInBatch $w" -width 8

    frame $w.f6 -relief ridge -bd 2
    frame $w.fr -relief sunken -bd 2

    text $w.fr.t -xscroll "$w.fr.hscr set" -yscroll "$w.fr.vscr set" \
	    -wrap none -width 0 -height 8 -font FixedFont -relief flat
    scrollbar $w.fr.vscr -orient vertical -comm "$w.fr.t yview"
    scrollbar $w.fr.hscr -orient horizontal -comm "$w.fr.t xview"

    button $w.f6.num -text [_ "Numbers"] -command "RBatchSetNumbers $w" -width 10
    button $w.f6.stop -text [_ "Mark break"] -command "RBatchMarkbreak $w"
    button $w.f6.clear -text [_ "Clear"] -command "RBatchClearbreak $w"
    
    grid $w.fr.t -sticky nsew -row 0 -column 0 -in $w.fr
    grid $w.fr.vscr -sticky ns -row 0 -column 1 -rowspan 2 -in $w.fr
    grid $w.fr.hscr -row 1 -column 0 -sticky ew -in $w.fr
    grid columnconf $w.fr 0 -weight 1 
    grid rowconf $w.fr 0 -weight 1
    grid $w.fr - - -sticky nsew -in $w.f6
    grid $w.f6.num $w.f6.stop $w.f6.clear
    grid columnconf $w.f6 0 -weight 1 
    grid columnconf $w.f6 1 -weight 1 
    grid columnconf $w.f6 2 -weight 1 
    grid rowconf $w.f6 0 -weight 1

    frame $w.f7
    button $w.f7.close -text [_ "Close"] -command "destroy $w"
    button $w.f7.write -text [_ "Write.."] -command "FileWriteBatchWin $w"
    grid $w.f7.close $w.f7.write


    grid $w.f1 -sticky ew
    grid $w.f2 -sticky ew
    grid $w.f25 -sticky ew -padx 10 -pady 5
    grid $w.f3 -sticky ew -padx 3
    grid $w.f4 -sticky ew
    grid $w.f5 -sticky ew
    grid $w.f55 -sticky w
    grid $w.b1 -sticky w

    grid $w.f6 -sticky nsew
    grid $w.f7 -sticky sew
    grid remove $w.f6
    grid columnconf $w 0 -weight 1 
    grid rowconf $w 8 -weight 1

    set ReadbPriv(stop) Istop
    set ReadbPriv(CurrentFileName) ""
    set ReadbPriv(AreLineNumbers) 0
    $w.fr.t tag configure tagbegin -foreground red
    $w.fr.t tag configure tagcurrent -foreground red
    $w.fr.t tag configure tagbreak -foreground red
    wm geom $w ""
    focus $w.file

}


#----------------------CopyMove ALONE---------------------------
if { $ReadBatchRunningAlone == 1 } {
    ReadBatch
} 
#-----------------------------------------------------------------
