/fix stream_prop; indenting
This commit is contained in:
parent
96bc776375
commit
87c58493d4
184
os/streams.c
184
os/streams.c
@ -145,10 +145,8 @@ int GetFreeStreamD(void) {
|
|||||||
|
|
||||||
int Yap_GetFreeStreamD(void) { return GetFreeStreamD(); }
|
int Yap_GetFreeStreamD(void) { return GetFreeStreamD(); }
|
||||||
|
|
||||||
|
static Term lineCount(int sno) {
|
||||||
static Term lineCount(int sno)
|
Term tout;
|
||||||
{
|
|
||||||
Term tout;
|
|
||||||
/* one has to be somewhat more careful because of terminals */
|
/* one has to be somewhat more careful because of terminals */
|
||||||
if (GLOBAL_Stream[sno].status & Tty_Stream_f) {
|
if (GLOBAL_Stream[sno].status & Tty_Stream_f) {
|
||||||
Int no = 1;
|
Int no = 1;
|
||||||
@ -166,9 +164,9 @@ static Term lineCount(int sno)
|
|||||||
else
|
else
|
||||||
my_stream = GLOBAL_Stream[sno].name;
|
my_stream = GLOBAL_Stream[sno].name;
|
||||||
for (i = 0; i < MaxStreams; i++) {
|
for (i = 0; i < MaxStreams; i++) {
|
||||||
if ((GLOBAL_Stream[i].status & ( Socket_Stream_f |
|
if ((GLOBAL_Stream[i].status &
|
||||||
Pipe_Stream_f | InMemory_Stream_f)) &&
|
(Socket_Stream_f | Pipe_Stream_f | InMemory_Stream_f)) &&
|
||||||
!(GLOBAL_Stream[i].status & ( Free_Stream_f)) &&
|
!(GLOBAL_Stream[i].status & (Free_Stream_f)) &&
|
||||||
GLOBAL_Stream[i].name == my_stream)
|
GLOBAL_Stream[i].name == my_stream)
|
||||||
no += GLOBAL_Stream[i].linecount - 1;
|
no += GLOBAL_Stream[i].linecount - 1;
|
||||||
}
|
}
|
||||||
@ -207,14 +205,14 @@ static Int p_check_if_stream(USES_REGS1) { /* '$check_stream'(Stream) */
|
|||||||
return sno != -1;
|
return sno != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int is_input(int sno
|
static Int
|
||||||
USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
is_input(int sno USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
bool rc = GLOBAL_Stream[sno].status & Input_Stream_f;
|
bool rc = GLOBAL_Stream[sno].status & Input_Stream_f;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int is_output(int sno
|
static Int
|
||||||
USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
is_output(int sno USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
bool rc = GLOBAL_Stream[sno].status & (Output_Stream_f | Append_Stream_f);
|
bool rc = GLOBAL_Stream[sno].status & (Output_Stream_f | Append_Stream_f);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -332,7 +330,6 @@ has_encoding(int sno,
|
|||||||
return Yap_unify(t2, MkAtomTerm(Yap_LookupAtom(s)));
|
return Yap_unify(t2, MkAtomTerm(Yap_LookupAtom(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
found_eof(int sno,
|
found_eof(int sno,
|
||||||
Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
Term t2 USES_REGS) { /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
@ -502,13 +499,10 @@ static bool do_stream_property(int sno,
|
|||||||
for (i = 0; i < STREAM_PROPERTY_END; i++) {
|
for (i = 0; i < STREAM_PROPERTY_END; i++) {
|
||||||
if (args[i].used) {
|
if (args[i].used) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case STREAM_PROPERTY_ALIAS:
|
case STREAM_PROPERTY_ALIAS: {
|
||||||
{
|
Term ta = args[STREAM_PROPERTY_ALIAS].tvalue;
|
||||||
Term ta = args[STREAM_PROPERTY_ALIAS].tvalue;
|
rc = rc & Yap_FetchStreamAlias(sno, ta PASS_REGS);
|
||||||
rc = rc & Yap_FetchStreamAlias(
|
} break;
|
||||||
sno, ta PASS_REGS);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case STREAM_PROPERTY_BOM:
|
case STREAM_PROPERTY_BOM:
|
||||||
rc = rc && has_bom(sno, args[STREAM_PROPERTY_BOM].tvalue PASS_REGS);
|
rc = rc && has_bom(sno, args[STREAM_PROPERTY_BOM].tvalue PASS_REGS);
|
||||||
break;
|
break;
|
||||||
@ -560,8 +554,8 @@ static bool do_stream_property(int sno,
|
|||||||
sno, args[STREAM_PROPERTY_POSITION].tvalue PASS_REGS);
|
sno, args[STREAM_PROPERTY_POSITION].tvalue PASS_REGS);
|
||||||
break;
|
break;
|
||||||
case STREAM_PROPERTY_REPOSITION:
|
case STREAM_PROPERTY_REPOSITION:
|
||||||
rc = rc &&
|
rc = rc && has_reposition(
|
||||||
has_reposition(sno, args[STREAM_PROPERTY_REPOSITION].tvalue PASS_REGS);
|
sno, args[STREAM_PROPERTY_REPOSITION].tvalue PASS_REGS);
|
||||||
break;
|
break;
|
||||||
case STREAM_PROPERTY_REPRESENTATION_ERRORS:
|
case STREAM_PROPERTY_REPRESENTATION_ERRORS:
|
||||||
rc = rc &&
|
rc = rc &&
|
||||||
@ -585,83 +579,81 @@ static bool do_stream_property(int sno,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static xarg *generate_property(int sno, Term t2,
|
static xarg *generate_property(int sno, Term t2,
|
||||||
stream_property_choices_t p USES_REGS)
|
stream_property_choices_t p USES_REGS) {
|
||||||
{
|
if (p == STREAM_PROPERTY_INPUT)
|
||||||
if (p == STREAM_PROPERTY_INPUT) Yap_unify(t2, MkAtomTerm(AtomInput));
|
Yap_unify(t2, MkAtomTerm(AtomInput));
|
||||||
else if (p == STREAM_PROPERTY_OUTPUT) Yap_unify(t2, MkAtomTerm(AtomOutput));
|
else if (p == STREAM_PROPERTY_OUTPUT)
|
||||||
else {
|
Yap_unify(t2, MkAtomTerm(AtomOutput));
|
||||||
Functor f = Yap_MkFunctor(Yap_LookupAtom(stream_property_defs[p].name), 1);
|
else {
|
||||||
Yap_unify( t2, Yap_MkNewApplTerm(f, 1));
|
Functor f = Yap_MkFunctor(Yap_LookupAtom(stream_property_defs[p].name), 1);
|
||||||
}
|
Yap_unify(t2, Yap_MkNewApplTerm(f, 1));
|
||||||
return Yap_ArgListToVector(t2, stream_property_defs,
|
}
|
||||||
STREAM_PROPERTY_END);
|
return Yap_ArgListToVector(t2, stream_property_defs, STREAM_PROPERTY_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
||||||
bool det;
|
bool det;
|
||||||
xarg *args;
|
xarg *args;
|
||||||
int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1));
|
int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1));
|
||||||
stream_property_choices_t p = STREAM_PROPERTY_END;
|
stream_property_choices_t p = STREAM_PROPERTY_END;
|
||||||
bool rc;
|
bool rc;
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
|
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
p = IntOfTerm(EXTRA_CBACK_ARG(2, 2));
|
p = IntOfTerm(EXTRA_CBACK_ARG(2, 2));
|
||||||
args = generate_property(i, t2, p++ PASS_REGS);
|
args = generate_property(i, t2, p++ PASS_REGS);
|
||||||
|
|
||||||
EXTRA_CBACK_ARG(2, 2) = MkIntTerm(p%STREAM_PROPERTY_END);
|
EXTRA_CBACK_ARG(2, 2) = MkIntTerm(p % STREAM_PROPERTY_END);
|
||||||
// otherwise, just drop through
|
// otherwise, just drop through
|
||||||
} else {
|
} else {
|
||||||
args = Yap_ArgListToVector(t2, stream_property_defs,
|
args = Yap_ArgListToVector(t2, stream_property_defs, STREAM_PROPERTY_END);
|
||||||
STREAM_PROPERTY_END);
|
|
||||||
}
|
}
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
||||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[i].streamlock);
|
LOCK(GLOBAL_Stream[i].streamlock);
|
||||||
if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
|
if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
|
||||||
// one solution only
|
// one solution only
|
||||||
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
|
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
if (i < 0 ||!Yap_unify(ARG1, Yap_MkStream(i) ) ) {
|
if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) {
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
cut_succeed();
|
cut_succeed();
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[i].streamlock);
|
LOCK(GLOBAL_Stream[i].streamlock);
|
||||||
rc = do_stream_property(i, args PASS_REGS);
|
rc = do_stream_property(i, args PASS_REGS);
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
if ( IsVarTerm(t1)) {
|
if (IsVarTerm(t1)) {
|
||||||
if (rc)
|
if (rc)
|
||||||
rc = Yap_unify(ARG1, Yap_MkStream(i));
|
rc = Yap_unify(ARG1, Yap_MkStream(i));
|
||||||
if (p == STREAM_PROPERTY_END ) {
|
if (p == STREAM_PROPERTY_END) {
|
||||||
// move to next existing stream
|
// move to next existing stream
|
||||||
LOCK(GLOBAL_StreamDescLock);
|
LOCK(GLOBAL_StreamDescLock);
|
||||||
while (++i < MaxStreams && GLOBAL_Stream[i].status & Free_Stream_f)
|
while (++i < MaxStreams && GLOBAL_Stream[i].status & Free_Stream_f) {
|
||||||
{}
|
}
|
||||||
UNLOCK(GLOBAL_StreamDescLock);
|
UNLOCK(GLOBAL_StreamDescLock);
|
||||||
if (i < MaxStreams) {
|
if (i < MaxStreams) {
|
||||||
EXTRA_CBACK_ARG(2, 1) = MkIntTerm(i);
|
EXTRA_CBACK_ARG(2, 1) = MkIntTerm(i);
|
||||||
det = false;
|
det = false;
|
||||||
} else {
|
} else {
|
||||||
det = true;
|
det = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
det = false;
|
det = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// done
|
// done
|
||||||
det = (p == STREAM_PROPERTY_END );
|
det = (p == STREAM_PROPERTY_END);
|
||||||
}
|
}
|
||||||
if (rc) {
|
if (rc) {
|
||||||
if (det)
|
if (det)
|
||||||
cut_succeed();
|
cut_succeed();
|
||||||
@ -690,22 +682,22 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */
|
|||||||
|
|
||||||
i = Yap_CheckStream(t1, Input_Stream_f | Output_Stream_f | Append_Stream_f,
|
i = Yap_CheckStream(t1, Input_Stream_f | Output_Stream_f | Append_Stream_f,
|
||||||
"current_stream/3");
|
"current_stream/3");
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
return false; // error...
|
return false; // error...
|
||||||
}
|
}
|
||||||
EXTRA_CBACK_ARG(2, 1) = MkIntTerm(i);
|
EXTRA_CBACK_ARG(2, 1) = MkIntTerm(i);
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
return cont_stream_property(PASS_REGS1);
|
return cont_stream_property(PASS_REGS1);
|
||||||
}
|
}
|
||||||
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
||||||
STREAM_PROPERTY_END);
|
STREAM_PROPERTY_END);
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
||||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
cut_fail();
|
cut_fail();
|
||||||
@ -761,8 +753,8 @@ static bool do_set_stream(int sno,
|
|||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_SET_STREAM_OPTION;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_SET_STREAM_OPTION;
|
||||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL);
|
||||||
}
|
}
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return false;
|
return false;
|
||||||
@ -785,15 +777,15 @@ static bool do_set_stream(int sno,
|
|||||||
SetCloseOnAbort(
|
SetCloseOnAbort(
|
||||||
sno, (args[SET_STREAM_CLOSE_ON_ABORT].tvalue == TermTrue));
|
sno, (args[SET_STREAM_CLOSE_ON_ABORT].tvalue == TermTrue));
|
||||||
break;
|
break;
|
||||||
case SET_STREAM_ENCODING:
|
case SET_STREAM_ENCODING: {
|
||||||
{
|
Term t2 = args[SET_STREAM_ENCODING].tvalue;
|
||||||
Term t2 = args[SET_STREAM_ENCODING].tvalue;
|
Atom atEnc = AtomOfTerm(t2);
|
||||||
Atom atEnc = AtomOfTerm(t2);
|
GLOBAL_Stream[sno].encoding =
|
||||||
GLOBAL_Stream[sno].encoding =
|
enc_id(atEnc->StrOfAE, (GLOBAL_Stream[sno].status & HAS_BOM_f
|
||||||
enc_id(atEnc->StrOfAE, (GLOBAL_Stream[sno].status & HAS_BOM_f ? GLOBAL_Stream[sno].encoding :ENC_OCTET ) );
|
? GLOBAL_Stream[sno].encoding
|
||||||
Yap_DefaultStreamOps( GLOBAL_Stream+sno);
|
: ENC_OCTET));
|
||||||
}
|
Yap_DefaultStreamOps(GLOBAL_Stream + sno);
|
||||||
break;
|
} break;
|
||||||
case SET_STREAM_EOF_ACTION: {
|
case SET_STREAM_EOF_ACTION: {
|
||||||
Term t2 = args[SET_STREAM_EOF_ACTION].tvalue;
|
Term t2 = args[SET_STREAM_EOF_ACTION].tvalue;
|
||||||
if (t2 == TermError) {
|
if (t2 == TermError) {
|
||||||
@ -882,14 +874,14 @@ void Yap_CloseStreams(int loud) {
|
|||||||
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;
|
||||||
if ((GLOBAL_Stream[sno].status & Popen_Stream_f)) {
|
if ((GLOBAL_Stream[sno].status & Popen_Stream_f)) {
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
|
|
||||||
_pclose(GLOBAL_Stream[sno].file);
|
_pclose(GLOBAL_Stream[sno].file);
|
||||||
#else
|
#else
|
||||||
pclose(GLOBAL_Stream[sno].file);
|
pclose(GLOBAL_Stream[sno].file);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (GLOBAL_Stream[sno].status & (Pipe_Stream_f | Socket_Stream_f))
|
if (GLOBAL_Stream[sno].status & (Pipe_Stream_f | Socket_Stream_f))
|
||||||
close(GLOBAL_Stream[sno].u.pipe.fd);
|
close(GLOBAL_Stream[sno].u.pipe.fd);
|
||||||
#if USE_SOCKET
|
#if USE_SOCKET
|
||||||
@ -938,7 +930,7 @@ static void CloseStream(int sno) {
|
|||||||
else if (GLOBAL_Stream[sno].status & Pipe_Stream_f) {
|
else if (GLOBAL_Stream[sno].status & Pipe_Stream_f) {
|
||||||
close(GLOBAL_Stream[sno].u.pipe.fd);
|
close(GLOBAL_Stream[sno].u.pipe.fd);
|
||||||
} else if (GLOBAL_Stream[sno].status & (InMemory_Stream_f)) {
|
} else if (GLOBAL_Stream[sno].status & (InMemory_Stream_f)) {
|
||||||
Yap_CloseMemoryStream( sno );
|
Yap_CloseMemoryStream(sno);
|
||||||
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
||||||
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||||
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
||||||
@ -1252,7 +1244,7 @@ static Int
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
||||||
/* reset the counters */
|
/* reset the counters */
|
||||||
GLOBAL_Stream[sno].linepos = 0;
|
GLOBAL_Stream[sno].linepos = 0;
|
||||||
GLOBAL_Stream[sno].linecount = 1;
|
GLOBAL_Stream[sno].linecount = 1;
|
||||||
GLOBAL_Stream[sno].charcount = 0;
|
GLOBAL_Stream[sno].charcount = 0;
|
||||||
|
Reference in New Issue
Block a user