2004-08-12 17:36:36 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
PORT* untag_port(CELL tagged)
|
|
|
|
{
|
|
|
|
PORT* p;
|
|
|
|
type_check(PORT_TYPE,tagged);
|
|
|
|
p = (PORT*)UNTAG(tagged);
|
|
|
|
/* after image load & save, ports are no longer valid */
|
|
|
|
if(p->fd == -1)
|
|
|
|
general_error(ERROR_PORT_EXPIRED,tagged);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
CELL port(CELL fd)
|
|
|
|
{
|
|
|
|
PORT* port = allot_object(PORT_TYPE,sizeof(PORT));
|
|
|
|
port->fd = fd;
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = NULL;
|
|
|
|
port->line = NULL;
|
2004-08-12 17:36:36 -04:00
|
|
|
port->buf_mode = B_NONE;
|
|
|
|
port->buf_fill = 0;
|
|
|
|
port->buf_pos = 0;
|
|
|
|
return tag_object(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_portp(void)
|
|
|
|
{
|
|
|
|
drepl(tag_boolean(typep(PORT_TYPE,dpeek())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_buffer(PORT* port, int mode)
|
|
|
|
{
|
|
|
|
if(port->buf_mode == B_NONE)
|
|
|
|
port->buffer = string(BUF_SIZE,'\0');
|
|
|
|
|
|
|
|
if(port->buf_mode != mode)
|
|
|
|
{
|
|
|
|
port->buf_fill = port->buf_pos = 0;
|
|
|
|
port->buf_mode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fixup_port(PORT* port)
|
|
|
|
{
|
|
|
|
port->fd = -1;
|
|
|
|
if(port->buffer != 0)
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = fixup_untagged_string(port->buffer);
|
|
|
|
if(port->line != 0)
|
2004-08-12 17:36:36 -04:00
|
|
|
{
|
2004-08-12 23:40:28 -04:00
|
|
|
port->line = (SBUF*)((CELL)port->line
|
2004-08-12 17:36:36 -04:00
|
|
|
+ (active->base - relocation_base));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_port(PORT* port)
|
|
|
|
{
|
|
|
|
if(port->buffer != 0)
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = copy_untagged_string(port->buffer);
|
|
|
|
if(port->line != 0)
|
2004-08-12 17:36:36 -04:00
|
|
|
{
|
2004-08-12 23:40:28 -04:00
|
|
|
port->line = (SBUF*)copy_untagged_object(
|
|
|
|
port->line,sizeof(SBUF));
|
2004-08-12 17:36:36 -04:00
|
|
|
}
|
|
|
|
}
|