os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/eolFix.tcl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/eolFix.tcl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,78 @@
1.4 +## Super aggressive EOL-fixer!
1.5 +##
1.6 +## Will even understand screwed up ones like CRCRLF.
1.7 +## (found in bad CVS repositories, caused by spacey developers
1.8 +## abusing CVS)
1.9 +##
1.10 +## davygrvy@pobox.com 3:41 PM 10/12/2001
1.11 +##
1.12 +
1.13 +package provide EOL-fix 1.1
1.14 +
1.15 +namespace eval ::EOL {
1.16 + variable outMode crlf
1.17 +}
1.18 +
1.19 +proc EOL::fix {filename {newfilename ""}} {
1.20 + variable outMode
1.21 +
1.22 + if {![file exists $filename]} { return }
1.23 + puts "EOL Fixing: $filename"
1.24 +
1.25 + file rename ${filename} ${filename}.o
1.26 + set fhnd [open ${filename}.o r]
1.27 +
1.28 + if {$newfilename != ""} {
1.29 + set newfhnd [open ${newfilename} w]
1.30 + } else {
1.31 + set newfhnd [open ${filename} w]
1.32 + }
1.33 +
1.34 + fconfigure $newfhnd -translation [list auto $outMode]
1.35 + seek $fhnd 0 end
1.36 + set theEnd [tell $fhnd]
1.37 + seek $fhnd 0 start
1.38 +
1.39 + fconfigure $fhnd -translation binary -buffersize $theEnd
1.40 + set rawFile [read $fhnd $theEnd]
1.41 + close $fhnd
1.42 +
1.43 + regsub -all {(\r)|(\r){1,2}(\n)} $rawFile "\n" rawFile
1.44 +
1.45 + set lineList [split $rawFile \n]
1.46 +
1.47 + foreach line $lineList {
1.48 + puts $newfhnd $line
1.49 + }
1.50 +
1.51 + close $newfhnd
1.52 + file delete ${filename}.o
1.53 +}
1.54 +
1.55 +proc EOL::fixall {args} {
1.56 + if {[llength $args] == 0} {
1.57 + puts stderr "no files to fix"
1.58 + exit 1
1.59 + } else {
1.60 + set cmd [lreplace $args -1 -1 glob -nocomplain]
1.61 + }
1.62 +
1.63 + foreach f [eval $cmd] {
1.64 + if {[file isfile $f]} {fix $f}
1.65 + }
1.66 +}
1.67 +
1.68 +if {$tcl_interactive == 0 && $argc > 0} {
1.69 + if {[string index [lindex $argv 0] 0] == "-"} {
1.70 + switch -- [lindex $argv 0] {
1.71 + -cr { set ::EOL::outMode cr }
1.72 + -crlf { set ::EOL::outMode crlf }
1.73 + -lf { set ::EOL::outMode lf }
1.74 + default { puts stderr "improper mode switch" ; exit 1 }
1.75 + }
1.76 + set argv [lrange $argv 1 end]
1.77 + }
1.78 + eval EOL::fixall $argv
1.79 +} else {
1.80 + return
1.81 +}