1#
2# string_file --
3#
4# Functions to read and write strings from a file that has not been opened.
5#------------------------------------------------------------------------------
6# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
7#
8# Permission to use, copy, modify, and distribute this software and its
9# documentation for any purpose and without fee is hereby granted, provided
10# that the above copyright notice appear in all copies.  Karl Lehenbauer and
11# Mark Diekhans make no representations about the suitability of this
12# software for any purpose.  It is provided "as is" without express or
13# implied warranty.
14#------------------------------------------------------------------------------
15# $Id: stringfile.tcl,v 1.1 2001/10/24 23:31:48 hobbs Exp $
16#------------------------------------------------------------------------------
17#
18
19#@package: TclX-stringfile_functions read_file write_file
20
21proc read_file {fileName args} {
22    if {$fileName == "-nonewline"} {
23        set flag $fileName
24        set fileName [lvarpop args]
25    } else {
26        set flag {}
27    }
28    set fp [open $fileName]
29    try_eval {
30        set result [eval read $flag $fp $args]
31    } {} {
32        close $fp
33    }
34    return $result
35}
36
37proc write_file {fileName args} {
38    set fp [open $fileName w]
39    try_eval {
40        foreach string $args {
41            puts $fp $string
42        }
43    } {} {
44        close $fp
45    }
46}
47
48
49
50