Eskil

Diff
Login

Differences From Artifact [92cb24a78a]:

To Artifact [a8e9684bb6]:


14
15
16
17
18
19
20




21
22
23




24
25
26
27
28
29
30
14
15
16
17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
32
33
34
35







+
+
+
+
-
-
-
+
+
+
+







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

package provide app-diff 1.0
package require Tk
catch {package require textSearch}
if {[catch {package require psballoon}]} {
    proc addBalloon {args} {}
} else {
    namespace import -force psballoon::addBalloon

set debug 1
set diffver "Version 1.9.7+  2003-08-07"
}

set debug 0
set diffver "Version 1.9.8  2003-08-13"
set tmpcnt 0
set tmpfiles {}
set thisscript [file join [pwd] [info script]]
set thisdir [file dirname $thisscript]
set ::diff(cvsExists) [expr {![string equal [auto_execok cvs] ""]}]
set ::diff(diffexe) diff
set ::diff(thisexe) [list [info nameofexecutable] $thisscript]
913
914
915
916
917
918
919
920

921
922
923
924

925
926
927
928
929
930
931
918
919
920
921
922
923
924

925
926
927
928

929
930
931
932
933
934
935
936







-
+



-
+







                incr mapMax $n1
            }
        }
    }
}

proc enableRedo {} {
    .mf.m entryconfigure 1 -state normal
    .mf.m entryconfigure 0 -state normal
}

proc disableRedo {} {
    .mf.m entryconfigure 1 -state disabled
    .mf.m entryconfigure 0 -state disabled
}

