io-redirect: some progress, some new tests.
This commit is contained in:
parent
049c4a20dc
commit
b6340bd612
3
check.sh
3
check.sh
|
@ -75,6 +75,9 @@ tests="
|
|||
41-dot
|
||||
|
||||
50-iohere
|
||||
50-redirect
|
||||
50-redirect-space
|
||||
50-redirect-in
|
||||
|
||||
60-function
|
||||
60-subst
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
assign < '='
|
||||
|
||||
io-redirect <-- [0-9]* (io-here / io-file)
|
||||
io-file <-- io-op ([0-9]+ / word)
|
||||
io-file <-- io-op ([0-9]+ / sp* word)
|
||||
io-op <- '<&' / '>&' / '>>' / '>' / '<>'/ '<' / '>|'
|
||||
io-here <-- io-here-op io-here-label sp* eol io-here-document
|
||||
io-here-op <- '<<-' / '<<'
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
(('pipeline command) (pke 'background: `(pipeline+ #f ,command)))
|
||||
(_ term)))
|
||||
|
||||
(define (command . args)
|
||||
(define (exec-command . args)
|
||||
(define (exec command)
|
||||
(cond ((procedure? command) command)
|
||||
((assoc-ref %functions (car command))
|
||||
|
@ -177,6 +177,20 @@
|
|||
(define-syntax-rule (substitution commands)
|
||||
(string-trim-right (with-output-to-string (lambda _ commands))))
|
||||
|
||||
(define-syntax command
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ word ... (io-redirect (io-file "<" file-name)))
|
||||
#'(with-input-from-file file-name (command word ...)))
|
||||
((_ word ... (io-redirect (io-file ">" file-name)))
|
||||
#'(with-output-to-file file-name (command word ...)))
|
||||
((_ word ... (io-redirect "1" (io-file ">" file-name)))
|
||||
#'(with-output-to-file file-name (command word ...)))
|
||||
((_ word ... (io-redirect "2" (io-file ">" file-name)))
|
||||
#'(with-error-to-file file-name (command word ...)))
|
||||
((_ word ...)
|
||||
#'(exec-command word ...)))))
|
||||
|
||||
(define-syntax-rule (ignore-error o)
|
||||
(let ((errexit (shell-opt? "errexit")))
|
||||
(when errexit
|
||||
|
@ -408,4 +422,4 @@
|
|||
o)
|
||||
|
||||
(define (test . o) ;; TODO replace with implementation in scheme
|
||||
(apply command (cons "test" o)))
|
||||
(command (cons "test" o)))
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
\cat < test/data/foo
|
|
@ -0,0 +1,3 @@
|
|||
echo foo > bar
|
||||
cat bar
|
||||
rm bar
|
|
@ -0,0 +1 @@
|
|||
foo
|
|
@ -0,0 +1,3 @@
|
|||
echo foo 1>./bar
|
||||
cat bar
|
||||
rm bar
|
|
@ -0,0 +1 @@
|
|||
foo
|
Loading…
Reference in New Issue