Eskil

Diff
Login

Differences From Artifact [6fdeba30b9]:

To Artifact [645d34b53a]:


98
99
100
101
102
103
104
105

106
107
108
109
110

111
112
113
114
115

116
117
118
119

120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
98
99
100
101
102
103
104

105
106
107
108
109

110
111
112
113
114

115
116
117
118

119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+




-
+




-
+



-
+










-
+







                (This is a bug)\nTerminating application." -type ok
    }
    if {$cont} return

    if {$::diff(diffexe) != "diff"} {
        catch {file delete $::diff(diffexe)}
    }
    cleartmp
    clearTmp
    exit
}

# Format a line number
proc myforml {lineNo} {
proc myFormL {lineNo} {
    if {![string is integer -strict $lineNo]} {return "$lineNo\n"}
      return [format "%3d: \n" $lineNo]
}

proc maxabs {a b} {
proc maxAbs {a b} {
    return [expr {abs($a) > abs($b) ? $a : $b}]
}

proc tmpfile {} {
proc tmpFile {} {
    if {[info exists ::tmpcnt]} {
        incr ::tmpcnt
    } else {
        set ::tmpcnt 0
    }
    set name [file join $::diff(tmpdir) "tmpd[pid]a$::tmpcnt"]
    lappend ::tmpfiles $name
    return $name
}

proc cleartmp {} {
proc clearTmp {} {
    if {[info exists ::tmpfiles]} {
        foreach f $::tmpfiles {
            catch {file delete $f}
        }
    }
    set ::tmpfiles {}
}
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447







-
+







        set apa [string length $diff]
        incr sumdiff2 $apa
    }
#    puts "Same ($sames)"
#    puts "D1   ($diffs1)"
#    puts "D2   ($diffs2)"
#    puts "S $sumsame D $sumdiff1 D $sumdiff2"
    return [expr {$sumsame - [maxabs $sumdiff1 $sumdiff2]}]
    return [expr {$sumsame - [maxAbs $sumdiff1 $sumdiff2]}]
}

# Decide how to display change blocks
# This tries to match the lines that resemble each other and put them
# next to each other.
# As the previous procedure, this would need a complete rework and a
# better algorithm.
662
663
664
665
666
667
668
669

670
671
672
673
674

675
676
677

678
679
680
681
682
683
684
685
686
687
688
689
690
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
662
663
664
665
666
667
668

669
670
671
672
673

674
675
676

677
678
679
680
681
682
683
684
685
686
687
688
689
690
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







-
+




-
+


-
+















-
-
+
+


















-
-
-
+
+
+







            incr t2
        }
    }
    return $apa
}

# Insert lineno and text
proc insert {top n line text {tag {}}} {
proc insertLine {top n line text {tag {}}} {
    $::diff($top,wDiff$n) insert end "$text\n" $tag
    if {$tag != ""} {
        set tag "hl$::HighLightCount $tag"
    }
    $::diff($top,wLine$n) insert end [myforml $line] $tag
    $::diff($top,wLine$n) insert end [myFormL $line] $tag
}

proc emptyline {top n {highlight 1}} {
proc emptyLine {top n {highlight 1}} {
    if {$highlight} {
        $::diff($top,wLine$n) insert end "\n" hl$::HighLightCount
    } else {
        $::diff($top,wLine$n) insert end "\n"
    }
    $::diff($top,wDiff$n) insert end "\n"
}

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

    if {$::diff(filter) != ""} {
        if {[regexp $::diff(filter) $line1]} {
            insert $top 1 $doingLine1 $line1
            insert $top 2 $doingLine2 $line2
            insertLine $top 1 $doingLine1 $line1
            insertLine $top 2 $doingLine2 $line2
            incr doingLine1
            incr doingLine2
            set ::diff(filterflag) 1
            return
        }
        set ::diff(filterflag) 0
    }

    if {$Pref(parse) != 0} {
        compareLines $line1 $line2 res1 res2
        if {$::diff(diffutil)} {
            compareLinesX $line1 $line2 xres1 xres2
            if {$res1 != $xres1 || $res2 != $xres2} {
                tk_messageBox -title Mismatch! \
                        -message ":$res1:\n:$res2:\n:$xres1:\n:$xres2:"
            }
        }
        set dotag 0
        set n [maxabs [llength $res1] [llength $res2]]
        $::diff($top,wLine1) insert end [myforml $doingLine1] "hl$::HighLightCount change"
        $::diff($top,wLine2) insert end [myforml $doingLine2] "hl$::HighLightCount change"
        set n [maxAbs [llength $res1] [llength $res2]]
        $::diff($top,wLine1) insert end [myFormL $doingLine1] "hl$::HighLightCount change"
        $::diff($top,wLine2) 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)} {
738
739
740
741
742
743
744
745
746


747
748
749
750
751
752
753
738
739
740
741
742
743
744


745
746
747
748
749
750
751
752
753







-
-
+
+







                $::diff($top,wDiff2) insert end $i2
                set dotag 1
            }
        }
        $::diff($top,wDiff1) insert end "\n"
        $::diff($top,wDiff2) insert end "\n"
    } else {
        insert $top 1 $doingLine1 $line1 "change"
        insert $top 2 $doingLine2 $line2 "change"
        insertLine $top 1 $doingLine1 $line1 "change"
        insertLine $top 2 $doingLine2 $line2 "change"
    }
    incr doingLine1
    incr doingLine2
}

