Eskil

Check-in [e1427ef4fa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Moved to .dirdiff toplevel. Moved some globals to dirdiff array.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e1427ef4fa2a58a7af8933193617c5b73cefba33
User & Date: peter 2003-08-24 18:43:44.000
Context
2003-08-24
19:34
A few small adjustments to prepare for integrating dirdiff. check-in: 5cc07cb4c3 user: peter tags: trunk
18:43
Moved to .dirdiff toplevel. Moved some globals to dirdiff array. check-in: e1427ef4fa user: peter tags: trunk
2003-08-20
20:39
Code cleanup. No lower case procs. check-in: 24888431ce user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to dirdiff.tcl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
#
# Copyright (C) 1999-2003 Peter Spjuth
#
#-----------------------------------------------
# $Revision$
#-----------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"

package require Tk 8.3

set debug 0
set thisScript [file join [pwd] [info script]]
set thisDir [file dirname $thisScript]

# Support for FreeWrap 5.5
if {[info proc ::freewrap::unpack] != ""} {
    set debug 0
    set thisDir [file dirname [info nameofexecutable]]
    set thisScript ""
    # Assume a wrapped diff too
    set tclDiffExe [list [file join $::thisDir diffw.exe]]
} else {
    if {[file type $thisScript] == "link"} {
        set tmplink [file readlink $thisScript]
        set thisDir [file dirname [file join $thisDir $tmplink]]
        unset tmplink
    }
    set tclDiffExe [list [info nameofexecutable] \
                            [file join $::thisDir diff.tcl]]
}


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













|

















|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
#
# Copyright (C) 1999-2003 Peter Spjuth
#
#-----------------------------------------------
# $Revision$
#-----------------------------------------------
# the next line restarts using wish \
exec wish "$0" "$@"

package require Tk 8.3

set debug 1
set thisScript [file join [pwd] [info script]]
set thisDir [file dirname $thisScript]

# Support for FreeWrap 5.5
if {[info proc ::freewrap::unpack] != ""} {
    set debug 0
    set thisDir [file dirname [info nameofexecutable]]
    set thisScript ""
    # Assume a wrapped diff too
    set tclDiffExe [list [file join $::thisDir diffw.exe]]
} else {
    if {[file type $thisScript] == "link"} {
        set tmplink [file readlink $thisScript]
        set thisDir [file dirname [file join $thisDir $tmplink]]
        unset tmplink
    }
    set tclDiffExe [list [info nameofexecutable] \
                            [file join $::thisDir diff.kit.tcl]]
}


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

60
61
62
63
64
65
66

67
68
69
70
71
72
73
    string compare -nocase $s1 $s2
}

proc flsort {l} {
    if {$::tcl_platform(platform) == "unix"} {
	return [lsort $l]
    }

    lsort -dictionary $l
}

proc compareFiles {file1 file2} {
    global Pref
    file stat $file1 stat1
    file stat $file2 stat2







>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    string compare -nocase $s1 $s2
}

proc flsort {l} {
    if {$::tcl_platform(platform) == "unix"} {
	return [lsort $l]
    }
    # Case insensitive on windows
    lsort -dictionary $l
}

proc compareFiles {file1 file2} {
    global Pref
    file stat $file1 stat1
    file stat $file2 stat2
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
        }
    }
    return $eq
}

# infoFiles: 1= noLeft 2 = noRight 4=left is dir  8= right is dir 16=diff
proc listFiles {df1 df2 diff level} {
    global leftFiles rightFiles infoFiles

    if {$::Pref(nodir)} {
        if {$df1 != "" && [file isdirectory $df1] && \
                $df2 != "" && [file isdirectory $df2] } {
            return
        }
    }







|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        }
    }
    return $eq
}

