Eskil

Diff
Login

Differences From Artifact [048b19a7b9]:

To Artifact [bd14b1f9bc]:


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
88
89
90


91
92
93
94
95
96
97
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
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
88
89
90
91
92
93
94
95
96
97
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







-
+




+
+

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








-
-
+
-
-
-
-
-
-
+






+
+
+
+
+



-
-
+
+
















-
-
-
-
+
+
+




-
-
+


-
+







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

set debug 1
set diffver "Version 1.9.4b  2002-03-15"
set diffver "Version 1.9.4b  2002-04-12"
set tmpcnt 0
set tmpfiles {}
set thisscript [file join [pwd] [info script]]
set thisdir [file dirname $thisscript]
set ::diff(cvsExists) [expr {![string equal [auto_execok cvs] ""]}]
set ::diff(diffexe) diff

if {[info exists env(TEMP)]} {
    set ::diff(tmpdir) $env(TEMP)
} elseif {[info exists env(TMP)]} {
    set ::diff(tmpdir) $env(TMP)
} else {
    if {$tcl_platform(platform) == "windows"} {
        set ::diff(tmpdir) c:/
    } else {
set diffexe diff
        set ::diff(tmpdir) .
    }
}

# Support for FreeWrap.
if {[info exists ::freewrap::contents]} {
    set debug 0
    set thisdir [pwd]
    set thisscript ""
    # If diff.exe is wrapped, copy it so we can use it.
    if {[info exists ::freewrap::pkgInfo(diff.exe)]} {
        if {[info exists env(TEMP)]} {
            set diffexe [file join $env(TEMP) diff.exe]
        set ::diff(diffexe) [file join $diff(tmpdir) diff.exe]
        } elseif {[info exists env(TMP)]} {
            set diffexe [file join $env(TMP) diff.exe]
        } else {
            set diffexe [file join c:/ diff.exe]
        }
        ::freewrap::pkgfilecopy diff.exe $diffexe force
        ::freewrap::pkgfilecopy diff.exe $::diff(diffexe) force
    }
}

if {$tcl_platform(platform) == "windows"} {
    cd $thisdir
    catch {package require dde}
    if {!$::diff(cvsExists) && [file exists "c:/bin/cvs.exe"]} {
        set env(PATH) "$env(PATH);c:\\bin"
        auto_reset
        set ::diff(cvsExists) [expr {![string equal [auto_execok cvs] ""]}]
    }
}

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

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

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

proc tmpfile {} {
    global tmpcnt tmpfiles
    incr tmpcnt
    set name "tmpd[pid]a$tmpcnt"
    lappend tmpfiles $name
    incr ::tmpcnt
    set name [file join $::diff(tmpdir) "tmpd[pid]a$::tmpcnt"]
    lappend ::tmpfiles $name
    return $name
}

proc cleartmp {} {
    global tmpfiles
    foreach f $tmpfiles {
    foreach f $::tmpfiles {
        file delete $f
    }
    set tmpfiles {}
    set ::tmpfiles {}
}

# 2nd stage line parsing
# Recursively look for common substrings in strings s1 and s2
##syntax compareMidString x x n n x?
proc compareMidString {s1 s2 res1Name res2Name {test 0}} {
    global Pref
1148
1149
1150
1151
1152
1153
1154





















1155
1156
1157
1158
1159
1160
1161
1157
1158
1159
1160
1161
1162
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
1188
1189
1190
1191







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







    if {$state != "none"} {
        displayOnePatch $leftLines $rightLines $leftLine $rightLine
    }

    close $ch

}

# Get a CVS revision
proc execCvsUpdate {filename outfile args} {
    set old ""
    set dir [file dirname $filename]
    if {$dir != "."} {
        set old [pwd]
        set outfile [file join [pwd] $outfile]
        cd $dir
        set filename [file tail $filename]
    }

    set cmd $args
    set cmd [linsert $args 0 exec cvs -z3 update -p]
    lappend cmd [file nativename $filename] > $outfile
    catch {eval $cmd}

    if {$old != ""} {
        cd $old
    }
}

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

    set revs {}
    set opts {}
1181
1182
1183
1184
1185
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
1224

1225
1226
1227
1228
1229
1230
1231
1211
1212
1213
1214
1215
1216
1217


1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232


1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248


1249


1250
1251
1252
1253
1254
1255
1256
1257







-
-
+














-
-
+















-
-
+
-
-
+







            # Compare local file with latest version.
            set diff(leftFile) [tmpfile]
            set diff(rightLabel) $diff(RCSFile)
            set diff(rightFile) $diff(RCSFile)

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

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

            if {$diff(mode) == "CVS"} {
                set diff(leftLabel) "$diff(RCSFile) (CVS $r1)"
                set diff(rightLabel) "$diff(RCSFile) (CVS $r2)"
                catch {exec cvs update -p -r $r1 \
                        [file nativename $diff(RCSFile)] > $diff(leftFile)}
                execCvsUpdate $diff(RCSFile) $diff(leftFile) -r $r1
                catch {exec cvs update -p -r $r2 \
                        [file nativename $diff(RCSFile)] > $diff(rightFile)}
                execCvsUpdate $diff(RCSFile) $diff(rightFile) -r $r2
            } else {
                set diff(leftLabel) "$diff(RCSFile) (RCS $r1)"
                set diff(rightLabel) "$diff(RCSFile) (RCS $r2)"
                catch {exec co -p$r1 [file nativename $diff(RCSFile)] > $diff(leftFile)}
                catch {exec co -p$r2 [file nativename $diff(RCSFile)] > $diff(rightFile)}
            }
        }
1287
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298
1299
1300
1301
1313
1314
1315
1316
1317
1318
1319

1320
1321
1322
1323
1324
1325
1326
1327







-
+







    } elseif {$diff(mode) == "RCS" || $diff(mode) == "CVS"} {
        prepareRCS
    } elseif {[string match "conflict*" $diff(mode)]} {
        prepareConflict
    }

    # Run diff and parse the result.
    set differr [catch {eval exec \$::diffexe $Pref(dopt) $Pref(ignore) \
    set differr [catch {eval exec \$::diff(diffexe) $Pref(dopt) $Pref(ignore) \
            \$diff(leftFile) \$diff(rightFile)} diffres]

    set apa [split $diffres "\n"]
    set result {}
    foreach i $apa {
        if {[string match {[0-9]*} $i]} {
            lappend result $i
2271
2272
2273
2274
2275
2276
2277
2278

2279
2280
2281
2282
2283
2284
2285
2297
2298
2299
2300
2301
2302
2303

2304
2305
2306
2307
2308
2309
2310
2311







-
+







        }
        if {$i < 66} {puts -nonewline $ch "\f"}
    }

    close $ch

    if {$::tcl_platform(platform) == "windows" &&\
            ![info exists env(ENSCRIPT_LIBRARY)]} {
            ![info exists ::env(ENSCRIPT_LIBRARY)]} {
        set ::env(ENSCRIPT_LIBRARY) [pwd]
    }
    set enscriptCmd [list enscript -2jcre]
    if {![regexp {^(.*)( \(.*?\))$} $::diff(leftLabel) -> lfile lrest]} {
        set lfile $::diff(leftLabel)
        set lrest ""
    }
2534
2535
2536
2537
2538
2539
2540


2541
2542
2543
2544
2545
2546
2547
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575







+
+







    .mf.m add command -label "Open Both (forget)" -command {openBoth 1}
    .mf.m add command -label "Open Left File" -command openLeft
    .mf.m add command -label "Open Right File" -command openRight
    .mf.m add command -label "Open Conflict File" -command openConflict
    .mf.m add command -label "Open Patch File" -command openPatch
    if {$tcl_platform(platform) == "unix"} {
        .mf.m add command -label "RCSDiff" -underline 0 -command openRCS
    }
    if {$::diff(cvsExists)} {
        .mf.m add command -label "CVSDiff" -underline 0 -command openCVS
    }
    .mf.m add separator
    .mf.m add command -label "Print" -underline 0 -command doPrint
    .mf.m add separator
    .mf.m add command -label "Quit" -command cleanupAndExit

3340
3341
3342
3343
3344
3345
3346



















3347
3348
3349
3350
3351
3352
3353
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400







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







    if {$autobrowse && (!$diff(leftOK) || !$diff(rightOK))} {
        if {!$diff(leftOK) && !$diff(rightOK)} {
            openBoth 0
        } elseif {!$diff(leftOK)} {
            openLeft
        } elseif {!$diff(rightOK)} {
            openRight
        }
        # If we cancel the second file and detect CVS, ask about it.
        if {$diff(leftOK) && !$diff(rightOK) && \
                [llength [glob -nocomplain [file join $fulldir CVS]]]} {

            if {[tk_messageBox -title Diff -icon question \
                    -message "Do CVS diff?" -type yesno] == "yes"} {
                set fulldir $diff(leftDir)
                set fullname $diff(leftFile)
                set diff(leftOK) 0
                set diff(mode) "CVS"
                set diff(rightDir) $fulldir
                set diff(RCSFile) $fullname
                set diff(rightLabel) $fullname
                set diff(rightFile) $fullname
                set diff(rightOK) 1
                set diff(leftLabel) "CVS"
                after idle doDiff
            }
        }
    }
}

proc saveOptions {} {
    global Pref