os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/eolFix.tcl
Update contrib.
1 ## Super aggressive EOL-fixer!
3 ## Will even understand screwed up ones like CRCRLF.
4 ## (found in bad CVS repositories, caused by spacey developers
7 ## davygrvy@pobox.com 3:41 PM 10/12/2001
10 package provide EOL-fix 1.1
12 namespace eval ::EOL {
16 proc EOL::fix {filename {newfilename ""}} {
19 if {![file exists $filename]} { return }
20 puts "EOL Fixing: $filename"
22 file rename ${filename} ${filename}.o
23 set fhnd [open ${filename}.o r]
25 if {$newfilename != ""} {
26 set newfhnd [open ${newfilename} w]
28 set newfhnd [open ${filename} w]
31 fconfigure $newfhnd -translation [list auto $outMode]
33 set theEnd [tell $fhnd]
36 fconfigure $fhnd -translation binary -buffersize $theEnd
37 set rawFile [read $fhnd $theEnd]
40 regsub -all {(\r)|(\r){1,2}(\n)} $rawFile "\n" rawFile
42 set lineList [split $rawFile \n]
44 foreach line $lineList {
49 file delete ${filename}.o
52 proc EOL::fixall {args} {
53 if {[llength $args] == 0} {
54 puts stderr "no files to fix"
57 set cmd [lreplace $args -1 -1 glob -nocomplain]
60 foreach f [eval $cmd] {
61 if {[file isfile $f]} {fix $f}
65 if {$tcl_interactive == 0 && $argc > 0} {
66 if {[string index [lindex $argv 0] 0] == "-"} {
67 switch -- [lindex $argv 0] {
68 -cr { set ::EOL::outMode cr }
69 -crlf { set ::EOL::outMode crlf }
70 -lf { set ::EOL::outMode lf }
71 default { puts stderr "improper mode switch" ; exit 1 }
73 set argv [lrange $argv 1 end]
75 eval EOL::fixall $argv