-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoc_file-1.0.tm
95 lines (56 loc) · 1.51 KB
/
oc_file-1.0.tm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#===============================================================================
# oc_file-1.0.tm
#
# File read/write shorthand.
#
# Copyright Sam O'Connor 2014
# Licenced for use under the same terms as Tcl 8.6. See:
# http://core.tcl.tk/tcl/artifact/537ba3f664b958496ab51849e23d7f564342014b
# http://github.com/tcltk/tcl/raw/core_8_6_1/license.terms
#===============================================================================
package provide oc_file 1.0
package require oclib::oc_proc
interp alias {} 💾 {} file
interp alias {} is_file {} file isfile
proc file_get {file} {
Read entire content of "file".
} require {
is_file $file
} do {
set f [open $file {RDONLY BINARY}]
set result [read $f]
close $f
return $result
}
proc file_lines {file} {
Read lines from "file".
} do {
lines [file_get $file]
}
proc file_csv {file} {
Read Comma Separated Values from "file"
} do {
parse csv [file_get $file]
}
proc file_set {file string} {
Write "string" to "file".
} do {
set f [open $file {WRONLY CREAT TRUNC BINARY}]
puts -nonewline $f $string
close $f
}
package require oclib::oc_ensemble
foreach cmd {
get
set
lines
csv
} {
extend_proc file $cmd file_$cmd
}
import_ensemble file f
package require oclib::oc_string
package require oclib::oc_dict
#===============================================================================
# End of file.
#===============================================================================