Eskil

Diff
Login

Differences From Artifact [b0cdafd6d0]:

To Artifact [b625ae2d9e]:


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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
        if {$i == -1} break
        set n [expr {(- $i - $index - 1) % 8 + 1}]
        set text [string replace $text $i $i [format %*s $n ""]]
    }
    return $text
}

# Format a line of text/tag pairs to enscript code
proc FormatLine {line} {
    set result ""
    foreach {text tag} $line {
        if {$tag eq ""} {
            append result $text
        } else {
            if {$tag eq "change"} {
                set gray $::Pref(grayLevel1)
            } elseif {[string match "new*" $tag]} {
                set gray $::Pref(grayLevel2)
            } else {
                # Should not happen
                set gray 1.0
                puts stderr "Bad tag in FormatLine: '$tag'"
            }
            append result "\0bggray\{$gray\}$text\0bggray\{1.0\}"
        }
    }
    return $result
}

# Find the lastnumber in a text widget
proc FindLastNumber {w} {
    set index [$w search -backwards -regexp {\d} end]
    set line [$w get "$index linestart" "$index lineend"]
    #puts "X '$line' '$index'"
    regexp {\d+} $line number
    return $number
}

# Main print function
proc PrintDiffs {top {quiet 0} {pdfprint 0}} {
    busyCursor $top
    update idletasks

    set tmpFile [file nativename ~/eskil.enscript]
    if {$::diff($top,printFile) != ""} {
        set tmpFile2 [file nativename $::diff($top,printFile)]
    } else {
        set tmpFile2 [file nativename ~/eskil.ps]
    }

    set lines1 {}
    set lines2 {}
    if {$pdfprint && [info exists ::Pref(printCharsPerLine)]} {
        set wraplength $::Pref(printCharsPerLine)
    } elseif {$::Pref(wideLines)} {
        set wraplength 100
        set linesPerPage 74
    } else {
        set wraplength 85
        set linesPerPage 66
    }

    set tdump1 [$::widgets($top,wDiff1) dump -tag -text 1.0 end]
    set tdump2 [$::widgets($top,wDiff2) dump -tag -text 1.0 end]

    # Figure out how many chars are needed for line numbers
    set len1 [string length [FindLastNumber $::widgets($top,wLine1)]]







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










|



<
<
<
<
<
<
<


|

<
<
<


<







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
        if {$i == -1} break
        set n [expr {(- $i - $index - 1) % 8 + 1}]
        set text [string replace $text $i $i [format %*s $n ""]]
    }
    return $text
}























# Find the lastnumber in a text widget
proc FindLastNumber {w} {
    set index [$w search -backwards -regexp {\d} end]
    set line [$w get "$index linestart" "$index lineend"]
    #puts "X '$line' '$index'"
    regexp {\d+} $line number
    return $number
}

# Main print function
proc PrintDiffs {top {quiet 0}} {
    busyCursor $top
    update idletasks








    set lines1 {}
    set lines2 {}
    if {[info exists ::Pref(printCharsPerLine)]} {
        set wraplength $::Pref(printCharsPerLine)



    } else {
        set wraplength 85

    }

    set tdump1 [$::widgets($top,wDiff1) dump -tag -text 1.0 end]
    set tdump2 [$::widgets($top,wDiff2) dump -tag -text 1.0 end]

    # Figure out how many chars are needed for line numbers
    set len1 [string length [FindLastNumber $::widgets($top,wLine1)]]
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
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
        } elseif {$w2 > $w1} {
            for {set t $w1} {$t < $w2} {incr t} {
                lappend wraplines1 {}
            }
        }
    }

    if {$pdfprint} {
        PdfPrint $top $wraplength $maxlen $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 {exec {*}$enscriptCmd} result]} {
            if {[string index $result 0] != "\["} {
                tk_messageBox -message "Enscript error: $result\ncmd: $enscriptCmd"
                return
            }
        }
    }

    # Finished

    normalCursor $top
    if {!$pdfprint && !$quiet} {
        destroy .dp
        toplevel .dp
        wm title .dp "Eskil Print"
        ttk::button .dp.b -text "Close" -command {destroy .dp}
        ttk::label .dp.l -anchor w -justify left \
                -text "The following files have\
                been created:\n\n$tmpFile\nInput file to enscript.\
                \n\n$tmpFile2\nCreated with\
                '[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 cpl cpln wraplines1 wraplines2} {

    if {$::diff($top,printFile) != ""} {
        set pdfFile $::diff($top,printFile)
    } else {







<
|
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







226
227
228
229
230
231
232

233



234
































































235
236
237















238
239
240
241
242
243
244
        } elseif {$w2 > $w1} {
            for {set t $w1} {$t < $w2} {incr t} {
                lappend wraplines1 {}
            }
        }
    }


    PdfPrint $top $wraplength $maxlen $wraplines1 $wraplines2




































































    # Finished

    normalCursor $top















}

proc PdfPrint {top cpl cpln wraplines1 wraplines2} {

    if {$::diff($top,printFile) != ""} {
        set pdfFile $::diff($top,printFile)
    } else {
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
            $pdf drawTextLine [lindex $wraplines2 $i2]
            $pdf newLine
        }
    }
    $pdf endPrint
}

