Eskil

Diff
Login

Differences From Artifact [4f9929eadb]:

To Artifact [faa35dbed1]:


49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#                               Added colour options, and Only diffs option
#                               Added 2nd stage line parsing
#                               Improved block parsing
#                               Added print
#     1.4     DA-PS    990210   Bug-fix in "Ignore nothing"
#                               Bug-fix in file handling
#                               Improved RCS handling.
#     1.5     DA-PS             Bug-fix and improvement in block parsing
#                               Added font selection
#                               Added "diff server" functionality


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

set debug 1
set diffver "Version 1.5 beta"
set tmpcnt 0


if {$tcl_platform(platform) == "windows"} {
    package require dde
}

proc myform {lineNo text} {
    return [format "%3d: %s\n" $lineNo $text]
}

proc myforml {lineNo} {
    return [format "%3d: " $lineNo]
}

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

proc tmpfile {} {







|


>
>





|
|

>










|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#                               Added colour options, and Only diffs option
#                               Added 2nd stage line parsing
#                               Improved block parsing
#                               Added print
#     1.4     DA-PS    990210   Bug-fix in "Ignore nothing"
#                               Bug-fix in file handling
#                               Improved RCS handling.
#     1.5     DA-PS    990623   Bug-fix and improvement in block parsing
#                               Added font selection
#                               Added "diff server" functionality
#                               Split text windows in lineno/text
#                               Added "Mark last" option
#
#-----------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"

set debug 0
set diffver "Version 1.5  990623"
set tmpcnt 0
set thisscript [file join [pwd] [info script]]

if {$tcl_platform(platform) == "windows"} {
    package require dde
}

proc myform {lineNo text} {
    return [format "%3d: %s\n" $lineNo $text]
}

proc myforml {lineNo} {
    return [format "%3d: \n" $lineNo]
}

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

proc tmpfile {} {
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
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
        } else {
            lappend apa $asym
            incr t2
        }
    }
    return $apa
}












#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"} {
        comparelines $line1 $line2 res1 res2
        set dotag 0

        .t1 insert end [myforml $doingLine1] change
        .t2 insert end [myforml $doingLine2] change



        foreach i1 $res1 i2 $res2 {

            if {$dotag} {





                if {$i1 == ""} {
                    .t2 insert end $i2 new2
                } elseif {$i2 == ""} {
                    .t1 insert end $i1 new1
                } else {
                    .t1 insert end $i1 change
                    .t2 insert end $i2 change
                }
                set dotag 0
            } else {
                .t1 insert end $i1
                .t2 insert end $i2
                set dotag 1
            }
        }
        .t1 insert end "\n"
        .t2 insert end "\n"
    } else {
        .t1 insert end [myform $doingLine1 $line1] change
        .t2 insert end [myform $doingLine2 $line2] change
    }
    incr doingLine1
    incr doingLine2
}

#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

    if {$n1 == 0 && $n2 == 0} {
        #All blocks has been processed. Continue until end of file.
        if {$Pref(onlydiffs) == 1} return
        while {[gets $ch2 apa] != -1} {
            .t2 insert end [myform $doingLine2 $apa]
            incr doingLine2
            incr mapMax
        }
        while {[gets $ch1 apa] != -1} {
            .t1 insert end [myform $doingLine1 $apa]
            incr doingLine1
        }
        return
    }

    if {$n1 == 0} {set tag2 new2} else {set tag2 change}
    if {$n2 == 0} {set tag1 new1} else {set tag1 change}

    #Display all equal lines before next diff
    if {$Pref(onlydiffs) == 1 && $doingLine1 < $line1} {
        .t1 insert end "\n"
        .t2 insert end "\n"
        incr mapMax
    }
    while {$doingLine1 < $line1} {
        gets $ch1 apa
        gets $ch2 bepa
        if {$Pref(onlydiffs) == 0} {
            .t1 insert end [myform $doingLine1 $apa]
            .t2 insert end [myform $doingLine2 $bepa]
            incr mapMax
        }
        incr doingLine1
        incr doingLine2
    }
    if {$doingLine2 != $line2} {
        .t1 insert end "**Bad alignment here!! $doingLine2 $line2**\n"
        .t2 insert end "**Bad alignment here!! $doingLine2 $line2**\n"


    }

    #Process the block

    if {$n1 == $n2 && ($n1 == 1 || $Pref(parse) != "block")} {
        for {set t 0} {$t < $n1} {incr t} {
            gets $ch1 line1







>
>
>
>
>
>
>
>
>
>
>









>
|
|
>
>
>

>

>
>
>
>
>

|

|

|
|



|
|



|
|

|
|

















|




|










|
|






|
|






|
|
>
>







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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
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
        } else {
            lappend apa $asym
            incr t2
        }
    }
    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
}

proc emptyline {n} {
    .ft$n.tl insert end \n
    .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) != "none"} {
        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
        set change change
        foreach i1 $res1 i2 $res2 {
            incr n -1
            if {$dotag} {
                if {$n == 1 && $Pref(marklast)} {
                    lappend new1 last
                    lappend new2 last
                    lappend change last
                }
                if {$i1 == ""} {
                    .ft2.tt insert end $i2 $new2
                } elseif {$i2 == ""} {
                    .ft1.tt insert end $i1 $new1
                } else {
                    .ft1.tt insert end $i1 $change
                    .ft2.tt insert end $i2 $change
                }
                set dotag 0
            } else {
                .ft1.tt insert end $i1
                .ft2.tt insert end $i2
                set dotag 1
            }
        }
        .ft1.tt insert end "\n"
        .ft2.tt insert end "\n"
    } else {
	insert 1 $doingLine1 $line1 change
	insert 2 $doingLine2 $line2 change
    }
    incr doingLine1
    incr doingLine2
}

#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

    if {$n1 == 0 && $n2 == 0} {
        #All blocks has been processed. Continue until end of file.
        if {$Pref(onlydiffs) == 1} return
        while {[gets $ch2 apa] != -1} {
	    insert 2 $doingLine2 $apa
            incr doingLine2
            incr mapMax
        }
        while {[gets $ch1 apa] != -1} {
	    insert 1 $doingLine1 $apa
            incr doingLine1
        }
        return
    }

    if {$n1 == 0} {set tag2 new2} else {set tag2 change}
    if {$n2 == 0} {set tag1 new1} else {set tag1 change}

    #Display all equal lines before next diff
    if {$Pref(onlydiffs) == 1 && $doingLine1 < $line1} {
	emptyline 1
	emptyline 2
        incr mapMax
    }
    while {$doingLine1 < $line1} {
        gets $ch1 apa
        gets $ch2 bepa
        if {$Pref(onlydiffs) == 0} {
	    insert 1 $doingLine1 $apa
	    insert 2 $doingLine2 $bepa
            incr mapMax
        }
        incr doingLine1
        incr doingLine2
    }
    if {$doingLine2 != $line2} {
        .ft1.tt insert end "**Bad alignment here!! $doingLine2 $line2**\n"
        .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")} {
        for {set t 0} {$t < $n1} {incr t} {
            gets $ch1 line1
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
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
                    set line2 [lindex $block2 $t2]
                    insertMatchingLines $line1 $line2
                    incr t1
                    incr t2
                }
                if {$c == "d"} {
                    set bepa [lindex $block1 $t1]
                    .t1 insert end [myforml $doingLine1] change
                    .t1 insert end "$bepa\n" new1
                    .t2 insert end "\n"
                    incr doingLine1
                    incr t1
                }
                if {$c == "a"} {
                    set bepa [lindex $block2 $t2]
                    .t2 insert end [myforml $doingLine2] change
                    .t2 insert end "$bepa\n" new2
                    .t1 insert end "\n"
                    incr doingLine2
                    incr t2
                }
            }
            lappend mapList $mapMax
            incr mapMax [llength $apa]
            lappend mapList $mapMax change
        } else {
            for {set t 0} {$t < $n1} {incr t} {
                gets $ch1 apa
                .t1 insert end [myform $doingLine1 $apa] $tag1
                incr doingLine1
            }
            for {set t 0} {$t < $n2} {incr t} {
                gets $ch2 apa
                .t2 insert end [myform $doingLine2 $apa] $tag2
                incr doingLine2
            }
            if {$n1 < $n2} {
                for {set t $n1} {$t < $n2} {incr t} {
                    .t1 insert end "\n"
                }
                lappend mapList $mapMax
                incr mapMax $n2
                lappend mapList $mapMax $tag2
            } elseif {$n2 < $n1} {
                for {set t $n2} {$t < $n1} {incr t} {
                    .t2 insert end "\n"
                }
                lappend mapList $mapMax
                incr mapMax $n1
                lappend mapList $mapMax $tag1
            }
        }
    }
}

