start work on read#

cvs
Slava Pestov 2004-08-20 00:48:41 +00:00
parent e363a194da
commit 4571d3a83b
4 changed files with 87 additions and 18 deletions

View File

@ -6,23 +6,6 @@ void init_io(void)
env.user[STDOUT_ENV] = tag_object(port(PORT_WRITE,1));
}
bool can_read_line(PORT* port)
{
if(port->line_ready)
return true;
else
{
read_line_step(port);
return port->line_ready;
}
}
void primitive_can_read_line(void)
{
PORT* port = untag_port(dpop());
dpush(tag_boolean(can_read_line(port)));
}
/* Return true if something was read */
bool read_step(PORT* port)
{
@ -108,6 +91,23 @@ bool read_line_step(PORT* port)
return false;
}
bool can_read_line(PORT* port)
{
if(port->line_ready)
return true;
else
{
read_line_step(port);
return port->line_ready;
}
}
void primitive_can_read_line(void)
{
PORT* port = untag_port(dpop());
dpush(tag_boolean(can_read_line(port)));
}
void primitive_read_line_fd_8(void)
{
PORT* port = untag_port(dpeek());
@ -122,6 +122,57 @@ void primitive_read_line_fd_8(void)
}
bool read_count_step(PORT* port, FIXNUM count)
{
int i;
char ch;
SBUF* line;
if(port->line == F)
{
line = sbuf(count);
port->line = tag_object(line);
}
else
{
line = untag_sbuf(port->line);
line->top = 0;
}
for(i = port->buf_pos; i < port->buf_fill; i++)
{
ch = bget((CELL)port->buffer + sizeof(STRING) + i);
set_sbuf_nth(line,line->top,ch);
if(line->top == count)
return true;
}
/* We've reached the end of the above loop, without seeing enough chars
or EOF, so read again */
return false;
}
#define CAN_READ_COUNT(sbuf) (untag_sbuf(port->line)->top >= count)
bool can_read_count(PORT* port, FIXNUM count)
{
if(port->line != F && CAN_READ_COUNT(sbuf))
return true;
else
{
read_count_step(port,count);
return CAN_READ_COUNT(sbuf);
}
}
void primitive_can_read_count(void)
{
FIXNUM len = to_fixnum(dpop());
PORT* port = untag_port(dpop());
dpush(tag_boolean(can_read_count(port,len)));
}
/* Return true if write was done */
bool write_step(PORT* port)
{

View File

@ -10,6 +10,9 @@ bool write_step(PORT* port);
void flush_buffer(PORT* port);
void init_io(void);
void primitive_read_line_fd_8(void);
bool read_count_step(PORT* port, FIXNUM count);
bool can_read_count(PORT* port, FIXNUM count);
void primitive_can_read_count(void);
bool can_write(PORT* port, FIXNUM len);
void primitive_can_write(void);
void write_fd_char_8(PORT* port, FIXNUM ch);

View File

@ -139,7 +139,18 @@ bool perform_read_line_io_task(PORT* port)
bool perform_read_count_io_task(PORT* port)
{
return false;
SBUF* line;
if(port->buf_pos >= port->buf_fill)
{
if(!read_step(port))
return false;
}
if(port->buf_fill == 0)
return true;
else
return read_count_step(port,port->count);
}
bool perform_write_io_task(PORT* port)

View File

@ -15,8 +15,12 @@ typedef struct {
/* tagged partial line used by read_line_fd */
CELL line;
/* is it ready to be returned? */
/* with the read# IO_TASK, this means that the operation is done */
bool line_ready;
/* count for read# */
FIXNUM count;
/* tagged client info used by accept_fd */
CELL client_host;
CELL client_port;