Add read-template function
This commit is contained in:
parent
23d2d07b1a
commit
1156b31463
@ -4,7 +4,9 @@
|
||||
|
||||
(import (srfi srfi-1)
|
||||
(srfi srfi-26)
|
||||
(srfi srfi-60))
|
||||
(srfi srfi-28)
|
||||
(srfi srfi-60)
|
||||
(ice-9 textual-ports))
|
||||
|
||||
(export log2 clog2 round-to
|
||||
one? power-of-two?
|
||||
@ -17,6 +19,7 @@
|
||||
has-duplicates? find-duplicates
|
||||
insert-between
|
||||
string-replace-text
|
||||
read-template
|
||||
|
||||
make-mux-selectors))
|
||||
(else
|
||||
@ -190,3 +193,21 @@
|
||||
(replace str (+ occ tlen 1))
|
||||
str))
|
||||
str))))))
|
||||
|
||||
;;; Read template and substitute replacements
|
||||
;;; Returns list of strings (lines)
|
||||
(define (read-template template-file template-format subst-list)
|
||||
(let ((ls (call-with-input-file template-file
|
||||
(lambda (port)
|
||||
(let loop ((l '()))
|
||||
(let ((s (get-line port)))
|
||||
(if (eof-object? s)
|
||||
(reverse l)
|
||||
(loop (cons s l)))))))))
|
||||
(map (lambda (str) (fold (lambda (s out)
|
||||
(string-replace-text
|
||||
out
|
||||
(format template-format (first s))
|
||||
(format "~a" (second s))))
|
||||
str subst-list))
|
||||
ls)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user