Fix SI::OPEN-PIPE and add SI::CLOSE-PIPE

This commit is contained in:
jjgarcia 2003-07-03 13:57:59 +00:00
parent 5761ce9e77
commit dadf9d34ed
4 changed files with 31 additions and 14 deletions

View file

@ -598,6 +598,8 @@ sweep_phase(void)
if (x->d.m == FREE)
continue;
else if (x->d.m) {
/* FIXME!!! Here should come a finalization
procedure for streams */
x->d.m = FALSE;
continue;
}

View file

@ -1027,6 +1027,7 @@ cl_symbols[] = {
{SYS_ "CHAR-SET", SI_ORDINARY, si_char_set, 3},
{SYS_ "CHDIR", SI_ORDINARY, si_chdir, 1},
{SYS_ "CLEAR-COMPILER-PROPERTIES", SI_ORDINARY, cl_identity, 1},
{SYS_ "CLOSE-PIPE", SI_ORDINARY, si_close_pipe, 1},
{SYS_ "COERCE-TO-FUNCTION", SI_ORDINARY, si_coerce_to_function, 1},
{SYS_ "COERCE-TO-PACKAGE", SI_ORDINARY, si_coerce_to_package, 1},
{SYS_ "COMPILED-FUNCTION-BLOCK", SI_ORDINARY, si_compiled_function_block, 1},

View file

@ -38,21 +38,34 @@ si_system(cl_object cmd)
cl_object
si_open_pipe(cl_object cmd)
{
FILE *ptr;
cl_object stream;
FILE *ptr;
cl_object stream;
assert_type_string(cmd);
if ((ptr = popen(cmd->string.self, OPEN_R)) == NULL)
@(return Cnil)
stream = cl_alloc_object(t_stream);
stream->stream.mode = smm_input;
stream->stream.file = ptr;
stream->stream.object0 = @'base-char';
stream->stream.object1 = cmd;
stream->stream.int0 = stream->stream.int1 = 0;
assert_type_string(cmd);
ptr = popen(cmd->string.self, "r");
if (ptr == NULL)
@(return Cnil);
stream = cl_alloc_object(t_stream);
stream->stream.mode = smm_input;
stream->stream.file = ptr;
stream->stream.object0 = @'base-char';
stream->stream.object1 = @'si::open-pipe';
stream->stream.int0 = stream->stream.int1 = 0;
#if !defined(GBC_BOEHM)
setbuf(ptr, stream->stream.buffer = cl_alloc_atomic(BUFSIZ));
setbuf(ptr, stream->stream.buffer = cl_alloc_atomic(BUFSIZ));
#endif
@(return stream)
@(return stream)
}
cl_object
si_close_pipe(cl_object stream)
{
if (type_of(stream) == t_stream &&
stream->stream.object1 == @'si::open-pipe') {
stream->stream.mode = smm_closed;
pclose(stream->stream.file);
stream->stream.file = NULL;
stream->stream.object0 = OBJNULL;
}
@(return)
}

View file

@ -1353,6 +1353,7 @@ extern void init_interrupt(void);
extern cl_object si_system(cl_object cmd);
extern cl_object si_open_pipe(cl_object cmd);
extern cl_object si_close_pipe(cl_object stream);
#ifdef __cplusplus
}