mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-04-27 19:50:44 -07:00
streams: get rid of last_code slot in the structure
It was used to store bytes for unread, but we are going to change how unread works, and we still can simply test for newline and encode behavior directly in unread-char for newlines.
This commit is contained in:
parent
c8f41912a0
commit
a726cdf879
5 changed files with 21 additions and 32 deletions
|
|
@ -45,7 +45,6 @@ ecl_alloc_stream(void)
|
|||
x->stream.byte_decoder = NULL;
|
||||
x->stream.last_char = EOF;
|
||||
x->stream.byte_stack = ECL_NIL;
|
||||
x->stream.last_code[0] = x->stream.last_code[1] = EOF;
|
||||
x->stream.eof_char = EOF;
|
||||
return x;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,6 @@ ecl_eformat_read_char(cl_object strm)
|
|||
return EOF;
|
||||
if (c != EOF) {
|
||||
strm->stream.last_char = c;
|
||||
strm->stream.last_code[0] = c;
|
||||
strm->stream.last_code[1] = EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
@ -90,28 +88,33 @@ ecl_eformat_unread_char(cl_object strm, ecl_character c)
|
|||
unlikely_if (c != strm->stream.last_char) {
|
||||
ecl_unread_twice(strm);
|
||||
}
|
||||
{
|
||||
if (c == ECL_CHAR_CODE_NEWLINE) {
|
||||
unsigned char *buffer = strm->stream.byte_buffer;
|
||||
int ndx = 0;
|
||||
cl_object l = strm->stream.byte_stack;
|
||||
cl_fixnum i;
|
||||
/* Byte stack lands in a reverse order. */
|
||||
i = strm->stream.last_code[1];
|
||||
if (i != EOF) {
|
||||
ndx = strm->stream.encoder(strm, buffer, i);
|
||||
while (ndx != 0) {
|
||||
l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
}
|
||||
}
|
||||
i = strm->stream.last_code[0];
|
||||
if (i != EOF) {
|
||||
ndx = strm->stream.encoder(strm, buffer, i);
|
||||
while (ndx != 0) {
|
||||
l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
int flags = strm->stream.flags;
|
||||
if (flags & ECL_STREAM_CR) {
|
||||
if (flags & ECL_STREAM_LF) {
|
||||
/* Byte stack lands in a reverse order. */
|
||||
ndx = strm->stream.encoder(strm, buffer, ECL_CHAR_CODE_LINEFEED);
|
||||
while (ndx != 0) l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
}
|
||||
ndx = strm->stream.encoder(strm, buffer, ECL_CHAR_CODE_RETURN);
|
||||
while (ndx != 0) l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
} else {
|
||||
ndx = strm->stream.encoder(strm, buffer, ECL_CHAR_CODE_NEWLINE);
|
||||
while (ndx != 0) l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
}
|
||||
strm->stream.byte_stack = l;
|
||||
strm->stream.last_char = EOF;
|
||||
} else {
|
||||
unsigned char *buffer = strm->stream.byte_buffer;
|
||||
int ndx = 0;
|
||||
cl_object l = strm->stream.byte_stack;
|
||||
ndx = strm->stream.encoder(strm, buffer, c);
|
||||
while (ndx != 0) l = CONS(ecl_make_fixnum(buffer[--ndx]), l);
|
||||
strm->stream.byte_stack = l;
|
||||
strm->stream.last_char = EOF;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,14 +158,10 @@ eformat_read_char_crlf(cl_object strm)
|
|||
if (c == ECL_CHAR_CODE_RETURN) {
|
||||
c = ecl_eformat_read_char(strm);
|
||||
if (c == ECL_CHAR_CODE_LINEFEED) {
|
||||
strm->stream.last_code[0] = ECL_CHAR_CODE_RETURN;
|
||||
strm->stream.last_code[1] = c;
|
||||
c = ECL_CHAR_CODE_NEWLINE;
|
||||
} else {
|
||||
ecl_eformat_unread_char(strm, c);
|
||||
c = ECL_CHAR_CODE_RETURN;
|
||||
strm->stream.last_code[0] = c;
|
||||
strm->stream.last_code[1] = EOF;
|
||||
}
|
||||
strm->stream.last_char = c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,7 +372,6 @@ static ecl_character io_file_decode_char_from_buffer(cl_object strm, unsigned ch
|
|||
/* Ugly handling of line breaks */
|
||||
if (crlf) {
|
||||
if (c == ECL_CHAR_CODE_LINEFEED) {
|
||||
strm->stream.last_code[1] = c;
|
||||
c = ECL_CHAR_CODE_NEWLINE;
|
||||
}
|
||||
else {
|
||||
|
|
@ -381,17 +380,12 @@ static ecl_character io_file_decode_char_from_buffer(cl_object strm, unsigned ch
|
|||
}
|
||||
} else if (strm->stream.flags & ECL_STREAM_CR && c == ECL_CHAR_CODE_RETURN) {
|
||||
if (strm->stream.flags & ECL_STREAM_LF) {
|
||||
strm->stream.last_code[0] = c;
|
||||
crlf = 1;
|
||||
goto AGAIN;
|
||||
}
|
||||
else
|
||||
c = ECL_CHAR_CODE_NEWLINE;
|
||||
}
|
||||
if (!crlf) {
|
||||
strm->stream.last_code[0] = c;
|
||||
strm->stream.last_code[1] = EOF;
|
||||
}
|
||||
strm->stream.last_char = c;
|
||||
return c;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -711,8 +711,6 @@ Buffer for unread bytes.
|
|||
File column.
|
||||
@item cl_fixnum last_char
|
||||
Last character read.
|
||||
@item cl_fixnum last_code[2]
|
||||
Actual composition of the last character.
|
||||
@item cl_fixnum int0 int1
|
||||
Some integers (may be used for a specific implementation purposes).
|
||||
@item cl_index byte_size
|
||||
|
|
|
|||
|
|
@ -690,10 +690,9 @@ struct ecl_stream {
|
|||
cl_object object0; /* some object */
|
||||
cl_object object1; /* some object */
|
||||
cl_object last_byte; /* last byte read */
|
||||
cl_fixnum last_char; /* last character read */
|
||||
cl_object byte_stack; /* buffer for unread bytes */
|
||||
cl_index column; /* file column */
|
||||
cl_fixnum last_char; /* last character read */
|
||||
cl_fixnum last_code[2]; /* actual composition of last character */
|
||||
cl_fixnum int0; /* some int */
|
||||
cl_fixnum int1; /* some int */
|
||||
cl_index byte_size; /* size of byte in binary streams */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue