Eskil

Diff
Login

Differences From Artifact [e31447253d]:

To Artifact [5491b0aa83]:


12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
12
13
14
15
16
17
18


19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38


39

40
41
42
43
44
45
46







-
-
+
+










-
+







-
-
+
-







#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"

package provide app-diff 1.0
package require Tcl 8.3
package require Tk
package require Tcl 8.4
package require Tk 8.4
catch {package require textSearch}

if {[catch {package require psballoon}]} {
    # Add a dummy if it does not exists.
    proc addBalloon {args} {}
} else {
    namespace import -force psballoon::addBalloon
}

set debug 1
set diffver "Version 1.9.8+  2003-09-01"
set diffver "Version 2.0a1  2003-09-28"
set thisScript [file join [pwd] [info script]]
set thisDir [file dirname $thisScript]

# Follow any link
set tmplink $thisScript
while {[file type $tmplink] == "link"} {
    set tmplink [file readlink $tmplink]
    # Change to this when this app starts to require 8.4
    #set tmplink [file normalize [file join $thisDir $tmplink]]
    set tmplink [file normalize [file join $thisDir $tmplink]]
    set tmplink [file join $thisDir $tmplink]
    set thisDir [file dirname $tmplink]
}
unset tmplink

set ::util(cvsExists) [expr {![string equal [auto_execok cvs] ""]}]
set ::util(diffexe) diff
set ::util(diffWrapped) 0
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
107
108
109
110
111
112
113


114
115
116
117
118
119
120
121







-
-
+







    if {$::tcl_platform(platform) == "unix"} {
        set util(editor) emacs
    } else {
        set util(editor) wordpad
        foreach dir [lsort -decreasing -dictionary \
                             [glob -nocomplain c:/apps/emacs*]] {
            set em [file join $dir bin runemacs.exe]
            # Remove catch when this app starts to require 8.4
            catch {set em [file normalize $em]}
            set em [file normalize $em]
            if {[file exists $em]} {
                set util(editor) $em
                break
            }
        }
    }
}
2698
2699
2700
2701
2702
2703
2704
2705

2706
2707
2708
2709
2710
2711
2712
2695
2696
2697
2698
2699
2700
2701

2702
2703
2704
2705
2706
2707
2708
2709







-
+








