-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFile.clcl
927 lines (790 loc) · 24.9 KB
/
File.clcl
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
inherit System
{
typedef mode_t int;
typedef dev_t ulong;
typedef uid_t int;
typedef gid_t int;
typedef DIR pointer;
typedef off_t ulong;
typedef clockid_t int;
S_IFMT: static int;
S_IFDIR: static int;
S_IFCHR: static int;
S_IFBLK: static int;
S_IFREG: static int;
S_IFIFO: static int;
S_IFLNK: static int;
S_IFSOCK: static int;
S_ISUID: static int;
S_ISGID: static int;
S_ISVTX: static int;
S_IRUSR: static int;
S_IWUSR: static int;
S_IXUSR: static int;
S_IRWXU: static int;
S_IRGRP: static int;
S_IWGRP: static int;
S_IXGRP: static int;
S_IRWXG: static int;
S_IROTH: static int;
S_IWOTH: static int;
S_IXOTH: static int;
S_IRWXO: static int;
R_OK: static int;
W_OK: static int;
X_OK: static int;
F_OK: static int;
O_APPEND: static int;
O_ASYNC: static int;
O_RDONLY: static int;
O_WRONLY: static int;
O_RDWR: static int;
O_CREAT: static int;
O_DIRECTORY: static int;
O_EXCL: static int;
O_NOCTTY: static int;
O_NOFOLLOW: static int;
O_TMPFILE: static int;
O_TRUNC: static int;
O_TTY_INIT: static int;
O_CLOEXEC: static int;
O_DIRECT: static int;
O_DSYNC: static int;
O_LARGEFILE: static int;
O_NOATIME: static int;
O_NONBLOCK: static int;
O_PATH: static int;
O_SYNC : static int;
FNM_NOESCAPE: static int;
FNM_PATHNAME: static int;
FNM_PERIOD: static int;
FNM_FILE_NAME: static int;
FNM_LEADING_DIR: static int;
FNM_CASEFOLD: static int;
CLOCK_REALTIME: static int;
CLOCK_REALTIME_COARSE: static int;
CLOCK_MONOTONIC: static int;
CLOCK_MONOTONIC_COARSE: static int;
CLOCK_MONOTONIC_RAW: static int;
CLOCK_BOOTTIME: static int;
CLOCK_PROCESS_CPUTIME_ID: static int;
CLOCK_THREAD_CPUTIME_ID: static int;
RTLD_LAZY:static int;
RTLD_NOW:static int;
RTLD_GLOBAL:static int;
RTLD_LOCAL:static int;
RTLD_NODELETE:static int;
RTLD_NOLOAD:static int;
RTLD_DEEPBIND:static int;
RTLD_DEFAULT: static pointer;
RTLD_NEXT: static pointer;
EOF: static int;
stdin: static pointer@FILE;
stdout: static pointer@FILE;
stderr: static pointer@FILE;
BUFSIZ: static int;
PATH_MAX: static int;
F_GETFL: static int;
F_SETFL: static int;
def initialize_file_system(): static native;
def initialize(): static {
inherit();
initialize_file_system();
}
def open(file_name:String, flags:int, mode:mode_t):static native int throws Exception;
def close(fd:int): static native int throws Exception;
def read(fd:int, buf:Buffer, size:size_t): static native ssize_t throws Exception;
def write(fd:int, buf:Buffer, size:size_t): static native ssize_t throws Exception;
def fcntl(fd:int, flag:int, val:int): static native int throws Exception;
def time(): static native time_t;
def localtime(time:time_t, tm_sec:pointer@of_int, tm_min:pointer@of_int, tm_hour:pointer@of_int, tm_mday:pointer@of_int, tm_mon:pointer@of_int, tm_year:pointer@of_int, tm_wday:pointer@of_int, tm_yday:pointer@of_int, tm_isdst:pointer@of_bool): static native throws Exception;
def mktime(time:tm): static native time_t throws Exception;
def lstat(path:String, stat_:stat): static native int throws Exception;
def stat(path:String, stat_:stat): static native int throws Exception;
def realpath(path:String): static native String throws Exception;
def dirname(path:String): static native String;
def basename(path:String): static native String;
def opendir(path:String): static native DIR throws Exception;
def readdir(dir:DIR): static native String? throws Exception;
def closedir(dir:DIR): static native int throws Exception;
def chmod(path:String, mode:mode_t): static native throws Exception;
def lchmod(path:String, mode:mode_t): static native throws Exception;
def fchmod(fd:int, mode:mode_t): static native throws Exception;
def chown(path:String, owner:uid_t, group:gid_t): static native throws Exception;
def lchown(path:String, owner:uid_t, group:gid_t): static native throws Exception;
def fchown(fd:int, owner:uid_t, group:gid_t): static native throws Exception;
def unlink(path:String): static native throws Exception;
def access(path:String, mode:int): static native int;
def utime(path:String, actime:time_t, modtime:time_t): static native throws Exception;
def fnmatch(pattern:String, path:String, flags:int): static native bool;
def link(old_path:String, new_path:String): static native throws Exception;
def symlink(old_path:String, new_path:String): static native throws Exception;
def readlink(path:String): static native String throws Exception;
def rename(oldpath:String, newpath:String): static native throws Exception;
def truncate(path:String, length:off_t): static native throws Exception;
def ftruncate(fd:int, length:off_t): static native throws Exception;
def chdir(path:String): static native throws Exception;
def fchdir(fd:int): static native throws Exception;
def rmdir(path:String): static native throws Exception;
def mkdir(path:String, mode:mode_t): static native throws Exception;
def clock_getres(clk_id:clockid_t, res:timespec): static native throws Exception;
def clock_gettime(clk_id:clockid_t, tp:timespec): static native throws Exception;
def clock_settime(clk_id:clockid_t, tp:timespec): static native throws Exception;
def dlopen(path:String, flags:int): static native pointer throws Exception;
def dlclose(handle:pointer): static native int throws Exception;
def dlsym(handle:pointer, symbol:String): static native pointer throws Exception;
def fopen(path:String, mode:String): static native pointer@FILE throws Exception;
def fclose(stream:pointer) : static native throws Exception;
def fwrite(buf:Buffer, size:size_t, stream: pointer@FILE): static native size_t throws Exception;
def fread(buf:Buffer, size:size_t, stream:pointer@FILE): static native size_t throws Exception;
def feof(stream: pointer@FILE): static native bool;
def fgetc(stream:pointer@FILE): native static int throws Exception;
def fgets(buf:Buffer, size:int, stream:pointer@FILE): native static pointer@pchar throws Exception;
def getchar(): native static int throws Exception;
def ungetc(c:int, stream:pointer@FILE): native static int throws Exception;
def getcwd(): native static String throws Exception;
def put_fun_to_hash_for_native_method(path:String, fun_name:String, native_method:pointer): static native;
def fileno(stream:pointer@FILE): native static int;
}
class tm
{
include MObjectBase;
tm_sec:int;
tm_min:int;
tm_hour:int;
tm_mday:int;
tm_mon:int;
tm_year:int;
tm_wday:int;
tm_yday:int;
tm_isdst:bool;
def initialize() {
self.initialize(time());
}
def initialize(time:time_t) {
localtime(time, &self.tm_sec, &self.tm_min, &self.tm_hour, &self.tm_mday, &self.tm_mon, &self.tm_year, &self.tm_wday, &self.tm_yday, &self.tm_isdst);
}
def initialize(year:int, month:int, day_of_month:int, hour:int, minuts:int, sec:int, day_of_week:int, day_of_year:int, isdst:bool)
{
self.setYear(year);
self.setMonth(month);
self.setDayOfMonth(day_of_month);
self.setHour(hour);
self.setMinuts(minuts);
self.setSecond(sec);
self.setDayOfWeek(day_of_week);
self.setDayOfYear(day_of_year);
self.setDaylightSavingTime(isdst);
}
def clone():tm {
result := tm();
result.tm_sec = self.tm_sec;
result.tm_min = self.tm_min;
result.tm_hour = self.tm_hour;
result.tm_mday = self.tm_mday;
result.tm_mon = self.tm_mon;
result.tm_year = self.tm_year;
result.tm_wday = self.tm_wday;
result.tm_yday = self.tm_yday;
result.tm_isdst = self.tm_isdst;
return result;
}
def second():int {
return self.tm_sec;
}
def setSecond(value:int) {
self.tm_sec = value;
}
def minuts():int {
return self.tm_min;
}
def setMinuts(value:int) {
self.tm_min = value;
}
def hour():int {
return self.tm_hour;
}
def setHour(value:int) {
self.tm_hour = value;
}
def dayOfMonth():int {
return self.tm_mday;
}
def setDayOfMonth(value:int) {
self.tm_mday = value;
}
def month():int {
return self.tm_mon + 1;
}
def setMonth(value:int) {
self.tm_mon = value -1;
}
def year():int {
return self.tm_year + 1900;
}
def setYear(value:int) {
self.tm_year = value - 1900;
}
def dayOfWeek():int {
return self.tm_wday;
}
def setDayOfWeek(value:int) {
self.tm_wday = value;
}
def dayOfYear():int {
return self.tm_yday;
}
def setDayOfYear(value:int) {
self.tm_yday = value;
}
def isDaylightSavingTime():bool {
return self.tm_isdst;
}
def setDaylightSavingTime(value:bool) {
self.tm_isdst = value;
}
def toString():String {
return sprintf("%d-%02d-%02d %02d:%02d", array { self.year().toInteger, self.month().toInteger, self.dayOfMonth().toInteger, self.hour().toInteger, self.minuts().toInteger });
}
def to_time_t():time_t throws Exception {
return mktime(self);
}
}
class stat
{
include MObjectBase;
st_dev:dev_t;
st_mode:mode_t;
st_uid:uid_t;
st_gid:gid_t;
st_rdev:dev_t;
st_size: size_t;
st_atime:time_t;
st_mtime:time_t;
st_ctime:time_t;
def initialize() {}
def initialize(path:String, lstat:bool) throws Exception {
if(lstat) {
System.lstat(path, self);
}
else {
System.stat(path, self);
}
}
def initialize(path:String) throws Exception {
self.initialize(path, false);
}
def clone():stat {
result := stat();
result.st_dev = self.st_dev;
result.st_mode = self.st_mode;
result.st_uid = self.st_uid;
result.st_gid = self.st_gid;
result.st_rdev = self.st_rdev;
result.st_size = self.st_size;
result.st_atime = self.st_atime;
result.st_mtime = self.st_mtime;
result.st_ctime = self.st_ctime;
return result;
}
def S_ISDIR():bool {
return (self.st_mode & S_IFMT) == S_IFDIR;
}
def S_ISCHR():bool {
return (self.st_mode & S_IFMT) == S_IFCHR;
}
def S_ISBLK():bool {
return (self.st_mode & S_IFMT) == S_IFBLK;
}
def S_ISREG():bool {
return (self.st_mode & S_IFMT) == S_IFREG;
}
def S_ISFIFO():bool {
return (self.st_mode & S_IFMT) == S_IFIFO;
}
def S_ISLNK():bool {
return (self.st_mode & S_IFMT) == S_IFLNK;
}
def S_ISSOCK():bool {
return (self.st_mode & S_IFMT) == S_IFSOCK;
}
def permission():int {
return self.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
}
def S_IXUGO():bool {
return ((self.st_mode & S_IXUSR) == S_IXUSR) && ((self.st_mode & S_IXGRP) == S_IXGRP) && ((self.st_mode & S_IXOTH) == S_IXOTH);
}
def atime():tm {
return tm(self.st_atime);
}
def ctime():tm {
return tm(self.st_ctime);
}
def mtime():tm {
return tm(self.st_mtime);
}
def size():size_t {
return self.st_size;
}
def uid():uid_t {
return self.st_uid;
}
def gid():gid_t {
return self.st_gid;
}
def userName():String {
result := "";
p"/etc/passwd".read().toString().split(/\n/).each(closure(line:String) {
fields := line.chomp().split(/:/);
if(fields.length() > 2 && fields.items(2).to_int() == self.st_uid) {
result = fields.items(0);
}
});
return result;
}
def groupName():String {
result := "";
p"/etc/group".read().toString().split(/\n/).each(closure(line:String) {
fields := line.chomp().split(/:/);
if(fields.length() > 2 && fields.items(2).to_int() == self.st_gid) {
result = fields.items(0);
}
});
return result;
}
}
inherit String
{
def toPath(): Path {
return Path(self);
}
}
class File
{
include MObjectBase;
fd:int;
fileName:String?;
stream:pointer?@FILE;
def initialize() {
self.fd = -1;
self.fileName = null;
self.stream = null;
}
def initialize(file_name:String, flags:int, mode:mode_t) throws Exception
{
self.fd = open(file_name, flags, mode);
self.fileName = file_name;
self.stream = null;
}
def initialize(file_name:String, mode:String) throws Exception {
self.fd = -1;
self.fileName = file_name;
self.stream = fopen(file_name, mode);
}
def initialize(file_name:String) throws Exception {
self.initialize(file_name, "r");
}
def finalize() {
self.close();
}
def clone(): File {
result := File();
result.fd = self.fd;
if(self.fileName.identifyWith(null)) {
result.fileName = null;
}
else {
result.fileName = self.fileName.clone();
}
result.stream = self.stream;
return result;
}
def close() {
if(self.fd != -1) {
System.close(self.fd);
self.fd = -1;
self.fileName = null;
}
if(self.stream != null) {
fclose(self.stream);
self.stream = null;
self.fileName = null;
}
}
def read(size:size_t): Buffer throws Exception {
if(self.fd == -1 && self.stream == null) {
throw Exception("File is not opened");
}
if(self.stream != null) {
result := Buffer(size+1);
fread(result, size, self.stream);
return result;
}
else {
result := Buffer(size+1);
System.read(self.fd, result, size);
return result;
}
}
def to_stat(): stat throws Exception {
if(self.fileName.identifyWith(null)) {
throw Exception("File is not opened");
}
return stat(self.fileName);
}
def to_lstat(): stat throws Exception {
if(self.fileName.identifyWith(null)) {
throw Exception("File is not opened");
}
return stat(self.fileName, true);
}
def read(file_name:String): static Buffer throws Exception {
f:File = File(file_name);
result := f.read();
f.close();
return result;
}
def read(): Buffer throws Exception {
if(self.fd == -1 && self.stream == null) {
throw Exception("File is not opened");
}
if(self.stream != null) {
size:size_t = self.to_stat().size();
result := Buffer(size+1.to_ulong);
fread(result, size, self.stream);
return result;
}
else {
size:size_t = self.to_stat().size();
result := Buffer(size+1.to_ulong);
System.read(self.fd, result, size);
return result;
}
}
def write(buf:Buffer, size:size_t):int throws Exception {
if(self.fd == -1 && self.stream == null) {
throw Exception("File is not opened");
}
if(self.stream != null) {
return fwrite(buf, size, self.stream);
}
else {
return System.write(self.fd, buf, size);
}
}
def write(buf:Buffer):int throws Exception {
return self.write(buf, buf.len);
}
def write(str:String):int throws Exception {
buf := str.toBuffer();
return self.write(buf);
}
def write(file_name:String, buf:Buffer, mode:mode_t): static int throws Exception
{
f := File(file_name, O_CREAT|O_TRUNC|O_WRONLY, mode);
result := f.write(buf);
f.close();
return result;
}
def write(file_name:String, buf:Buffer, mode:String): static throws Exception
{
f := File(file_name, mode);
f.write(buf);
f.close();
}
def write(file_name:String, buf:Buffer, append:bool=false): static throws Exception {
if(append) {
File.write(file_name, buf, "a");
}
else {
File.write(file_name, buf, "w");
}
}
}
class Path
{
include MObjectBase;
path: delegate String;
def initialize() {}
def initialize(path:String) {
self.path = path;
}
def clone():Path {
result := Path();
if(self.path.identifyWith(null).negative()) {
result.path = self.path.clone();
}
return result;
}
def to_stat():stat {
return stat(self.path);
}
def to_lstat():stat {
return stat(self.path,true);
}
def toString(): String {
return self.path;
}
def equals(path:Path):bool {
if(path.is("WildCard")) {
return true;
}
else {
return self.path.equals(path.path)
}
}
def equals(right:WildCard):bool {
return true;
}
def compare(item:Path): int {
return self.path.compare(item.path);
}
def add(right:Path): Path {
result := self.clone();
result.path.append(right.path);
return result;
}
def realpath():Path throws Exception {
return System.realpath(self.path).toPath();
}
def dirname(): Path {
return System.dirname(self.path).toPath();
}
def basename():Path {
return System.basename(self.path).toPath();
}
def extname(): Path {
index := -1;
for(i := self.path.len-1; i>=0; i--) {
if(self.path.chars(i) == '.') {
index = i;
break;
}
}
dirname := self.dirname();
if(index == -1 || index == 0 || self.path.chars(index-1) == '/'
|| index < dirname.path.length())
{
return p"";
}
else {
return self.path.subString(index+1, -1).toPath();
}
}
def read(): Buffer {
return File.read(self.path);
}
def write(buf:Buffer, append:bool=false) {
File.write(self.path, buf, append);
}
def chmod(mode:mode_t) throws Exception {
System.chmod(self.toString(), mode);
}
def lchmod(mode:mode_t) throws Exception {
System.lchmod(self.toString(), mode);
}
def chown(owner:uid_t, group:gid_t) throws Exception {
System.chown(self.toString(), owner, group);
}
def lchown(owner:uid_t, group:gid_t) throws Exception {
System.lchown(self.toString(), owner, group);
}
def unlink() throws Exception {
System.unlink(self.toString());
}
def access(mode:int):int {
return System.access(self.toString(), mode);
}
def utime(actime:time_t, modtime:time_t) throws Exception {
System.utime(self.toString(), actime, modtime);
}
def fnmatch(pattern:String, flags:int): bool {
return System.fnmatch(pattern, self.toString(), flags);
}
def fnmatch(pattern:String): bool {
return self.fnmatch(pattern, 0);
}
def link(new_path:String) throws Exception {
System.link(self.toString(), new_path);
}
def symlink(new_path:String) throws Exception {
System.symlink(self.toString(), new_path);
}
def readlink(): String throws Exception {
return System.readlink(self.toString());
}
def rename(path:String) throws Exception {
System.rename(self.toString(), path);
}
def truncate(length:off_t) throws Exception {
System.truncate(self.toString(), length);
}
def chdir() throws Exception {
System.chdir(self.toString());
}
def rmdir() throws Exception {
System.rmdir(self.toString());
}
def mkdir(mode:mode_t) throws Exception {
System.mkdir(self.toString(), mode);
}
def mkdir() throws Exception {
System.mkdir(self.toString(), 0755);
}
def entries(): SortableList<String> throws Exception {
return Directory.entries(self.toString());
}
def glob(pattern:String, flags:int): SortableList<String> throws Exception {
return Directory.glob(self.toString(), pattern, flags);
}
def glob(pattern:String): SortableList<String> throws Exception {
return Directory.glob(self.toString(), pattern, 0);
}
}
inherit Global
{
def glob(pattern:String): static SortableList<String> throws Exception {
return Directory.glob(".", pattern, 0);
}
}
class Directory
{
include MObjectBase;
path:String;
dir:DIR;
def initialize() {}
def initialize(path:String) throws Exception {
self.path = path;
self.dir = opendir(path);
}
def finalize() {
if(self.dir != 0.to_pointer) {
System.closedir(self.dir);
}
}
def clone(): Directory {
result := Directory();
if(self.path.identifyWith(null).negative()) {
result.path = self.path.clone();
}
result.dir = self.dir;
return result;
}
def readdir(): String? throws Exception {
if(self.dir == 0.to_pointer) {
throw Exception("This directory is not opened");
}
return System.readdir(self.dir);
}
def closedir() {
if(self.dir != 0.to_pointer) {
System.closedir(self.dir);
self.dir = 0.to_pointer;
}
}
def entries(path:String): static SortableList<String> throws Exception {
dir := Directory(path);
result:SortableList<String> = SortableList<String>();
while(true) {
entry:String? = dir.readdir();
if(entry.identifyWith(null)) {
break;
}
if(!entry.equals(".") && !entry.equals("..")) {
if(path.chars(-1) == '/') {
entry2:String = sprintf("%s%s", array { path, entry });
result.add(entry2);
}
else {
entry2:String = sprintf("%s/%s", array { path, entry });
result.add(entry2);
}
}
}
dir.closedir();
return result;
}
def glob(path:String, pattern:String, flags:int): static SortableList<String> throws Exception {
dir := Directory(path);
result:SortableList<String> = SortableList<String>();
while(true) {
entry:String? = dir.readdir();
if(entry.identifyWith(null)) {
break;
}
if(fnmatch(pattern, entry, flags)) {
if(path.chars(-1) == '/') {
entry2:String = sprintf("%s%s", array { path, entry });
result.add(entry2);
}
else {
entry2:String = sprintf("%s/%s", array { path, entry });
result.add(entry2);
}
}
}
dir.closedir();
return result;
}
def glob(path:String, pattern:String): static SortableList<String> throws Exception {
return Directory.glob(path, pattern, 0);
}
def glob(pattern:String, flags:int):static SortableList<String> throws Exception {
return Directory.glob(".", pattern, flags);
}
def glob(pattern:String):static SortableList<String> throws Exception {
return Directory.glob(".", pattern, 0);
}
def globWithOnePath(path:String, flags:int):static SortableList<String> throws Exception
{
dir := System.dirname(path);
if(dir.equals(".")) {
return sortable_list { path };
}
else {
pattern := path.subString(dir.length()+1, -1);
return Directory.glob(dir, pattern, flags);
}
}
def globWithOnePath(path:String):static SortableList<String> throws Exception {
return Directory.globWithOnePath(path, 0);
}
def isGlobString(str:String):static bool {
for(i:=0; i<str.length(); i++) {
c:char = str.chars(i);
if(c == '*' || c == '?' || c == '[' || c == ']') {
return true;
}
}
return false;
}
}
inherit Clover
{
def time(block_:lambda()):static time_t {
time1:time_t = System.time();
block_();
time2:time_t = System.time();
return time2 - time1;
}
def realtime(block_:lambda()):static timespec {
ts1 := timespec();
clock_gettime(CLOCK_MONOTONIC, ts1);
block_();
ts2 := timespec();
clock_gettime(CLOCK_MONOTONIC, ts2);
return ts2.minus(ts1);
}
}
inherit String
{
def write(file_name:String, append:bool =false) {
File.write(file_name, self.toBuffer(), append);
}
}
inherit Buffer
{
def write(file_name:String, append:bool=false) {
File.write(file_name, self, append);
}
}