# infoFiles: 1= noLeft 2 = noRight 4=left is dir  8= right is dir 16=diff
proc listFiles {df1 df2 diff level} {
    global dirdiff leftFiles rightFiles infoFiles

    if {$::Pref(nodir)} {
        if {$df1 != "" && [file isdirectory $df1] && \
                $df2 != "" && [file isdirectory $df2] } {
            return
        }
    }
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
            set tag2 changed
        } else {
            set tag2 change
        }
    }
    if {$df2 == ""} {
	set tag1 new1
	.t2 insert end \n
    } else {
        if {$info & 4} {
            set tag1 changed
        } else {
            set tag1 change
        }
	.t2 insert end [format "%-30s %8d %16s\n" $f2 [file size $df2] \

		[clock format [file mtime $df2] -format "%Y-%m-%d %H:%M"]] \
		$tag2
    }
    if {!$diff} {
	set tag1 ""
    }
    if {$df1 == ""} {
	.t1 insert end \n
    } else {
	.t1 insert end [format "%-30s %8d %16s\n" $f1 [file size $df1] \

		[clock format [file mtime $df1] -format "%Y-%m-%d %H:%M"]] \
		$tag1
    }
    lappend infoFiles $info
}

proc compareDirs {dir1 dir2 {level 0}} {







|






|
>







|

|
>







180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
            set tag2 changed
        } else {
            set tag2 change
        }
    }
    if {$df2 == ""} {
	set tag1 new1
	$dirdiff(wRight) insert end \n
    } else {
        if {$info & 4} {
            set tag1 changed
        } else {
            set tag1 change
        }
	$dirdiff(wRight) insert end [format "%-30s %8d %16s\n" \
                $f2 [file size $df2] \
		[clock format [file mtime $df2] -format "%Y-%m-%d %H:%M"]] \
		$tag2
    }
    if {!$diff} {
	set tag1 ""
    }
    if {$df1 == ""} {
	$dirdiff(wLeft) insert end \n
    } else {
	$dirdiff(wLeft) insert end [format "%-30s %8d %16s\n" \
                $f1 [file size $df1] \
		[clock format [file mtime $df1] -format "%Y-%m-%d %H:%M"]] \
		$tag1
    }
    lappend infoFiles $info
}

proc compareDirs {dir1 dir2 {level 0}} {
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
	} else {
	    break
	}
    }
}

proc doCompare {} {
    global leftDir rightDir leftFiles rightFiles infoFiles
    if {![file isdirectory $leftDir]} return
    if {![file isdirectory $rightDir]} return
    set leftFiles {}
    set rightFiles {}
    set infoFiles {}
    .t1 delete 1.0 end
    .t2 delete 1.0 end
    compareDirs $leftDir $rightDir
}

proc browseDir {dirVar} {
    global Pref
    upvar #0 $dirVar dir

    set newdir $dir
    while {$newdir != "." && ![file isdirectory $newdir]} {
        set newdir [file dirname $newdir]
    }
    set newdir [tk_chooseDirectory -initialdir $newdir -title "Select Directory"]
    if {$newdir != ""} {
        set dir $newdir
    }
    if {$Pref(autocompare)} doCompare
}

proc selectFile {w x y} {
    global leftDir rightDir leftFiles rightFiles infoFiles Pref

    set row [expr {int([$w index @$x,$y]) - 1}]
    set lf [lindex $leftFiles $row]
    set rf [lindex $rightFiles $row]
    set i [lindex $infoFiles $row]
    if {($i & 12) == 12} { # Both are dirs
        set leftDir $lf
        set rightDir $rf
        if {$Pref(autocompare)} doCompare
    } elseif {$i & 4} { # Left is dir
        set leftDir $lf
        if {$Pref(autocompare)} doCompare
    } elseif {$i & 8} { # Right is dir
        set rightDir $rf
        if {$Pref(autocompare)} doCompare
    } elseif {($i & 3) == 0} { # Both exists
        remoteDiff $lf $rf
    }
}

proc rightClick {w x y X Y} {
    global leftDir rightDir leftFiles rightFiles infoFiles Pref

    set row [expr {int([$w index @$x,$y]) - 1}]
    set lf [lindex $leftFiles $row]
    set rf [lindex $rightFiles $row]
    set i [lindex $infoFiles $row]


    destroy .m
    menu .m -tearoff 0
    if {($i & 12) == 12} { # Both are dirs
        .m add command -label "Compare Directories" -command "
            [list set leftDir $lf]
            [list set rightDir $rf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {$i & 4} { # Left is dir
        .m add command -label "Step down left directory" -command "
            [list set leftDir $lf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {$i & 8} { # Right is dir
        .m add command -label "Step down right directory" -command "
            [list set rightDir $rf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {($i & 3) == 0} { # Both exists
        .m add command -label "Compare Files" -command [list \
                remoteDiff $lf $rf]
    }
    if {$w == ".t1" && ($i & 13) == 0} {
        .m add command -label "Copy File" -command [list \
                copyFile $row right]
        .m add command -label "Edit File" -command [list \
                editFile $row left]
    }
    if {$w == ".t2" && ($i & 14) == 0} {
        .m add command -label "Copy File" -command [list \
                copyFile $row left]
        .m add command -label "Edit File" -command [list \
                editFile $row right]
    }

    tk_popup .m $X $Y
}

proc copyFile {row to} {
    global leftDir rightDir leftFiles rightFiles infoFiles Pref

    if {$to == "left"} {
        set src [lindex $rightFiles $row]
        set n [expr {[string length $rightDir] + 1}]
        set dst [file join $leftDir [string range $src $n end]]
    } elseif {$to == "right"} {
        set src [lindex $leftFiles $row]
        set n [expr {[string length $leftDir] + 1}]
        set dst [file join $rightDir [string range $src $n end]]
    } else {
        error "Bad to argument to copyFile: $to"
    }

    if {[file exists $dst]} {
        if {[tk_messageBox -icon question -title "Overwrite file?" -message \
                "Copy\n$src\noverwriting\n$dst ?" -type yesno] == "yes"} {
            file copy -force $src $dst
        }
    } else {
        if {[tk_messageBox -icon question -title "Copy file?" -message \
                "Copy\n$src\nto\n$dst ?" -type yesno] == "yes"} {
            file copy $src $dst
        }
    }
}

proc editFile {row from} {
    global leftDir rightDir leftFiles rightFiles infoFiles Pref

    if {$from == "left"} {
        set src [file join $leftDir [lindex $leftFiles $row]]
    } elseif {$from == "right"} {
        set src [file join $rightDir [lindex $rightFiles $row]]
    } else {
        error "Bad from argument to editFile: $from"
    }

    exec $::editor $src &
}








|
|
|



|
|
|


















|






|
|


|


|







|






>
|
|

|
|
|



|
|



|
|



|


|
|
|
|
|

|
|
|
|
|


|



|



|
|


|
|


















|


|

|







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
	} else {
	    break
	}
    }
}

proc doCompare {} {
    global dirdiff leftFiles rightFiles infoFiles
    if {![file isdirectory $dirdiff(leftDir)]} return
    if {![file isdirectory $dirdiff(rightDir)]} return
    set leftFiles {}
    set rightFiles {}
    set infoFiles {}
    $dirdiff(wLeft) delete 1.0 end
    $dirdiff(wRight) delete 1.0 end
    compareDirs $dirdiff(leftDir) $dirdiff(rightDir)
}

proc browseDir {dirVar} {
    global Pref
    upvar #0 $dirVar dir

    set newdir $dir
    while {$newdir != "." && ![file isdirectory $newdir]} {
        set newdir [file dirname $newdir]
    }
    set newdir [tk_chooseDirectory -initialdir $newdir -title "Select Directory"]
    if {$newdir != ""} {
        set dir $newdir
    }
    if {$Pref(autocompare)} doCompare
}

proc selectFile {w x y} {
    global dirdiff leftFiles rightFiles infoFiles Pref

    set row [expr {int([$w index @$x,$y]) - 1}]
    set lf [lindex $leftFiles $row]
    set rf [lindex $rightFiles $row]
    set i [lindex $infoFiles $row]
    if {($i & 12) == 12} { # Both are dirs
        set dirdiff(leftDir) $lf
        set dirdiff(rightDir) $rf
        if {$Pref(autocompare)} doCompare
    } elseif {$i & 4} { # Left is dir
        set dirdiff(leftDir) $lf
        if {$Pref(autocompare)} doCompare
    } elseif {$i & 8} { # Right is dir
        set dirdiff(rightDir) $rf
        if {$Pref(autocompare)} doCompare
    } elseif {($i & 3) == 0} { # Both exists
        remoteDiff $lf $rf
    }
}

proc rightClick {w x y X Y} {
    global dirdiff leftFiles rightFiles infoFiles Pref

    set row [expr {int([$w index @$x,$y]) - 1}]
    set lf [lindex $leftFiles $row]
    set rf [lindex $rightFiles $row]
    set i [lindex $infoFiles $row]

    set m .dirdiff.m
    destroy $m
    menu $m -tearoff 0
    if {($i & 12) == 12} { # Both are dirs
        $m add command -label "Compare Directories" -command "
            [list set dirdiff(leftDir) $lf]
            [list set dirdiff(rightDir) $rf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {$i & 4} { # Left is dir
        $m add command -label "Step down left directory" -command "
            [list set dirdiff(leftDir) $lf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {$i & 8} { # Right is dir
        $m add command -label "Step down right directory" -command "
            [list set dirdiff(rightDir) $rf]
            [list if \$Pref(autocompare) "after idle doCompare"]
        "
    } elseif {($i & 3) == 0} { # Both exists
        $m add command -label "Compare Files" -command [list \
                remoteDiff $lf $rf]
    }
    if {$w == $dirdiff(wLeft) && ($i & 13) == 0} {
        $m add command -label "Copy File" \
                -command [list copyFile $row right]
        $m add command -label "Edit File" \
                -command [list editFile $row left]
    }
    if {$w == $dirdiff(wRight) && ($i & 14) == 0} {
        $m add command -label "Copy File" \
                -command [list copyFile $row left]
        $m add command -label "Edit File" \
                -command [list editFile $row right]
    }

    tk_popup $m $X $Y
}

proc copyFile {row to} {
    global dirdiff leftFiles rightFiles infoFiles Pref

    if {$to == "left"} {
        set src [lindex $rightFiles $row]
        set n [expr {[string length $dirdiff(rightDir)] + 1}]
        set dst [file join $dirdiff(leftDir) [string range $src $n end]]
    } elseif {$to == "right"} {
        set src [lindex $leftFiles $row]
        set n [expr {[string length $dirdiff(leftDir)] + 1}]
        set dst [file join $dirdiff(rightDir) [string range $src $n end]]
    } else {
        error "Bad to argument to copyFile: $to"
    }

    if {[file exists $dst]} {
        if {[tk_messageBox -icon question -title "Overwrite file?" -message \
                "Copy\n$src\noverwriting\n$dst ?" -type yesno] == "yes"} {
            file copy -force $src $dst
        }
    } else {
        if {[tk_messageBox -icon question -title "Copy file?" -message \
                "Copy\n$src\nto\n$dst ?" -type yesno] == "yes"} {
            file copy $src $dst
        }
    }
}

proc editFile {row from} {
    global dirdiff leftFiles rightFiles infoFiles Pref

    if {$from == "left"} {
        set src [file join $dirdiff(leftDir) [lindex $leftFiles $row]]
    } elseif {$from == "right"} {
        set src [file join $dirdiff(rightDir) [lindex $rightFiles $row]]
    } else {
        error "Bad from argument to editFile: $from"
    }

    exec $::editor $src &
}

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

443
444
445
446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471


472


473




474
475
476
477



478

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550




551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
	    after 500
	    catch {dde eval -async Diff $cmd}
	}
    }
}

proc upDir {{n 0}} {
    global leftDir rightDir Pref
    switch $n {
        0 {
            set leftDir [file dirname $leftDir]
            set rightDir [file dirname $rightDir]
            if {$Pref(autocompare)} doCompare
        } 
        1 {
            set leftDir [file dirname $leftDir]
            if {$Pref(autocompare)} doCompare
        }
        2 {
            set rightDir [file dirname $rightDir]
            if {$Pref(autocompare)} doCompare
        }
    }            
}

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)
    .t1 tag configure changed -foreground $Pref(colorchange)
    .t2 tag configure new2 -foreground $Pref(colornew2) -background $Pref(bgnew2)
    .t2 tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
    .t2 tag configure changed -foreground $Pref(colorchange)
}

proc makeDirDiffWin {} {
    global Pref



    eval destroy [winfo children .]







    frame .fm
    frame .fe1
    frame .fe2




    menubutton .mo -menu .mo.m -text Preferences

    menu .mo.m
    .mo.m add checkbutton -variable Pref(recursive) -label Recursive
    .mo.m add cascade -label Check -menu .mo.mc
    .mo.m add checkbutton -variable Pref(diffonly) -label "Diffs Only"
    .mo.m add checkbutton -variable Pref(nodir)    -label "No Directory"
    .mo.m add checkbutton -variable Pref(autocompare) -label "Auto Compare"

    menu .mo.mc
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 0 \
            -label "Do not check contents"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 1 \
            -label "Internal compare"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 1b \
            -label "Internal compare (bin)"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 2 \
            -label "Use Diff"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 3 \
            -label "Diff, ignore blanks"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 4 \
            -label "Diff, ignore case"
    .mo.mc add radiobutton -variable Pref(comparelevel) -value 5 \
            -label "Diff, ignore RCS"
    pack .mo -in .fm -side left
    if {$::debug} {
        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 "Reread Source" -command {source $thisScript}
        .md.m add separator
        .md.m add command -label "Redraw Window" -command {makeDirDiffWin}
        pack .md -in .fm -side left
    }

    button .bc -text Compare -command doCompare

    button .bu -text Up -command upDir

    button .bu1 -text Up -command {upDir 1}
    button .bu2 -text Up -command {upDir 2}
    pack .bc .bu -in .fm -side right

    catch {font delete myfont}
    font create myfont -family $Pref(fontfamily) -size $Pref(fontsize)

    entry .e1 -textvariable leftDir
    entry .e2 -textvariable rightDir
    button .bb1 -text Browse -command {browseDir leftDir}
    button .bb2 -text Browse -command {browseDir rightDir}
    bind .e1 <Return> doCompare
    bind .e2 <Return> doCompare

    pack .bb1 .bu1 -in .fe1 -side right
    pack .e1 -in .fe1 -side left -fill x -expand 1
    pack .bb2 .bu2 -in .fe2 -side right
    pack .e2 -in .fe2 -side left -fill x -expand 1

    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"
    canvas .c -width 4

    bind .t1 <Double-Button-1> "after idle selectFile .t1 %x %y"
    bind .t2 <Double-Button-1> "after idle selectFile .t2 %x %y"
    bind .t1 <Button-3> "rightClick .t1 %x %y %X %Y"
    bind .t2 <Button-3> "rightClick .t2 %x %y %X %Y"





    applyColor

    grid .fm   - - -   -     -sticky we
    grid .fe1  x  x    .fe2  -sticky we
    grid .t1   .c .sby .t2   -sticky news
    grid .sbx1 x  x    .sbx2 -sticky we

    grid rowconfigure    . 2 -weight 1
    grid columnconfigure . {0 3} -weight 1
}

proc getOptions {} {
    global Pref

    set Pref(fontsize) 9
    set Pref(fontfamily) courier







|


|
|



|



|






>
|
|



>
|










|

|
|
|
|
|
|



|

>
>
|
>
>
|
>
>
>
>
|
|
|

>
>
>
|
>
|
|
|
|
|
|

|
|

|

|

|

|

|

|

|

|
|

|

|

|
|
|
|


|
>
|
>
|
|
|




|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|

>
>
>
>


|
|
|
|

|
|







421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
	    after 500
	    catch {dde eval -async Diff $cmd}
	}
    }
}

