5 .param pmc argv :slurpy
10 if argc == 0 goto few_args
12 .local string subcommand_name
13 subcommand_name = shift argv
16 options = get_root_global ['_tcl'; 'helpers'; 'file'], 'options'
18 .local pmc select_option
19 select_option = get_root_global ['_tcl'], 'select_option'
21 .local string canonical_subcommand
22 canonical_subcommand = select_option(options, subcommand_name)
24 .local pmc subcommand_proc
26 subcommand_proc = get_root_global ['_tcl';'helpers';'file'], canonical_subcommand
27 if_null subcommand_proc, bad_args
29 .return subcommand_proc(argv)
32 .return ('') # once all commands are implemented, remove this...
35 die 'wrong # args: should be "file option ?arg ...?"'
40 .namespace [ 'helpers'; 'file' ]
42 .sub 'normalize' # RT#40721: Stub for testing
53 if argc == 0 goto bad_args
56 $P1 = get_root_global ['_tcl'], 'slash'
65 if ii == argc goto name_loop_done
67 .local string name,char
70 char = substr name, 0, 1
71 if char == dirsep goto absolute
80 if ii == argc goto name_loop_done
88 die 'wrong # args: should be "file join name ?name ...?"'
97 if argc != 2 goto bad_args
99 .local string file,varname
105 $P2 = $P1.'stat'(file)
109 setVar = find_global 'setVar'
132 $I2 = 0o170000 #S_IFMT
135 $P4 = find_global 'filetypes'
147 # RT#40731: should be more discriminating about the error messages .OS generates
149 $S0 = 'could not read "'
151 $S0 .= '": no such file or directory'
154 die 'wrong # args: should be "file stat name varName"'
163 if argc != 1 goto bad_args
170 $P2 = $P1.'stat'(file)
174 $I3 = $I1 & 0o170000 #S_IFMT
176 if $I3 == 0o040000 goto true # directory mask
183 # RT#40732: should be more discriminating about the error messages .OS generates
185 $S0 = 'could not read "'
187 $S0 .= '": no such file or directory'
190 die 'wrong # args: should be "file isdirectory name"'
200 if argc != 1 goto bad_args
207 $P2 = $P1.'stat'(file)
211 $I3 = $I1 & 0o170000 #S_IFMT
213 if $I3 == 0o100000 goto true # file mask
220 # RT#40733: should be more discriminating about the error messages .OS generates
222 $S0 = 'could not read "'
224 $S0 .= '": no such file or directory'
227 die 'wrong # args: should be "file isfile name"'
237 if argc != 1 goto bad_args
244 $P2 = $P1.'stat'(file)
248 $I2 = 0o170000 #S_IFMT
251 $P4 = find_global 'filetypes'
255 # RT#40734: should be more discriminating about the error messages .OS generates
257 $S0 = 'could not read "'
259 $S0 .= '": no such file or directory'
262 die 'wrong # args: should be "file type name"'
271 if argc != 1 goto bad_args
278 $P2 = $P1.'stat'(file)
283 # RT#40735: should be more discriminating about the error messages .OS generates
285 $S0 = 'could not read "'
287 $S0 .= '": no such file or directory'
290 die 'wrong # args: should be "file size name"'
299 if argc != 1 goto bad_args
306 $P2 = $P1.'stat'(file)
311 # RT#40736: should be more discriminating about the error messages .OS generates
313 $S0 = 'could not read "'
315 $S0 .= '": no such file or directory'
318 die 'wrong # args: should be "file atime name ?time?"'
327 if argc != 1 goto bad_args
334 $P2 = $P1.'stat'(file)
339 # RT#40737: should be more discriminating about the error messages .OS generates
341 $S0 = 'could not read "'
343 $S0 .= '": no such file or directory'
346 die 'wrong # args: should be "file mtime name ?time?"'
349 # RT#40722: needs windows OS testing
355 if argc != 1 goto bad_args
357 .local string filename
360 .local string separator
361 $P0 = get_root_global ['_tcl'], 'slash'
364 $S0 = substr filename, -1, 1
365 if $S0 != separator goto continue
370 array = split separator, filename
372 unless $S0 == '' goto skip
377 if $I0 == 0 goto empty
379 $P1 = new 'ResizableStringArray'
381 unless array goto done
383 if $S0 == '' goto loop
388 $S0 = join separator, $P1
389 $S1 = concat separator, $S0 # guessing that this won't be needed in win
396 die 'wrong # args: should be "file dirname name"'
399 # RT#40723: Stub (unixy)
404 if argc != 1 goto bad_args
406 if $S0 == '' goto whole
407 $S1 = substr $S0, -1, 1
409 # Trailing dirsep is removed.
410 if $S1 != "/" goto continue
414 .local int pos, idx, last_idx
419 idx = index $S0, '/', pos
420 if idx == -1 goto done
427 if last_idx == -1 goto whole
429 substr $S0, 0, last_idx, ''
435 die 'wrong # args: should be "file tail name"'
438 # RT#40724: Stub for test parsing
444 # RT#40725: Stub for test parsing
455 if argc != 1 goto badargs
470 die 'wrong # args: should be "file exists name"'
473 # RT#40727: Stub for test parsing
484 if argc != 1 goto bad_args
486 .local string filename
489 $P0 = split '.', filename
491 if $I0 == 1 goto done
494 .local string separator
495 $P1 = get_root_global ['_tcl'], 'slash'
498 $I0 = index $S0, separator
499 if $I0 != -1 goto done
508 die 'wrong # args: should be "file rootname name"'
515 # check if filename arg exists
517 if argc != 1 goto bad_args
522 # test if filename has dots
524 if $I0 == -1 goto no_dot
526 # calculate file extension
538 die 'wrong # args: should be "file extension name"'
546 if argc != 1 goto bad_args
549 die 'wrong # args: should be "file owned name"'
552 # XXX: Stub for test parsing
563 if argc != 0 goto bad_args
568 die 'wrong # args: should be "file volumes"'
571 .sub 'anon' :anon :load
573 options = new 'TclList'
574 push options, 'atime'
575 push options, 'attributes'
576 push options, 'channels'
578 push options, 'delete'
579 push options, 'dirname'
580 push options, 'executable'
581 push options, 'exists'
582 push options, 'extension'
583 push options, 'isdirectory'
584 push options, 'isfile'
587 push options, 'lstat'
588 push options, 'mtime'
589 push options, 'mkdir'
590 push options, 'nativename'
591 push options, 'normalize'
592 push options, 'owned'
593 push options, 'pathtype'
594 push options, 'readable'
595 push options, 'readlink'
596 push options, 'rename'
597 push options, 'rootname'
598 push options, 'separator'
600 push options, 'split'
602 push options, 'system'
605 push options, 'volumes'
606 push options, 'writable'
608 set_root_global ['_tcl'; 'helpers'; 'file'], 'options', options
615 # vim: expandtab shiftwidth=4 ft=pir: