︙ | | |
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
-
+
|
# Added CVS support.
#
#-----------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"
set debug 1
set diffver "Version 1.8b 000831"
set diffver "Version 1.8b 000914"
set tmpcnt 0
set tmpfiles {}
set thisscript [file join [pwd] [info script]]
set thisdir [file dirname $thisscript]
if {$tcl_platform(platform) == "windows"} {
cd $thisdir
|
︙ | | |
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
-
+
+
+
+
-
+
-
-
+
+
|
}
}
return $apa
}
# Insert lineno and text
proc insert {n line text {tag {}}} {
.ft$n.tl insert end [myforml $line] $tag
.ft$n.tt insert end "$text\n" $tag
if {$tag != ""} {
set tag "hl$::HighLightCount $tag"
}
.ft$n.tl insert end [myforml $line] $tag
}
proc emptyline {n} {
.ft$n.tl insert end "\n"
.ft$n.tl insert end "\n" hl$::HighLightCount
.ft$n.tt insert end "\n"
}
# 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) != 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
.ft1.tl insert end [myforml $doingLine1] "hl$::HighLightCount change"
.ft2.tl insert end [myforml $doingLine2] "hl$::HighLightCount change"
set new1 new1
set new2 new2
set change change
foreach i1 $res1 i2 $res2 {
incr n -1
if {$dotag} {
if {$n == 1 && $Pref(marklast)} {
|
︙ | | |
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
-
+
|
# Process one of the change/add/delete blocks reported by diff.
# ch1 is a file channel for the left file
# ch2 is a file channel for the right file
# n1/n2 is the number of lines involved
# line1/line2 says on what lines this block starts
proc dotext {ch1 ch2 n1 n2 line1 line2} {
global doingLine1 doingLine2 Pref mapList mapMax
global doingLine1 doingLine2 Pref mapMax changesList
if {$n1 == 0 && $n2 == 0} {
# All blocks have been processed. Continue until end of file.
if {$Pref(onlydiffs) == 1} return
while {[gets $ch2 apa] != -1} {
insert 2 $doingLine2 $apa
incr doingLine2
|
︙ | | |
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
|
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
-
-
-
+
+
+
-
+
-
-
-
-
+
+
+
-
+
+
-
+
+
-
+
+
-
-
+
+
-
-
+
+
-
|
.ft2.tl insert end "\n"
}
# Process the 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
gets $ch1 textline1
gets $ch2 textline2
insertMatchingLines $textline1 $textline2
}
lappend mapList $mapMax
lappend changesList $mapMax $n1 change $line1 $n1 $line2 $n2
incr mapMax $n1
lappend mapList $mapMax change
} else {
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} {
gets $ch2 apa
lappend block2 $apa
}
set apa [compareblocks $block1 $block2]
set t1 0
set t2 0
foreach c $apa {
if {$c == "c"} {
set line1 [lindex $block1 $t1]
set line2 [lindex $block2 $t2]
insertMatchingLines $line1 $line2
set textline1 [lindex $block1 $t1]
set textline2 [lindex $block2 $t2]
insertMatchingLines $textline1 $textline2
incr t1
incr t2
}
if {$c == "d"} {
set bepa [lindex $block1 $t1]
.ft1.tl insert end [myforml $doingLine1] change
.ft1.tl insert end [myforml $doingLine1] \
"hl$::HighLightCount change"
.ft1.tt insert end "$bepa\n" new1
emptyline 2
incr doingLine1
incr t1
}
if {$c == "a"} {
set bepa [lindex $block2 $t2]
.ft2.tl insert end [myforml $doingLine2] change
.ft2.tl insert end [myforml $doingLine2] \
"hl$::HighLightCount change"
.ft2.tt insert end "$bepa\n" new2
emptyline 1
incr doingLine2
incr t2
}
}
lappend mapList $mapMax
lappend changesList $mapMax [llength $apa] change \
$line1 $n1 $line2 $n2
incr mapMax [llength $apa]
lappend mapList $mapMax change
} else {
for {set t 0} {$t < $n1} {incr t} {
gets $ch1 apa
insert 1 $doingLine1 $apa $tag1
incr doingLine1
}
for {set t 0} {$t < $n2} {incr t} {
gets $ch2 apa
insert 2 $doingLine2 $apa $tag2
incr doingLine2
}
if {$n1 < $n2} {
for {set t $n1} {$t < $n2} {incr t} {
emptyline 1
}
lappend mapList $mapMax
lappend changesList $mapMax $n2 $tag2 \
$line1 $n1 $line2 $n2
incr mapMax $n2
lappend mapList $mapMax $tag2
} elseif {$n2 < $n1} {
for {set t $n2} {$t < $n1} {incr t} {
emptyline 2
}
lappend mapList $mapMax
lappend changesList $mapMax $n1 $tag1 \
$line1 $n1 $line2 $n2
incr mapMax $n1
lappend mapList $mapMax $tag1
}
}
}
}
# Scroll windows to next diff
proc findNext {} {
|
︙ | | |
819
820
821
822
823
824
825
826
827
828
829
830
831
832
|
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
set apa 1.0
}
foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
$w yview $apa
}
}
# Scroll windows to next/previous diff
proc findDiff {delta} {
global CurrentHighLight
showDiff [expr {$CurrentHighLight + $delta}]
}
# Scroll windows to diff
proc showDiff {num} {
global CurrentHighLight changesList
highLightChange $num
set line1 [lindex $changesList [expr {$CurrentHighLight * 7}]]
if {$CurrentHighLight < 0} {
set line1 1.0
set line2 1.0
set linep 1.0
set linen 1.0
} elseif {$line1 == ""} {
set line1 end
set line2 end
set linep end
set linen end
} else {
set line2 [expr {$line1 + \
[lindex $changesList [expr {$CurrentHighLight * 7 + 1}]]}]
incr line1
set linep [expr {$line1 - 5}].0
set linen [expr {$line2 + 5}].0
set line1 $line1.0
set line2 $line2.0
}
foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
$w see $line2
$w see $line1
$w see $linep
$w see $linen
if {[llength [$w bbox $line1]] == 0} {
$w yview $linep
}
if {[llength [$w bbox $line2]] == 0} {
$w yview $line1
}
}
}
proc enableRedo {} {
.mf.m entryconfigure 1 -state normal
}
proc disableRedo {} {
.mf.m entryconfigure 1 -state disabled
|
︙ | | |
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
|
-
+
-
+
+
|
set Pref(dopt) $Pref(old_dopt)
unset Pref(old_dopt)
}
proc doDiff {} {
global leftFile rightFile leftOK rightOK
global eqLabel RCSmode Pref doingLine1 doingLine2
global mapList mapMax
global mapMax changesList
if {$RCSmode == 0 && ($leftOK == 0 || $rightOK == 0)} {
disableRedo
return
} else {
enableRedo
}
busyCursor
foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
$w configure -state normal
$w delete 1.0 end
}
set mapList {}
set changesList {}
set mapMax 0
highLightChange -1
update idletasks
if {$RCSmode} {
prepareRCS
}
|
︙ | | |
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
|
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
|
+
|
if {$::tcl_platform(platform) == "windows" && $Pref(crlf)} {
fconfigure $ch1 -translation crlf
fconfigure $ch2 -translation crlf
}
set doingLine1 1
set doingLine2 1
set t 0
set ::HighLightCount 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
|
︙ | | |
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
|
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
|
+
|
}
if {[incr t] >= 10} {
update idletasks
.ft2.tl see end
update idletasks
set t 0
}
incr ::HighLightCount
}
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
|
︙ | | |
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
|
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
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
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
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
1368
1369
1370
1371
1372
|
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
#####################################
# Map stuff
#####################################
proc drawMap {newh} {
global mapList mapMax Pref
global mapMax Pref changesList
set oldh [map cget -height]
if {$oldh == $newh} return
map blank
if {![info exists mapList] || $mapList == ""} return
if {![info exists changesList] || [llength $changesList] == 0} return
set w [winfo width .c]
set h [winfo height .c]
set x2 [expr {$w - 1}]
map configure -width $w -height $h
incr h -1
foreach {start stop type} $mapList {
foreach {start length type dum1 dum2 dum3 dum4} $changesList {
set y1 [expr {$start * $h / $mapMax + 1}]
if {$y1 < 1} {set y1 1}
if {$y1 > $h} {set y1 $h}
set y2 [expr {$stop * $h / $mapMax + 1}]
set y2 [expr {($start + $length) * $h / $mapMax + 1}]
if {$y2 < 1} {set y2 1}
if {$y2 <= $y1} {set y2 [expr {$y1 + 1}]}
if {$y2 > $h} {set y2 $h}
incr y2
map put $Pref(color$type) -to 1 $y1 $x2 $y2
}
}
######################################
proc highLightChange {n} {
global CurrentHighLight changesList
if {[info exists CurrentHighLight] && $CurrentHighLight >= 0} {
.ft1.tl tag configure hl$CurrentHighLight -background {}
.ft2.tl tag configure hl$CurrentHighLight -background {}
}
set CurrentHighLight $n
if {$CurrentHighLight < 0} {
set CurrentHighLight -1
} elseif {$CurrentHighLight * 7 >= [llength $changesList]} {
set CurrentHighLight [expr {[llength $changesList] / 7}]
} else {
.ft1.tl tag configure hl$CurrentHighLight -background yellow
.ft2.tl tag configure hl$CurrentHighLight -background yellow
}
}
proc collectMergeData {} {
global changesList leftFile rightFile mergeSelection
set leftData {}
set rightData {}
if {![info exists changesList]} {
set changesList {}
}
set ch1 [open $leftFile r]
set ch2 [open $rightFile r]
set doingLine1 0
set doingLine2 0
set changeNo 0
foreach {start length type line1 n1 line2 n2} $changesList {
set data1 {}
set data2 {}
while {$doingLine1 < $line1} {
gets $ch1 apa
lappend data1 $apa
incr doingLine1
}
while {$doingLine2 < $line2} {
gets $ch2 apa
lappend data2 $apa
incr doingLine2
}
lappend leftData [join $data1 \n]
lappend rightData [join $data2 \n]
set data1 {}
set data2 {}
for {set t 0} {$t < $n1} {incr t} {
gets $ch1 apa
lappend data1 $apa
incr doingLine1
}
for {set t 0} {$t < $n2} {incr t} {
gets $ch2 apa
lappend data2 $apa
incr doingLine2
}
lappend leftData [join $data1 \n]
lappend rightData [join $data2 \n]
set mergeSelection($changeNo) 2
incr changeNo
}
set data1 {}
set data2 {}
while {[gets $ch1 apa] != -1} {
lappend data1 $apa
incr doingLine1
}
while {[gets $ch2 apa] != -1} {
gets $ch2 apa
lappend data2 $apa
incr doingLine2
}
lappend leftData [join $data1 \n]
lappend rightData [join $data2 \n]
close $ch1
close $ch2
}
proc makeMergeWin {} {
destroy .merge
toplevel .merge
}
#####################################
# Printing stuff
#####################################
# Format a line number for printing
|
︙ | | |
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
|
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
|
-
+
-
+
|
set tdump [$w dump -tag -text 1.0 end]
set gray 1.0
set line ""
set lines {}
foreach {key value index} $tdump {
if {$key == "tagon"} {
if {$value == "change"} {
set gray 0.6
set gray $::grayLevel1
} else {
set gray 0.8
set gray $::grayLevel2
}
} elseif {$key == "tagoff"} {
set gray 1.0
} elseif {$key == "text"} {
append line $value
if {[string index $value end] == "\n"} {
set line [string trim [string trim $line] :]
|
︙ | | |
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
|
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
|
+
-
+
-
+
-
+
-
|
set len [string length $value]
}
append line $value
incr chars $len
}
tagon {
if {$value == "change"} {
set gray $::grayLevel1
append line "\0bggray\{.6\}"
append line "\0bggray\{$gray\}"
set gray 0.6
} elseif {$value != "last"} {
set gray $::grayLevel2
append line "\0bggray\{.8\}"
append line "\0bggray\{$gray\}"
set gray 0.8
}
}
tagoff {
if {$value != "last"} {
append line "\0bggray\{1.0\}"
set gray 1.0
}
|
︙ | | |
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
|
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
been created:\n\n$tmpFile\nInput file to enscript.\
\n\n$tmpFile2\nCreated with 'enscript -c -B -e -p $tmpFile2\
$tmpFile'\n\n$tmpFile3\nCreated with 'mpage -bA4 -a2 $tmpFile2 >\
$tmpFile3'" -font "Courier 8"
pack .dp.b -side bottom
pack .dp.l -side top
}
proc doPrint {} {
destroy .pr
toplevel .pr
wm title .pr "Print diffs"
label .pr.l1 -justify left -text "The print function is just on an\
experimental level. It will write a postcript file\
\"tcldiff.ps\" in your home directory."
label .pr.l2 -justify left -text "Below you can adjust the what gray scale\
level is used on the background to mark changes.\
The first value is used for changed text. The second for\
new/deleted text."
.pr.l1 configure -wraplength 300
.pr.l2 configure -wraplength 300
if {![info exists ::grayLevel1]} {
set ::grayLevel1 0.6
set ::grayLevel2 0.8
}
scale .pr.s1 -orient horizontal -resolution 0.1 -showvalue 1 -from 0.0 \
-to 1.0 -variable grayLevel1
scale .pr.s2 -orient horizontal -resolution 0.1 -showvalue 1 -from 0.0 \
-to 1.0 -variable grayLevel2
button .pr.b1 -text Print -command {destroy .pr; update; printDiffs}
button .pr.b2 -text Cancel -command {destroy .pr}
grid .pr.l1 - -sticky we
grid .pr.l2 - -sticky we
grid .pr.s1 - -sticky we
grid .pr.s2 - -sticky we
grid .pr.b1 .pr.b2 -sticky w
grid .pr.b2 -sticky e
}
#####################################
# GUI stuff
#####################################
proc my_yview args {
foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
|
︙ | | |
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
|
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
|
-
+
|
.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 command -label "Print" -underline 0 -command doPrint
}
.mf.m add separator
.mf.m add command -label "Quit" -command cleanupAndExit
menubutton .mo -text Options -underline 0 -menu .mo.m
menu .mo.m
.mo.m add cascade -label Font -underline 0 -menu .mo.mf
|
︙ | | |
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
|
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
|
-
-
+
+
|
.mo.mp add checkbutton -label "Mark last" -variable Pref(marklast)
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
button .bfn -text "Next Diff" -relief raised -command findNext
button .bfp -text "Prev Diff" -relief raised -command findPrev
button .bfn -text "Next Diff" -relief raised -command {findDiff 1}
button .bfp -text "Prev Diff" -relief raised -command {findDiff -1}
entry .eo -width 10 -textvariable Pref(dopt)
label .lo -text "Diff Options"
catch {font delete myfont}
font create myfont -family $Pref(fontfamily) -size $Pref(fontsize)
label .l1 -textvariable leftLabel -anchor e -width 10
|
︙ | | |
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
|
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
|
+
-
+
+
-
+
|
}
}
set len [llength $files]
if {$len == 1} {
set fullname [file join [pwd] $files]
set fulldir [file dirname $fullname]
if {!$autobrowse && \
if {[llength [glob -nocomplain [file join $fulldir RCS]]]} {
[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 {!$autobrowse && \
} elseif {[llength [glob -nocomplain [file join $fulldir CVS]]]} {
[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"
|
︙ | | |