summaryrefslogtreecommitdiffstats
path: root/tools/eolFix.tcl
diff options
context:
space:
mode:
authorandreask <andreask>2013-01-22 19:24:25 (GMT)
committerandreask <andreask>2013-01-22 19:24:25 (GMT)
commit6d8a36d84d2843681302604a082e2f787c3c3674 (patch)
tree9d3b4ee05189203cf7ce94b4b2a6d2d911aaa18d /tools/eolFix.tcl
parent296aebbd6ee092a25741684fa37ee31ef5a3e222 (diff)
downloadtcl-6d8a36d84d2843681302604a082e2f787c3c3674.zip
tcl-6d8a36d84d2843681302604a082e2f787c3c3674.tar.gz
tcl-6d8a36d84d2843681302604a082e2f787c3c3674.tar.bz2
Contribution by Patrick Fradin <patrick.fradin@planar.com>
Quoting his mail: <pre> ========================================================== Hi Jeff, I spent some of my time to contribute to the TclTk community ! I'm in late for Christmas gift but like we said in French : "Mieux vaut tard que jamais". ;-) I've use TclDevKit 5.3.0 tclchecker to analyse TclTk code in Tcl and Tk library directories (library, tools and tests) to correct a lot of warnings and few errors. (encapsulate some expr, use 'chan xxx' instead of fconfigure, fileevent...) I've made some improvements too : Examples : - Use 'lassign' instead of many 'lindex' of 'foreach/break' loop. - Use 'in' or 'ni' operators instead of 'lsearch -exact' or to factorise some eq/ne && / || tests. - Use 'eq' or 'ne' to tests strings instead of '==' or '!='. - Use 'unset -nocomplain' to avoid 'catch {unset...}'. - Remove some useless catch around 'destroy' calls. - Use expand {*} instead of 'eval'. Don't touch a lot of code because I don't know all structs and lists. I think it could be a greater improvement to reduce 'eval' calls. Due to previous experience, I dot not change any indentation ! ;-) ========================================================== </pre>
Diffstat (limited to 'tools/eolFix.tcl')
-rw-r--r--tools/eolFix.tcl35
1 files changed, 19 insertions, 16 deletions
diff --git a/tools/eolFix.tcl b/tools/eolFix.tcl
index 3f35ed4..4d5d955 100644
--- a/tools/eolFix.tcl
+++ b/tools/eolFix.tcl
@@ -13,7 +13,7 @@ namespace eval ::EOL {
variable outMode crlf
}
-proc EOL::fix {filename {newfilename {}}} {
+proc EOL::fix {filename {newfilename ""}} {
variable outMode
if {![file exists $filename]} {
@@ -21,23 +21,23 @@ proc EOL::fix {filename {newfilename {}}} {
}
puts "EOL Fixing: $filename"
- file rename ${filename} ${filename}.o
- set fhnd [open ${filename}.o r]
+ file rename -- $filename $filename.o
+ set fhnd [open $filename.o r]
if {$newfilename ne ""} {
- set newfhnd [open ${newfilename} w]
+ set newfhnd [open $newfilename w]
} else {
- set newfhnd [open ${filename} w]
+ set newfhnd [open $filename w]
}
- fconfigure $newfhnd -translation [list auto $outMode]
+ chan configure $newfhnd -translation [list auto $outMode]
seek $fhnd 0 end
- set theEnd [tell $fhnd]
- seek $fhnd 0 start
+ set theEnd [chan tell $fhnd]
+ chan seek $fhnd 0 start
- fconfigure $fhnd -translation binary -buffersize $theEnd
- set rawFile [read $fhnd $theEnd]
- close $fhnd
+ chan configure $fhnd -translation binary -buffersize $theEnd
+ set rawFile [chan read $fhnd $theEnd]
+ chan close $fhnd
regsub -all {(\r)|(\r){1,2}(\n)} $rawFile "\n" rawFile
@@ -47,12 +47,12 @@ proc EOL::fix {filename {newfilename {}}} {
puts $newfhnd $line
}
- close $newfhnd
- file delete ${filename}.o
+ chan close $newfhnd
+ file delete -- ${filename}.o
}
proc EOL::fixall {args} {
- if {[llength $args] == 0} {
+ if {![llength $args]} {
puts stderr "no files to fix"
exit 1
} else {
@@ -64,13 +64,16 @@ proc EOL::fixall {args} {
}
}
-if {$tcl_interactive == 0 && $argc > 0} {
+if {($tcl_interactive == 0) && ($argc > 0)} {
if {[string index [lindex $argv 0] 0] eq "-"} {
switch -- [lindex $argv 0] {
-cr {set ::EOL::outMode cr}
-crlf {set ::EOL::outMode crlf}
-lf {set ::EOL::outMode lf}
- default {puts stderr "improper mode switch"; exit 1}
+ default {
+ puts stderr "improper mode switch"
+ exit 1
+ }
}
set argv [lrange $argv 1 end]
}