From c1c492389ff2d37e5b6cd76d0134de1aba979a9d Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Tue, 22 Oct 2024 10:49:19 +0300 Subject: Replace (guix build utils) functions with guile in-built ones. Signed-off-by: Munyoki Kilyungi --- generate-ttl-files.scm | 138 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 112 insertions(+), 26 deletions(-) diff --git a/generate-ttl-files.scm b/generate-ttl-files.scm index 2f14b25..ded6423 100755 --- a/generate-ttl-files.scm +++ b/generate-ttl-files.scm @@ -3,12 +3,98 @@ (use-modules (ice-9 format) (ice-9 getopt-long) - (guix build utils) + (ice-9 ftw) + (ice-9 regex) (srfi srfi-26) (srfi srfi-34) (srfi srfi-35)) +;; Copied over from GNU/Guix source tree. +(define (file-name-predicate regexp) + "Return a predicate that returns true when passed a file name whose base +name matches REGEXP." + (let ((file-rx (if (regexp? regexp) + regexp + (make-regexp regexp)))) + (lambda (file stat) + (regexp-exec file-rx (basename file))))) + +(define* (find-files dir #:optional (pred (const #t)) + #:key (stat lstat) + directories? + fail-on-error?) + "Return the lexicographically sorted list of files under DIR for which PRED +returns true. PRED is passed two arguments: the absolute file name, and its +stat buffer; the default predicate always returns true. PRED can also be a +regular expression, in which case it is equivalent to (file-name-predicate +PRED). STAT is used to obtain file information; using 'lstat' means that +symlinks are not followed. If DIRECTORIES? is true, then directories will +also be included. If FAIL-ON-ERROR? is true, raise an exception upon error." + (let ((pred (if (procedure? pred) + pred + (file-name-predicate pred)))) + ;; Sort the result to get deterministic results. + (sort (file-system-fold (const #t) + (lambda (file stat result) ; leaf + (if (pred file stat) + (cons file result) + result)) + (lambda (dir stat result) ; down + (if (and directories? + (pred dir stat)) + (cons dir result) + result)) + (lambda (dir stat result) ; up + result) + (lambda (file stat result) ; skip + result) + (lambda (file stat errno result) + (format (current-error-port) "find-files: ~a: ~a~%" + file (strerror errno)) + (when fail-on-error? + (error "find-files failed")) + result) + '() + dir + stat) + string