diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-14 21:21:05 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-14 21:21:05 -0700 |
commit | 05d55b8e42f7326b234f74f6114157f1990ac7da (patch) | |
tree | d11b880240e991be2d72979f61ebdb59cd31945e /share | |
parent | 244c24e0b295023e227f37f62dcab83c28c7614a (diff) | |
download | txr-05d55b8e42f7326b234f74f6114157f1990ac7da.tar.gz txr-05d55b8e42f7326b234f74f6114157f1990ac7da.tar.bz2 txr-05d55b8e42f7326b234f74f6114157f1990ac7da.zip |
buf: new buffer stream.
* buf.c (struct buf_strm): New struct type.
(buf_strm_mark, int buf_strm_put_byte_callback,
buf_strm_put_string, buf_strm_put_char, buf_strm_put_byte,
buf_strm_get_byte_callback, buf_strm_get_char,
buf_strm_get_byte, buf_strm_unget_char, buf_strm_unget_byte,
buf_strm_seek, buf_strm_truncate, buf_strm_get_prop,
buf_strm_set_prop, buf_strm_get_error,
buf_strm_get_error_str): New static functions.
(buf_strm_ops): New static struct.
(buf_strm): New static function.
(make_buf_stream, get_buf_from_stream): New functions.
(buf_init): Register new intrinsic functiions make-buf-stream
and get-buf-from-stream.
Call fill_stream_ops on new buf_strm_ops to fill
default operations in place of function pointers
that have been left null.
* buf.h (make_buf_stream, get_buf_from_stream): Declared.
* lisplib.c (with_stream_set_entries): Add with-out-buf-stream
and with-in-buf-stream to auto-load symbols for with-stream.tl
module.
* share/txr/stdlib/with-stream.tl (with-out-buf-stream,
with-in-buf-stream): New macros.
* txr.1: New section about buffer streams.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/with-stream.tl | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/share/txr/stdlib/with-stream.tl b/share/txr/stdlib/with-stream.tl index 40043237..a422a07c 100644 --- a/share/txr/stdlib/with-stream.tl +++ b/share/txr/stdlib/with-stream.tl @@ -34,6 +34,11 @@ ,*body (get-list-from-stream ,stream))) +(defmacro with-out-buf-stream ((stream : buf) . body) + ^(let ((,stream (make-buf-stream ,*[[iff have list] buf]))) + ,*body + (get-buf-from-stream ,stream))) + (defmacro with-in-string-stream ((stream string) . body) ^(let ((,stream (make-string-input-stream ,string))) ,*body)) @@ -42,6 +47,10 @@ ^(let ((,stream (make-string-byte-input-stream ,string))) ,*body)) +(defmacro with-in-buf-stream ((stream buf) . body) + ^(let ((,stream (make-buf-stream ,buf))) + ,*body)) + (defmacro with-stream ((var stream) . body) ^(let ((,var ,stream)) (unwind-protect |