︙ | | | ︙ | |
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#----------------------------------------------------------------------
# Helpers, replace with sugar macros or mathops if available in 8.5
proc + {a b} { expr {$a + $b} }
proc - {a b} { expr {$a - $b} }
# Format a line number for printing
# It will always be 5 chars wide.
proc FormatLineno {lineno} {
if {[string is integer -strict $lineno]} {
set res [format "%3d: " $lineno]
} else {
# Non-numerical linenumbers might turn up in some cases
set res [format "%-5s" $lineno]
}
if {[string length $res] > 5} {
set res [string range $res end-5 end-1]
}
return $res
}
# Process the line numbers from the line number widget into a list
# of "linestarters"
proc ProcessLineno {w} {
set tdump [$w dump -tag -text 1.0 end]
set tag ""
set line ""
set lines {}
foreach {key value index} $tdump {
if {$key eq "tagon"} {
if {$value eq "change" || [string match "new*" $value]} {
|
|
|
|
|
>
>
|
>
|
|
|
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#----------------------------------------------------------------------
# Helpers, replace with sugar macros or mathops if available in 8.5
proc + {a b} { expr {$a + $b} }
proc - {a b} { expr {$a - $b} }
# Format a line number for printing
# It will always be maxlen chars wide.
proc FormatLineno {lineno maxlen} {
if {[string is integer -strict $lineno]} {
set res [format "%d: " $lineno]
} else {
# Non-numerical linenumbers might turn up in some cases
set res $lineno
if {[string length $res] > $maxlen} {
set res [string range $res 0 [expr {$maxlen - 1}]]
}
}
if {[string length $res] < $maxlen} {
set res [format "%*s" $maxlen $res]
}
return $res
}
# Process the line numbers from the line number widget into a list
# of "linestarters"
proc ProcessLineno {w maxlen} {
set tdump [$w dump -tag -text 1.0 end]
set tag ""
set line ""
set lines {}
foreach {key value index} $tdump {
if {$key eq "tagon"} {
if {$value eq "change" || [string match "new*" $value]} {
|
︙ | | | ︙ | |
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# Collect until end of line
if {[string index $value end] eq "\n"} {
# Clean everything but the line number
set line [string trim [string trim $line] :]
if {$line eq ""} {
lappend lines {}
} else {
lappend lines [list [FormatLineno $line] $tag]
}
set line ""
}
}
}
return $lines
}
|
>
|
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# Collect until end of line
if {[string index $value end] eq "\n"} {
# Clean everything but the line number
set line [string trim [string trim $line] :]
if {$line eq ""} {
lappend lines {}
} else {
set formatline [FormatLineno $line $maxlen]
lappend lines [list $formatline $tag]
}
set line ""
}
}
}
return $lines
}
|
︙ | | | ︙ | |
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
puts stderr "Bad tag in FormatLine: '$tag'"
}
append result "\0bggray\{$gray\}$text\0bggray\{1.0\}"
}
}
return $result
}
# Main print function
proc PrintDiffs {top {quiet 0} {pdfprint 0}} {
busyCursor $top
update idletasks
set tmpFile [file nativename ~/eskil.enscript]
|
>
>
>
>
>
>
>
>
>
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
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]
|
︙ | | | ︙ | |
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
} 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]
set lineNo1 [ProcessLineno $::widgets($top,wLine1)]
set lineNo2 [ProcessLineno $::widgets($top,wLine2)]
# Loop over left and right displays, collecting lines from each.
# Line numbers and text are put together and lines are wrapped if needed.
foreach tdump [list $tdump1 $tdump2] \
lineName {lines1 lines2} wrapName {wrap1 wrap2} \
lineNo [list $lineNo1 $lineNo2] {
|
>
>
>
>
>
>
>
>
>
|
|
>
>
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
} 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)]]
set len2 [string length [FindLastNumber $::widgets($top,wLine2)]]
# Find maximum value (at least 3)
set maxlen [lindex [lsort -integer [list 3 $len1 $len2]] end]
# Add space for a colon and space
incr maxlen 2
set lineNo1 [ProcessLineno $::widgets($top,wLine1) $maxlen]
set lineNo2 [ProcessLineno $::widgets($top,wLine2) $maxlen]
set linepad [string repeat " " $maxlen]
# Loop over left and right displays, collecting lines from each.
# Line numbers and text are put together and lines are wrapped if needed.
foreach tdump [list $tdump1 $tdump2] \
lineName {lines1 lines2} wrapName {wrap1 wrap2} \
lineNo [list $lineNo1 $lineNo2] {
|
︙ | | | ︙ | |
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
set len [string length $value]
while {$chars + $len > $wraplength} {
set wrap [expr {$wraplength - $chars}]
set val1 [string range $value 0 [expr {$wrap - 1}]]
set value [string range $value $wrap end]
# The newline has its own element to simplify finding
# it later.
lappend line $val1 $tag "\n" {} " " {}
set chars 5
incr wrapc
set len [string length $value]
}
lappend line $value $tag
incr chars $len
}
tagon {
|
|
|
|
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
set len [string length $value]
while {$chars + $len > $wraplength} {
set wrap [expr {$wraplength - $chars}]
set val1 [string range $value 0 [expr {$wrap - 1}]]
set value [string range $value $wrap end]
# The newline has its own element to simplify finding
# it later.
lappend line $val1 $tag "\n" {} $linepad {}
set chars $maxlen
incr wrapc
set len [string length $value]
}
lappend line $value $tag
incr chars $len
}
tagon {
|
︙ | | | ︙ | |
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
for {set t $w1} {$t < $w2} {incr t} {
lappend wraplines1 {}
}
}
}
if {$pdfprint} {
PdfPrint $top $wraplength $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
|
|
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
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
|
︙ | | | ︙ | |
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
|
[lrange $enscriptCmd end-2 end]'" \
-font "Courier 8"
pack .dp.b -side bottom
pack .dp.l -side "top"
}
}
proc PdfPrint {top cpl wraplines1 wraplines2} {
if {$::diff($top,printFile) != ""} {
set pdfFile $::diff($top,printFile)
} else {
set pdfFile ~/eskil.pdf
}
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
set pdf [eskilprint %AUTO% -file $pdfFile -cpl $cpl \
-headleft $lfile -headright $rfile -headsize 10]
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]
|
|
|
|
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
|
[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 {
set pdfFile ~/eskil.pdf
}
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
set pdf [eskilprint %AUTO% -file $pdfFile -cpl $cpl -cpln $cpln \
-headleft $lfile -headright $rfile -headsize 10]
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]
|
︙ | | | ︙ | |