mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-01 23:30:40 -08:00
Export ecl_stream_handle()
This commit is contained in:
parent
d87dce61ec
commit
147a8ff62b
6 changed files with 41 additions and 37 deletions
|
|
@ -339,6 +339,7 @@ EXPORTS
|
|||
cl_file_length
|
||||
ecl_file_column
|
||||
ecl_make_stream_from_fd
|
||||
ecl_stream_to_handle
|
||||
|
||||
|
||||
; format.c
|
||||
|
|
|
|||
|
|
@ -345,6 +345,7 @@ EXPORTS
|
|||
cl_file_length
|
||||
ecl_file_column
|
||||
ecl_make_stream_from_fd
|
||||
ecl_stream_to_handle
|
||||
|
||||
|
||||
; format.c
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ ECL 1.0:
|
|||
(ffi:clines "#include <math.h>")
|
||||
(ffi:c-inline (x) (:double) :double "sin(#0)" :one-liner t))
|
||||
|
||||
- Function ecl_stream_to_handle() now exported.
|
||||
|
||||
* Contributed code:
|
||||
|
||||
- New examples: cmdline/ls.lsp, ffi/uffi.lsp
|
||||
|
|
|
|||
30
src/c/file.d
30
src/c/file.d
|
|
@ -2810,6 +2810,36 @@ ecl_make_stream_from_fd(cl_object fname, int fd, enum ecl_smmode smm)
|
|||
return(stream);
|
||||
}
|
||||
|
||||
int
|
||||
ecl_stream_to_handle(cl_object s, bool output)
|
||||
{
|
||||
FILE *f;
|
||||
BEGIN:
|
||||
if (type_of(s) != t_stream)
|
||||
return -1;
|
||||
switch ((enum ecl_smmode)s->stream.mode) {
|
||||
case smm_input:
|
||||
if (output) return -1;
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_output:
|
||||
if (!output) return -1;
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_io:
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_synonym:
|
||||
s = symbol_value(s->stream.object0);
|
||||
goto BEGIN;
|
||||
case smm_two_way:
|
||||
s = output? s->stream.object1 : s->stream.object0;
|
||||
goto BEGIN;
|
||||
default:
|
||||
error("illegal stream mode");
|
||||
}
|
||||
return fileno(f);
|
||||
}
|
||||
|
||||
void
|
||||
init_file(void)
|
||||
|
|
|
|||
|
|
@ -87,37 +87,6 @@ si_close_pipe(cl_object stream)
|
|||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
stream_to_handle(cl_object s, bool output)
|
||||
{
|
||||
FILE *f;
|
||||
BEGIN:
|
||||
if (type_of(s) != t_stream)
|
||||
return -1;
|
||||
switch ((enum ecl_smmode)s->stream.mode) {
|
||||
case smm_input:
|
||||
if (output) return -1;
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_output:
|
||||
if (!output) return -1;
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_io:
|
||||
f = s->stream.file;
|
||||
break;
|
||||
case smm_synonym:
|
||||
s = symbol_value(s->stream.object0);
|
||||
goto BEGIN;
|
||||
case smm_two_way:
|
||||
s = output? s->stream.object1 : s->stream.object0;
|
||||
goto BEGIN;
|
||||
default:
|
||||
error("illegal stream mode");
|
||||
}
|
||||
return fileno(f);
|
||||
}
|
||||
|
||||
@(defun ext::run-program (command argv &key (input @':stream') (output @':stream')
|
||||
(error @'t'))
|
||||
int parent_write = 0, parent_read = 0;
|
||||
|
|
@ -170,7 +139,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
/* The child inherits a duplicate of our input
|
||||
handle. Creating a duplicate avoids problems when
|
||||
the child closes it */
|
||||
int stream_handle = stream_to_handle(SYM_VAL(@'*standard-input*'), 0);
|
||||
int stream_handle = ecl_stream_to_handle(SYM_VAL(@'*standard-input*'), 0);
|
||||
if (stream_handle >= 0)
|
||||
DuplicateHandle(current, _get_osfhandle(stream_handle) /*GetStdHandle(STD_INPUT_HANDLE)*/,
|
||||
current, &child_stdin, 0, TRUE,
|
||||
|
|
@ -202,7 +171,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
/* The child inherits a duplicate of our output
|
||||
handle. Creating a duplicate avoids problems when
|
||||
the child closes it */
|
||||
int stream_handle = stream_to_handle(SYM_VAL(@'*standard-output*'), 1);
|
||||
int stream_handle = ecl_stream_to_handle(SYM_VAL(@'*standard-output*'), 1);
|
||||
if (stream_handle >= 0)
|
||||
DuplicateHandle(current, _get_osfhandle(stream_handle) /*GetStdHandle(STD_OUTPUT_HANDLE)*/,
|
||||
current, &child_stdout, 0, TRUE,
|
||||
|
|
@ -223,7 +192,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
/* The child inherits a duplicate of our output
|
||||
handle. Creating a duplicate avoids problems when
|
||||
the child closes it */
|
||||
int stream_handle = stream_to_handle(SYM_VAL(@'*error-output*'), 1);
|
||||
int stream_handle = ecl_stream_to_handle(SYM_VAL(@'*error-output*'), 1);
|
||||
if (stream_handle >= 0)
|
||||
DuplicateHandle(current, _get_osfhandle(stream_handle) /*GetStdHandle(STD_ERROR_HANDLE)*/,
|
||||
current, &child_stderr, 0, TRUE,
|
||||
|
|
@ -308,7 +277,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
} else {
|
||||
child_stdin = -1;
|
||||
if (input == @'t')
|
||||
child_stdin = stream_to_handle(SYM_VAL(@'*standard-input*'), 0);
|
||||
child_stdin = ecl_stream_to_handle(SYM_VAL(@'*standard-input*'), 0);
|
||||
if (child_stdin >= 0)
|
||||
child_stdin = dup(child_stdin);
|
||||
else
|
||||
|
|
@ -322,7 +291,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
} else {
|
||||
child_stdout = -1;
|
||||
if (output == @'t')
|
||||
child_stdout = stream_to_handle(SYM_VAL(@'*standard-output*'), 1);
|
||||
child_stdout = ecl_stream_to_handle(SYM_VAL(@'*standard-output*'), 1);
|
||||
if (child_stdout >= 0)
|
||||
child_stdout = dup(child_stdout);
|
||||
else
|
||||
|
|
@ -331,7 +300,7 @@ stream_to_handle(cl_object s, bool output)
|
|||
if (error == @':output') {
|
||||
child_stderr = child_stdout;
|
||||
} else if (error == @'t') {
|
||||
child_stderr = stream_to_handle(SYM_VAL(@'*error-output*'), 1);
|
||||
child_stderr = ecl_stream_to_handle(SYM_VAL(@'*error-output*'), 1);
|
||||
} else {
|
||||
child_stderr = -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -579,6 +579,7 @@ extern cl_object ecl_file_position(cl_object strm);
|
|||
extern cl_object ecl_file_position_set(cl_object strm, cl_object disp);
|
||||
extern int ecl_file_column(cl_object strm);
|
||||
extern cl_object ecl_make_stream_from_fd(cl_object host, int fd, enum ecl_smmode smm);
|
||||
extern int ecl_stream_to_handle(cl_object s, bool output);
|
||||
|
||||
/* finalize.c */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue