Version 0 of source with encoding

Updated 2002-12-14 00:51:44

For those having source files containing data not encoded in the system encoding (and thus being not recognized correct by source), this small helper proc may help you:

---

 proc encsource {source_file encoding} {    
     if {![catch {open $source_file r} fid]} {
       if {![catch {fconfigure $fid -encoding $encoding}} msg]} {
         set script [read $fid]
         catch {close $fid}
       } else {
         # make sure channel gets closed
         catch {close $fid}
         return -code error "unknown encoding \"$encoding\""
       }
     } else {
         # return error message similar to source cmd
         return -code error "couldn't read file \"$source_file\": no such file or directory"
     } 
     uplevel 1 $script

}

---

 Usage:
   % encsource "test.tcl" utf-8

---