Initial Revision
[ohcount] / test / src_dir / tcl1.tcl
1 #!/usr/local/bin/tclsh
2
3 # Dos2Unix
4 #       Convert a file to Unix-style line endings
5 #       If the file is a directory, then recursively
6 #       convert all the files in the directory and below.
7 #
8 # Arguments
9 #       f       The name of a file or directory.
10 #
11 # Side Effects:
12 #       Rewrites the file to have LF line-endings
13
14 proc Dos2Unix {f} {
15     puts $f
16     if {[file isdirectory $f]} {
17         foreach g [glob [file join $f *]] {
18             Dos2Unix $g
19         }
20     } else {
21         set in [open $f]
22         set out [open $f.new w]
23         fconfigure $out -translation lf
24         puts -nonewline $out [read $in]
25         close $out
26         close $in
27         file rename -force $f.new $f
28     }
29 }
30
31 # Process each command-line argument
32
33 foreach f $argv {
34     Dos2Unix $f
35 }