From 6907a5c947daab579d656cede43589d31dcd808c Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Tue, 2 Oct 2012 00:46:18 +0100 Subject: Use better ->string conversion routine --- scsh-process.scm | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scsh-process.scm b/scsh-process.scm index 7350edb..bdb40aa 100644 --- a/scsh-process.scm +++ b/scsh-process.scm @@ -43,9 +43,7 @@ ;; macros run/collecting run/string run/strings run/port run/file run/sexp run/sexps - || && - (& run-final-thunk maybe-symbol->string) - (run maybe-symbol->string) (exec-epf maybe-symbol->string)) + || && (& run-final-thunk maybe->string) (run maybe->string) (exec-epf maybe->string)) (import chicken scheme data-structures) @@ -55,8 +53,7 @@ ;; execve can be used in a sensible way? Scsh has its own PATH, so we could ;; use something similar to that, but it's more work. (define (exec-path prog . args) - ;; Args can include numbers and such, too! That's why we're using ->string - (process-execute (maybe-symbol->string prog) (map ->string args))) + (process-execute (maybe->string prog) (map maybe->string args))) ;; TODO: continue-threads argument (define (fork/pipe #!optional thunk) @@ -107,9 +104,10 @@ (define %fork/pipe fork/pipe) (define %fork/pipe+ fork/pipe+) -(define (maybe-symbol->string s) - (if (symbol? s) (symbol->string s) s)) - +(define (maybe->string s) + (cond ((string? s) s) + ((or (symbol? s) (number? s)) (->string s)) + (else (error "Expected a string, symbol or number")))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Baroque procedural interface ;; @@ -220,16 +218,15 @@ ((_ (> ?file-name)) (setup-redirection (> 1 ?file-name))) ((_ (>> ?file-name)) (setup-redirection (>> 1 ?file-name))) ((_ (> ?fd ?file-name)) - (duplicate-fileno (file-open (maybe-symbol->string `?file-name) + (duplicate-fileno (file-open (maybe->string `?file-name) (fx+ open/wronly open/creat)) `?fd)) ((_ (>> ?fd ?file-name)) - (duplicate-fileno (file-open (maybe-symbol->string `?file-name) + (duplicate-fileno (file-open (maybe->string `?file-name) (fx+ open/wronly (fx+ open/append open/creat))) `?fd)) ((_ (< ?fd ?file-name)) - (duplicate-fileno (file-open (maybe-symbol->string `?file-name) - open/rdonly) + (duplicate-fileno (file-open (maybe->string `?file-name) open/rdonly) `?fd)) ((_ (<< ?fd ?object)) (fork/pipe (lambda () (display ?object)))) -- cgit v1.2.3