mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-09 06:30:32 -07:00
streams: echo-stream treats last_byte as a flag
Instead of remembering the last unread object and its type, it simply yots down the fact that something has been unread (and clears on read), and delegates the question to the input stream.
This commit is contained in:
parent
31a3fc904e
commit
c8f41912a0
1 changed files with 15 additions and 22 deletions
|
|
@ -443,13 +443,13 @@ static cl_object
|
|||
echo_read_byte(cl_object strm)
|
||||
{
|
||||
cl_object byte = strm->stream.last_byte;
|
||||
if (byte == OBJNULL) {
|
||||
if (byte != OBJNULL) {
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
byte = ecl_read_byte(ECHO_STREAM_INPUT(strm));
|
||||
} else {
|
||||
byte = ecl_read_byte(ECHO_STREAM_INPUT(strm));
|
||||
if (byte != OBJNULL)
|
||||
ecl_write_byte(byte, ECHO_STREAM_OUTPUT(strm));
|
||||
} else {
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
byte = ecl_read_byte(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
|
@ -466,31 +466,28 @@ echo_unread_byte(cl_object strm, cl_object byte)
|
|||
unlikely_if (strm->stream.last_byte != OBJNULL) {
|
||||
ecl_unread_twice(strm);
|
||||
}
|
||||
strm->stream.last_byte = byte;
|
||||
strm->stream.last_byte = ECL_T;
|
||||
ecl_unread_byte(byte, ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
|
||||
static cl_object
|
||||
echo_peek_byte(cl_object strm)
|
||||
{
|
||||
cl_object byte = strm->stream.last_byte;
|
||||
if (byte == OBJNULL) {
|
||||
byte = ecl_peek_byte(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
return byte;
|
||||
return ecl_peek_byte(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
|
||||
static ecl_character
|
||||
echo_read_char(cl_object strm)
|
||||
{
|
||||
ecl_character c = strm->stream.last_code[0];
|
||||
if (c == EOF) {
|
||||
cl_object byte = strm->stream.last_byte;
|
||||
ecl_character c;
|
||||
if (byte != OBJNULL) {
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
c = ecl_read_char(ECHO_STREAM_INPUT(strm));
|
||||
} else {
|
||||
c = ecl_read_char(ECHO_STREAM_INPUT(strm));
|
||||
if (c != EOF)
|
||||
ecl_write_char(c, ECHO_STREAM_OUTPUT(strm));
|
||||
} else {
|
||||
strm->stream.last_code[0] = EOF;
|
||||
ecl_read_char(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
@ -504,21 +501,17 @@ echo_write_char(cl_object strm, ecl_character c)
|
|||
static void
|
||||
echo_unread_char(cl_object strm, ecl_character c)
|
||||
{
|
||||
unlikely_if (strm->stream.last_code[0] != EOF) {
|
||||
unlikely_if (strm->stream.last_byte != OBJNULL) {
|
||||
ecl_unread_twice(strm);
|
||||
}
|
||||
strm->stream.last_code[0] = c;
|
||||
strm->stream.last_byte = ECL_T;;
|
||||
ecl_unread_char(c, ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
|
||||
static ecl_character
|
||||
echo_peek_char(cl_object strm)
|
||||
{
|
||||
ecl_character c = strm->stream.last_code[0];
|
||||
if (c == EOF) {
|
||||
c = ecl_peek_char(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
return c;
|
||||
return ecl_peek_char(ECHO_STREAM_INPUT(strm));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue