2005-09-27 04:57:28 -04:00
|
|
|
(define *configuration* '())
|
|
|
|
|
|
|
|
(define (init-config config-file)
|
2005-10-11 11:38:18 -04:00
|
|
|
(with-input-from-file
|
2005-09-27 04:57:28 -04:00
|
|
|
config-file
|
|
|
|
(set! *configuration* (read))))
|
2005-10-11 11:38:18 -04:00
|
|
|
|
2005-09-27 04:57:28 -04:00
|
|
|
(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 (cdr option.value))))
|
|
|
|
(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*)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|