18static char SccsId[] =
"%W% %G%";
50#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
61static int PipePutc(
int,
int);
62static int ConsolePipePutc(
int,
int);
63static int PipeGetc(
int);
64static int ConsolePipeGetc(
int);
68ConsolePipePutc (
int sno,
int ch)
81 out = write(s->u.pipe.fd, &c,
sizeof(c));
84 Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil,
"error writing stream pipe: %s", strerror(errno));
86 Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil,
"error writing stream pipe");
91 count_output_char(ch,s);
96PipePutc (
int sno,
int ch)
109 out = write(s->u.pipe.fd, &c,
sizeof(c));
112 Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil,
"error writing stream pipe: %s", strerror(errno));
114 Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil,
"error writing stream pipe");
119 console_count_output_char(ch,s);
129ConsolePipeGetc(
int sno)
135#if _MSC_VER || defined(__MINGW32__)
143 char *cptr = LOCAL_Prompt, ch;
145 while ((ch = *cptr++) !=
'\0') {
146 GLOBAL_Stream[StdErrStream].stream_putc(StdErrStream, ch);
148 strncpy(LOCAL_Prompt, RepAtom (LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT);
149 LOCAL_newline =
false;
152 LOCAL_PrologMode |= ConsoleGetcMode;
153 count = read(s->u.pipe.fd, &c,
sizeof(
char));
154 LOCAL_PrologMode &= ~ConsoleGetcMode;
156 return console_post_process_eof(s);
157 }
else if (count > 0) {
160 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"read");
161 return console_post_process_eof(s);
163 return console_post_process_read_char(ch, s);
176 count = read(s->u.pipe.fd, &c,
sizeof(
char));
179 }
else if (count > 0) {
183 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"at pipe getc: %s", strerror(errno));
185 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"at pipe getc");
195 st->stream_putc = PipePutc;
202 st->stream_putc = ConsolePipePutc;
207open_pipe_stream (USES_REGS1)
215#
if _MSC_VER || defined(__MINGW32__)
217 _pipe(filedes, 1024, O_TEXT)
223 return (PlIOError (SYSTEM_ERROR_INTERNAL,TermNil,
"error %s", strerror(errno)) );
225 sno = GetFreeStreamD();
227 return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil,
"new stream not available for open_pipe_stream/2"));
228 t1 = Yap_MkStream (sno);
229 st = &GLOBAL_Stream[sno];
230 st->status = Input_Stream_f | Pipe_Stream_f;
234 st->stream_putc = PipePutc;
237 Yap_DefaultStreamOps( st );
238 st->u.pipe.fd = filedes[0];
239 st->file = fdopen( filedes[0],
"r");
240 UNLOCK(st->streamlock);
241 sno = GetFreeStreamD();
243 return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil,
"new stream not available for open_pipe_stream/2"));
244 st = &GLOBAL_Stream[sno];
245 st->status = Output_Stream_f | Pipe_Stream_f;
250 st->stream_putc = PipePutc;
252 Yap_DefaultStreamOps( st );
253 st->u.pipe.fd = filedes[1];
254 st->file = fdopen( filedes[1],
"w");
255 UNLOCK(st->streamlock);
256 t2 = Yap_MkStream (sno);
258 Yap_unify (ARG1, t1) &&
259 Yap_unify (ARG2, t2);
265 Yap_InitCPred (
"open_pipe_stream", 2, open_pipe_stream, SafePredFlag);
int(* stream_getc)(int)
function the stream uses for writing a character
struct vfs * vfs
function the stream uses for reading a character