#Scroll windows to next diff
proc findNext {} {
    set i [.t1 index @0,0+1line]
    set n1 [.t1 tag nextrange new1 $i]
    set c1 [.t1 tag nextrange change $i]
    set i [.t2 index @0,0+1line]
    set n2 [.t2 tag nextrange new2 $i]
    set c2 [.t2 tag nextrange change $i]

    set apa [lsort -dictionary "$n1 $c1 $n2 $c2"]

    if {[llength $apa] != 0} {
        .t1 yview [lindex $apa 0]
        .t2 yview [lindex $apa 0]
    } else {
        .t1 yview end



        .t2 yview end
    }
}

#Scroll windows to previous diff
proc findPrev {} {
    set i [.t1 index @0,0]
    set n1 [.t1 tag prevrange new1 $i]
    set c1 [.t1 tag prevrange change $i]
    set i [.t2 index @0,0]
    set n2 [.t2 tag prevrange new2 $i]
    set c2 [.t2 tag prevrange change $i]

    set apa [lsort -decreasing -dictionary "$n1 $c1 $n2 $c2"]
    if {[llength $apa] != 0} {
        .t1 yview [lindex $apa 1]
        .t2 yview [lindex $apa 1]
    } else {
        .t1 yview 1.0



        .t2 yview 1.0
    }
}

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

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

proc busyCursor {} {
    global oldcursor oldcursor2
    if {![info exists oldcursor]} {
        set oldcursor [. cget -cursor]
        set oldcursor2 [.t1 cget -cursor]
    }
    . config -cursor watch
    .t1 config -cursor watch
    .t2 config -cursor watch

}

proc normalCursor {} {
    global oldcursor oldcursor2
    . config -cursor $oldcursor
    .t1 config -cursor $oldcursor2
    .t2 config -cursor $oldcursor2

}

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

    set revs {}
    set opts {}







|
|
|





|
|
|










|




|




|






|











|
|
|
|
|
|




|
<

|
>
>
>
|





|
|
|
|
|
|



|
<

|
>
>
>
|















|


|
|
>





|
|
>







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
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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
                    set line2 [lindex $block2 $t2]
                    insertMatchingLines $line1 $line2
                    incr t1
                    incr t2
                }
                if {$c == "d"} {
                    set bepa [lindex $block1 $t1]
                    .ft1.tl insert end [myforml $doingLine1] 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.tt insert end "$bepa\n" new2
		    emptyline 1
                    incr doingLine2
                    incr t2
                }
            }
            lappend mapList $mapMax
            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
                incr mapMax $n2
                lappend mapList $mapMax $tag2
            } elseif {$n2 < $n1} {
                for {set t $n2} {$t < $n1} {incr t} {
		    emptyline 2
                }
                lappend mapList $mapMax
                incr mapMax $n1
                lappend mapList $mapMax $tag1
            }
        }
    }
}

#Scroll windows to next diff
proc findNext {} {
    set i [.ft1.tt index @0,0+1line]
    set n1 [.ft1.tt tag nextrange new1 $i]
    set c1 [.ft1.tt tag nextrange change $i]
    set i [.ft2.tt index @0,0+1line]
    set n2 [.ft2.tt tag nextrange new2 $i]
    set c2 [.ft2.tt tag nextrange change $i]

    set apa [lsort -dictionary "$n1 $c1 $n2 $c2"]

    if {[llength $apa] != 0} {
	set apa [lindex $apa 0]

    } else {
	set apa end
    }

    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
	$w yview $apa
    }
}

#Scroll windows to previous diff
proc findPrev {} {
    set i [.ft1.tt index @0,0]
    set n1 [.ft1.tt tag prevrange new1 $i]
    set c1 [.ft1.tt tag prevrange change $i]
    set i [.ft2.tt index @0,0]
    set n2 [.ft2.tt tag prevrange new2 $i]
    set c2 [.ft2.tt tag prevrange change $i]

    set apa [lsort -decreasing -dictionary "$n1 $c1 $n2 $c2"]
    if {[llength $apa] != 0} {
	set apa [lindex $apa 1]

    } else {
	set apa 1.0
    }
    
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
	$w yview $apa
    }
}

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

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

