mes: dirname: Fix for absolute file names.

* mes/module/mes/guile.mes (dirname): Fix absolute files.
This commit is contained in:
Jan Nieuwenhuizen 2018-11-11 10:15:12 +01:00
parent e0a2d540f4
commit c61c6866b5
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 7 additions and 3 deletions

View File

@ -99,9 +99,13 @@
port))
(define (dirname file-name)
(let ((lst (filter (negate string-null?) (string-split file-name #\/))))
(if (<= (length lst) 1) "."
(string-join (list-head lst (1- (length lst))) "/"))))
(let* ((lst (string-split file-name #\/))
(lst (filter (negate string-null?) lst)))
(if (null? lst) (if (string-prefix? "/" file-name) "/" ".")
(let ((dir (string-join (list-head lst (1- (length lst))) "/")))
(if (string-prefix? "/" file-name) (string-append "/" dir)
(if (string-null? dir) "."
dir))))))
;; FIXME: c&p from display
(define (with-output-to-string thunk)