proc busyCursor {} {
    global oldcursor oldcursor2
    if {![info exists oldcursor]} {
        set oldcursor [. cget -cursor]
        set oldcursor2 [.ft1.tt cget -cursor]
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286

1287
1288
1289
1290
1291
1292
1293
1294



1295
1296
1297
1298
1299
1300
1301
1277
1278
1279
1280
1281
1282
1283


1284
1285


1286


1287








1288
1289
1290
1291
1292
1293
1294
1295
1296
1297







-
-


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







}

# Prepare for RCS/CVS diff. Checkout copies of the versions needed.
proc prepareRCS {} {
    global diff Pref

    set revs {}
    set opts {}
    set Pref(old_dopt) $Pref(dopt)

    # Search for revision options
    set nextIsRev 0
    foreach opt $Pref(dopt) {
    if {$Pref(doptrev1) != ""} {
        if {$nextIsRev} {
            lappend revs $opt
        lappend revs $Pref(doptrev1)
            set nextIsRev 0
        } elseif {[string equal "-r" $opt]} {
            set nextIsRev 1
        } elseif {[string match "-r*" $opt]} {
            lappend revs [string range $opt 2 end]
        } else {
            lappend opts $opt
        }
    }
    if {$Pref(doptrev2) != ""} {
        lappend revs $Pref(doptrev2)
    }

    switch [llength $revs] {
        0 {
            # Compare local file with latest version.
            set diff(leftFile) [tmpfile]
            set diff(rightLabel) $diff(RCSFile)
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352
1353


1354
1355
1356
1357
1358
1359
1360







-









-
-







                catch {exec co -p$r1 [file nativename $diff(RCSFile)] > $diff(leftFile)}
                catch {exec co -p$r2 [file nativename $diff(RCSFile)] > $diff(rightFile)}
            }
        }
    }
    # Make sure labels are updated before processing starts
    update idletasks
    set Pref(dopt) $opts
}

# Clean up after a RCS/CVS diff.
proc cleanupRCS {} {
    global diff Pref

    cleartmp
    set diff(rightFile) $diff(RCSFile)
    set diff(leftFile) $diff(RCSFile)
    set Pref(dopt) $Pref(old_dopt)
    unset Pref(old_dopt)
}

# Prepare for a diff by creating needed temporary files
proc prepareFiles {} {
    if {$::diff(mode) == "RCS" || $::diff(mode) == "CVS"} {
        prepareRCS
    } elseif {[string match "conflict*" $::diff(mode)]} {
2742
2743
2744
2745
2746
2747
2748

2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768






2769
2770

2771
2772
2773

2774
2775
2776

2777
2778
2779
2780

2781
2782
2783
2784
2785




2786
2787
2788
2789
2790
2791
2792
2793
2794
2795

2796
2797
2798
2799
2800
2801
2802
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756






2757
2758
2759
2760
2761
2762
2763

2764
2765
2766

2767
2768
2769

2770
2771
2772
2773

2774
2775




2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788

2789
2790
2791
2792
2793
2794
2795
2796







+














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

-
+


-
+


-
+



-
+

-
-
-
-
+
+
+
+









-
+







}

# Build the main window
proc makeDiffWin {} {
    global Pref tcl_platform debug
    eval destroy [winfo children .]

    option add *Menu.tearOff 0
    wm protocol . WM_DELETE_WINDOW cleanupAndExit

    frame .f
    grid .f - - - -row 0 -sticky news

    menubutton .mf -text File -underline 0 -menu .mf.m
    menu .mf.m
    if {$debug == 1} {
        .mf.m add command -label "Redo Diff" -underline 5 -command doDiff
    } else {
        .mf.m add command -label "Redo Diff" -underline 5 -command doDiff \
                -state disabled
    }
    .mf.m add separator
    .mf.m add command -label "Open Both" -underline 0 -command {openBoth 0}
    .mf.m add command -label "Open Both (forget)" -command {openBoth 1}
    .mf.m add command -label "Open Left File" -command openLeft
    .mf.m add command -label "Open Right File" -command openRight
    .mf.m add command -label "Open Conflict File" -command openConflict
    .mf.m add command -label "Open Patch File" -command openPatch
    .mf.m add command -label "Open Both..." -underline 0 -command {openBoth 0}
    .mf.m add command -label "Open Both (forget)..." -command {openBoth 1}
    .mf.m add command -label "Open Left File..." -command openLeft
    .mf.m add command -label "Open Right File..." -command openRight
    .mf.m add command -label "Open Conflict File..." -command openConflict
    .mf.m add command -label "Open Patch File..." -command openPatch
    if {$tcl_platform(platform) == "unix"} {
        .mf.m add command -label "RCSDiff" -underline 0 -command openRCS
        .mf.m add command -label "RCSDiff..." -underline 0 -command openRCS
    }
    if {$::diff(cvsExists)} {
        .mf.m add command -label "CVSDiff" -underline 0 -command openCVS
        .mf.m add command -label "CVSDiff..." -underline 0 -command openCVS
    }
    .mf.m add separator
    .mf.m add command -label "Print" -underline 0 -command doPrint
    .mf.m add command -label "Print..." -underline 0 -command doPrint
    .mf.m add separator
    .mf.m add command -label "Quit" -underline 0 -command cleanupAndExit

    menubutton .mo -text Options -underline 0 -menu .mo.m
    menubutton .mo -text "Options" -underline 0 -menu .mo.m
    menu .mo.m
    .mo.m add cascade -label Font -underline 0 -menu .mo.mf
    .mo.m add cascade -label Ignore -underline 0 -menu .mo.mi
    .mo.m add cascade -label Parse -underline 0 -menu .mo.mp
    .mo.m add command -label Colours -underline 0 -command makePrefWin
    .mo.m add cascade -label "Font" -underline 0 -menu .mo.mf
    .mo.m add cascade -label "Ignore" -underline 0 -menu .mo.mi
    .mo.m add cascade -label "Parse" -underline 0 -menu .mo.mp
    .mo.m add command -label "Colours..." -underline 0 -command makePrefWin
    .mo.m add checkbutton -label "Diffs only" -variable Pref(onlydiffs)
    if {$tcl_platform(platform) == "windows"} {
        .mo.m add checkbutton -label "Force crlf translation" \
                -variable Pref(crlf)
    }
    .mo.m add separator
    .mo.m add command -label "Save default" -command saveOptions

    menu .mo.mf
    .mo.mf add command -label "Select" -command makeFontWin
    .mo.mf add command -label "Select..." -command makeFontWin
    .mo.mf add radiobutton -label 6 -variable Pref(fontsize) -value 6 \
            -command chFont
    .mo.mf add radiobutton -label 7 -variable Pref(fontsize) -value 7 \
            -command chFont
    .mo.mf add radiobutton -label 8 -variable Pref(fontsize) -value 8 \
            -command chFont
    .mo.mf add radiobutton -label 9 -variable Pref(fontsize) -value 9 \
2827
2828
2829
2830
2831
2832
2833


2834
2835
2836
2837
2838
2839
2840











2841
2842
2843
2844




2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860


2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873


2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889


2890

2891
2892
2893
2894
2895
2896
2897
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847




2848
2849
2850
2851


2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864

2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878

2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907







+
+







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













-
+
+












-
+
+
















+
+

+







            -variable Pref(extralineparse)
    .mo.mp add checkbutton -label "Mark last" -variable Pref(marklast)

    menubutton .ms -text Search -underline 0 -menu .ms.m
    menu .ms.m
    if {[info proc textSearch::searchMenu] != ""} {
        textSearch::searchMenu .ms.m
    } else {
        .ms.m add command -label "Text search not available" -state disabled
    }

    menubutton .mh -text Help -underline 0 -menu .mh.m
    menu .mh.m
    .mh.m add command -label "Help" -command makeHelpWin
    .mh.m add command -label "About" -command makeAboutWin

    label .lo -text "Diff Options"
    addBalloon .lo "Options passed to the external diff.\nNote\
            that options for ignoring whitespace are available in\
            the Options menu."
    entry .eo -width 6 -textvariable Pref(dopt)
    label .lr1 -text "Rev 1"
    addBalloon .lr1 "Revision number for CVS/RCS diff."
    entry .er1 -width 6 -textvariable Pref(doptrev1)
    label .lr2 -text "Rev 2"
    addBalloon .lr2 "Revision number for CVS/RCS diff."
    entry .er2 -width 6 -textvariable Pref(doptrev2)
    button .bfn -text "Next Diff" -relief raised -command {findDiff 1} \
            -underline 0
    button .bfp -text "Prev Diff" -relief raised -command {findDiff -1} \
            -underline 0
    button .bfp -text "Prev Diff" -relief raised -command {findDiff -1} \
            -underline 0 -padx 15
    button .bfn -text "Next Diff" -relief raised -command {findDiff 1} \
            -underline 0 -padx 15
    entry .eo -width 10 -textvariable Pref(dopt)
    label .lo -text "Diff Options"
    bind . <Alt-n> {findDiff 1}
    bind . <Alt-p> {findDiff -1}

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

    #label .l1 -textvariable diff(leftLabel) -anchor e -width 10
    #label .l2 -textvariable diff(rightLabel) -anchor e -width 10
    fileLabel .l1 -textvariable diff(leftLabel)
    fileLabel .l2 -textvariable diff(rightLabel)

    frame .ft1 -borderwidth 2 -relief sunken
    text .ft1.tl -height 40 -width 5 -wrap none -yscrollcommand my_yscroll \
            -font myfont -borderwidth 0 -padx 0 -highlightthickness 0
            -font myfont -borderwidth 0 -padx 0 -highlightthickness 0 \
            -takefocus 0
    text .ft1.tt -height 40 -width 80 -wrap none -yscrollcommand my_yscroll \
            -xscrollcommand ".sbx1 set" -font myfont -borderwidth 0 -padx 1 \
            -highlightthickness 0
    frame .ft1.f -width 2 -height 2 -bg lightgray
    pack .ft1.tl -side left -fill y
    pack .ft1.f -side left -fill y
    pack .ft1.tt -side right -fill both -expand 1
    scrollbar .sby -orient vertical -command "my_yview"
    scrollbar .sbx1 -orient horizontal -command ".ft1.tt xview"

    frame .ft2 -borderwidth 2 -relief sunken
    text .ft2.tl -height 60 -width 5 -wrap none -yscrollcommand my_yscroll \
            -font myfont -borderwidth 0 -padx 0 -highlightthickness 0
            -font myfont -borderwidth 0 -padx 0 -highlightthickness 0 \
            -takefocus 0
    text .ft2.tt -height 60 -width 80 -wrap none -yscrollcommand my_yscroll \
            -xscrollcommand ".sbx2 set" -font myfont -borderwidth 0 -padx 1 \
            -highlightthickness 0
    frame .ft2.f -width 2 -height 2 -bg lightgray
    pack .ft2.tl -side left -fill y
    pack .ft2.f -side left -fill y
    pack .ft2.tt -side right -fill both -expand 1
    scrollbar .sbx2 -orient horizontal -command ".ft2.tt xview"

    # Set up a tag for incremental search bindings
    if {[info proc textSearch::enableSearch] != ""} {
        textSearch::enableSearch .ft1.tt -label ::diff(isearchLabel)
        textSearch::enableSearch .ft2.tt -label ::diff(isearchLabel)
    }

    label .le -textvariable ::diff(eqLabel) -width 1
    addBalloon .le "* means external diff is running.\n= means files do\
            not differ.\nBlank means files differ."
    label .ls -width 1 -pady 0 -padx 0 -textvariable ::diff(isearchLabel)
    addBalloon .ls "Incremental search indicator"
    canvas .c -width 6 -bd 0 -selectborderwidth 0 -highlightthickness 0


    applyColor
    .ft1.tt tag configure last -underline 1
    .ft2.tt tag configure last -underline 1
    foreach w {.ft1.tt .ft2.tt} {
2905
2906
2907
2908
2909
2910
2911

2912

2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923

2924

2925
2926

2927
2928
2929
2930
2931
2932
2933
2915
2916
2917
2918
2919
2920
2921
2922

2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935

2936
2937

2938
2939
2940
2941
2942
2943
2944
2945







+
-
+











+
-
+

-
+








    grid .l1   .le -    .l2   -row 1 -sticky news
    grid .ft1  .c  .sby .ft2  -row 2 -sticky news
    grid .sbx1 .ls -    .sbx2 -row 3 -sticky news
    grid columnconfigure . {0 3} -weight 1
    grid rowconfigure . 2 -weight 1
    grid .c -pady [expr {[.sby cget -width] + 2}]
    grid .ls -sticky ""

    
    image create photo map
    .c create image 0 0 -anchor nw -image map
    bind .c <Configure> {drawMap %h}

    bind . <Key-Up> {scroll -1 u}
    bind . <Key-Down> {scroll 1 u}
    bind . <Key-Prior> {scroll -1 p}
    bind . <Key-Next> {scroll 1 p}
    bind . <Key-Escape> {focus .}

    pack .mf .mo .ms .mh -in .f -side left
    pack .bfn -in .f -side right -padx {3 6}
    pack .bfn .bfp .eo .lo -in .f -side right
    pack .bfp .er2 .lr2 .er1 .lr1 .eo .lo -in .f -side right -padx 3
    if {$debug == 1} {
        menubutton .md -text Debug -menu .md.m -relief ridge
        menubutton .md -text Debug -menu .md.m
        menu .md.m
        if {$tcl_platform(platform) == "windows"} {
            .md.m add checkbutton -label Console -variable consolestate \
                    -onvalue show -offvalue hide \
                    -command {console $consolestate}
            .md.m add separator
        }
3455
3456
3457
3458
3459
3460
3461

3462
3463
3464
3465
3466
3467
3468
3469


3470
3471
3472
3473
3474
3475
3476
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481

3482
3483
3484
3485
3486
3487
3488
3489
3490







+







-
+
+







    set diff(conflictFile) ""
    set diff(limitlines) 0

    if {$argc == 0} return

    set files ""
    set nextArg ""
    set revNo 1
    foreach arg $argv {
        if {$nextArg != ""} {
            if {$nextArg == "mergeFile"} {
                set diff(mergeFile) [file join [pwd] $arg]
            } elseif {$nextArg == "printFile"} {
                set diff(printFile) [file join [pwd] $arg]
            } elseif {$nextArg == "revision"} {
                set Pref(dopt) "$Pref(dopt) -r$arg"
                set Pref(doptrev$revNo) $arg
                incr revNo
            } elseif {$nextArg == "limitlines"} {
                set diff(limitlines) $arg
            }
            set nextArg ""
            continue
        }
        if {$arg == "-w"} {
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







+
+
+







            } else {
                tk appname Diff
            }
        } elseif {$arg == "-o"} {
            set nextArg mergeFile
        } elseif {$arg == "-r"} {
            set nextArg revision
        } elseif {[string range $arg 0 1] == "-r"} {
            set Pref(doptrev$revNo) [string range $arg 2 end]
            incr revNo
        } elseif {[string range $arg 0 0] == "-"} {
            set Pref(dopt) "$Pref(dopt) $arg"
        } else {
            set apa [glob -nocomplain [file join [pwd] $arg]]
            if {$apa == ""} {
                puts "Ignoring argument: $arg"
            } else {
3642
3643
3644
3645
3646
3647
3648
3649

3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662


3663
3664
3665
3666
3667
3668
3669
3659
3660
3661
3662
3663
3664
3665

3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688







-
+













+
+







    if {[catch {set ch [open "~/.diffrc" w]} err]} {
        tk_messageBox -icon error -title "File error" -message \
                "Error when trying to save preferences:\n$err"
        return
    }

    foreach i [array names Pref] {
        if {$i != "dopt"} {
        if {![string match "dopt*" $i]} {
            puts $ch [list set Pref($i) $Pref($i)]
        }
    }
    close $ch
}

proc getOptions {} {
    global Pref

    set Pref(fontsize) 9
    set Pref(fontfamily) courier
    set Pref(ignore) "-b"
    set Pref(dopt) ""
    set Pref(doptrev1) ""
    set Pref(doptrev2) ""
    set Pref(parse) 2
    set Pref(lineparsewords) "0"
    set Pref(extralineparse) 1
    set Pref(colorchange) red
    set Pref(colornew1) darkgreen
    set Pref(colornew2) blue
    set Pref(bgchange) #ffe0e0