3 acat {-s cp866 -d koi8-r -l crlf}
4 wcat {-s cp1251 -d koi8-r -l crlf}
5 mcat {-s macCyrillic -d koi8-r -l cr}
6 icat {-s iso8859-5 -d koi8-r -l lf}
10 puts "Usage ucat options \[files\]
12 -s charset - set source charset
13 -d charset - set destination charset
14 -l mode - set input eol translation mode (one of cr, crlf, lf)
15 -r - reverese input output
21 if [info exists defaults([file tail $argv0])] {
22 set argv [concat $defaults([file tail $argv0]) $argv]
26 proc next_key {list raise_Error} {
28 if {$raise_Error && ![llength $l]} {
29 puts stderr "Option requires an argument"
33 set l [lrange $l 1 end]
39 global incharset outcharset inlf outlf
40 fconfigure $f -encoding $incharset -translation $inlf
42 puts -nonewline [read $f 4096]
47 set outcharset [encoding system]
49 switch $tcl_platform(platform) {
51 windows {set outlf crlf}
53 default {set outlf lf}
55 while {[llength [set key [next_key argv 0]]]} {
56 if {$key=="-" || ![string match -* $key]} {
57 set argv [concat $key $argv]
60 switch -exact -- $key {
61 -s { set incharset [next_key argv 1] }
62 -d {set outcharset [next_key argv 1]}
64 -l {set inlf [next_key argv 1]}
66 puts stderr "Invalid option $key"
74 set incharset $outcharset
81 fconfigure stdout -encoding $outcharset -translation $outlf
82 if {$outcharset=="unicode"} {
83 puts -nonewline "\uFEFF"
85 if {![llength $argv]} {
92 if [catch {open $file} f] {
93 puts stderr "$file: $f"