# Create a print dialog.
proc doPrint {top {quiet 0}} {
    if {![info exists ::diff(prettyPrint)]} {
        set ::diff(prettyPrint) ""
    }
    if {$quiet} {
        PrintDiffs $top 1
        return
    }

    destroy .pr
    toplevel .pr
    wm title .pr "Print diffs"

    ttk::label .pr.l1 -justify left -anchor w \
            -text "The print function is just on an\
            experimental level. It will use 'enscript' to write a postcript\
            file \"eskil.ps\" in your home directory."
    ttk::label .pr.l2 -justify left -anchor w \
            -text "Below you can adjust the gray scale\
            levels that are used on the background to mark changes.\
            The first value is used for changed text. The second for\
            new/deleted text."
    .pr.l1 configure -wraplength 400
    .pr.l2 configure -wraplength 400

    ttk::scale .pr.s1 -orient horizontal -from 0.0 \
            -to 1.0 -variable Pref(grayLevel1)
    ttk::scale .pr.s2 -orient horizontal -from 0.0 \
            -to 1.0 -variable Pref(grayLevel2)
    ttk::frame .pr.f
    ttk::radiobutton .pr.r1 -text "No Syntax" -variable diff(prettyPrint) \
            -value ""
    ttk::radiobutton .pr.r2 -text "VHDL" -variable diff(prettyPrint) \
            -value "vhdl"
    ttk::radiobutton .pr.r3 -text "Tcl"  -variable diff(prettyPrint) \
            -value "tcl"
    ttk::radiobutton .pr.r4 -text "C"    -variable diff(prettyPrint) \
            -value "c"

    ttk::frame .pr.fs
    ttk::radiobutton .pr.fs.r1 -text "80 char" -variable Pref(wideLines) \
            -value 0
    ttk::radiobutton .pr.fs.r2 -text "95 char" -variable Pref(wideLines) \
            -value 1
    pack .pr.fs.r1 .pr.fs.r2 -side left -padx 10

    ttk::button .pr.b1 -text "Print to File" \
            -command "destroy .pr; update; PrintDiffs $top"
    ttk::button .pr.b2 -text "Cancel" -command {destroy .pr}

    grid .pr.l1 - - -sticky we
    grid .pr.l2 - - -sticky we
    grid .pr.s1 - - -sticky we
    grid .pr.s2 - - -sticky we
    grid .pr.f  - - -sticky we
    grid .pr.fs - - -sticky we
    grid .pr.b1 x .pr.b2 -sticky we -padx 5 -pady 5 -ipadx 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
    }







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







285
286
287
288
289
290
291
































































292
293
294
295
296
297
298
            $pdf drawTextLine [lindex $wraplines2 $i2]
            $pdf newLine
        }
    }
    $pdf endPrint
}

































































# 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
    }
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
    if {$apa ne ""} {
        set ::diff($top,printFile) $apa
        $entry xview end
    }
}

# Create a print dialog for PDF.
proc doPrint2 {top {quiet 0}} {
    if {$quiet} {
        PrintDiffs $top 1 1
        return
    }

    destroy .pr
    toplevel .pr -padx 3 -pady 3
    wm title .pr "Print diffs to PDF"








|

|







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    if {$apa ne ""} {
        set ::diff($top,printFile) $apa
        $entry xview end
    }
}

# Create a print dialog for PDF.
proc doPrint {top {quiet 0}} {
    if {$quiet} {
        PrintDiffs $top 1
        return
    }

    destroy .pr
    toplevel .pr -padx 3 -pady 3
    wm title .pr "Print diffs to PDF"

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605

    if {$::diff($top,printFile) eq ""} {
        set ::diff($top,printFile) "~/eskil.pdf"
    }

    ttk::frame .pr.fb
    ttk::button .pr.b1 -text "Print to File" \
            -command "destroy .pr; update; PrintDiffs $top 0 1"
    ttk::button .pr.b2 -text "Cancel" -command {destroy .pr}
    pack .pr.b1 -in .pr.fb -side left  -padx 3 -pady 3 -ipadx 5
    pack .pr.b2 -in .pr.fb -side right -padx 3 -pady 3 -ipadx 5

    grid .pr.hsl .pr.hss         -sticky we -padx 3 -pady 3
    grid .pr.psl .pr.psc         -sticky we -padx 3 -pady 3
    grid .pr.cll .pr.cle .pr.clf -sticky we -padx 3 -pady 3







|







411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

    if {$::diff($top,printFile) eq ""} {
        set ::diff($top,printFile) "~/eskil.pdf"
    }

    ttk::frame .pr.fb
    ttk::button .pr.b1 -text "Print to File" \
            -command "destroy .pr; update; PrintDiffs $top"
    ttk::button .pr.b2 -text "Cancel" -command {destroy .pr}
    pack .pr.b1 -in .pr.fb -side left  -padx 3 -pady 3 -ipadx 5
    pack .pr.b2 -in .pr.fb -side right -padx 3 -pady 3 -ipadx 5

    grid .pr.hsl .pr.hss         -sticky we -padx 3 -pady 3
    grid .pr.psl .pr.psc         -sticky we -padx 3 -pady 3
    grid .pr.cll .pr.cle .pr.clf -sticky we -padx 3 -pady 3