[Wisp-cvs] wisp/users/pisi dialect.pisi.wim,1.8,1.9
Status: Alpha
Brought to you by:
digg
From: <pi...@us...> - 2003-02-25 08:16:54
|
Update of /cvsroot/wisp/wisp/users/pisi In directory sc8-pr-cvs1:/tmp/cvs-serv27806 Modified Files: dialect.pisi.wim Log Message: introduced searchpath Index: dialect.pisi.wim =================================================================== RCS file: /cvsroot/wisp/wisp/users/pisi/dialect.pisi.wim,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- dialect.pisi.wim 10 Feb 2003 10:50:46 -0000 1.8 +++ dialect.pisi.wim 25 Feb 2003 08:16:51 -0000 1.9 @@ -6,28 +6,28 @@ ;; ;;;; @(#) $Id$ +; this file at the moment deals with unix integration so most of the tools +; are for interacting with the unix environment and acting as a shell + (module dialect.pisi) (export - forever unix-command) - -(use lists strings unix) + forever unix-command unix-search-path reaper talk-to-process) -;;; (forever ...) - do something forever. -(defmacro (forever . body) - `(let (loop) - (hide loop ,@body) - (loop))) +(use lists strings unix syscalls) +;;; this is like $PATH in unix this should be local to callers and threads.. hmm. +;;; if we get called FROM an existing unix environment we adapt to the existing path +;;; this way one can set a new sarch path using (set! (unix-search-path) '(..)) +(define *unix-search-path* (make-box '())) -;;; (executable? /filename/) +(define (unix-search-path (:= new-path)) + (if (not :=?) + (map string-copy (box-ref *unix-search-path*)) + (set! (box-ref *unix-search-path*) (map string-copy new-path)))) ;;; (unix-command "command with options" (pathref)) -(define (unix-command commando - (pathlist (cond - ((env-ref "PATH") => - (cut split-by-char #\: <>)) - (else '())))) +(define (unix-command commando (pathlist (unix-search-path))) (if (not (any (lambda (otsikoht) (try @@ -43,23 +43,53 @@ ) + +;;; (forever ...) - do something forever. +(defmacro (forever . body) + `(let (loop) + (hide loop ,@body) + (loop))) + + + +;;; reaper - loops and waits +(define (reaper) (forever + (my exitproc (sys:waitpid -1 0) + (print "exited: $,[exitproc]\n"))) +) + + + ;;;; Talk-to-process (define (talk-to-process proc masterproc) (let* ((pipe-child (sys:pipe)) - (pipe-parent (sys:pipe)) - (child (sys:fork))) - (if (zero? child) - ;; child continues - (begin - (sys:dup2 (car pipe-parent) 0) (sys:close (cdr pipe-parent)) - (sys:dup2 (cdr pipe-child) 1) (sys:close (car pipe-child)) - (dedicated proc)) - ;; parent - (my saved-data (cons (sys:dup 0) (sys:dup 1)) - (sys:dup2 (car pipe-child) 0) (sys:close (cdr pipe-child)) - (sys:dup2 (cdr pipe-parent) 1) (sys:close (car pipe-parent)) - (masterproc) - (sys:dup2 (car saved-data) 0) - (sys:dup2 (cdr saved-data) 1) - )))) + (pipe-parent (sys:pipe)) + (child (sys:fork))) +(if (zero? child) +;; child continues +(begin +(sys:dup2 (car pipe-parent) 0) (sys:close (cdr pipe-parent)) +(sys:dup2 (cdr pipe-child) 1) (sys:close (car pipe-child)) +(dedicated proc)) +;; parent +(my saved-data (cons (sys:dup 0) (sys:dup 1)) +(sys:dup2 (car pipe-child) 0) (sys:close (cdr pipe-child)) +(sys:dup2 (cdr pipe-parent) 1) (sys:close (car pipe-parent)) +(masterproc) +(sys:dup2 (car saved-data) 0) +(sys:dup2 (cdr saved-data) 1) +)))) + + + +;;; module initalization +(begin +;; set the path +(set! (unix-search-path) + (cond + ;;; we were called from existing UNIX environment + ((env-ref "PATH") => (cut split-by-char #\: <>)) + ;;; make up a reasonable searchpath + (else '("/bin" "/usr/bin" "/sbin" "/usr/sbin")))) +) |