#! /usr/local/bin/tclsh

proc convert {translation file} {
    set tmp $file.fixnltmp

    set f [open $file r]
    set content [read $f]
    close $f

    # File might get shorter (if go from CRLF to LF only, for example)
    # so can't just open/read/seek/write/close, but must reopen

    set f [open $tmp w]
    fconfigure $f -translation $translation
    puts -nonewline $f $content
    close $f
    file rename $tmp $file
}

set translation crlf
switch -exact -- [lindex $argv 0] {
    -lf - -cr - -crlf {
	set translation [string range [lindex $argv 0] 1 end]
	set argv [lrange $argv 1 end]
    }
}

foreach filename $argv {
    convert $translation $filename
}
exit
