commit 6b4f6b0
chld
·
2026-08-15 20:31:35 +0000 UTC
parent 6dc5842
spaces in vars yay
M
test.scm
+8,
-6
1@@ -1,5 +1,6 @@
2 (use-modules (util)
3- (srfi srfi-1))
4+ (srfi srfi-1)
5+ (srfi srfi-13))
6
7 ;; a needs c so put it first
8 ;; a then put a
9@@ -21,10 +22,7 @@
10 (if (string-contains (list-ref f-list l) "=")
11 (if (string=? (list-ref (string-split (list-ref f-list l) #\space)1) "=")
12 (set! v-list
13- (cons (cons
14- (list-ref (string-split (list-ref f-list l)#\space) 0)
15- (list-ref (string-split (list-ref f-list l)#\space) 2)
16- v-list)))
17+ (cons (var-parse (list-ref f-list l)) v-list))
18 )
19 ))
20 )
21@@ -66,7 +64,11 @@
22 (system (string-delete #\@ (substring (list-ref f-list r)1)))
23 (begin
24 (format #t "+ ~a" (string-delete #\tab (list-ref f-list r)))(newline)
25- (system (substring (list-ref f-list r)1))
26+
27+ (if (string-contains (list-ref f-list r) "$(")
28+ (system (var-expand (substring (list-ref f-list r) 1)v-list))
29+ (system (substring (list-ref f-list r)1))
30+ )
31 )
32 )
33 )
M
util.scm
+23,
-1
1@@ -1,7 +1,8 @@
2 (define-module (util)
3 #:use-module (ice-9 popen)
4 #:use-module (ice-9 rdelim)
5- #:export (file-read line-parse list-sort)
6+ #:use-module (srfi srfi-1)
7+ #:export (file-read line-parse list-sort var-expand var-parse)
8 )
9
10 (define (file-read f)
11@@ -35,3 +36,24 @@
12
13 (visit t)
14 (reverse r)))
15+
16+(define (var-parse v)
17+ (let ((p (string-contains v "=")))
18+ (cons
19+ (string-trim-both (substring v 0 p))
20+ (string-trim-both
21+ (substring v (+ p 1))))))
22+
23+(define (var-expand s l)
24+ (fold
25+ (lambda (l s)
26+ (let* ((old (string-append "$(" (car l) ")"))
27+ (pos (string-contains s old)))
28+ (if pos
29+ (string-replace s
30+ (cdr l)
31+ pos
32+ (+ pos (string-length old)))
33+ s)))
34+ s
35+ l))