init
This commit is contained in:
parent
50c8724322
commit
713e9dc9d8
@ -1207,6 +1207,7 @@ static void check_bom(int sno, StreamDesc *st) {
|
|||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
char buf[YAP_FILENAME_MAX + 1];
|
char buf[YAP_FILENAME_MAX + 1];
|
||||||
name = Yap_guessFileName(fileno(fd), sno, buf, YAP_FILENAME_MAX);
|
name = Yap_guessFileName(fileno(fd), sno, buf, YAP_FILENAME_MAX);
|
||||||
|
if (name)
|
||||||
st->name = Yap_LookupAtom(name);
|
st->name = Yap_LookupAtom(name);
|
||||||
}
|
}
|
||||||
st->user_name = file_name;
|
st->user_name = file_name;
|
||||||
|
@ -258,7 +258,7 @@ GetCurInpPos (StreamDesc * inp_stream)
|
|||||||
return (inp_stream->linecount);
|
return (inp_stream->linecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PlIOError(type, culprit,...) PlIOError__(__FILE__, __FUNCTION__, __LINE__, type, culprit, __VA_ARGS__)
|
#define PlIOError(type, culprit,...) PlIOError__(__FILE__, __FUNCTION__, __LINE__, type, culprit, __VA_ARGS__)
|
||||||
|
|
||||||
Int PlIOError__( const char *, const char *, int, yap_error_number, Term, ...);
|
Int PlIOError__( const char *, const char *, int, yap_error_number, Term, ...);
|
||||||
|
|
||||||
|
60
os/streams.c
60
os/streams.c
@ -235,6 +235,9 @@ char *Yap_guessFileName(int f, int sno, char *nameb, size_t max) {
|
|||||||
return nameb;
|
return nameb;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (!StreamName(sno)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
|
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +258,7 @@ static Int representation_error(int sno, Term t2 USES_REGS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int file_name(int sno, Term t2 USES_REGS) {
|
static Int file_name(int sno, Term t2 USES_REGS) {
|
||||||
return Yap_unify_constant(t2, MkAtomTerm(GLOBAL_Stream[sno].name) );
|
return Yap_unify_constant(t2, MkAtomTerm(GLOBAL_Stream[sno].name));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int file_no(int sno, Term t2 USES_REGS) {
|
static Int file_no(int sno, Term t2 USES_REGS) {
|
||||||
@ -368,16 +371,14 @@ stream_position(int sno,
|
|||||||
return Yap_unify(t2, tout);
|
return Yap_unify(t2, tout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool stream_line_count(
|
||||||
stream_line_count(int sno,
|
int sno, Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
|
||||||
Term tout = StreamPosition(GLOBAL_Stream[sno].linecount);
|
Term tout = StreamPosition(GLOBAL_Stream[sno].linecount);
|
||||||
return Yap_unify(t2, MkIntegerTerm(tout));
|
return Yap_unify(t2, MkIntegerTerm(tout));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool stream_line_number(
|
||||||
stream_line_number(int sno,
|
int sno, Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
|
||||||
Term tout = StreamPosition(GLOBAL_Stream[sno].linecount);
|
Term tout = StreamPosition(GLOBAL_Stream[sno].linecount);
|
||||||
return Yap_unify(t2, MkIntegerTerm(tout));
|
return Yap_unify(t2, MkIntegerTerm(tout));
|
||||||
}
|
}
|
||||||
@ -386,7 +387,8 @@ static bool
|
|||||||
SetBuffering(int sno, Atom at) { /* '$set_bufferingt'(+Stream,-ErrorMessage) */
|
SetBuffering(int sno, Atom at) { /* '$set_bufferingt'(+Stream,-ErrorMessage) */
|
||||||
if (at == AtomFull) {
|
if (at == AtomFull) {
|
||||||
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOFBF, 0) < 0)
|
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOFBF, 0) < 0)
|
||||||
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno), "could not set buffer");
|
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno),
|
||||||
|
"could not set buffer");
|
||||||
} else if (at == AtomLine) {
|
} else if (at == AtomLine) {
|
||||||
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOLBF, 0) < 0)
|
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOLBF, 0) < 0)
|
||||||
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno),
|
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno),
|
||||||
@ -407,7 +409,8 @@ SetBuffering(int sno, Atom at) { /* '$set_bufferingt'(+Stream,-ErrorMessage) */
|
|||||||
static bool SetBuffer(int sno,
|
static bool SetBuffer(int sno,
|
||||||
Int sz) { /* '$set_bufferingt'(+Stream,-ErrorMessage) */
|
Int sz) { /* '$set_bufferingt'(+Stream,-ErrorMessage) */
|
||||||
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOFBF, sz) < 0) {
|
if (setvbuf(GLOBAL_Stream[sno].file, NULL, _IOFBF, sz) < 0) {
|
||||||
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno), "could not set buffer");
|
return PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno),
|
||||||
|
"could not set buffer");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -430,10 +433,9 @@ eof_action(int sno,
|
|||||||
return Yap_unify(t2, TermEOfCode);
|
return Yap_unify(t2, TermEOfCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define STREAM_PROPERTY_DEFS() \
|
#define STREAM_PROPERTY_DEFS() \
|
||||||
PAR("alias", filler, STREAM_PROPERTY_ALIAS), \
|
PAR("alias", filler, STREAM_PROPERTY_ALIAS), \
|
||||||
PAR("bom", filler, STREAM_PROPERTY_BOM), \
|
PAR("bom", filler, STREAM_PROPERTY_BOM), \
|
||||||
PAR("close_on_abort", filler, STREAM_PROPERTY_CLOSE_ON_ABORT), \
|
PAR("close_on_abort", filler, STREAM_PROPERTY_CLOSE_ON_ABORT), \
|
||||||
PAR("encoding", filler, STREAM_PROPERTY_ENCODING), \
|
PAR("encoding", filler, STREAM_PROPERTY_ENCODING), \
|
||||||
PAR("end_of_stream", filler, STREAM_PROPERTY_END_OF_STREAM), \
|
PAR("end_of_stream", filler, STREAM_PROPERTY_END_OF_STREAM), \
|
||||||
@ -511,10 +513,12 @@ static bool do_stream_property(int sno,
|
|||||||
rc = rc && is_input(sno PASS_REGS);
|
rc = rc && is_input(sno PASS_REGS);
|
||||||
break;
|
break;
|
||||||
case STREAM_PROPERTY_LINE_NUMBER:
|
case STREAM_PROPERTY_LINE_NUMBER:
|
||||||
rc = rc && stream_line_number(sno, args[STREAM_PROPERTY_LINE_NUMBER].tvalue PASS_REGS);
|
rc = rc && stream_line_number(
|
||||||
|
sno, args[STREAM_PROPERTY_LINE_NUMBER].tvalue PASS_REGS);
|
||||||
break;
|
break;
|
||||||
case STREAM_PROPERTY_LINE_COUNT:
|
case STREAM_PROPERTY_LINE_COUNT:
|
||||||
rc = rc && stream_line_count(sno, args[STREAM_PROPERTY_LINE_COUNT].tvalue PASS_REGS);
|
rc = rc && stream_line_count(
|
||||||
|
sno, args[STREAM_PROPERTY_LINE_COUNT].tvalue PASS_REGS);
|
||||||
break;
|
break;
|
||||||
case STREAM_PROPERTY_MODE:
|
case STREAM_PROPERTY_MODE:
|
||||||
rc =
|
rc =
|
||||||
@ -580,8 +584,8 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
|||||||
while (GLOBAL_Stream[i].status & Free_Stream_f) {
|
while (GLOBAL_Stream[i].status & Free_Stream_f) {
|
||||||
++i;
|
++i;
|
||||||
if (i == MaxStreams) {
|
if (i == MaxStreams) {
|
||||||
UNLOCK(GLOBAL_StreamDescLock);
|
UNLOCK(GLOBAL_StreamDescLock);
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[i].streamlock);
|
LOCK(GLOBAL_Stream[i].streamlock);
|
||||||
@ -621,7 +625,7 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */
|
|||||||
"current_stream/3");
|
"current_stream/3");
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
||||||
STREAM_PROPERTY_END);
|
STREAM_PROPERTY_END);
|
||||||
@ -710,8 +714,7 @@ static bool do_set_stream(int sno,
|
|||||||
GLOBAL_Stream[sno].status |= Eof_Error_Stream_f;
|
GLOBAL_Stream[sno].status |= Eof_Error_Stream_f;
|
||||||
GLOBAL_Stream[sno].status &= ~Reset_Eof_Stream_f;
|
GLOBAL_Stream[sno].status &= ~Reset_Eof_Stream_f;
|
||||||
} else if (t2 == TermReset) {
|
} else if (t2 == TermReset) {
|
||||||
GLOBAL_Stream[sno].status &=
|
GLOBAL_Stream[sno].status &= ~Eof_Error_Stream_f;
|
||||||
~Eof_Error_Stream_f;
|
|
||||||
GLOBAL_Stream[sno].status |= Reset_Eof_Stream_f;
|
GLOBAL_Stream[sno].status |= Reset_Eof_Stream_f;
|
||||||
} else if (t2 == TermEOfCode) {
|
} else if (t2 == TermEOfCode) {
|
||||||
GLOBAL_Stream[sno].status &= ~Eof_Error_Stream_f;
|
GLOBAL_Stream[sno].status &= ~Eof_Error_Stream_f;
|
||||||
@ -789,7 +792,7 @@ static Int set_stream(USES_REGS1) { /* Init current_stream */
|
|||||||
void Yap_CloseStreams(int loud) {
|
void Yap_CloseStreams(int loud) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
fflush( NULL );
|
fflush(NULL);
|
||||||
for (sno = 3; sno < MaxStreams; ++sno) {
|
for (sno = 3; sno < MaxStreams; ++sno) {
|
||||||
if (GLOBAL_Stream[sno].status & Free_Stream_f)
|
if (GLOBAL_Stream[sno].status & Free_Stream_f)
|
||||||
continue;
|
continue;
|
||||||
@ -828,12 +831,11 @@ void Yap_CloseStreams(int loud) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void CloseStream(int sno) {
|
||||||
CloseStream(int sno) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
fflush( NULL );
|
fflush(NULL);
|
||||||
if (!(GLOBAL_Stream[sno].status &
|
if (!(GLOBAL_Stream[sno].status &
|
||||||
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
#if HAVE_SOCKET
|
#if HAVE_SOCKET
|
||||||
@ -1160,7 +1162,8 @@ static Int
|
|||||||
GLOBAL_Stream[sno].linepos = IntOfTerm(tp);
|
GLOBAL_Stream[sno].linepos = IntOfTerm(tp);
|
||||||
if (fseek(GLOBAL_Stream[sno].file, (long)(char_pos), 0) == -1) {
|
if (fseek(GLOBAL_Stream[sno].file, (long)(char_pos), 0) == -1) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, tp, "fseek failed for set_stream_position/2");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, tp,
|
||||||
|
"fseek failed for set_stream_position/2");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
||||||
@ -1183,8 +1186,8 @@ static Int
|
|||||||
}
|
}
|
||||||
if (fseek(GLOBAL_Stream[sno].file, 0L, SEEK_END) == -1) {
|
if (fseek(GLOBAL_Stream[sno].file, 0L, SEEK_END) == -1) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
PlIOError(SYSTEM_ERROR_INTERNAL, tp, "fseek failed for set_stream_position/2: %s",
|
PlIOError(SYSTEM_ERROR_INTERNAL, tp,
|
||||||
strerror(errno));
|
"fseek failed for set_stream_position/2: %s", strerror(errno));
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
||||||
@ -1406,8 +1409,7 @@ void Yap_InitIOStreams(void) {
|
|||||||
Yap_InitCPred("stream_select", 3, p_stream_select,
|
Yap_InitCPred("stream_select", 3, p_stream_select,
|
||||||
SafePredFlag | SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
#endif
|
#endif
|
||||||
Yap_InitCPred("line_count", 2, line_count,
|
Yap_InitCPred("line_count", 2, line_count, SafePredFlag | SyncPredFlag);
|
||||||
SafePredFlag | SyncPredFlag );
|
|
||||||
Yap_InitCPred("$show_stream_position", 2, p_show_stream_position,
|
Yap_InitCPred("$show_stream_position", 2, p_show_stream_position,
|
||||||
SafePredFlag | SyncPredFlag | HiddenPredFlag);
|
SafePredFlag | SyncPredFlag | HiddenPredFlag);
|
||||||
Yap_InitCPred("set_stream_position", 2, set_stream_position,
|
Yap_InitCPred("set_stream_position", 2, set_stream_position,
|
||||||
|
Reference in New Issue
Block a user