proc busyCursor {} {
    global oldcursor oldcursor2
    if {![info exists oldcursor]} {
        set oldcursor [. cget -cursor]
        set oldcursor2 [.ft1.tt cget -cursor]
    }
    . config -cursor watch
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
	$w config -cursor watch
    }
}

proc normalCursor {} {
    global oldcursor oldcursor2
    . 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

    set revs {}
    set opts {}
898
899
900
901
902
903
904

905
906

907
908
909
910
911
912
913
        return
    } else {
        enableRedo
    }

    busyCursor


    .t1 delete 1.0 end
    .t2 delete 1.0 end

    set mapList {}
    set mapMax 0

    update idletasks

    if {$RCS} {
        prepareRCS







>
|
|
>







930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
        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 mapMax 0

    update idletasks

    if {$RCS} {
        prepareRCS
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
947
948
949
950
951
952
        if {[string match {[0-9]*} $i]} {
            lappend result $i
        }
    }

    if {[llength $result] == 0} {
        if {$differr == 1} {
            .t1 insert end $diffres
            normalCursor
            return
        } else {
            set eqLabel "="
        }
    } else {
        set eqLabel " "
    }

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

    foreach i $result {
        if {![regexp {(.*)([acd])(.*)} $i apa l c r]} {
            .t1 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
            } else {
                set n1 1
                set line1 $l







|
















|







955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
        if {[string match {[0-9]*} $i]} {
            lappend result $i
        }
    }

    if {[llength $result] == 0} {
        if {$differr == 1} {
            .ft1.tt insert end $diffres
            normalCursor
            return
        } else {
            set eqLabel "="
        }
    } else {
        set eqLabel " "
    }

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

    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
            } else {
                set n1 1
                set line1 $l
980
981
982
983
984
985
986



987
988
989
990
991
992
993
    close $ch2

    if {$RCS} {
        cleanupRCS
    }

    drawMap -1



    normalCursor
}

proc remoteDiff {file1 file2} {
    global leftFile rightFile leftOK rightOK
    global leftDir rightDir leftLabel rightLabel








>
>
>







1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
    close $ch2

    if {$RCS} {
        cleanupRCS
    }

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

proc remoteDiff {file1 file2} {
    global leftFile rightFile leftOK rightOK
    global leftDir rightDir leftLabel rightLabel

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
    set tmpFile2 [file nativename ~/tcldifftmp.ps]
    set tmpFile3 [file nativename ~/tcldiff.ps]
    set ch [open $tmpFile "w"]

    set lines1 {}
    set lines2 {}

    set tdump1 [.t1 dump -tag -text 1.0 end]
    set tdump2 [.t2 dump -tag -text 1.0 end]

    foreach tdump [list $tdump1 $tdump2] \
            lineName {lines1 lines2} wrapName {wrap1 wrap2} {
        set lines {}
        set wraps {}
        set line ""
        set newline 0







|
|







1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
    set tmpFile2 [file nativename ~/tcldifftmp.ps]
    set tmpFile3 [file nativename ~/tcldiff.ps]
    set ch [open $tmpFile "w"]

    set lines1 {}
    set lines2 {}

    set tdump1 [.ft1.tt dump -tag -text 1.0 end]
    set tdump2 [.ft2.tt dump -tag -text 1.0 end]

    foreach tdump [list $tdump1 $tdump2] \
            lineName {lines1 lines2} wrapName {wrap1 wrap2} {
        set lines {}
        set wraps {}
        set line ""
        set newline 0
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177

1178
1179
1180
1181
1182
1183
1184
                    append line $value
                    incr chars $len
                }
                tagon {
                    if {$value == "change"} {
                        append line "\0bggray\{.6\}"
                        set gray 0.6
                    } else {
                        append line "\0bggray\{.8\}"
                        set gray 0.8
                    }
                }
                tagoff {

                    append line "\0bggray\{1.0\}"
                    set gray 1.0

                }
            }
        }
        set $lineName $lines
        set $wrapName $wraps
    }








|





>
|
|
>







1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
                    append line $value
                    incr chars $len
                }
                tagon {
                    if {$value == "change"} {
                        append line "\0bggray\{.6\}"
                        set gray 0.6
                    } elseif {$value != "last"} {
                        append line "\0bggray\{.8\}"
                        set gray 0.8
                    }
                }
                tagoff {
                    if {$value != "last"} {
                        append line "\0bggray\{1.0\}"
                        set gray 1.0
                    }
                }
            }
        }
        set $lineName $lines
        set $wrapName $wraps
    }

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
            $tmpFile'\n$tmpFile3\nCreated with 'mpage -aA2P $tmpFile2 >\
            $tmpFile3'"
    pack .dp.b -side bottom
    pack .dp.l -side top
}

proc my_yview args {
    eval .t1 yview $args
    eval .t2 yview $args

}

proc my_yscroll args {
    eval .sby set $args
    my_yview moveto [lindex $args 0]
}

proc chFont {} {
    global Pref

    font configure myfont -size $Pref(fontsize) -family $Pref(fontfamily)
}

proc applyColor {} {
    global Pref


    .t1 tag configure new1 -foreground $Pref(colornew1) -background $Pref(bgnew1)
    .t1 tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
    .t2 tag configure new2 -foreground $Pref(colornew2) -background $Pref(bgnew2)
    .t2 tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)

}

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








|
|
>
















>
|
|
|
|
>







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
            $tmpFile'\n$tmpFile3\nCreated with 'mpage -aA2P $tmpFile2 >\
            $tmpFile3'"
    pack .dp.b -side bottom
    pack .dp.l -side top
}

proc my_yview args {
    foreach w {.ft1.tl .ft1.tt .ft2.tl .ft2.tt} {
	eval $w yview $args
    }
}

proc my_yscroll args {
    eval .sby set $args
    my_yview moveto [lindex $args 0]
}

proc chFont {} {
    global Pref

    font configure myfont -size $Pref(fontsize) -family $Pref(fontfamily)
}

proc applyColor {} {
    global Pref

    foreach w {.tl .tt} {
	.ft1$w tag configure new1 -foreground $Pref(colornew1) -background $Pref(bgnew1)
	.ft1$w tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
	.ft2$w tag configure new2 -foreground $Pref(colornew2) -background $Pref(bgnew2)
	.ft2$w tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
    }
}

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

1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
        .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
    menu .mo.m
    .mo.m add cascade -label Fontsize -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)
    .mo.m add separator
    .mo.m add command -label "Save default" -command saveOptions








|







