/usr/lib/s9fes/dirname.scm is in scheme9 2010.11.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; See the LICENSE file of the S9fES package for terms of use
;
; (dirname string) ==> string
;
; Return the directory part of the path name in STRING. Note that
; DIRNAME performs merely a syntaxical operation without any regard
; to the actual file system structure, i.e.
;
; (dirname "/foo/bar") ==> "/foo"
;
; even if "bar" is also a directory. DIRNAME also takes care of
; trailing slashes and recognizes some special cases (see examples).
;
; Example: (dirname "/foo/bar/baz") ==> "/foo/bar"
; (dirname "foo/bar") ==> "foo"
; (dirname "foo/bar/") ==> "foo"
; (dirname "/foo") ==> "/"
; (dirname "/") ==> "/"
; (dirname "foo") ==> "."
(load-from-library "string-split.scm")
(load-from-library "string-unsplit.scm")
(define (dirname path)
(letrec
((cut
(lambda (s)
(let loop ((s (reverse! s)))
(cond ((null? s)
'(""))
((string=? "" (car s))
(loop (cdr s)))
(else
(reverse! (cdr s))))))))
(let* ((dirs (string-split #\/ path)))
(if (null? (cdr dirs))
"."
(let ((dir (string-unsplit #\/ (cut dirs))))
(if (string=? "" dir)
"/"
dir))))))
|