53 lines
1.3 KiB
Scheme
53 lines
1.3 KiB
Scheme
(define *configuration* '())
|
|
|
|
(define (init-config config-file)
|
|
(with-input-from-file
|
|
config-file
|
|
(set! *configuration* (read))))
|
|
|
|
(define (read-config config-file)
|
|
(call-with-input-file config-file read))
|
|
|
|
(define (config-file-to-use)
|
|
(let ((from-env (getenv "CMDRSRC"))
|
|
(default-location
|
|
(string-append (home-dir) "/.cmdrsrc")))
|
|
(if (and from-env (file-exists? from-env))
|
|
from-env
|
|
default-location)))
|
|
|
|
(define (read-config-file!)
|
|
(with-errno-handler
|
|
((errno data)
|
|
(else #f))
|
|
(let ((conf-file (config-file-to-use)))
|
|
(for-each
|
|
(lambda (option.value)
|
|
(cond
|
|
((and (pair? option.value)
|
|
(pair? (car option.value))
|
|
(symbol? (caar option.value))
|
|
(symbol? (cdar option.value))
|
|
(assoc (car option.value) *configuration*))
|
|
=> (lambda (p)
|
|
(set-cdr! p (eval-s-expr (cdr option.value) 'commander-s-config-eval))))
|
|
(else
|
|
(error "Unknown option value or ill-formed option"
|
|
option.value conf-file))))
|
|
(read-config conf-file)))))
|
|
|
|
(define (config module option)
|
|
(let ((probe (assoc (cons module option) *configuration*)))
|
|
(if probe
|
|
(cdr probe)
|
|
(error "unknown configuration option" option))))
|
|
|
|
(define (define-option module option-name default-value)
|
|
(set! *configuration*
|
|
(cons (cons (cons module option-name) default-value)
|
|
*configuration*)))
|
|
|
|
|
|
|
|
|