57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
-
+
|
(define configf:key-sys-pr (regexp "^(\\S+)\\s+\\[system\\s+(\\S+.*)\\]\\s*$"))
(define configf:key-val-pr (regexp "^(\\S+)(\\s+(.*)|())$"))
(define configf:comment-rx (regexp "^\\s*#.*"))
(define configf:cont-ln-rx (regexp "^(\\s+)(\\S+.*)$"))
;; read a line and process any #{ ... } constructs
(define configf:var-expand-regex (regexp "^(.*)#\\{(scheme|system|shell|getenv|get|runconfigs-get)\\s+([^\\}\\{]*)\\}(.*)"))
(define configf:var-expand-regex (regexp "^(.*)#\\{(scheme|system|shell|getenv|get|runconfigs-get|rget)\\s+([^\\}\\{]*)\\}(.*)"))
(define (configf:process-line l ht)
(let loop ((res l))
(if (string? res)
(let ((matchdat (string-search configf:var-expand-regex res)))
(if matchdat
(let* ((prestr (list-ref matchdat 1))
(cmdtype (list-ref matchdat 2)) ;; eval, system, shell, getenv
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
+
|
((getenv)(conc "(lambda (ht)(get-environment-variable \"" cmd "\"))"))
((get)
(let* ((parts (string-split cmd))
(sect (car parts))
(var (cadr parts)))
(conc "(lambda (ht)(config-lookup ht \"" sect "\" \"" var "\"))")))
((runconfigs-get) (conc "(lambda (ht)(runconfigs-get ht \"" cmd "\"))"))
((rget) (conc "(lambda (ht)(runconfigs-get ht \"" cmd "\"))"))
(else "(lambda (ht)(print \"ERROR\") \"ERROR\")"))))
;; (print "fullcmd=" fullcmd)
(with-input-from-string fullcmd
(lambda ()
(set! result ((eval (read)) ht))))
(loop (conc prestr result poststr)))
res))
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
|
(print "ERROR: " cmd " returned bad exit code " status))
""))))
;; Lookup a value in runconfigs based on -reqtarg or -target
(define (runconfigs-get config var)
(let ((targ (or (args:get-arg "-reqtarg")(args:get-arg "-target"))))
(if targ
(config-lookup config targ var)
#f)))
(or (configf:lookup config targ var)
(configf:lookup config "default" var))
(configf:lookup config "default" var))))
(define-inline (configf:read-line p ht allow-processing)
(let loop ((inl (read-line p)))
(if (and (string? inl)
(not (string-null? inl))
(equal? "\\" (string-take-right inl 1))) ;; last character is \
(let ((nextl (read-line p)))
(if (not (eof-object? nextl))
(loop (string-append inl nextl))))
(if (and allow-processing
(not (eq? allow-processing 'return-string)))
(configf:process-line (read-line p) ht)
(read-line p)))
(if (and allow-processing
(not (eq? allow-processing 'return-string)))
(configf:process-line inl ht)
inl))))
;; read a config file, returns hash table of alists
;; read a config file, returns hash table of alists
;; adds to ht if given (must be #f otherwise)
;; envion-patt is a regex spec that identifies sections that will be eval'd
;; in the environment on the fly
|