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
19 ;; Base variables initialization ----------------------------------;
\r
20 ;; (may be overriden later when parsing conf-file)
\r
22 (define conf:lib-dir "lib")
\r
24 ;; Filesystem browsing --------------------------------------------;
\r
26 ;;;; The following function was retrieved from
\r
27 ;;;; a mail posted by Russ McManus in 1998...
\r
28 ;;;; http://sources.redhat.com/ml/guile/1998-07/msg00370.html
\r
30 (define-public (find-files dir . arg-ls)
\r
31 "List files in DIR, in alphabetical order. Two optional arguments
\r
32 are supported: a regexp filter, and a boolean that determines whether
\r
33 subdirectories should be included (defaults to true)."
\r
34 (let* ((n-args (length arg-ls))
\r
35 (pred (cond ((= n-args 0)
\r
37 ((procedure? (list-ref arg-ls 0))
\r
38 (list-ref arg-ls 0))
\r
39 ((string? (list-ref arg-ls 0))
\r
40 (let ((rx (make-regexp (list-ref arg-ls 0)
\r
41 ;; better use case-insensitive flag here
\r
43 (lambda (file) (regexp-exec rx file))))
\r
44 (#t (error "bad predicate" (list-ref arg-ls 0)))))
\r
45 (recurse? (if (>= n-args 2) (list-ref arg-ls 1) #t)))
\r
46 (define (do-file file basename ret-ls)
\r
47 (let* ((v (lstat file)))
\r
48 (cond ((string=? basename ".") ret-ls)
\r
49 ((string=? basename "..") ret-ls)
\r
50 ((and (eq? (stat:type v) 'directory)
\r
52 (do-dir file ret-ls))
\r
53 ((pred file) (cons file ret-ls))
\r
55 (define (do-dir dir-name ret-ls)
\r
56 (let ((dir (opendir dir-name)))
\r
57 (do ((file (readdir dir) (readdir dir)))
\r
58 ((eof-object? file) ret-ls)
\r
61 ;; (string) now only accepts chars,
\r
62 ;; use (string-append) instead
\r
63 (string-append dir-name "/" file) file ret-ls)))
\r
66 (sort (do-dir dir '()) string<?)))
\r
68 ;; Automatic includes ---------------------------------------------;
\r
69 (define-public (include-scm dir . numbered)
\r
70 "Load all Scheme files in DIR. If NUMBERED is set,
\r
71 load only numbered files."
\r
72 (let* ((regx (if numbered "[0-9].*.scm$" ".scm$"))
\r
73 (scm-files (find-files dir regx)))
\r
75 (begin (if (ly:get-option 'debug-messages)
\r
76 (ly:message "Loading ~a..." x))
\r
81 ;;;;;;;;;;;;;;;;;;;;;;;;;; Load libraries ;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
84 ;;;;;;;;;;;;;;;;;;;;;; Define music-functions ;;;;;;;;;;;;;;;;;;;;;;
\r
86 ;; Required by main.ly --------------------------------------------;
\r
88 ; #(define-music-function (parser location lang-code) (string?)
\r
89 ; (input-language lang-code)
\r
90 ; (make-sequential-music 'void #t))
\r
93 ; #(define-music-function (parser location lang-code) (string?)
\r
94 ; (edition-language lang-code)
\r
95 ; (make-sequential-music 'void #t))
\r
98 ; #(define-music-function (parser location dir) (string?)
\r
99 ; (use-score-dir dir))
\r
102 ;------------------------------------------------------------------;
\r