summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorhobbs <hobbs>2001-11-20 10:15:06 (GMT)
committerhobbs <hobbs>2001-11-20 10:15:06 (GMT)
commitcc9ab9d07a41e1b6dacb17935cf3c504c7f37bd8 (patch)
tree1a4871a876a13bf1b592ba2e1949ebc452237cf9 /tools
parentefc5cb86481e5b94396404ff21921ca044118de8 (diff)
downloadtcl-cc9ab9d07a41e1b6dacb17935cf3c504c7f37bd8.zip
tcl-cc9ab9d07a41e1b6dacb17935cf3c504c7f37bd8.tar.gz
tcl-cc9ab9d07a41e1b6dacb17935cf3c504c7f37bd8.tar.bz2
* tools/eolFix.tcl (new-file):
* unix/Makefile.in: added EOL correction for Windows bat files to dist target. [Bug #219409] (davygrvy)
Diffstat (limited to 'tools')
-rw-r--r--tools/eolFix.tcl78
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/eolFix.tcl b/tools/eolFix.tcl
new file mode 100644
index 0000000..11c410d
--- /dev/null
+++ b/tools/eolFix.tcl
@@ -0,0 +1,78 @@
+## Super aggressive EOL-fixer!
+##
+## Will even understand screwed up ones like CRCRLF.
+## (found in bad CVS repositories, caused by spacey developers
+## abusing CVS)
+##
+## davygrvy@pobox.com 3:41 PM 10/12/2001
+##
+
+package provide EOL-fix 1.1
+
+namespace eval ::EOL {
+ variable outMode crlf
+}
+
+proc EOL::fix {filename {newfilename ""}} {
+ variable outMode
+
+ if {![file exist $filename]} { return }
+ puts "EOL Fixing: $filename"
+
+ file rename ${filename} ${filename}.o
+ set fhnd [open ${filename}.o r]
+
+ if {$newfilename != ""} {
+ set newfhnd [open ${newfilename} w]
+ } else {
+ set newfhnd [open ${filename} w]
+ }
+
+ fconfigure $newfhnd -translation [list auto $outMode]
+ seek $fhnd 0 end
+ set theEnd [tell $fhnd]
+ seek $fhnd 0 start
+
+ fconfigure $fhnd -translation binary -buffersize $theEnd
+ set rawFile [read $fhnd $theEnd]
+ close $fhnd
+
+ regsub -all {(\r)|(\r){1,2}(\n)} $rawFile "\n" rawFile
+
+ set lineList [split $rawFile \n]
+
+ foreach line $lineList {
+ puts $newfhnd $line
+ }
+
+ close $newfhnd
+ file delete ${filename}.o
+}
+
+proc EOL::fixall {args} {
+ if {[llength $args] == 0} {
+ puts stderr "no files to fix"
+ exit 1
+ } else {
+ set cmd [lreplace $args -1 -1 glob -nocomplain]
+ }
+
+ foreach f [eval $cmd] {
+ if {[file isfile $f]} {fix $f}
+ }
+}
+
+if {$tcl_interactive == 0 && $argc > 0} {
+ if {[string index [lindex $argv 0] 0] == "-"} {
+ 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 }
+ }
+ set argv [lrange $argv 1 end]
+ }
+ eval EOL::fixall $argv
+} else {
+ return
+}