diff --git a/include/clasp/core/lispStream.h b/include/clasp/core/lispStream.h index cf7f9f6152..80cca029d0 100644 --- a/include/clasp/core/lispStream.h +++ b/include/clasp/core/lispStream.h @@ -674,6 +674,7 @@ class StringInputStream_O : public StringStream_O { void unread_char(claspCharacter c); claspCharacter peek_char(); int listen(); + void clear_input(); bool input_p() const; T_sp element_type() const; @@ -739,7 +740,7 @@ class SynonymStream_O : public AnsiStream_O { T_sp length(); T_sp position(); T_sp set_position(T_sp pos); - int column(); + int column() const; int set_column(int column); int input_handle(); @@ -794,7 +795,7 @@ class TwoWayStream_O : public AnsiStream_O { T_sp element_type() const; T_sp position(); - int column(); + int column() const; int set_column(int column); int input_handle(); @@ -841,7 +842,7 @@ class BroadcastStream_O : public AnsiStream_O { T_sp position(); T_sp set_position(T_sp pos); T_sp string_length(T_sp string); - int column(); + int column() const; int set_column(int column); T_sp close(T_sp abort); }; // BroadcastStream class @@ -872,6 +873,7 @@ class ConcatenatedStream_O : public AnsiStream_O { claspCharacter read_char(); void unread_char(claspCharacter c); int listen(); + void clear_input(); bool input_p() const; T_sp element_type() const; @@ -923,7 +925,7 @@ class EchoStream_O : public AnsiStream_O { T_sp element_type() const; T_sp position(); - int column(); + int column() const; int set_column(int column); int input_handle(); diff --git a/src/core/lispStream.cc b/src/core/lispStream.cc index 186c75c3f7..24bb1d336c 100644 --- a/src/core/lispStream.cc +++ b/src/core/lispStream.cc @@ -1267,6 +1267,8 @@ claspCharacter StringInputStream_O::peek_char() { int StringInputStream_O::listen() { return (_InputPosition < _InputLimit) ? CLASP_LISTEN_AVAILABLE : CLASP_LISTEN_EOF; } +void StringInputStream_O::clear_input() {} + T_sp StringInputStream_O::element_type() const { return _Contents->element_type(); } T_sp StringInputStream_O::position() { return Integer_O::create((gc::Fixnum)_InputPosition); } @@ -1385,7 +1387,7 @@ T_sp TwoWayStream_O::element_type() const { return stream_element_type(_In); } T_sp TwoWayStream_O::position() { return nil(); } -int TwoWayStream_O::column() { return stream_column(_Out); } +int TwoWayStream_O::column() const { return stream_column(_Out); } int TwoWayStream_O::set_column(int column) { return stream_set_column(_Out, column); } @@ -1513,7 +1515,7 @@ T_sp BroadcastStream_O::string_length(T_sp string) { : stream_string_length(oCar(cl__last(_Streams, clasp_make_fixnum(1))), string); } -int BroadcastStream_O::column() { return _Streams.nilp() ? -1 : stream_column(oCar(_Streams)); } +int BroadcastStream_O::column() const { return _Streams.nilp() ? -1 : stream_column(oCar(_Streams)); } int BroadcastStream_O::set_column(int column) { for (T_sp cur = _Streams; cur.consp(); cur = gc::As_unsafe(cur)->cdr()) { @@ -1638,7 +1640,7 @@ T_sp EchoStream_O::element_type() const { return stream_element_type(_In); } T_sp EchoStream_O::position() { return nil(); } -int EchoStream_O::column() { return stream_column(_Out); } +int EchoStream_O::column() const { return stream_column(_Out); } int EchoStream_O::set_column(int column) { return stream_set_column(_Out, column); } @@ -1700,6 +1702,8 @@ CL_DEFUN T_sp cl__echo_stream_output_stream(T_sp strm) { */ cl_index ConcatenatedStream_O::read_byte8(unsigned char* c, cl_index n) { + check_open(); + cl_index out = 0; while (out < n && !_List.nilp()) { cl_index delta = stream_read_byte8(oCar(_List), c + out, n - out); @@ -1712,6 +1716,8 @@ cl_index ConcatenatedStream_O::read_byte8(unsigned char* c, cl_index n) { } T_sp ConcatenatedStream_O::read_byte() { + check_open(); + T_sp l = _List; T_sp c = nil(); while (!l.nilp()) { @@ -1731,6 +1737,8 @@ bool ConcatenatedStream_O::input_p() const { return true; } T_sp ConcatenatedStream_O::element_type() const { return _List.nilp() ? _lisp->_true() : stream_element_type(oCar(_List)); } claspCharacter ConcatenatedStream_O::read_char() { + check_open(); + T_sp l = _List; claspCharacter c = EOF; while (!l.nilp()) { @@ -1743,11 +1751,15 @@ claspCharacter ConcatenatedStream_O::read_char() { } void ConcatenatedStream_O::unread_char(claspCharacter c) { + check_open(); + unlikely_if(_List.nilp()) unread_error(asSmartPtr()); stream_unread_char(oCar(_List), c); } int ConcatenatedStream_O::listen() { + check_open(); + while (!_List.nilp()) { int f = stream_listen(oCar(_List)); if (f != CLASP_LISTEN_EOF) { @@ -1758,6 +1770,13 @@ int ConcatenatedStream_O::listen() { return CLASP_LISTEN_EOF; } +void ConcatenatedStream_O::clear_input() { + check_open(); + + if (_List.notnilp()) + stream_clear_input(oCar(_List)); +} + T_sp ConcatenatedStream_O::position() { return nil(); } T_sp ConcatenatedStream_O::close(T_sp abort) { @@ -1868,7 +1887,7 @@ T_sp SynonymStream_O::position() { return stream_position(stream()); } T_sp SynonymStream_O::set_position(T_sp pos) { return stream_set_position(stream(), pos); } -int SynonymStream_O::column() { return stream_column(stream()); } +int SynonymStream_O::column() const { return stream_column(stream()); } int SynonymStream_O::set_column(int column) { return stream_set_column(stream(), column); }