ebuild-autogen/ebuild/utils.scm
2025-06-30 16:15:39 +02:00

71 lines
3 KiB
Scheme

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; utils.scm
;; Copyright (C) 2025 Cor Legemaat <cor@cor.za.net>
;;
;; This file is part of ebuild-autogen: you can redistribute it and/or modify it
;; under the terms of the GNU Affero General Public License as published by the
;; Free Software Foundation, version 3 of the License.
;;
;; ebuild-autogen is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
;; more details.
;;
;; You should have received a copy of the GNU General Public License along with
;; ebuild-autogen. If not, see <https://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (ebuild utils)
#:use-module (srfi srfi-1))
(define-public list->str-list
(lambda* (in-list glue #:key (pre "") (post ""))
""
;;(display "in-list=") (display in-list) (newline)
(if (null? in-list)
""
(string-concatenate
(append (list pre)
(cdr (append-map (lambda (item)
(append (list glue)
(list item)))
in-list))
(list post))))))
(define-public any-str-list
(lambda (test-list val)
""
(any (lambda (test-val)
(if (string=? test-val val)
#t #f))
test-list)))
(define-public mkpath
(lambda (path)
(let* ((split-path (filter-map (lambda (str)
(if (string<> str "") str #f))
(string-split path
(car (string->list
file-name-separator-string)))))
(fixed-path (string-append (string-concatenate (map (lambda (folder)
(string-append "/" folder))
split-path))
"/"))
(path-1up (string-concatenate (map (lambda (folder)
(string-append "/" folder))
(reverse (cdr (reverse split-path)))))))
(if (not (access? fixed-path F_OK))
(if (access? path-1up F_OK)
(if (access? path-1up W_OK)
(mkdir fixed-path)
(error (string-append "Error no write permission in \""
path-1up
"\" to create \""
(car (reverse split-path))
"\" folder!")))
(begin (mkpath path-1up)
(mkdir path)))))))
(define-public cmp-str-lists
(lambda (list1 list2)
""
(every string=? list1 list2)))