diff options
author | Jim Blandy <jimb@red-bean.com> | 1997-06-13 05:50:37 +0000 |
---|---|---|
committer | Jim Blandy <jimb@red-bean.com> | 1997-06-13 05:50:37 +0000 |
commit | ec8469e7cbf7d19ac611a77a0008191a7a977a16 (patch) | |
tree | 2ee1a49ee0b3526fb3b93ae0f692d8fb59f728cb | |
parent | c6b15ad07e26d45323b2556e48a497ea6c9dbb7f (diff) | |
download | guile-ec8469e7cbf7d19ac611a77a0008191a7a977a16.tar.gz |
* expect.scm: Turn this into a module, (ice-9 expect).
(expect-port, expect-timeout, expect-timeout-proc,
expect-eof-proc, expect-char-proc, expect, expect-strings,
expect-select): Make these public definitions.
(expect-strings): Use make-regexp and regexp-exec, instead of
regcomp and regexec. We've omitted the REG_NEWLINE flag; hope
that's okay.
-rw-r--r-- | ice-9/expect.scm | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/ice-9/expect.scm b/ice-9/expect.scm index e312b71e9..d902bd3d1 100644 --- a/ice-9/expect.scm +++ b/ice-9/expect.scm @@ -19,20 +19,22 @@ ;;;; +(define-module (ice-9 expect)) + ;;; Expect: a macro for selecting actions based on what it reads from a port. ;;; The idea is from Don Libes' expect based on Tcl. ;;; This version by Gary Houston incorporating ideas from Aubrey Jaffer. -(define expect-port #f) -(define expect-timeout #f) -(define expect-timeout-proc #f) -(define expect-eof-proc #f) -(define expect-char-proc #f) +(define-public expect-port #f) +(define-public expect-timeout #f) +(define-public expect-timeout-proc #f) +(define-public expect-eof-proc #f) +(define-public expect-char-proc #f) ;;; expect: each test is a procedure which is applied to the accumulating ;;; string. -(defmacro expect clauses +(defmacro-public expect clauses (let ((s (gentemp)) (c (gentemp)) (port (gentemp)) @@ -66,8 +68,8 @@ (set! ,s (string-append ,s (string ,c))) (cond ,@(let next-expr ((tests (map car clauses)) - (exprs (map cdr clauses)) - (body ())) + (exprs (map cdr clauses)) + (body ())) (cond ((null? tests) (reverse body)) @@ -96,7 +98,7 @@ ;;; the regexec front-end to expect: ;;; each test must evaluate to a regular expression. -(defmacro expect-strings clauses +(defmacro-public expect-strings clauses `(let ,@(let next-test ((tests (map car clauses)) (exprs (map cdr clauses)) (defs ()) @@ -107,17 +109,17 @@ (let ((rxname (gentemp))) (next-test (cdr tests) (cdr exprs) - (cons `(,rxname (regcomp ,(car tests) - REG_NEWLINE)) + ;; should maybe use REG_NEWLINE below? + (cons `(,rxname (make-regexp ,(car tests))) defs) (cons `((lambda (s) - (regexec ,rxname s "")) + (regexp-exec ,rxname s)) ,@(car exprs)) body)))))))) ;;; simplified select: returns #t if input is waiting or #f if timed out. ;;; timeout is an absolute time in floating point seconds. -(define (expect-select port timeout) +(define-public (expect-select port timeout) (let* ((secs-usecs (gettimeofday)) (relative (- timeout (car secs-usecs) |