proc upDir {{n 0}} {
    global dirdiff Pref
    switch $n {
        0 {
            set dirdiff(leftDir) [file dirname $dirdiff(leftDir)]
            set dirdiff(rightDir) [file dirname $dirdiff(rightDir)]
            if {$Pref(autocompare)} doCompare
        } 
        1 {
            set dirdiff(leftDir) [file dirname $dirdiff(leftDir)]
            if {$Pref(autocompare)} doCompare
        }
        2 {
            set dirdiff(rightDir) [file dirname $dirdiff(rightDir)]
            if {$Pref(autocompare)} doCompare
        }
    }            
}

proc my_yview {args} {
    global dirdiff
    eval $dirdiff(wLeft) yview $args
    eval $dirdiff(wRight) yview $args
}

proc my_yscroll {args} {
    global dirdiff
    eval $dirdiff(wY) set $args
    my_yview moveto [lindex $args 0]
}

proc chFont {} {
    global Pref

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

proc applyColor {} {
    global dirdiff Pref

    $dirdiff(wLeft) tag configure new1 -foreground $Pref(colornew1) -background $Pref(bgnew1)
    $dirdiff(wLeft) tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
    $dirdiff(wLeft) tag configure changed -foreground $Pref(colorchange)
    $dirdiff(wRight) tag configure new2 -foreground $Pref(colornew2) -background $Pref(bgnew2)
    $dirdiff(wRight) tag configure change -foreground $Pref(colorchange) -background $Pref(bgchange)
    $dirdiff(wRight) tag configure changed -foreground $Pref(colorchange)
}

proc makeDirDiffWin {} {
    global Pref dirdiff

    set top .dirdiff
    if {[winfo exists $top] && [winfo toplevel $top] == $top} {
        eval destroy [winfo children $top]
    } else {
        toplevel $top
    }

    wm title $top "Directory Diff"
    wm protocol $top WM_DELETE_WINDOW exit

    frame $top.fm
    frame $top.fe1
    frame $top.fe2

    menubutton $top.mf -menu $top.mf.m -text "File" -underline 0
    menu $top.mf.m
    $top.mf.m add command -label "Quit" -underline 0 -command exit

    menubutton $top.mo -menu $top.mo.m -text "Preferences" -underline 0
    menu $top.mo.m
    $top.mo.m add checkbutton -variable Pref(recursive) -label "Recursive"
    $top.mo.m add cascade -label "Check" -menu $top.mo.mc
    $top.mo.m add checkbutton -variable Pref(diffonly) -label "Diffs Only"
    $top.mo.m add checkbutton -variable Pref(nodir)    -label "No Directory"
    $top.mo.m add checkbutton -variable Pref(autocompare) -label "Auto Compare"

    menu $top.mo.mc
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 0 \
            -label "Do not check contents"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 1 \
            -label "Internal compare"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 1b \
            -label "Internal compare (bin)"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 2 \
            -label "Use Diff"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 3 \
            -label "Diff, ignore blanks"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 4 \
            -label "Diff, ignore case"
    $top.mo.mc add radiobutton -variable Pref(comparelevel) -value 5 \
            -label "Diff, ignore RCS"
    pack $top.mf $top.mo -in $top.fm -side left
    if {$::debug} {
        menubutton $top.md -text "Debug" -menu $top.md.m -underline 0
        menu $top.md.m
        if {$::tcl_platform(platform) == "windows"} {
            $top.md.m add checkbutton -label "Console" -variable consolestate \
                    -onvalue show -offvalue hide -command {console $consolestate}
            $top.md.m add separator
        }
        $top.md.m add command -label "Reread Source" -command {source $thisScript}
        $top.md.m add separator
        $top.md.m add command -label "Redraw Window" -command {makeDirDiffWin}
        pack $top.md -in $top.fm -side left -padx 20
    }

    button $top.bc -text "Compare" -command doCompare -underline 0
    bind $top <Alt-c> "$top.bc invoke"
    button $top.bu -text "Up Both" -command upDir -underline 0
    bind $top <Alt-u> "$top.bu invoke"
    button $top.bu1 -text "Up" -command {upDir 1}
    button $top.bu2 -text "Up" -command {upDir 2}
    pack $top.bc $top.bu -in $top.fm -side right

    catch {font delete myfont}
    font create myfont -family $Pref(fontfamily) -size $Pref(fontsize)

    entry $top.e1 -textvariable dirdiff(leftDir)
    entry $top.e2 -textvariable dirdiff(rightDir)
    button $top.bb1 -text "Browse" -command {browseDir dirdiff(leftDir)}
    button $top.bb2 -text "Browse" -command {browseDir dirdiff(rightDir)}
    bind $top.e1 <Return> doCompare
    bind $top.e2 <Return> doCompare

    pack $top.bb1 $top.bu1 -in $top.fe1 -side right
    pack $top.e1 -in $top.fe1 -side left -fill x -expand 1
    pack $top.bb2 $top.bu2 -in $top.fe2 -side right
    pack $top.e2 -in $top.fe2 -side left -fill x -expand 1

    text $top.t1 -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand "$top.sbx1 set" -font myfont
    scrollbar $top.sby -orient vertical -command "my_yview"
    scrollbar $top.sbx1 -orient horizontal -command "$top.t1 xview"
    text $top.t2 -height 40 -width 60 -wrap none -yscrollcommand my_yscroll \
	    -xscrollcommand "$top.sbx2 set" -font myfont
    scrollbar $top.sbx2 -orient horizontal -command "$top.t2 xview"
    canvas $top.c -width 4

    bind $top.t1 <Double-Button-1> "after idle selectFile $top.t1 %x %y"
    bind $top.t2 <Double-Button-1> "after idle selectFile $top.t2 %x %y"
    bind $top.t1 <Button-3> "rightClick $top.t1 %x %y %X %Y"
    bind $top.t2 <Button-3> "rightClick $top.t2 %x %y %X %Y"

    set dirdiff(wLeft)  $top.t1
    set dirdiff(wRight) $top.t2
    set dirdiff(wY) $top.sby

    applyColor

    grid $top.fm   - - -   -     -sticky we
    grid $top.fe1  x  x    $top.fe2  -sticky we
    grid $top.t1   $top.c $top.sby $top.t2   -sticky news
    grid $top.sbx1 x  x    $top.sbx2 -sticky we

    grid rowconfigure    $top  2    -weight 1
    grid columnconfigure $top {0 3} -weight 1
}

proc getOptions {} {
    global Pref

    set Pref(fontsize) 9
    set Pref(fontfamily) courier
578
579
580
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

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

proc parseCommandLine {} {
    global argc argv leftDir rightDir Pref

    if {$argc == 2} {
        set leftDir [file join [pwd] [lindex $argv 0]]
        set rightDir [file join [pwd] [lindex $argv 1]]
    } elseif {$argc == 1} {
        set leftDir [file join [pwd] [lindex $argv 0]]
        set rightDir $leftDir
    } else {
        set leftDir [pwd]
        set rightDir [pwd]
    }
}


if {![winfo exists .fm]} {

    getOptions
    parseCommandLine
    makeDirDiffWin

    if {$leftDir != "" && $rightDir != "" && $leftDir != $rightDir} {

        update idletasks
        .e1 xview end
        .e2 xview end
        doCompare
    }
}







|


|
|

|
|

|
|



>
|
>



>
|
>

|
|



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

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

proc parseCommandLine {} {
    global argc argv dirdiff Pref

    if {$argc == 2} {
        set dirdiff(leftDir) [file join [pwd] [lindex $argv 0]]
        set dirdiff(rightDir) [file join [pwd] [lindex $argv 1]]
    } elseif {$argc == 1} {
        set dirdiff(leftDir) [file join [pwd] [lindex $argv 0]]
        set dirdiff(rightDir) $dirdiff(leftDir)
    } else {
        set dirdiff(leftDir) [pwd]
        set dirdiff(rightDir) [pwd]
    }
}


if {![info exists gurkmeja]} {
    set gurkmeja 1
    getOptions
    parseCommandLine
    makeDirDiffWin
    wm withdraw .
    if {$dirdiff(leftDir) != "" && $dirdiff(rightDir) != "" && \
                $dirdiff(leftDir) != $dirdiff(rightDir)} {
        update idletasks
        #.e1 xview end
        #.e2 xview end
        doCompare
    }
}