summaryrefslogtreecommitdiff
path: root/tclcompat.tcl
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-01-27 14:19:00 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:46 +1000
commitcf077dff22b3c9ca0c528fd64e1392971e2d6027 (patch)
tree084df123c747d4ca4212f27274b78982ff9c1095 /tclcompat.tcl
parent8ca4eb0a1561cdd3ccd92d797cc744b6f8b0ea8d (diff)
Improve stack trace handling
*: Get rid of JIM_ERR_ADDSTACK and use interp->addStackTrace instead *: 'return -code error' doesn't add a stack frame *: Rename _file_copy to {file copy} for better error messages *: Use 'return -code' to prevent excessive levels in the stack trace Also rename info_nameofexecutable to {info nameofexecutable}
Diffstat (limited to 'tclcompat.tcl')
-rw-r--r--tclcompat.tcl25
1 files changed, 12 insertions, 13 deletions
diff --git a/tclcompat.tcl b/tclcompat.tcl
index 266f0d9..a8cbefb 100644
--- a/tclcompat.tcl
+++ b/tclcompat.tcl
@@ -94,7 +94,7 @@ proc errorInfo {error {stacktrace ""}} {
return $result
}
-proc info_nameofexecutable {} {
+proc {info nameofexecutable} {} {
if {[info exists ::jim_argv0]} {
if {[string first "/" $::jim_argv0] >= 0} {
return $::jim_argv0
@@ -110,18 +110,17 @@ proc info_nameofexecutable {} {
}
# Implements 'file copy' - single file mode only
-proc _file_copy {{force {}} source target} {
- switch -- $force \
- -force {} \
- {} {
- if {[file exists $target]} {
- error "error copying \"$source\" to \"$target\": file already exists"
- }
- } \
- default {
- error "bad option \"$force\": should be -force"
- }
- set in [open $source]
+proc {file copy} {{force {}} source target} {
+ if {$force ni {{} -force}} {
+ return -code error "bad option \"$force\": should be -force"
+ }
+ if {[catch {open $source} in]} {
+ return -code error $in
+ }
+ if {$force eq "" && [file exists $target]} {
+ $in close
+ return -code error "error copying \"$source\" to \"$target\": file already exists"
+ }
set rc [catch {
set out [open $target w]
bio copy $in $out