1 ;------------------------------------------------------------------;
\r
2 ; opus_libre -- init.scm ;
\r
4 ; (c) 2008-2010 Valentin Villenave <valentin@villenave.net> ;
\r
6 ; opus_libre is a free framework for GNU LilyPond: you may ;
\r
7 ; redistribute it and/or modify it under the terms of the GNU ;
\r
8 ; General Public License, version 3 or later: gnu.org/licenses ;
\r
10 ;------------------------------------------------------------------;
\r
12 ; Init file: mandatory variables and functions.
\r
21 (define-public (ly:debug-message string . rest)
\r
22 (if (ly:get-option 'verbose)
\r
23 (apply ly:message (cons string rest))))
\r
25 ;; Base variables initialization ----------------------------------;
\r
26 ;; (may be overriden later when parsing conf-file)
\r
28 (define conf:lib-dir "lib")
\r
30 ;; Filesystem browsing --------------------------------------------;
\r
32 ;;;; The following function was retrieved from
\r
33 ;;;; a mail posted by Russ McManus in 1998...
\r
34 ;;;; http://sources.redhat.com/ml/guile/1998-07/msg00370.html
\r
36 (define-public (find-files dir . arg-ls)
\r
37 "List files in DIR, in alphabetical order. Two optional arguments
\r
38 are supported: a regexp filter, and a boolean that determines whether
\r
39 subdirectories should be included (defaults to true)."
\r
40 (let* ((n-args (length arg-ls))
\r
41 (pred (cond ((= n-args 0)
\r
43 ((procedure? (list-ref arg-ls 0))
\r
44 (list-ref arg-ls 0))
\r
45 ((string? (list-ref arg-ls 0))
\r
46 (let ((rx (make-regexp (list-ref arg-ls 0)
\r
47 ;; better use case-insensitive flag here
\r
49 (lambda (file) (regexp-exec rx file))))
\r
50 (#t (error "bad predicate" (list-ref arg-ls 0)))))
\r
51 (recurse? (if (>= n-args 2) (list-ref arg-ls 1) #t)))
\r
52 (define (do-file file basename ret-ls)
\r
53 (let* ((v (lstat file)))
\r
54 (cond ((string=? basename ".") ret-ls)
\r
55 ((string=? basename "..") ret-ls)
\r
56 ((and (eq? (stat:type v) 'directory)
\r
58 (do-dir file ret-ls))
\r
59 ((pred file) (cons file ret-ls))
\r
61 (define (do-dir dir-name ret-ls)
\r
62 (let ((dir (opendir dir-name)))
\r
63 (do ((file (readdir dir) (readdir dir)))
\r
64 ((eof-object? file) ret-ls)
\r
67 ;; (string) now only accepts chars,
\r
68 ;; use (string-append) instead
\r
69 (string-append dir-name "/" file) file ret-ls)))
\r
72 (sort (do-dir dir '()) string<?)))
\r
74 ;; Automatic includes ---------------------------------------------;
\r
75 (define-public (include-scm dir . numbered?)
\r
76 "Load all Scheme files in DIR. If NUMBERED is set,
\r
77 load only numbered files."
\r
78 (let* ((regx (if numbered? "[0-9].*.scm$" ".scm$"))
\r
79 (scm-files (find-files dir regx)))
\r
81 (begin (ly:debug-message "Loading ~a..." x)
\r
85 ;------------------------------------------------------------------;
\r