diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-11-23 13:25:45 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-11-23 13:25:45 (GMT) |
| commit | fefd5e71dcb3969e41112b186b2d30918ad62010 (patch) | |
| tree | c7f8968d3f2a6dbed22973a4b87d5c438b350a26 /library/writefile.tcl | |
| parent | 097954529a4f7cbc2bba17841f07a4283b68f1cc (diff) | |
| parent | 613ad6861bdef8e2bfcde5630c0b34af183c6f56 (diff) | |
| download | tcl-fefd5e71dcb3969e41112b186b2d30918ad62010.zip tcl-fefd5e71dcb3969e41112b186b2d30918ad62010.tar.gz tcl-fefd5e71dcb3969e41112b186b2d30918ad62010.tar.bz2 | |
Merge 8.7
Diffstat (limited to 'library/writefile.tcl')
| -rw-r--r-- | library/writefile.tcl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/library/writefile.tcl b/library/writefile.tcl new file mode 100644 index 0000000..fbd9138 --- /dev/null +++ b/library/writefile.tcl @@ -0,0 +1,37 @@ +# writeFile: +# Write the contents of a file. +# +# Copyright © 2023 Donal K Fellows. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# + +proc writeFile {args} { + # Parse the arguments + switch [llength $args] { + 2 { + lassign $args filename data + set mode text + } + 3 { + lassign $args filename mode data + set MODES {binary text} + set ERR [list -level 1 -errorcode [list TCL LOOKUP MODE $mode]] + set mode [tcl::prefix match -message "mode" -error $ERR $MODES $mode] + } + default { + set COMMAND [lindex [info level 0] 0] + return -code error -errorcode {TCL WRONGARGS} \ + "wrong # args: should be \"$COMMAND filename ?mode? data\"" + } + } + + # Write the file + set f [open $filename [dict get {text w binary wb} $mode]] + try { + puts -nonewline $f $data + } finally { + close $f + } +} |
