notebook
This commit is contained in:
12
os/format.c
12
os/format.c
@@ -1114,7 +1114,7 @@ static Int with_output_to(USES_REGS1) {
|
||||
static Int format(Term tf, Term tas, Term tout USES_REGS) {
|
||||
Int out;
|
||||
Functor f;
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
int output_stream;
|
||||
bool mem_stream = false;
|
||||
|
||||
if (IsVarTerm(tout)) {
|
||||
@@ -1122,17 +1122,17 @@ static Int format(Term tf, Term tas, Term tout USES_REGS) {
|
||||
return false;
|
||||
}
|
||||
yhandle_t hl = Yap_StartHandles(), yo = Yap_PushHandle(tout);
|
||||
if (IsApplTerm(tout) && (f = FunctorOfTerm(tout))) {
|
||||
if (f == FunctorAtom || f == FunctorString1 || f == FunctorCodes1 ||
|
||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars){
|
||||
if (IsApplTerm(tout) && (f = FunctorOfTerm(tout)) &&
|
||||
(f == FunctorAtom || f == FunctorString1 || f == FunctorCodes1 ||
|
||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) ){
|
||||
output_stream = Yap_OpenBufWriteStream(PASS_REGS1);
|
||||
mem_stream = true;
|
||||
}
|
||||
if (!mem_stream) {
|
||||
if (output_stream <0 ||!mem_stream) {
|
||||
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
/* needs to change LOCAL_c_output_stream for write */
|
||||
output_stream = Yap_CheckStream(tout, Output_Stream_f, "format/3");
|
||||
}
|
||||
}
|
||||
if (output_stream == -1) {
|
||||
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
return false;
|
||||
|
36
os/iopreds.c
36
os/iopreds.c
@@ -1761,6 +1761,42 @@ int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term arg,
|
||||
const char *msg) {
|
||||
int sno, kind = Output_Stream_f;
|
||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||
return -1;
|
||||
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
if (kind & Output_Stream_f)
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
else
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
return -1;
|
||||
}
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckTextReadStream__(const char *file, const char *f, int line, Term arg,
|
||||
const char *msg) {
|
||||
int sno, kind = Input_Stream_f;
|
||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||
return -1;
|
||||
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
if (kind & Input_Stream_f)
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
else
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
return -1;
|
||||
}
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckBinaryStream__(const char *file, const char *f, int line, Term arg,
|
||||
int kind, const char *msg) {
|
||||
int sno;
|
||||
|
11
os/iopreds.h
11
os/iopreds.h
@@ -43,7 +43,16 @@ extern int Yap_CheckStream__(const char *, const char *, int, Term, int,
|
||||
extern int Yap_CheckTextStream__(const char *, const char *, int, Term, int,
|
||||
const char *);
|
||||
|
||||
#define Yap_CheckBinaryStream(arg, kind, msg) \
|
||||
#define Yap_CheckTextReadStream(arg, msg) \
|
||||
Yap_CheckTextReadStream__(__FILE__, __FUNCTION__, __LINE__, arg, msg)
|
||||
extern int Yap_CheckTextReadStream__(const char *, const char *, int, Term,
|
||||
const char *);
|
||||
#define Yap_CheckTextWriteStream(arg, msg) \
|
||||
Yap_CheckTextWriteStream__(__FILE__, __FUNCTION__, __LINE__, arg, msg)
|
||||
extern int Yap_CheckTextWriteStream__(const char *, const char *, int, Term,
|
||||
const char *);
|
||||
|
||||
#define Yap_CheckBinaryStream(arg, kind, msg) \
|
||||
Yap_CheckBinaryStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
||||
extern int Yap_CheckBinaryStream__(const char *, const char *, int, Term, int,
|
||||
const char *);
|
||||
|
Reference in New Issue
Block a user