1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
        .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
    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 checkbutton -label "Diffs only" -variable Pref(onlydiffs)
    .mo.m add separator
    .mo.m add command -label "Save default" -command saveOptions

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
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
    .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 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" -variable Pref(extralineparse)


    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
    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
    label .l2 -textvariable rightLabel -anchor e -width 10




    text .t1 -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand ".sbx1 set" -font myfont



    scrollbar .sby -orient vertical -command "my_yview"
    scrollbar .sbx1 -orient horizontal -command ".t1 xview"




    text .t2 -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand ".sbx2 set" -font myfont



    scrollbar .sbx2 -orient horizontal -command ".t2 xview"
    label .le -textvariable eqLabel -width 1
    canvas .c -width 4

    applyColor



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

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

    if {$debug == 1} {
        menubutton .md -text Debug -menu .md.m -relief ridge
        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
        }
        .md.m add command -label "Stack trace" -command {bgerror Debug}
        .md.m add separator
        .md.m add command -label "Reread Source" -command {source diff.tcl}
        .md.m add separator
        .md.m add command -label "Redraw Window" -command {makeDiffWin}
        .md.m add separator
        .md.m add command -label "Normal Cursor" -command {normalCursor}
        
        pack .mf .mo .mh .md -in .f -side left
    } else {







>
















>
>
>
>
|
|
>
>
>

|
>
>
>
>
|
|
>
>
>
|




>
>


|



















|







1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
    .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 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" -variable Pref(extralineparse)
    .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
    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
    label .l2 -textvariable rightLabel -anchor e -width 10

    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
    text .ft1.tt -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand ".sbx1 set" -font myfont -borderwidth 0 -padx 0 \
            -highlightthickness 0
    pack .ft1.tl -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 40 -width 5 -wrap none -yscrollcommand my_yscroll \
	    -font myfont -borderwidth 0 -padx 0 -highlightthickness 0
    text .ft2.tt -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand ".sbx2 set" -font myfont -borderwidth 0 -padx 0 \
            -highlightthickness 0
    pack .ft2.tl -side left -fill y
    pack .ft2.tt -side right -fill both -expand 1
    scrollbar .sbx2 -orient horizontal -command ".ft2.tt xview"
    label .le -textvariable eqLabel -width 1
    canvas .c -width 4

    applyColor
    .ft1.tt tag configure last -underline 1
    .ft2.tt tag configure last -underline 1

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

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

    if {$debug == 1} {
        menubutton .md -text Debug -menu .md.m -relief ridge
        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
        }
        .md.m add command -label "Stack trace" -command {bgerror Debug}
        .md.m add separator
        .md.m add command -label "Reread Source" -command {source $thisscript}
        .md.m add separator
        .md.m add command -label "Redraw Window" -command {makeDiffWin}
        .md.m add separator
        .md.m add command -label "Normal Cursor" -command {normalCursor}
        
        pack .mf .mo .mh .md -in .f -side left
    } else {
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634
1635
1636
1637
1638
1639
  Open Right File: Select a file for right window, run diff
  RCSDiff        : (UNIX only) Select one file and diff like rcsdiff.
  Print          : (UNIX only) Experimental print function.
                   It currently creates a postscript file ~/tcldiff.ps
  Quit           : Guess

Options Menu
  Fontsize : Select fontsize for the two main text windows
  Ignore   : Diff options for handling whitespace
  Parse    : Additional parsing made by diff.tcl to improve the display.
             See examples below.
             Nothing: No parsing made.
             Lines  : When there is a changed block with the same number
                      of lines in both right and left files, diff.tcl
                      compares corresponding lines and tries to highlight
                      only the part that has been changed.
             Blocks : When the number of lines in a changed block is not
                      the same in both files, diff.tcl tries to find lines
                      that look the same and place them abreast.
             The Char and Word options selects if the line parsing should
             highlight full words only, or check single characters.
             2nd stage  : More thorough parsing of a line.

  Diffs only : Only differing lines will be displayed.
  Colours  : Choose highlight colours.
  Save default: Save current option settings in ~/.diffrc

Diff Options Field: Any text written here will be passed to diff.
                    In RCS mode, any -r options will be used to select versions.








|














>







1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
  Open Right File: Select a file for right window, run diff
  RCSDiff        : (UNIX only) Select one file and diff like rcsdiff.
  Print          : (UNIX only) Experimental print function.
                   It currently creates a postscript file ~/tcldiff.ps
  Quit           : Guess

Options Menu
  Font     : Select font ant fontsize for the two main text windows
  Ignore   : Diff options for handling whitespace
  Parse    : Additional parsing made by diff.tcl to improve the display.
             See examples below.
             Nothing: No parsing made.
             Lines  : When there is a changed block with the same number
                      of lines in both right and left files, diff.tcl
                      compares corresponding lines and tries to highlight
                      only the part that has been changed.
             Blocks : When the number of lines in a changed block is not
                      the same in both files, diff.tcl tries to find lines
                      that look the same and place them abreast.
             The Char and Word options selects if the line parsing should
             highlight full words only, or check single characters.
             2nd stage  : More thorough parsing of a line.
             Mark last  : Last change of a line is underlined
  Diffs only : Only differing lines will be displayed.
  Colours  : Choose highlight colours.
  Save default: Save current option settings in ~/.diffrc

Diff Options Field: Any text written here will be passed to diff.
                    In RCS mode, any -r options will be used to select versions.

1846
1847
1848
1849
1850
1851
1852

1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
    set Pref(colorchange) red
    set Pref(colornew1) darkgreen
    set Pref(colornew2) blue
    set Pref(bgchange) gray
    set Pref(bgnew1) gray
    set Pref(bgnew2) gray
    set Pref(onlydiffs) 0


    if {[file exists "~/.diffrc"]} {
        source "~/.diffrc"
    }
}

if {![winfo exists .f]} {
    getOptions
    makeDiffWin
    update idletasks
    parseCommandLine
}







>












1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
    set Pref(colorchange) red
    set Pref(colornew1) darkgreen
    set Pref(colornew2) blue
    set Pref(bgchange) gray
    set Pref(bgnew1) gray
    set Pref(bgnew2) gray
    set Pref(onlydiffs) 0
    set Pref(marklast) 1

    if {[file exists "~/.diffrc"]} {
        source "~/.diffrc"
    }
}

if {![winfo exists .f]} {
    getOptions
    makeDiffWin
    update idletasks
    parseCommandLine
}