Commits

Peter Bex committed 9eff8e3

Use better ->string conversion routine

  • Participants
  • Parent commits a86c716

Comments (0)

Files changed (1)

File scsh-process.scm

 
    ;; 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)
 
 ;; 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)
 (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 ;;
     ((_ (> ?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))))