reworked inner loop; now checks for a lisp symbol before trying to run on the system shell. also added helper function for converting a shell programs output to a list.

master
Thomas Hintz 13 years ago
parent 9c4bb87ae8
commit c3e712f381

@ -1,5 +1,5 @@
;;; documentation at http://thintz.com/chicken-scheme-shell ;;; documentation at http://thintz.com/chicken-scheme-shell
(use shell readline) (use readline symbol-utils)
(define (getenv2 e) (define (getenv2 e)
;; handles exorcism of getenv from 4.6.4 onwards ;; handles exorcism of getenv from 4.6.4 onwards
@ -21,20 +21,37 @@
(define exit? (make-parameter #f)) (define exit? (make-parameter #f))
(define (exit) (exit? #t)) (define (exit) (exit? #t))
; now we can can actually use things in a more lispy way
; #;1> (cmd->list "ls" read-line)
; (file1 file2 file3)
; #;2> (map (lambda (file) (run (string-append "cat " file)))
; (cmd->list "ls" read-line))
; ...contents of all the files in the current directory
(define (cmd->list cmd read-func)
(with-input-from-pipe
cmd
(lambda ()
(letrec ((get-next (lambda (o)
(let ((v (read-func)))
(if (not (eof-object? v))
(get-next (cons v o))
(reverse o))))))
(get-next '())))))
(define (run cmd) (process-wait (process-run cmd)))
(define (shell-repl) (define (shell-repl)
(if (exit?) (if (exit?)
#t #t
(let ((x (read))) (let ((x (read)))
(begin (handle-exceptions
exn
(handle-exceptions (handle-exceptions
exn exn
(begin (print-error-message exn) (begin (print-error-message exn)
(display (with-output-to-string (lambda () (print-call-chain))))) (display (with-output-to-string (lambda () (print-call-chain)))))
(execute (list x))) (if (unbound? x)
(display (eval x)) (run (symbol->string x))
(display (eval x)))
(newline)) (newline))
(newline) (shell-repl))))
(shell-repl)))))
(shell-repl) (shell-repl)

Loading…
Cancel
Save