# Insert two blocks of lines in the compare windows.
# Returns number of lines used to display the blocks
768
769
770
771
772
773
774
775

776
777
778

779
780
781
782
783
784
785
786
787
788

789
790
791

792
793
794
795
796
797

798
799
800

801
802
803
804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
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
768
769
770
771
772
773
774

775
776
777

778
779
780
781
782
783
784
785
786
787

788
789
790

791
792
793
794
795
796

797
798
799

800
801
802
803
804
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
820
821
822
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







-
+


-
+









-
+


-
+





-
+


-
+












-
+


















-
+







-
+







        }
        if {$c == "C"} {
	    # This is two lines that the block matching considered
	    # too different to use line parsing on them.
	    # Marked the whole line as deleted/inserted
            set textline1 [lindex $block1 $t1]
            set textline2 [lindex $block2 $t2]
            $::diff($top,wLine1) insert end [myforml $doingLine1] \
            $::diff($top,wLine1) insert end [myFormL $doingLine1] \
                    "hl$::HighLightCount change"
            $::diff($top,wDiff1) insert end "$textline1\n" new1
            $::diff($top,wLine2) insert end [myforml $doingLine2] \
            $::diff($top,wLine2) insert end [myFormL $doingLine2] \
                    "hl$::HighLightCount change"
            $::diff($top,wDiff2) insert end "$textline2\n" new2
            incr doingLine1
            incr doingLine2
            incr t1
            incr t2
        }
        if {$c == "d"} {
            set bepa [lindex $block1 $t1]
            $::diff($top,wLine1) insert end [myforml $doingLine1] \
            $::diff($top,wLine1) insert end [myFormL $doingLine1] \
                    "hl$::HighLightCount change"
            $::diff($top,wDiff1) insert end "$bepa\n" new1
            emptyline $top 2
            emptyLine $top 2
            incr doingLine1
            incr t1
        }
        if {$c == "a"} {
            set bepa [lindex $block2 $t2]
            $::diff($top,wLine2) insert end [myforml $doingLine2] \
            $::diff($top,wLine2) insert end [myFormL $doingLine2] \
                    "hl$::HighLightCount change"
            $::diff($top,wDiff2) insert end "$bepa\n" new2
            emptyline $top 1
            emptyLine $top 1
            incr doingLine2
            incr t2
        }
    }
    return [llength $apa]
}

# 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 {top ch1 ch2 n1 n2 line1 line2} {
proc doText {top ch1 ch2 n1 n2 line1 line2} {
    global doingLine1 doingLine2 Pref mapMax changesList

    if {$n1 == 0 && $n2 == 0} {
        # All blocks have been processed. Continue until end of file.
        # If "only diffs" is on, just display a couple of context lines.
        set limit -1
        if {$Pref(onlydiffs) == 1} {
            set limit $Pref(context)
        }
	# Consider any total limit on displayed lines.
        if {$::diff($top,limitlines)} {
            set limit [expr {$::diff($top,limitlines) - $mapMax}]
            if {$limit < 0} {
                set limit 0
            }
        }
        set t 0
        while {[gets $ch2 apa] != -1} {
            insert $top 2 $doingLine2 $apa
            insertLine $top 2 $doingLine2 $apa
            incr doingLine2
            incr mapMax
            incr t
            if {$limit >= 0 && $t >= $limit} break
        }
        set t 0
        while {[gets $ch1 apa] != -1} {
            insert $top 1 $doingLine1 $apa
            insertLine $top 1 $doingLine1 $apa
            incr doingLine1
            incr t
            if {$limit >= 0 && $t >= $limit} break
        }
        return
    }

859
860
861
862
863
864
865
866
867


868
869
870
871


872
873
874
875
876
877
878
859
860
861
862
863
864
865


866
867
868
869


870
871
872
873
874
875
876
877
878







-
-
+
+


-
-
+
+







    }
    set t 0
    while {$doingLine1 < $line1} {
        gets $ch1 apa
        gets $ch2 bepa
        if {$limit < 0 || ($t < $limit && $doingLine1 > $limit) || \
                ($line1 - $doingLine1) <= $limit} {
            insert $top 1 $doingLine1 $apa
            insert $top 2 $doingLine2 $bepa
            insertLine $top 1 $doingLine1 $apa
            insertLine $top 2 $doingLine2 $bepa
            incr mapMax
        } elseif {$t == $limit} {
            emptyline $top 1 0
            emptyline $top 2 0
            emptyLine $top 1 0
            emptyLine $top 2 0
            incr mapMax
        }
        incr doingLine1
        incr doingLine2
        incr t
        if {$::diff($top,limitlines) && $mapMax > $::diff($top,limitlines)} {
            return
924
925
926
927
928
929
930
931

932
933
934
935
936

937
938
939
940
941

942
943
944
945
946
947
948

949
950
951
952
953
954
955
924
925
926
927
928
929
930

931
932
933
934
935

936
937
938
939
940

941
942
943
944
945
946
947

948
949
950
951
952
953
954
955







-
+




-
+




-
+






-
+







            lappend changesList $mapMax $apa change \
                    $line1 $n1 $line2 $n2
            incr mapMax $apa
        } else {
            # No extra parsing at all.
            for {set t 0} {$t < $n1} {incr t} {
                gets $ch1 apa
                insert $top 1 $doingLine1 $apa $tag1
                insertLine $top 1 $doingLine1 $apa $tag1
                incr doingLine1
            }
            for {set t 0} {$t < $n2} {incr t} {
                gets $ch2 apa
                insert $top 2 $doingLine2 $apa $tag2
                insertLine $top 2 $doingLine2 $apa $tag2
                incr doingLine2
            }
            if {$n1 <= $n2} {
                for {set t $n1} {$t < $n2} {incr t} {
                    emptyline $top 1
                    emptyLine $top 1
                }
                lappend changesList $mapMax $n2 $tag2 \
                        $line1 $n1 $line2 $n2
                incr mapMax $n2
            } elseif {$n2 < $n1} {
                for {set t $n2} {$t < $n1} {incr t} {
                    emptyline $top 2
                    emptyLine $top 2
                }
                lappend changesList $mapMax $n1 $tag1 \
                        $line1 $n1 $line2 $n2
                incr mapMax $n1
            }
        }
    }
985
986
987
988
989
990
991
992
993


994
995
996
997
998
999
1000
985
986
987
988
989
990
991


992
993
994
995
996
997
998
999
1000







-
-
+
+







    }
}

# Read a conflict file and extract the two versions.
proc prepareConflict {top} {
    global diff Pref

    set diff($top,leftFile) [tmpfile]
    set diff($top,rightFile) [tmpfile]
    set diff($top,leftFile) [tmpFile]
    set diff($top,rightFile) [tmpFile]

    set ch1 [open $diff($top,leftFile) w]
    set ch2 [open $diff($top,rightFile) w]
    set ch [open $diff($top,conflictFile) r]

    set diff($top,conflictDiff) {}
    set leftLine 1
1042
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052
1053
1054
1055
1056
1057


1058
1059
1060
1061
1062
1063
1064
1042
1043
1044
1045
1046
1047
1048

1049
1050
1051
1052
1053
1054
1055


1056
1057
1058
1059
1060
1061
1062
1063
1064







-
+






-
-
+
+







    update idletasks
}

# Clean up after a conflict diff.
proc cleanupConflict {top} {
    global diff Pref

    #cleartmp ;# FIXA
    #clearTmp ;# FIXA
    set diff($top,rightFile) $diff($top,conflictFile)
    set diff($top,leftFile) $diff($top,conflictFile)
}

# Display one chunk from a patch file
proc displayOnePatch {top leftLines rightLines leftLine rightLine} {
    emptyline $top 1
    emptyline $top 2
    emptyLine $top 1
    emptyLine $top 2

    set leftlen [llength $leftLines]
    set rightlen [llength $rightLines]

    set leftc 0
    set rightc 0
    set lblock {}
1120
1121
1122
1123
1124
1125
1126
1127
1128


1129
1130
1131
1132
1133
1134
1135
1136


1137
1138
1139
1140
1141
1142
1143


1144
1145
1146
1147
1148
1149
1150
1120
1121
1122
1123
1124
1125
1126


1127
1128
1129
1130
1131
1132
1133
1134


1135
1136
1137
1138
1139
1140
1141


1142
1143
1144
1145
1146
1147
1148
1149
1150







-
-
+
+






-
-
+
+





-
-
+
+







            set ::doingLine1 $lblockl
            set ::doingLine2 $rblockl
            incr ::mapMax [insertMatchingBlocks $top $lblock $rblock]
            set lblock {}
            set rblock {}
        }
        if {$lmode == "" && $rmode == ""} {
            insert $top 1 $lline $lstr
            insert $top 2 $rline $rstr
            insertLine $top 1 $lline $lstr
            insertLine $top 2 $rline $rstr
            incr leftc
            incr rightc
            incr ::mapMax
            continue
        }
        if {$lmode == "-"} {
            insert $top 1 $lline $lstr new1
            emptyline $top 2
            insertLine $top 1 $lline $lstr new1
            emptyLine $top 2
            incr leftc
            incr ::mapMax
            continue
        }
        if {$rmode == "+"} {
            insert $top 2 $rline $rstr new2
            emptyline $top 1
            insertLine $top 2 $rline $rstr new2
            emptyLine $top 1
            incr rightc
            incr ::mapMax
            continue
        }
    }
}

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
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







-
-
-
-
+
+
+
+





-
-
-
-
+
+
+
+





-
+
+







        if {$state == "none" && [regexp {^---} $line]} {
            set state newfile
            set style u
            set leftRE {^---\s+(.*)$}
            set rightRE {^\+\+\+\s+(.*)$}
        }
        if {$state == "newfile" && [regexp $leftRE $line -> sub]} {
            emptyline $top 1
            insert $top 1 "" $divider
            insert $top 1 "" $sub
            insert $top 1 "" $divider
            emptyLine $top 1
            insertLine $top 1 "" $divider
            insertLine $top 1 "" $sub
            insertLine $top 1 "" $divider
            lappend ::changesList $mapMax 4 change 0 0 0 0
            incr mapMax 4
            continue
        }
        if {$state == "newfile" && [regexp $rightRE $line -> sub]} {
            emptyline $top 2
            insert $top 2 "" $divider
            insert $top 2 "" $sub
            insert $top 2 "" $divider
            emptyLine $top 2
            insertLine $top 2 "" $divider
            insertLine $top 2 "" $sub
            insertLine $top 2 "" $divider
            continue
        }
        # A new section in a -u style diff
        if {[regexp {^@@\s+-(\d+),\d+\s+\+(\d+),} $line -> sub1 sub2]} {
            if {$state == "both"} {
                displayOnePatch $top $leftLines $rightLines $leftLine $rightLine
                displayOnePatch $top $leftLines $rightLines \
                        $leftLine $rightLine
            }
            set state both
            set leftLine $sub1
            set rightLine $sub2
            set leftLines {}
            set rightLines {}
            continue
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
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
1373







-
+















-
+
















-
-
+
+







    if {$diff($top,doptrev2) != ""} {
        lappend revs $diff($top,doptrev2)
    }

    switch [llength $revs] {
        0 {
            # Compare local file with latest version.
            set diff($top,leftFile) [tmpfile]
            set diff($top,leftFile) [tmpFile]
            set diff($top,rightLabel) $diff($top,RCSFile)
            set diff($top,rightFile) $diff($top,RCSFile)

            if {$diff($top,mode) == "CVS"} {
                set diff($top,leftLabel) "$diff($top,RCSFile) (CVS)"
                execCvsUpdate $diff($top,RCSFile) $diff($top,leftFile)
            } else {
                set diff($top,leftLabel) "$diff($top,RCSFile) (RCS)"
                catch {exec co -p [file nativename $diff($top,RCSFile)] \
                        > $diff($top,leftFile)}
            }
        }
        1 {
            # Compare local file with specified version.
            set r [lindex $revs 0]
            set diff($top,leftFile) [tmpfile]
            set diff($top,leftFile) [tmpFile]
            set diff($top,rightLabel) $diff($top,RCSFile)
            set diff($top,rightFile) $diff($top,RCSFile)

            if {$diff($top,mode) == "CVS"} {
                set diff($top,leftLabel) "$diff($top,RCSFile) (CVS $r)"
                execCvsUpdate $diff($top,RCSFile) $diff($top,leftFile) -r $r
            } else {
                set diff($top,leftLabel) "$diff($top,RCSFile) (RCS $r)"
                catch {exec co -p$r [file nativename $diff($top,RCSFile)] \
                        > $diff($top,leftFile)}
            }
        }
        default {
            # Compare the two specified versions.
            set r1 [lindex $revs 0]
            set r2 [lindex $revs 1]
            set diff($top,leftFile) [tmpfile]
            set diff($top,rightFile) [tmpfile]
            set diff($top,leftFile) [tmpFile]
            set diff($top,rightFile) [tmpFile]

            if {$diff($top,mode) == "CVS"} {
                set diff($top,leftLabel) "$diff($top,RCSFile) (CVS $r1)"
                set diff($top,rightLabel) "$diff($top,RCSFile) (CVS $r2)"
                execCvsUpdate $diff($top,RCSFile) $diff($top,leftFile) -r $r1
                execCvsUpdate $diff($top,RCSFile) $diff($top,rightFile) -r $r2
            } else {
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398







-
+







    update idletasks
}

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

    #cleartmp ;# FIXA
    #clearTmp ;# FIXA
    set diff($top,rightFile) $diff($top,RCSFile)
    set diff($top,leftFile) $diff($top,RCSFile)
}

# Prepare for a diff by creating needed temporary files
proc prepareFiles {top} {
    if {$::diff($top,mode) == "RCS" || $::diff($top,mode) == "CVS"} {
1521
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531

1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531

1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1560







-
+


-
+



-
+
















-
+







            } else {
                set n2 1
                set line2 $r
            }
            switch $c {
                a {
                    # lucka i left, new i right
                    dotext $top $ch1 $ch2 0 $n2 [expr {$line1 + 1}] $line2
                    doText $top $ch1 $ch2 0 $n2 [expr {$line1 + 1}] $line2
                }
                c {
                    dotext $top $ch1 $ch2 $n1 $n2 $line1 $line2
                    doText $top $ch1 $ch2 $n1 $n2 $line1 $line2
                }
                d {
                    # lucka i right, new i left
                    dotext $top $ch1 $ch2 $n1 0 $line1 [expr {$line2 + 1}]
                    doText $top $ch1 $ch2 $n1 0 $line1 [expr {$line2 + 1}]
                }
            }
        }
        if {$::diff($top,limitlines) && $::mapMax > $::diff($top,limitlines)} {
            break
        }
        if {[incr t] >= 10} {
	    update idletasks
	    $::diff($top,wLine2) see end
	    update idletasks
            set t 0
        }
        bindHighlight $top
        incr ::HighLightCount
    }

    dotext $top $ch1 $ch2 0 0 0 0
    doText $top $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 item {wLine1 wDiff1 wLine2 wDiff2} {
        set w $::diff($top,$item)
        if {[$w index end] > $max} {
1790
1791
1792
1793
1794
1795
1796
1797

1798
1799
1800
1801
1802
1803
1804
1791
1792
1793
1794
1795
1796
1797

1798
1799
1800
1801
1802
1803
1804
1805







-
+







    }
}

#####################################
# Map stuff
#####################################

proc drawMap {top newh} { # FIXA top
proc drawMap {top newh} {
    global mapMax Pref changesList

    set oldh [map$top cget -height]
    if {$oldh == $newh} return

    map$top blank
    if {![info exists changesList] || [llength $changesList] == 0} return
2149
2150
2151
2152
2153
2154
2155
2156

2157
2158
2159
2160
2161
2162
2163
2150
2151
2152
2153
2154
2155
2156

2157
2158
2159
2160
2161
2162
2163
2164







-
+







            }
        }
    }
    return $lines
}

# Handle wrapping of a too long line for printing
proc linewrap {gray} {
proc lineWrap {gray} {
    if {$gray == "1.0"} {
        return "\n     "
    } else {
        return "\0bggray\{1.0\}\n     \0bggray\{$gray\}"
    }
}

2227
2228
2229
2230
2231
2232
2233
2234

2235
2236
2237
2238
2239
2240
2241
2228
2229
2230
2231
2232
2233
2234

2235
2236
2237
2238
2239
2240
2241
2242







-
+







                    }
                    set len [string length $value]
                    while {$chars + $len > 84} {
                        set wrap [expr {84 - $chars}]
                        set val1 [string range $value 0 [expr {$wrap - 1}]]
                        set value [string range $value $wrap end]
                        append line $val1
                        append line [linewrap $gray]
                        append line [lineWrap $gray]
                        set chars 5
                        incr wrapc
                        set len [string length $value]
                    }
                    append line $value
                    incr chars $len
                }
2481
2482
2483
2484
2485
2486
2487
2488
2489


2490
2491
2492
2493
2494

2495
2496
2497
2498
2499
2500
2501
2502


2503
2504
2505
2506
2507
2508
2509
2482
2483
2484
2485
2486
2487
2488


2489
2490
2491
2492
2493
2494

2495
2496
2497
2498
2499
2500
2501


2502
2503
2504
2505
2506
2507
2508
2509
2510







-
-
+
+




-
+






-
-
+
+







        for {set t 1} {$t <= $level} {incr t} {
            lappend pre [formatAlignPattern $pattern]
            incr pattern
            lappend post [formatAlignPattern $pattern]
            incr pattern
        }

        set fix1($lline) [list [join $pre \n] [join $post \n]]
        set fix2($rline) [list [join $pre \n] [join $post \n]]
        set fix(1,$lline) [list [join $pre \n] [join $post \n]]
        set fix(2,$rline) [list [join $pre \n] [join $post \n]]
    }

    prepareFiles $top
    foreach n {1 2} src {leftFile rightFile} {
        set tmp [tmpfile]
        set tmp [tmpFile]
        set f($n) $tmp
        set cho [open $tmp w]
        #puts $cho hej
        set chi [open $::diff($top,$src) r]
        set lineNo 1
        while {[gets $chi line] >= 0} {
            if {[info exists fix${n}($lineNo)]} {
                foreach {pre post} [set fix${n}($lineNo)] break
            if {[info exists fix($n,$lineNo)]} {
                foreach {pre post} $fix($n,$lineNo) break
                puts $cho $pre
                puts $cho $line
                puts $cho $post
            } else {
                puts $cho $line
            }
            incr lineNo
2583
2584
2585
2586
2587
2588
2589
2590
2591


2592
2593
2594
2595
2596
2597
2598
2584
2585
2586
2587
2588
2589
2590


2591
2592
2593
2594
2595
2596
2597
2598
2599







-
-
+
+







        set range [$wl tag ranges hl$::diff($top,separate$n)]
    }
    set text [eval $wd get $range]
    set ::diff($top,separatetext$n) $text

    if {[info exists ::diff($top,separate1)] && \
            [info exists ::diff($top,separate2)]} {
        set f1 [tmpfile]
        set f2 [tmpfile]
        set f1 [tmpFile]
        set f2 [tmpFile]
        set ch [open $f1 w]
        puts $ch $::diff($top,separatetext1)
        close $ch
        set ch [open $f2 w]
        puts $ch $::diff($top,separatetext2)
        close $ch

2790
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800
2801
2802
2803
2804
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800
2801
2802
2803
2804
2805







-
+







            $w tag configure new2 -foreground $Pref(colornew2) \
                    -background $Pref(bgnew2)
        }
    }
}

# Scroll text windows
proc scroll {top n what} {
proc scrollText {top n what} {
    # Do not scroll if focus is in a text window.
    # This is for scroll bindings in the toplevel.
    if {[winfo class [focus]] != "Text"} {
        $::diff($top,wDiff1) yview scroll $n $what
    }
}

2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971






2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983




2984
2985
2986
2987
2988
2989
2990
2961
2962
2963
2964
2965
2966
2967





2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981




2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992







-
-
-
-
-
+
+
+
+
+
+








-
-
-
-
+
+
+
+







            -command chFont
    $top.mo.mf add radiobutton -label 9 -variable Pref(fontsize) -value 9 \
            -command chFont
    $top.mo.mf add radiobutton -label 10 -variable Pref(fontsize) -value 10 \
            -command chFont

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

    menu $top.mo.mp
    $top.mo.mp add radiobutton -label "Nothing" -variable Pref(parse) -value 0
    $top.mo.mp add radiobutton -label "Lines" -variable Pref(parse) -value 1
    $top.mo.mp add radiobutton -label "Blocks (small)" -variable Pref(parse) \
            -value 2
    $top.mo.mp add radiobutton -label "Blocks" -variable Pref(parse) -value 3
    $top.mo.mp add separator
    $top.mo.mp add radiobutton -label "Characters" -variable Pref(lineparsewords) \
            -value "0"
    $top.mo.mp add radiobutton -label "Words" -variable Pref(lineparsewords) \
            -value "1"
    $top.mo.mp add radiobutton -label "Characters" \
            -variable Pref(lineparsewords) -value "0"
    $top.mo.mp add radiobutton -label "Words" \
            -variable Pref(lineparsewords) -value "1"
    $top.mo.mp add separator
    $top.mo.mp add checkbutton -label "Use 2nd stage" \
            -variable Pref(extralineparse)
    $top.mo.mp add checkbutton -label "Mark last" -variable Pref(marklast)

    menubutton $top.ms -text Search -underline 0 -menu $top.ms.m
    menu $top.ms.m
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108




3109
3110
3111
3112
3113
3114
3115
3100
3101
3102
3103
3104
3105
3106




3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117







-
-
-
-
+
+
+
+







    grid $top.c -pady [expr {[$top.sby cget -width] + 2}]
    grid $top.ls -sticky ""
    
    image create photo map$top
    $top.c create image 0 0 -anchor nw -image map$top
    bind $top.c <Configure> [list drawMap $top %h]

    bind $top <Key-Up>    [list scroll $top -1 u]
    bind $top <Key-Down>  [list scroll $top  1 u]
    bind $top <Key-Prior> [list scroll $top -1 p]
    bind $top <Key-Next>  [list scroll $top  1 p]
    bind $top <Key-Up>    [list scrollText $top -1 u]
    bind $top <Key-Down>  [list scrollText $top  1 u]
    bind $top <Key-Prior> [list scrollText $top -1 p]
    bind $top <Key-Next>  [list scrollText $top  1 p]
    bind $top <Key-Escape> [list focus $top]

    pack $top.mf $top.mo $top.ms $top.mh -in $top.f -side left
    pack $top.bfn -in $top.f -side right -padx {3 6}
    pack $top.bfp $top.er2 $top.lr2 $top.er1 $top.lr1 $top.eo $top.lo \
            -in $top.f -side right -padx 3
    if {$debug == 1} {