1 ;------------------------------------------------------------------;
2 ; opus_libre -- init.scm ;
4 ; (c) 2008-2011 Valentin Villenave <valentin@villenave.net> ;
6 ; opus_libre is a free framework for GNU LilyPond: you may ;
7 ; redistribute it and/or modify it under the terms of the GNU ;
8 ; General Public License as published by the Free Software ;
9 ; Foundation, either version 3 of the License, or (at your option) ;
10 ; any later version. ;
11 ; This program is distributed WITHOUT ANY WARRANTY; without ;
12 ; even the implied warranty of MERCHANTABILITY or FITNESS FOR A ;
13 ; PARTICULAR PURPOSE. You should have received a copy of the GNU ;
14 ; General Public License along with this program (typically in the ;
15 ; share/doc/ directory). If not, see http://www.gnu.org/licenses/ ;
17 ;------------------------------------------------------------------;
20 ; Init file: mandatory variables and functions.
36 (define-public (not-null? x) (not (null? x)))
37 (define-public (false-or-null? x) (or (not x) (null? x)))
39 (define-public (ly:debug-message string . rest)
40 (if (ly:get-option 'verbose)
41 (apply ly:message (cons string rest))))
43 ;; Base variables initialization ----------------------------------;
44 ;; (may be overriden later when parsing conf-file)
46 (define conf:lib-dir "lib")
48 ;; Filesystem browsing --------------------------------------------;
50 ;;;; The following function was retrieved from
51 ;;;; a mail posted by Russ McManus in 1998...
52 ;;;; http://sources.redhat.com/ml/guile/1998-07/msg00370.html
54 (define-public (find-files dir . arg-ls)
55 "List files in DIR, in alphabetical order. Two optional arguments
56 are supported: a regexp filter, and a boolean that determines whether
57 subdirectories should be included (defaults to true)."
58 (let* ((n-args (length arg-ls))
59 (pred (cond ((= n-args 0)
61 ((procedure? (list-ref arg-ls 0))
63 ((string? (list-ref arg-ls 0))
64 (let ((rx (make-regexp (list-ref arg-ls 0)
65 ;; better use case-insensitive flag here
67 (lambda (file) (regexp-exec rx file))))
68 (#t (error "bad predicate" (list-ref arg-ls 0)))))
69 (recurse? (if (>= n-args 2) (list-ref arg-ls 1) #t)))
70 (define (do-file file basename ret-ls)
71 (let* ((v (lstat file)))
72 (cond ((string=? basename ".") ret-ls)
73 ((string=? basename "..") ret-ls)
74 ((and (eq? (stat:type v) 'directory)
77 ((pred file) (cons file ret-ls))
79 (define (do-dir dir-name ret-ls)
80 (let ((dir (opendir dir-name)))
81 (do ((file (readdir dir) (readdir dir)))
82 ((eof-object? file) ret-ls)
85 ;; (string) now only accepts chars,
86 ;; use (string-append) instead
87 (string-append dir-name "/" file) file ret-ls)))
90 (sort (do-dir dir '()) string<?)))
92 ;; Loading files (similar to ly:load) -----------------------------;
94 (define-public (scm-load file-name)
95 (ly:debug "[~A" file-name)
97 (if (ly:get-option 'verbose)
100 ;; Automatic includes ---------------------------------------------;
102 (define-public (include-scm dir . numbered?)
103 "Load all Scheme files in DIR. If NUMBERED is set,
104 load only numbered files."
105 (let* ((regx (if (not (false-or-null? numbered?)) "/[0-9].*\\.scm$" ".scm$"))
106 (scm-files (find-files dir regx)))
111 ;------------------------------------------------------------------;