forked from pmichaud/pmtcl
/
file.pm
265 lines (214 loc) · 5.48 KB
/
file.pm
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
our sub file(*@args) {
File::dispatch_command(|@args);
}
module File;
our %Arg_limits;
our %funcs;
our %Auto_vivify;
INIT {
## Negative limit in "max" position => unlimited.
%funcs<atime> := File::append;
%Arg_limits<atime> := [ 0, -1, "" ];
%funcs<attributes> := File::attributes;
%Arg_limits<attributes> := [ 0, -1, "" ];
%funcs<channels> := File::channels;
%Arg_limits<channels> := [ 0, -1, "" ];
%funcs<copy> := File::copy;
%Arg_limits<copy> := [ 0, -1, "" ];
%funcs<delete> := File::delete;
%Arg_limits<delete> := [ 0, -1, "" ];
%funcs<dirname> := File::dirname;
%Arg_limits<dirname> := [ 1, 1, "name" ];
%funcs<executable> := File::executable;
%Arg_limits<executable> := [ 0, -1, "" ];
%funcs<exists> := File::exists;
%Arg_limits<exists> := [ 0, -1, "" ];
%funcs<extension> := File::extension;
%Arg_limits<extension> := [ 0, -1, "" ];
%funcs<exists> := File::exists;
%Arg_limits<exists> := [ 0, -1, "" ];
%funcs<isdirectory> := File::isdirectory;
%Arg_limits<isdirectory> := [ 0, -1, "" ];
%funcs<isfile> := File::isfile;
%Arg_limits<isfile> := [ 0, -1, "" ];
%funcs<join> := File::join;
%Arg_limits<join> := [ 0, -1, "" ];
%funcs<link> := File::link;
%Arg_limits<link> := [ 0, -1, "" ];
%funcs<lstat> := File::lstat;
%Arg_limits<lstat> := [ 0, -1, "" ];
%funcs<mkdir> := File::mkdir;
%Arg_limits<mkdir> := [ 0, -1, "" ];
%funcs<mtime> := File::mtime;
%Arg_limits<mtime> := [ 0, -1, "" ];
%funcs<nativename> := File::nativename;
%Arg_limits<nativename> := [ 0, -1, "" ];
%funcs<normalize> := File::normalize;
%Arg_limits<normalize> := [ 0, -1, "" ];
%funcs<owned> := File::owned;
%Arg_limits<owned> := [ 0, -1, "" ];
%funcs<pathtype> := File::pathtype;
%Arg_limits<pathtype> := [ 0, -1, "" ];
%funcs<readable> := File::readable;
%Arg_limits<readable> := [ 0, -1, "" ];
%funcs<readlink> := File::readlink;
%Arg_limits<readlink> := [ 0, -1, "" ];
%funcs<rename> := File::rename;
%Arg_limits<rename> := [ 0, -1, "" ];
%funcs<rootname> := File::rootname;
%Arg_limits<rootname> := [ 0, -1, "" ];
%funcs<separator> := File::separator;
%Arg_limits<separator> := [ 0, -1, "" ];
%funcs<size> := File::size;
%Arg_limits<size> := [ 0, -1, "" ];
%funcs<split> := File::split;
%Arg_limits<split> := [ 0, -1, "" ];
%funcs<stat> := File::stat;
%Arg_limits<stat> := [ 0, -1, "" ];
%funcs<system> := File::system;
%Arg_limits<system> := [ 0, -1, "" ];
%funcs<tail> := File::tail;
%Arg_limits<tail> := [ 0, -1, "" ];
%funcs<type> := File::type;
%Arg_limits<type> := [ 0, -1, "" ];
%funcs<volumes> := File::volumes;
%Arg_limits<volumes> := [ 0, -1, "" ];
%funcs<writable> := File::writable;
%Arg_limits<writable> := [ 0, -1, "" ];
}
# Parses optional -args, and generates "wrong#args" errors
# Dispatches to fairly normal NQP subs for the detailed work.
our sub dispatch_command(*@args) {
my $num_args := +@args -1 ; # need option
if $num_args < 0 {
error('wrong # args: should be "file subcommand ?argument ...?"');
}
my @opts := <atime attributes channels copy delete dirname executable exists extension isdirectory isfile join link lstat mkdir mtime nativename normalize owned pathtype readable readlink rename rootname separator size split stat system tail type volumes writable>;
my $cmd := _tcl::select_option(@opts, @args.shift, 'subcommand');
my @limits := %Arg_limits{$cmd};
if (@limits[1] >= 0 && $num_args > @limits[1]) || $num_args < @limits[0] {
my $msg := @limits[2];
$msg := " $msg" unless $msg eq '';
error("wrong # args: should be \"file $cmd$msg\"")
}
my &subcommand := %funcs{$cmd};
&subcommand(|@args);
}
my sub atime(*@args) {
''
}
my sub attributes(*@args) {
''
}
my sub channels(*@args) {
''
}
my sub copy(*@args) {
''
}
my sub delete(*@args) {
''
}
my sub dirname($filename) {
my %PConfig := pir::getinterp[8]; ## .IGLOBALS_CONFIG_HASH
my $slash := %PConfig<slash>;
if pir::substr($filename, -1, 1) eq $slash {
$filename := pir::chopn__ssi($filename, 1);
}
my @array := pir::split($slash, $filename);
if @array[+@array-1] ne "" {
@array.pop();
}
if ! +@array {
return '.';
}
my @result := pir::new('TclList');
for @array -> $element {
if $element ne "" {
@result.push($element)
}
}
return ($slash ~ @result.join($slash));
}
my sub executable(*@args) {
''
}
my sub exists(*@args) {
''
}
my sub extension(*@args) {
''
}
my sub isdirectory(*@args) {
''
}
my sub isfile(*@args) {
''
}
my sub join(*@args) {
''
}
my sub link(*@args) {
''
}
my sub lstat(*@args) {
''
}
my sub mkdir(*@args) {
''
}
my sub mtime(*@args) {
''
}
my sub nativename(*@args) {
''
}
my sub normalize(*@args) {
''
}
my sub owned(*@args) {
''
}
my sub pathtype(*@args) {
''
}
my sub readable(*@args) {
''
}
my sub readlink(*@args) {
''
}
my sub rename(*@args) {
''
}
my sub rootname(*@args) {
''
}
my sub separator(*@args) {
''
}
my sub size(*@args) {
''
}
my sub split(*@args) {
''
}
my sub stat(*@args) {
''
}
my sub system(*@args) {
''
}
my sub tail(*@args) {
''
}
my sub type(*@args) {
''
}
my sub volumes(*@args) {
''
}
my sub writable(*@args) {
''
}
# vim: expandtab shiftwidth=4 ft=perl6: