237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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
|
} elseif {$w2 > $w1} {
for {set t $w1} {$t < $w2} {incr t} {
lappend wraplines1 {}
}
}
}
# Write all lines to a file, taking one page at a time from each
# side.
set ch [open $tmpFile "w"]
fconfigure $ch -encoding binary
set len1 [llength $wraplines1]
set len2 [llength $wraplines2]
set i1 0
set i2 0
while {$i1 < $len1 && $i2 < $len2} {
for {set i 0} {$i < $linesPerPage && $i1 < $len1} {incr i ; incr i1} {
puts $ch [FormatLine [lindex $wraplines1 $i1]]
}
if {$i < $linesPerPage} {puts -nonewline $ch "\f"}
for {set i 0} {$i < $linesPerPage && $i2 < $len2} {incr i ; incr i2} {
puts $ch [FormatLine [lindex $wraplines2 $i2]]
}
if {$i < $linesPerPage} {puts -nonewline $ch "\f"}
}
close $ch
# Run enscript to generate postscript
if {$::tcl_platform(platform) eq "windows" &&\
![info exists ::env(ENSCRIPT_LIBRARY)]} {
set ::env(ENSCRIPT_LIBRARY) [pwd]
}
if {[auto_execok enscript.bin] ne ""} {
set enscriptCmd [list enscript.bin]
} else {
set enscriptCmd [list enscript]
}
lappend enscriptCmd -2jcre -L $linesPerPage -M A4
if {$::Pref(wideLines)} {
lappend enscriptCmd -f Courier6
}
if {![regexp {^(.*)( \(.*?\))$} $::diff($top,leftLabel) -> lfile lrest]} {
set lfile $::diff($top,leftLabel)
set lrest ""
}
set lfile [file tail $lfile]$lrest
if {![regexp {^(.*)( \(.*?\))$} $::diff($top,rightLabel) -> rfile rrest]} {
set rfile $::diff($top,rightLabel)
set rrest ""
}
set rfile [file tail $rfile]$rrest
lappend enscriptCmd "--header=$lfile|Page \$% of \$=|$rfile"
if {$::diff(prettyPrint) != ""} {
lappend enscriptCmd -E$::diff(prettyPrint)
}
lappend enscriptCmd -p $tmpFile2 $tmpFile
if {[catch {eval exec $enscriptCmd} result]} {
if {[string index $result 0] != "\["} {
tk_messageBox -message "Enscript error: $result\ncmd: $enscriptCmd"
return
}
}
# Finished
normalCursor $top
if {!$quiet} {
|
<
<
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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
|
} elseif {$w2 > $w1} {
for {set t $w1} {$t < $w2} {incr t} {
lappend wraplines1 {}
}
}
}
if 0 {
PdfPrint $top $wraplines1 $wraplines2
} else {
# Write all lines to a file, taking one page at a time from each
# side.
set ch [open $tmpFile "w"]
fconfigure $ch -encoding binary
set len1 [llength $wraplines1]
set len2 [llength $wraplines2]
set i1 0
set i2 0
while {$i1 < $len1 && $i2 < $len2} {
for {set i 0} {$i < $linesPerPage && $i1 < $len1} {incr i ; incr i1} {
puts $ch [FormatLine [lindex $wraplines1 $i1]]
}
if {$i < $linesPerPage} {puts -nonewline $ch "\f"}
for {set i 0} {$i < $linesPerPage && $i2 < $len2} {incr i ; incr i2} {
puts $ch [FormatLine [lindex $wraplines2 $i2]]
}
if {$i < $linesPerPage} {puts -nonewline $ch "\f"}
}
close $ch
# Run enscript to generate postscript
if {$::tcl_platform(platform) eq "windows" &&\
![info exists ::env(ENSCRIPT_LIBRARY)]} {
set ::env(ENSCRIPT_LIBRARY) [pwd]
}
if {[auto_execok enscript.bin] ne ""} {
set enscriptCmd [list enscript.bin]
} else {
set enscriptCmd [list enscript]
}
lappend enscriptCmd -2jcre -L $linesPerPage -M A4
if {$::Pref(wideLines)} {
lappend enscriptCmd -f Courier6
}
if {![regexp {^(.*)( \(.*?\))$} $::diff($top,leftLabel) -> lfile lrest]} {
set lfile $::diff($top,leftLabel)
set lrest ""
}
set lfile [file tail $lfile]$lrest
if {![regexp {^(.*)( \(.*?\))$} $::diff($top,rightLabel) -> rfile rrest]} {
set rfile $::diff($top,rightLabel)
set rrest ""
}
set rfile [file tail $rfile]$rrest
lappend enscriptCmd "--header=$lfile|Page \$% of \$=|$rfile"
if {$::diff(prettyPrint) != ""} {
lappend enscriptCmd -E$::diff(prettyPrint)
}
lappend enscriptCmd -p $tmpFile2 $tmpFile
if {[catch {eval exec $enscriptCmd} result]} {
if {[string index $result 0] != "\["} {
tk_messageBox -message "Enscript error: $result\ncmd: $enscriptCmd"
return
}
}
}
# Finished
normalCursor $top
if {!$quiet} {
|
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
'[lrange $enscriptCmd 0 end-3] \\\n \
[lrange $enscriptCmd end-2 end]'" \
-font "Courier 8"
pack .dp.b -side bottom
pack .dp.l -side "top"
}
}
# Create a print dialog.
proc doPrint {top {quiet 0}} {
if {![info exists ::diff(prettyPrint)]} {
set ::diff(prettyPrint) ""
}
if {$quiet} {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
'[lrange $enscriptCmd 0 end-3] \\\n \
[lrange $enscriptCmd end-2 end]'" \
-font "Courier 8"
pack .dp.b -side bottom
pack .dp.l -side "top"
}
}
proc PdfPrint {top wraplines1 wraplines2} {
if {$::diff($top,printFile) != ""} {
set pdfFile [file nativename $::diff($top,printFile)]
} else {
set pdfFile [file nativename ~/eskil.pdf]
}
set pdf [eskilprint %AUTO% -file $pdfFile]
set linesPerPage [$pdf getNLines]
$pdf setTag change "0.8 0.4 0.4"
$pdf setTag new1 "0.4 0.8 0.4"
$pdf setTag new2 "0.4 0.4 0.8"
set len1 [llength $wraplines1]
set len2 [llength $wraplines2]
set max [expr {$len1 > $len2 ? $len1 : $len2}]
set npages [expr {($max + $linesPerPage - 1) / $linesPerPage}]
$pdf configure -headnpages $npages
set i1 0
set i2 0
while {$i1 < $len1 && $i2 < $len2} {
$pdf newPage
$pdf setHalf left
for {set i 0} {$i < $linesPerPage && $i1 < $len1} {incr i ; incr i1} {
$pdf drawTextLine [lindex $wraplines1 $i1]
$pdf newLine
}
$pdf setHalf right
for {set i 0} {$i < $linesPerPage && $i2 < $len2} {incr i ; incr i2} {
$pdf drawTextLine [lindex $wraplines2 $i2]
$pdf newLine
}
}
$pdf finish
$pdf destroy
}
# Create a print dialog.
proc doPrint {top {quiet 0}} {
if {![info exists ::diff(prettyPrint)]} {
set ::diff(prettyPrint) ""
}
if {$quiet} {
|
380
381
382
383
384
385
386
|
grid .pr.fs - - -sticky we
grid .pr.b1 x .pr.b2 -sticky we -padx 5 -pady 5
grid columnconfigure .pr {0 2} -uniform a
grid columnconfigure .pr 1 -weight 1
pack .pr.r1 .pr.r2 .pr.r3 .pr.r4 -in .pr.f -side left -fill x -expand 1
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
grid .pr.fs - - -sticky we
grid .pr.b1 x .pr.b2 -sticky we -padx 5 -pady 5
grid columnconfigure .pr {0 2} -uniform a
grid columnconfigure .pr 1 -weight 1
pack .pr.r1 .pr.r2 .pr.r3 .pr.r4 -in .pr.f -side left -fill x -expand 1
}
# Count the length of a line during a text dump
proc AccumulateMax {key value index} {
set index [lindex [split $index "."] 1]
set len [expr {[string length $value] + $index - 1}]
if {$len > $::diff(currentCharsPerLine)} {
set ::diff(currentCharsPerLine) $len
}
}
# Count the longest line length in the current display
proc CountCharsPerLine {top} {
set ::diff(currentCharsPerLine) 0
$::widgets($top,wDiff1) dump -text 1.0 end -command AccumulateMax
$::widgets($top,wDiff2) dump -text 1.0 end -command AccumulateMax
return $::diff(currentCharsPerLine)
}
# Create a print dialog.
proc doPrint2 {top {quiet 0}} {
if {$quiet} {
PrintDiffs $top 1
return
}
destroy .pr
toplevel .pr
wm title .pr "Print diffs to PDF"
label .pr.hsl -anchor w -text "Header Size"
spinbox .pr.hss -textvariable ::Pref(printHeaderSize) \
-from 5 -to 16 -width 3
label .pr.cll -anchor w -text "Chars per line"
entry .pr.cle -textvariable ::Pref(printCharsPerLine) -width 4
frame .pr.clf
set values [lsort -uniq -integer [list 80 [CountCharsPerLine]]]
foreach value $values {
radiobutton .pr.clf.$value -variable ::Pref(printCharsPerLine) \
-value $value -text $value
pack .pr.clf.$value -side left
}
label .pr.fnl -anchor w -text "File name"
entry .pr.fne -textvariable ::Pref(printFileName) -width 20
button .pr.fnb -text Browse -command BrowsePrintFileName
frame .pr.fb
button .pr.b1 -text "Print to File" -padx 5\
-command "destroy .pr; update; PrintDiffs $top"
button .pr.b2 -text "Cancel" -padx 5 \
-command {destroy .pr}
pack .pr.b1 -in .pr.fb -side left -padx 5 -pady 5
pack .pr.b2 -in .pr.fb -side right -padx 5 -pady 5
grid .pr.hsl .pr.hss -sticky we
grid .pr.cll .pr.cle .pr.clf -sticky we
grid .pr.fnl .pr.fne - .pr.fnb -sticky we
grid .pr.fb - - - -sticky we
grid columnconfigure .pr 2 -weight 1
}
|