Eskil

Diff
Login

Differences From Artifact [4a935d8c13]:

To Artifact [84b89584b4]:


61
62
63
64
65
66
67
68
69


70
71
72
73
74
75
76
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76







-
-
+
+







#     1.6     DA-PS    000131   Added scroll-keys
#                               Bug-fixes in scroll map and printing
#
#-----------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"

set debug 0
set diffver "Version 1.6  000131"
set debug 1
set diffver "Version 1.7b  000426"
set tmpcnt 0
set thisscript [file join [pwd] [info script]]
set thisdir [file dirname $thisscript]

if {$tcl_platform(platform) == "windows"} {
    cd $thisdir
    package require dde
478
479
480
481
482
483
484





485
486
487
488
489
490
491
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496







+
+
+
+
+







}

#Decide how to display change blocks
proc compareblocks {block1 block2} {
    set size1 [llength $block1]
    set size2 [llength $block2]
    
    if {$size1 * $size2 > 1000} {
        puts "Diff warning: Analyzing a large block. ($size1 $size2)"
        update idletasks
    }

    #Swap if block1 is bigger
    if {$size1 > $size2} {
        set apa $block1
        set block1 $block2
        set block2 $apa
        set size1 [llength $block1]
        set size2 [llength $block2]
615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634







-
+







}

#Insert one line in each text widget.
#Mark them as changed, and optionally parse them.
proc insertMatchingLines {line1 line2} {
    global doingLine1 doingLine2 Pref

    if {$Pref(parse) != "none"} {
    if {$Pref(parse) != 0} {
        comparelines $line1 $line2 res1 res2
        set dotag 0
        set n [maxabs [llength $res1] [llength $res2]]
        .ft1.tl insert end [myforml $doingLine1] change
        .ft2.tl insert end [myforml $doingLine2] change
        set new1 new1
        set new2 new2
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726


727
728
729
730
731
732
733
714
715
716
717
718
719
720

721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738
739







-
+









-
+
+







        .ft2.tt insert end "**Bad alignment here!! $doingLine2 $line2**\n"
	.ft1.tl insert end "\n"
	.ft2.tl insert end "\n"
    }

    #Process the block

    if {$n1 == $n2 && ($n1 == 1 || $Pref(parse) != "block")} {
    if {$n1 == $n2 && ($n1 == 1 || $Pref(parse) < 2)} {
        for {set t 0} {$t < $n1} {incr t} {
            gets $ch1 line1
            gets $ch2 line2
            insertMatchingLines $line1 $line2
        }
        lappend mapList $mapMax
        incr mapMax $n1
        lappend mapList $mapMax change
    } else {
        if {$n1 != 0 && $n2 != 0 && $Pref(parse) == "block"} {
        if {$n1 != 0 && $n2 != 0 && $Pref(parse) >= 2 && \
                ($n1 * $n2 < 1000 || $Pref(parse) == 3)} {
            set block1 {}
            for {set t 0} {$t < $n1} {incr t} {
                gets $ch1 apa
                lappend block1 $apa
            }
            set block2 {}
            for {set t 0} {$t < $n2} {incr t} {
868
869
870
871
872
873
874
875

876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895





896


897
898
899
900
901
902
903
904





905


906
907
908
909
910
911
912
913
914








915
916



917
918
919
920
921
922
923
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

897
898
899
900
901
902
903
904
905

906
907
908
909
910

911
912
913
914
915
916
917
918
919

920
921
922
923
924
925

926

927
928
929
930
931
932
933
934
935
936


937
938
939
940
941
942
943
944
945
946







-
+















-




+
+
+
+
+
-
+
+



-




+
+
+
+
+
-
+
+




-

-


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







    . config -cursor $oldcursor
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
	$w config -cursor $oldcursor2
    }
}

proc prepareRCS {} {
    global leftFile rightFile RCSFile leftLabel rightLabel Pref
    global leftFile rightFile RCSFile leftLabel rightLabel Pref RCSmode

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

    foreach opt $Pref(dopt) {
        if {[string match "-r*" $opt]} {
            lappend revs [string range $opt 2 end]
        } else {
            lappend opts $opt
        }
    }

    switch [llength $revs] {
        0 {
            set leftLabel "$RCSFile (RCS)"
            set leftFile [tmpfile]
            set rightLabel $RCSFile
            set rightFile $RCSFile

            if {$RCSmode == 2} {
                set leftLabel "$RCSFile (CVS)"
                catch {exec cvs update -p [file nativename $RCSFile] > $leftFile}
            } else {
                set leftLabel "$RCSFile (RCS)"
            catch {exec co -p [file nativename $RCSFile] > $leftFile}
                catch {exec co -p [file nativename $RCSFile] > $leftFile}
            }
        }
        1 {
            set r [lindex $revs 0]
            set leftLabel "$RCSFile (RCS $r)"
            set leftFile [tmpfile]
            set rightLabel $RCSFile
            set rightFile $RCSFile

            if {$RCSmode == 2} {
                set leftLabel "$RCSFile (CVS $r)"
                catch {exec cvs update -p$r [file nativename $RCSFile] > $leftFile}
            } else {
                set leftLabel "$RCSFile (RCS $r)"
            catch {exec co -p$r [file nativename $RCSFile] > $leftFile}
                catch {exec co -p$r [file nativename $RCSFile] > $leftFile}
            }
        }
        default {
            set r1 [lindex $revs 0]
            set r2 [lindex $revs 1]
            set leftLabel "$RCSFile (RCS $r1)"
            set leftFile [tmpfile]
            set rightLabel "$RCSFile (RCS $r2)"
            set rightFile [tmpfile]
            
            if {$RCSmode == 2} {
                set leftLabel "$RCSFile (CVS $r1)"
                set rightLabel "$RCSFile (CVS $r2)"
                catch {exec cvs update -p$r1 [file nativename $RCSFile] > $leftFile}
                catch {exec cvs update -p$r2 [file nativename $RCSFile] > $rightFile}
            } else {
                set leftLabel "$RCSFile (RCS $r1)"
                set rightLabel "$RCSFile (RCS $r2)"
            catch {exec co -p$r1 [file nativename $RCSFile] > $leftFile}
            catch {exec co -p$r2 [file nativename $RCSFile] > $rightFile}
                catch {exec co -p$r1 [file nativename $RCSFile] > $leftFile}
                catch {exec co -p$r2 [file nativename $RCSFile] > $rightFile}
            }
        }
    }
    update idletasks
    set Pref(dopt) $opts
}

proc cleanupRCS {} {
953
954
955
956
957
958
959
960
961


962
963
964
965
966
967
968
976
977
978
979
980
981
982


983
984
985
986
987
988
989
990
991







-
-
+
+








    update idletasks

    if {$RCSmode} {
        prepareRCS
    }

    set differr [catch {eval exec diff $Pref(dopt) $Pref(ignore) $leftFile \
            $rightFile} diffres]
    set differr [catch {eval exec diff $Pref(dopt) $Pref(ignore) \$leftFile \
            \$rightFile} diffres]
    
    set apa [split $diffres "\n"]
    set result {}
    foreach i $apa {
        if {[string match {[0-9]*} $i]} {
            lappend result $i
        }
980
981
982
983
984
985
986
987

988
989
990
991
992
993
994
1003
1004
1005
1006
1007
1008
1009

1010
1011
1012
1013
1014
1015
1016
1017







-
+







        set eqLabel " "
    }

    set ch1 [open $leftFile]
    set ch2 [open $rightFile]
    set doingLine1 1
    set doingLine2 1

    set t 0
    foreach i $result {
        if {![regexp {(.*)([acd])(.*)} $i apa l c r]} {
            .ft1.tt insert 1.0 "No regexp match for $i\n"
        } else {
            if {[regexp {([0-9]+),([0-9]+)} $l apa start stop]} {
                set n1 [expr {$stop - $start + 1}]
                set line1 $start
1013
1014
1015
1016
1017
1018
1019






1020
1021
1022















1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034


1035
1036
1037
1038
1039
1040
1041
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087







+
+
+
+
+
+



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












+
+







                } 
                d {
                    # lucka i right, new i left
                    dotext $ch1 $ch2 $n1 0 $line1 [expr {$line2 + 1}]
                }
            }
        }
        if {[incr t] >= 10} { 
            update idletasks
            .ft2.tl see end
            update idletasks
            set t 0
        }
    }

    dotext $ch1 $ch2 0 0 0 0

    # Make sure all text widgets have the same number of lines.
    # The common y scroll doesn't work well if not.
    set max 0.0
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
        if {[$w index end] > $max} {
            set max [$w index end]
        }
    }
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
        set d [expr {int($max - [$w index end])}]
        for {set t 0} {$t < $d} {incr t} {
            $w insert end \n
        }
    }

    close $ch1
    close $ch2

    if {$RCSmode} {
        cleanupRCS
    }

    drawMap -1
    foreach w {.ft1.tl .ft2.tl} {
	$w configure -state disabled
    }
    update idletasks
    .ft2.tl see 1.0
    normalCursor
}

# This is the entrypoint to do a diff via DDE or Send
proc remoteDiff {file1 file2} {
    global leftFile rightFile leftOK rightOK
    global leftDir rightDir leftLabel rightLabel
1117
1118
1119
1120
1121
1122
1123











1124
1125
1126
1127
1128
1129
1130
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187







+
+
+
+
+
+
+
+
+
+
+







        set RCSmode 1
        set RCSFile $rightFile
        set leftLabel "RCS"
        set leftOK 0
        doDiff
    }
}

proc openCVS {} {
    global RCSmode leftFile rightFile leftOK RCSFile
    if {[doOpenRight]} {
        set RCSmode 2
        set RCSFile $rightFile
        set leftLabel "CVS"
        set leftOK 0
        doDiff
    }
}

proc openBoth {forget} {
    global RCSmode
    if {[doOpenLeft]} {
        if {[doOpenRight $forget]} {
            set RCSmode 0
            doDiff
1394
1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465







+







    .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
    if {$tcl_platform(platform) == "unix"} {
        .mf.m add command -label "RCSDiff" -underline 0 -command openRCS
        .mf.m add command -label "CVSDiff" -underline 0 -command openCVS
        .mf.m add separator
        .mf.m add command -label "Print" -underline 0 -command printDiffs
    }
    .mf.m add separator
    .mf.m add command -label "Quit" -command exit

    menubutton .mo -text Options -underline 0 -menu .mo.m
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440





1441
1442
1443
1444
1445
1446
1447
1489
1490
1491
1492
1493
1494
1495



1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507







-
-
-
+
+
+
+
+







    .mo.mi add radiobutton -label "Nothing" -variable Pref(ignore) -value " "
    .mo.mi add radiobutton -label "Space changes (-b)" -variable Pref(ignore) \
            -value "-b"
    .mo.mi add radiobutton -label "All spaces (-w)" -variable Pref(ignore) \
            -value "-w"

    menu .mo.mp
    .mo.mp add radiobutton -label "Nothing" -variable Pref(parse) -value "none"
    .mo.mp add radiobutton -label "Lines" -variable Pref(parse) -value "line"
    .mo.mp add radiobutton -label "Blocks" -variable Pref(parse) -value "block"
    .mo.mp add radiobutton -label "Nothing" -variable Pref(parse) -value 0
    .mo.mp add radiobutton -label "Lines" -variable Pref(parse) -value 1
    .mo.mp add radiobutton -label "Blocks (small)" -variable Pref(parse) \
            -value 2
    .mo.mp add radiobutton -label "Blocks" -variable Pref(parse) -value 3
    .mo.mp add separator
    .mo.mp add radiobutton -label "Characters" -variable Pref(lineparsewords) \
            -value "0"
    .mo.mp add radiobutton -label "Words" -variable Pref(lineparsewords) \
            -value "1"
    .mo.mp add separator
    .mo.mp add checkbutton -label "Use 2nd stage" \
1896
1897
1898
1899
1900
1901
1902
1903

1904
1905

1906
1907

1908
1909
1910
1911
1912
1913
1914
1956
1957
1958
1959
1960
1961
1962

1963
1964

1965
1966

1967
1968
1969
1970
1971
1972
1973
1974







-
+

-
+

-
+







        if {$arg == "-w"} {
            set Pref(ignore) "-w"
        } elseif {$arg == "-b"} {
            set Pref(ignore) "-b"
        } elseif {$arg == "-noignore"} {
            set Pref(ignore) " "
        } elseif {$arg == "-noparse"} {
            set Pref(parse) "none"
            set Pref(parse) 0
        } elseif {$arg == "-line"} {
            set Pref(parse) "line"
            set Pref(parse) 1
        } elseif {$arg == "-block"} {
            set Pref(parse) "block"
            set Pref(parse) 3
        } elseif {$arg == "-char"} {
            set Pref(lineparsewords) 0
        } elseif {$arg == "-word"} {
            set Pref(lineparsewords) 1
        } elseif {$arg == "-2nd"} {
            set Pref(extralineparse) 1
        } elseif {$arg == "-no2nd"} {
1935
1936
1937
1938
1939
1940
1941
1942

1943
1944
1945
1946
1947
1948
1949
1950
1951













1952
1953
1954
1955
1956
1957
1958
1995
1996
1997
1998
1999
2000
2001

2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031







-
+









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







        }
    }

    set len [llength $files]
    if {$len == 1} {
        set fullname [file join [pwd] $files]
        set fulldir [file dirname $fullname]
        if {[glob -nocomplain [file join $fulldir RCS]] != ""} {
        if {[llength [glob -nocomplain [file join $fulldir RCS]]]} {
            set RCSmode 1
            set rightDir $fulldir
            set RCSFile $fullname
            set rightLabel $fullname
            set rightFile $fullname
            set rightOK 1
            set leftLabel "RCS"
            if {$noautodiff} {
                enableRedo
            } else {
                after idle doDiff
            }
        } elseif {[llength [glob -nocomplain [file join $fulldir CVS]]]} {
            set RCSmode 2
            set rightDir $fulldir
            set RCSFile $fullname
            set rightLabel $fullname
            set rightFile $fullname
            set rightOK 1
            set leftLabel "CVS"
            if {$noautodiff} {
                enableRedo
            } else {
                after idle doDiff
            }
        } else {
            set leftDir $fulldir
            set leftFile $fullname
            set leftLabel $fullname
1975
1976
1977
1978
1979
1980
1981
1982

1983
1984
1985
1986
1987
1988
1989
2048
2049
2050
2051
2052
2053
2054

2055
2056
2057
2058
2059
2060
2061
2062







-
+







            enableRedo
        } else {
            after idle doDiff
        }
    }
    if {$autobrowse && (!$leftOK || !$rightOK)} {
        if {!$leftOK && !$rightOK} {
            openBoth
            openBoth 0
        } elseif {!$leftOK} {
            openLeft
        } elseif {!$rightOK} {
            openRight
        }
    }
}
2004
2005
2006
2007
2008
2009
2010
2011

2012
2013
2014
2015
2016
2017
2018
2077
2078
2079
2080
2081
2082
2083

2084
2085
2086
2087
2088
2089
2090
2091







-
+







proc getOptions {} {
    global Pref

    set Pref(fontsize) 9
    set Pref(fontfamily) courier
    set Pref(ignore) "-b"
    set Pref(dopt) ""
    set Pref(parse) "block"
    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) gray
    set Pref(bgnew1) gray