-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrookery.tcl
204 lines (167 loc) · 4.56 KB
/
rookery.tcl
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#! /usr/bin/env tclsh
namespace eval ::Rookery {
# stores the name of target directory
variable cabinet
# stores the path to target file
variable pathway
# stores the name of file to be written to
variable postdoc
# stores the name of the source file
# which holds the content to be copied
variable section
set cabinet robin
set postdoc egretta.tcl
set pathway [file nativename [file join $cabinet $postdoc]]
# takes two file arguments and copies
# the content of capsule to destiny
proc transcribe {capsule destiny} {
if [file exists $capsule] then {
set chandle [open $capsule r]
set content [read $chandle]
close $chandle
} else {
puts stderr "$capsule not found"
exit 1
}
# append content
if [file exists $destiny] then {
set chapter [open $destiny a]
puts $chapter $content
flush $chapter
close $chapter
} else {
puts stderr "$destiny not found"
exit 1
}
unset capsule chandle
unset chapter content destiny
return
}
# takes two file and one integer argument
# and copies the content starting at line
# number of file capsule to file destiny
proc seditorial {capsule destiny {erasure 0}} {
if [file exists $capsule] then {
set chandle [open $capsule r]
set content [read $chandle]
close $chandle
# split content lines to list
set splines [split $content "\n"]
} else {
puts stderr "$capsule not found"
exit 1
}
# append content
if [file exists $destiny] then {
set chapter [open $destiny a]
foreach recline [lrange $splines $erasure end] {
puts $chapter $recline
}
flush $chapter
close $chapter
} else {
puts stderr "$destiny not found"
exit 1
}
unset capsule chandle chapter content
unset destiny erasure recline splines
return
}
# slurpermit and inscribe docstring
proc commentate {capsule destiny} {
if [file exists $capsule] then {
set chandle [open $capsule r]
set content [read $chandle]
close $chandle
# replace substrings then split content words to list
set swords [lrange [split [
string map {"\n\n" "\x20"} $content]] 4 end-1]
} else {
puts stderr "$capsule not found"
exit 1
}
# append content
if [file exists $destiny] then {
set chapter [open $destiny a]
set letters 0
puts $chapter "# \\"
foreach betoken $swords {
puts -nonewline $chapter [string cat $betoken "\x20"]
if {50 < [set letters [expr {$letters + [string length $betoken]}]]
} then {
puts $chapter "\\"
set letters 0
}
}
puts $chapter "\n"
flush $chapter
close $chapter
} else {
puts stderr "$destiny not found"
exit 1
}
unset betoken capsule chandle chapter
unset content destiny letters swords
return
}
# make directory and create file or
# overwrite and truncate existing file
apply {{folder destiny} {
file mkdir $folder
if [file isdirectory $folder] then {
set chandle [open $destiny w]
if [file isfile $destiny] then {
set content {}
puts -nonewline $chandle $content
} else {
puts stderr "$destiny not created"
exit 1
}
flush $chandle
close $chandle
unset chandle content
} else {
puts stderr "$folder not created"
exit 1
}
unset destiny folder
return
}} $cabinet $pathway
# shebang headline
apply {{destiny} {
if [file exists $destiny] then {
set chandle [open $destiny w]
set content "#! /usr/bin/env tclsh\n"
puts $chandle $content
flush $chandle
close $chandle
unset chandle content destiny
} else {
puts stderr "$destiny not found"
exit 1
}
return
}} $pathway
set section LICENSE.txt
commentate $section $pathway
set section estrilda.tcl
transcribe $section $pathway
set section ploceus.tcl
transcribe $section $pathway
set section sturnus.tcl
transcribe $section $pathway
set section syrinx.tcl
seditorial $section $pathway 20
set section tyranni.tcl
seditorial $section $pathway 20
file attributes $pathway -permissions u+x
file stat $pathway estates
puts "\n\tSuccessfully wrote to $pathway\n"
puts "\tmodified: ${estates(mtime)}"
puts "\tinodenum: ${estates(ino)}"
puts "\tmodebits: ${estates(mode)}"
puts "\tfilesize: ${estates(size)}\n"
# cleanup
unset cabinet estates
unset pathway postdoc section
} ;# close Rookery