This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ss
33 lines (33 loc) · 1.58 KB
/
config.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#lang scheme
(provide reread-config config-file SERVER DAEMON SERVER-PORT DAEMON-PORT NAME FORMAT-STRING DATASTORE-TYPE)
(define config-file (string-append (path->string (find-system-path 'pref-dir)) "code-immersion.config"))
(define read-config (lambda ()
(if (file-exists? config-file)
(call-with-input-file config-file
(lambda (in) (read in))
#:mode 'text)
null)))
(define default '((SERVER "localhost")
(DAEMON "localhost")
(SERVER-PORT 2000)
(DAEMON-PORT 2005)
(NAME "Unconfigured Name")
(FORMAT-STRING "~a from ~a: ~a~n")
(DATASTORE-TYPE "hash-datastore")))
(define config (read-config))
(define reread-config
(lambda () (set! config (read-config))))
(define SERVER
(lambda () (second (or (assoc 'SERVER config) (assoc 'SERVER default)))))
(define DAEMON
(lambda () (second (or (assoc 'DAEMON config) (assoc 'DAEMON default)))))
(define SERVER-PORT
(lambda () (second (or (assoc 'SERVER-PORT config) (assoc 'SERVER-PORT default)))))
(define DAEMON-PORT
(lambda () (second (or (assoc 'DAEMON-PORT config) (assoc 'DAEMON-PORT default)))))
(define NAME
(lambda () (second (or (assoc 'NAME config) (assoc 'NAME default)))))
(define FORMAT-STRING
(lambda () (second (or (assoc 'FORMAT-STRING config) (assoc 'FORMAT-STRING default)))))
(define DATASTORE-TYPE
(lambda () (second (or (assoc 'DATASTORE-TYPE config) (assoc 'DATASTORE-TYPE default)))))