proc rowPopup {w X Y x y} {
    set top [winfo toplevel $w]
    if {[info exists ::diff($top,nopopup)] && $::diff($top,nopopup)} return
    destroy .lpm
    menu .lpm

    regexp {\d+} $w n
    regexp {(\d+)\D*$} $w -> n
    if {[alignMenu .lpm $top $n $x $y]} {
        return
    }

    set ::diff($top,nopopup) 1
    tk_popup .lpm $X $Y
    after idle [list after 1 [list set ::diff($top,nopopup) 0]]
2727
2728
2729
2730
2731
2732
2733
2734

2735
2736
2737
2738
2739
2740
2741
2724
2725
2726
2727
2728
2729
2730

2731
2732
2733
2734
2735
2736
2737
2738







-
+







    set top [winfo toplevel $w]
    # Get the row that was clicked
    set index [$w index @$x,$y]
    set row [lindex [split $index "."] 0]

    # Check if it is selected
    if {[lsearch [$w tag names $index] sel] >= 0} {
        regexp {\d+} $w n
        regexp {(\d+)\D*$} $w -> n
        hlPopup $top $n "" $X $Y $x $y
        return
    }

    # Extract the data
    set data(1) [$::diff($top,wDiff1) dump -tag -text $row.0 $row.end]
    set data(2) [$::diff($top,wDiff2) dump -tag -text $row.0 $row.end]
2782
2783
2784
2785
2786
2787
2788
2789

2790
2791
2792

2793
2794
2795

2796
2797

2798
2799
2800
2801
2802
2803

2804
2805

2806
2807
2808
2809
2810
2811
2812

2813
2814
2815
2816
2817
2818
2819
2779
2780
2781
2782
2783
2784
2785

2786
2787
2788

2789
2790
2791

2792
2793

2794
2795
2796
2797
2798
2799

2800
2801

2802
2803
2804
2805
2806
2807
2808

2809
2810
2811
2812
2813
2814
2815
2816







-
+


-
+


-
+

-
+





-
+

-
+






-
+







    }

    # Let geometry requests propagate
    update idletasks

    # Is the balloon within the diff window?
    set wid [winfo reqwidth $top.balloon]
    if {$wid + $wx > [winfo rootx .] + [winfo width .]} {
    if {$wid + $wx > [winfo rootx $top] + [winfo width $top]} {
        # No.
        # Center on diff window
        set wx [expr {([winfo width .] - $wid) / 2 + [winfo rootx .]}]
        set wx [expr {([winfo width $top] - $wid) / 2 + [winfo rootx $top]}]
        if {$wx < 0} {set wx 0}
        # Is the balloon not within the screen?
        if {$wx + $wid > [winfo screenwidth .]} {
        if {$wx + $wid > [winfo screenwidth $top]} {
            # Center in screen
            set wx [expr {([winfo screenwidth .] - $wid) / 2}]
            set wx [expr {([winfo screenwidth $top] - $wid) / 2}]
            if {$wx < 0} {set wx 0}
        }
    }

    # Does the balloon fit within the screen?
    if {$wid > [winfo screenwidth .]} {
    if {$wid > [winfo screenwidth $top]} {
        # How many rows does it take?
        set rows [expr {ceil(double($wid) / [winfo screenwidth .])}]
        set rows [expr {ceil(double($wid) / [winfo screenwidth $top])}]
        # Add rows and fill screen width
        $top.balloon.t1 configure -height $rows
        $top.balloon.t2 configure -height $rows
        # Let geometry requests propagate
        update idletasks
        wm geometry $top.balloon \
                [winfo screenwidth .]x[winfo reqheight $top.balloon]
                [winfo screenwidth $top]x[winfo reqheight $top.balloon]
        set wx 0
    }
    wm geometry $top.balloon +$wx+$wy
    wm deiconify $top.balloon
}

proc unzoomRow {w} {
2939
2940
2941
2942
2943
2944
2945
2946

2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2936
2937
2938
2939
2940
2941
2942

2943



2944
2945
2946
2947
2948
2949
2950







-
+
-
-
-







    set font [$w cget -font]
    destroy $w

    entry $w -relief flat -bd 0 -highlightthickness 0 \
            -foreground $fg -background $bg -font $font
    eval $w configure $args

    $w configure -takefocus 0 -state disabled
    $w configure -takefocus 0 -state readonly -readonlybackground $bg
    if {[info tclversion] >= 8.4} {
        $w configure -state readonly -readonlybackground $bg
    }

    set i [lsearch $args -textvariable]
    if {$i >= 0} {
	set var [lindex $args [expr {$i + 1}]]
	uplevel \#0 "trace variable $var w \
		{after idle {$w xview end} ;#}"
    }
3290
3291
3292
3293
3294
3295
3296
3297
3298


3299
3300
3301
3302
3303
3304
3305
3284
3285
3286
3287
3288
3289
3290


3291
3292
3293
3294
3295
3296
3297
3298
3299







-
-
+
+







                -command [list makeDiffWin $top]
        $top.md.m add separator
        $top.md.m add command -label "Normal Cursor" \
                -command [list normalCursor $top]
        $top.md.m add separator
        $top.md.m add command -label "Evalstats" -command {evalstats}
        $top.md.m add command -label "_stats" -command {parray _stats}
        $top.md.m add command -label "Nuisance" -command {makeNuisance \
                "It looks like you are trying out the debug menu."}
        $top.md.m add command -label "Nuisance" -command [list makeNuisance \
                $top "It looks like you are trying out the debug menu."]
        pack $top.md -in $top.f -side left -padx 20 -anchor n
    }

    initDiffData $top
}

# Set new preferences.
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605

3606
3607
3608
3609
3610
3611
3612
3488
3489
3490
3491
3492
3493
3494




































































































3495
3496
3497
3498

3499
3500
3501
3502
3503
3504
3505
3506







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+







    exampleFont $lb
}

#####################################
# Registry section
#####################################

# A little labelframe thingy for pre 8.4
proc myLabelFrame {w args} {
    if {[info tclversion] >= 8.4} {
        return [eval [list labelframe $w] $args]
    }
    if {([llength $args] % 2) != 0} {
        error "wrong # args: should be \"myLabelFrame pathName ?options?\""
    }

    set allopts {}
    set fopts {}
    set lopts {}
    set labelanchor nw
    set padx 0
    set pady 0
    set bd 2
    set relief groove
    set labelwindow ""
    set text ""

    foreach {opt val} $args {
        switch -- $opt {
            -bd - -borderwidth {
                set bd $val
            }
            -relief {
                set relief $val
            }
            -text {
                lappend lopts $opt $val
                set text $val
            }
            -font - -fg - -foreground {
                lappend lopts $opt $val
            }
            -labelanchor {
                set labelanchor $val
            }
            -labelwindow {
                set labelwindow $val
            }
            -padx {
                set padx $val
            }
            -pady {
                set pady $val
            }
            -bg - -background - -cursor {
                lappend allopts $opt $val
            }
            default {
                error "Unknown or unsupported option: $opt"
            }
        }
    }
    lappend fopts -relief $relief -bd $bd

    eval [list frame $w] $allopts
    eval [list frame $w.bd] $fopts $allopts 
    if {$labelwindow != ""} {
        set lw $labelwindow
        raise $labelwindow $w
    } elseif {$text != ""} {
        set lw $w.l
        eval [list label $lw] $lopts $allopts -highlightthickness 0 -bd 0
    } else {
        set lw ""
    }
    eval [list frame $w.f] $allopts

    grid columnconfigure $w {2 4} -minsize $padx
    grid rowconfigure $w {2 4} -minsize $pady
    grid columnconfigure $w 3 -weight 1
    grid rowconfigure $w 3 -weight 1
    grid columnconfigure $w {1 5} -minsize $bd
    grid rowconfigure $w {1 5} -minsize $bd

    grid $w.bd -row 1 -col 1 -rowspan 5 -columnspan 5 -sticky news
    grid $w.f -row 3 -col 3 -sticky news

    if {$lw != ""} {
        switch -glob $labelanchor {
            n* {
                grid $lw -in $w -row 0 -col 2 -rowspan 2 -columnspan 3 -padx 4
            }
            s* {
                grid $lw -in $w -row 5 -col 2 -rowspan 2 -columnspan 3 -padx 4
            }
            w* {
                grid $lw -in $w -row 2 -col 0 -rowspan 3 -columnspan 2 -pady 4
            }
            e* {
                grid $lw -in $w -row 2 -col 5 -rowspan 3 -columnspan 2 -pady 4
            }
        }
        grid $lw -sticky [string index $labelanchor 1]
    }
    return $w.f
}

proc makeRegistryFrame {w label key newvalue} {
    set old {}
    catch {set old [registry get $key {}]}

    set l [myLabelFrame $w -text $label -padx 4 -pady 4]
    set l [labelframe $w -text $label -padx 4 -pady 4]

    label $l.key1 -text "Key:"
    label $l.key2 -text $key
    label $l.old1 -text "Old value:"
    label $l.old2 -text $old
    label $l.new1 -text "New value:"
    label $l.new2 -text $newvalue
3622
3623
3624
3625
3626
3627
3628















3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551



3552
3553
3554
3555
3556
3557
3558







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
-
-







    grid $l.new1 $l.new2 -sticky w -padx 4 -pady 4
    grid $l.change -     -sticky e -padx 4 -pady 4
    grid columnconfigure $l 1 -weight 1
}

proc makeRegistryWin {} {
    global thisDir thisScript util

    # Locate executable for this program
    set exe [info nameofexecutable]
    if {[regexp {^(.*wish)\d+\.exe$} $exe -> pre]} {
        set alt $pre.exe
        if {[file exists $alt]} {
            set a [tk_messageBox -icon question -title "Which Wish" -message \
                    "Would you prefer to use the executable\n\
                    \"$alt\"\ninstead of\n\
                    \"$exe\"\nin the registry settings?" -type yesno]
            if {$a == "yes"} {
                set exe $alt
            }
        }
    }

    set top .reg
    destroy $top
    toplevel $top
    wm title $top "Register Diff"

    # Registry keys

    #set keyg {HKEY_CLASSES_ROOT\Folder\shell\Grep\command}
    set keydd {HKEY_CLASSES_ROOT\Folder\shell\Diff\command}
    set keyd {HKEY_CLASSES_ROOT\*\shell\Diff\command}
    set keyc {HKEY_CLASSES_ROOT\*\shell\DiffC\command}
    set keye {HKEY_CLASSES_ROOT\*\shell\Emacs\command}
    
    # Locate executable for this program
    set exe [info nameofexecutable]

    # Are we in a starkit?
    if {[info exists ::starkit::topdir]} {
        # In a starpack ?
        set exe [file normalize $exe]
        if {[string equal [file normalize $::starkit::topdir] $exe]} {
            set myexe [list $exe]
        } else {
4178
4179
4180
4181
4182
4183
4184
4185

4186
4187
4188

4189
4190

4191
4192

4193
4194
4195
4196
4197
4198
4199



4200
4201
4202



4203
4204
4205
4206


4207
4208


4209
4210
4211
4212
4213
4214
4215
4084
4085
4086
4087
4088
4089
4090

4091
4092
4093

4094
4095

4096
4097
4098
4099
4100
4101
4102
4103
4104


4105
4106
4107
4108


4109
4110
4111
4112
4113
4114

4115
4116
4117

4118
4119
4120
4121
4122
4123
4124
4125
4126







-
+


-
+

-
+


+





-
-
+
+
+

-
-
+
+
+



-
+
+

-
+
+







                    -onvalue show -offvalue hide -command {console $consolestate}
            $top.md.m add separator
        }
        $top.md.m add command -label "Reread Source" -underline 0 \
                -command {source $thisScript}
        $top.md.m add separator
        $top.md.m add command -label "Redraw Window" -command {makeDirDiffWin 1}
        pack $top.md -in $top.fm -side left -padx 20
        pack $top.md -in $top.fm -side left -padx 20 -anchor n
    }

    button $top.bu -text "Up Both" -command upDir -underline 0
    button $top.bu -text "Up Both" -command upDir -underline 0 -padx 10
    bind $top <Alt-u> "$top.bu invoke"
    button $top.bc -text "Compare" -command doCompare -underline 0
    button $top.bc -text "Compare" -command doCompare -underline 0 -padx 10
    bind $top <Alt-c> "$top.bc invoke"
    pack $top.bc $top.bu -in $top.fm -side right
    pack $top.bu -padx 6

    catch {font delete myfont}
    font create myfont -family $Pref(fontfamily) -size $Pref(fontsize)

    entry $top.e1 -textvariable dirdiff(leftDir)
    button $top.bu1 -text "Up" -command {upDir 1}
    button $top.bb1 -text "Browse" -command {browseDir dirdiff(leftDir)}
    button $top.bu1 -text "Up" -padx 10 -command {upDir 1}
    button $top.bb1 -text "Browse"  -padx 10 \
            -command {browseDir dirdiff(leftDir)}
    entry $top.e2 -textvariable dirdiff(rightDir)
    button $top.bu2 -text "Up" -command {upDir 2}
    button $top.bb2 -text "Browse" -command {browseDir dirdiff(rightDir)}
    button $top.bu2 -text "Up" -padx 10 -command {upDir 2}
    button $top.bb2 -text "Browse" -padx 10 \
            -command {browseDir dirdiff(rightDir)}
    bind $top.e1 <Return> doCompare
    bind $top.e2 <Return> doCompare

    pack $top.bb1 $top.bu1 -in $top.fe1 -side right
    pack $top.bb1 $top.bu1 -in $top.fe1 -side right -pady 1
    pack $top.bu1 -padx 6
    pack $top.e1 -in $top.fe1 -side left -fill x -expand 1
    pack $top.bb2 $top.bu2 -in $top.fe2 -side right
    pack $top.bb2 $top.bu2 -in $top.fe2 -side right -pady 1
    pack $top.bu2 -padx 6
    pack $top.e2 -in $top.fe2 -side left -fill x -expand 1

    text $top.t1 -height 40 -width 60 -wrap none -font myfont \
	    -xscrollcommand "$top.sbx1 set" -takefocus 0
    scrollbar $top.sby -orient vertical
    scrollbar $top.sbx1 -orient horizontal -command "$top.t1 xview"
    text $top.t2 -height 40 -width 60 -wrap none -font myfont \
4327
4328
4329
4330
4331
4332
4333
4334

4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350








4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361










4362
4363
4364
4365
4366
4367
4368
4238
4239
4240
4241
4242
4243
4244

4245
4246
4247
4248
4249
4250
4251
4252
4253








4254
4255
4256
4257
4258
4259
4260
4261
4262
4263









4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280







-
+








-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







    grid columnconfigure $top {0 1} -weight 1
}

#####################################
# Help and startup functions
#####################################

proc makeNuisance {{str {Hi there!}}} {
proc makeNuisance {top {str {Hi there!}}} {
    global thisDir

    if {[lsearch [image names] nuisance] < 0} {
        set file [file join $thisDir Nuisance.gif]
        if {![file exists $file]} return
        image create photo nuisance -file $file
    }

    destroy .nui
    toplevel .nui
    wm transient .nui .
    wm geometry .nui +400+400
    wm title .nui ""
    label .nui.l -image nuisance
    pack .nui.l
    wm protocol .nui WM_DELETE_WINDOW {destroy .nui2 .nui}
    destroy $top.nui
    toplevel $top.nui
    wm transient $top.nui $top
    wm geometry $top.nui +400+400
    wm title $top.nui ""
    label $top.nui.l -image nuisance
    pack $top.nui.l
    wm protocol $top.nui WM_DELETE_WINDOW [list destroy $top.nui2 $top.nui]
    update

    destroy .nui2
    toplevel .nui2 -bg yellow
    wm transient .nui2 .nui
    wm overrideredirect .nui2 1
    wm title .nui2 ""
    label .nui2.l -text "$str\nDo you want help?" -justify left -bg yellow
    button .nui2.b -text "No, get out of my face!" -command {destroy .nui2 .nui} -bg yellow
    pack .nui2.l .nui2.b -side top -fill x
    wm geometry .nui2 +[expr {405 + [winfo width .nui]}]+400
    destroy $top.nui2
    toplevel $top.nui2 -bg yellow
    wm transient $top.nui2 $top.nui
    wm overrideredirect $top.nui2 1
    wm title $top.nui2 ""
    label $top.nui2.l -text "$str\nDo you want help?" -justify left -bg yellow
    button $top.nui2.b -text "No, get out of my face!" \
            -command [list destroy $top.nui2 $top.nui] -bg yellow
    pack $top.nui2.l $top.nui2.b -side top -fill x
    wm geometry $top.nui2 +[expr {405 + [winfo width $top.nui]}]+400
}

proc helpWin {w title} {
    destroy $w

    toplevel $w
    wm title $w $title
4594
4595
4596
4597
4598
4599
4600
4601
4602


4603
4604
4605

4606
4607
4608
4609
4610
4611
4612
4506
4507
4508
4509
4510
4511
4512


4513
4514
4515
4516

4517
4518
4519
4520
4521
4522
4523
4524







-
-
+
+


-
+







            set nextArg revision
        } elseif {[string range $arg 0 1] == "-r"} {
            set opts(doptrev$revNo) [string range $arg 2 end]
            incr revNo
        } elseif {[string range $arg 0 0] == "-"} {
            append opts(dopt) " $arg"
        } else {
            set apa [glob -nocomplain [file join [pwd] $arg]]
            if {$apa == ""} {
            set apa [file normalize [file join [pwd] $arg]]
            if {![file exists $apa]} {
                puts "Ignoring argument: $arg"
            } else {
                lappend files [lindex $apa 0]
                lappend files $apa
            }
        }
    }

    # Do we start in clip diff mode?
    if {$doclip} {
        makeClipDiffWin