fix eof handling + indent
This commit is contained in:
parent
62e0f0bece
commit
54985f4678
77
os/iopreds.c
77
os/iopreds.c
@ -96,7 +96,6 @@ static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
#include "iopreds.h"
|
||||
|
||||
|
||||
#define GETW get_wchar_from_FILE
|
||||
#define GETC() fgetwc(st->file)
|
||||
#include "getw.h"
|
||||
@ -269,7 +268,6 @@ static void unix_upd_stream_info(StreamDesc *s) {
|
||||
s->status |= Seekable_Stream_f;
|
||||
}
|
||||
|
||||
|
||||
static void InitFileIO(StreamDesc *s) {
|
||||
CACHE_REGS
|
||||
if (s->status & Socket_Stream_f) {
|
||||
@ -663,7 +661,6 @@ int post_process_read_wchar(int ch, ssize_t n, StreamDesc *s) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
int post_process_weof(StreamDesc *s) {
|
||||
if (!ResetEOF(s)) {
|
||||
s->status |= Eof_Stream_f;
|
||||
@ -695,7 +692,6 @@ int PlGetc(int sno) {
|
||||
return fgetc(s->file);
|
||||
}
|
||||
|
||||
|
||||
// layered version
|
||||
static int get_wchar__(int sno) { return fgetwc(GLOBAL_Stream[sno].file); }
|
||||
|
||||
@ -796,8 +792,7 @@ int PlGetc(int sno) {
|
||||
}
|
||||
return ch;
|
||||
break;
|
||||
case ENC_UTF16_LE:
|
||||
{
|
||||
case ENC_UTF16_LE: {
|
||||
if (ch < 0x10000) {
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (ch & 0xff));
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||
@ -814,8 +809,7 @@ int PlGetc(int sno) {
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
case ENC_UTF16_BE:
|
||||
{
|
||||
case ENC_UTF16_BE: {
|
||||
// computations
|
||||
if (ch < 0x10000) {
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||
@ -828,12 +822,10 @@ int PlGetc(int sno) {
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (lead & 0xff));
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (trail >> 8));
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (trail & 0xff));
|
||||
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
case ENC_UCS2_LE:
|
||||
{
|
||||
case ENC_UCS2_LE: {
|
||||
if (ch >= 0x10000) {
|
||||
return 0;
|
||||
}
|
||||
@ -841,8 +833,7 @@ int PlGetc(int sno) {
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||
return ch;
|
||||
}
|
||||
case ENC_UCS2_BE:
|
||||
{
|
||||
case ENC_UCS2_BE: {
|
||||
// computations
|
||||
if (ch < 0x10000) {
|
||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||
@ -873,8 +864,8 @@ int PlGetc(int sno) {
|
||||
/* used by user-code to read characters from the current input stream */
|
||||
int Yap_PlGetchar(void) {
|
||||
CACHE_REGS
|
||||
return (GLOBAL_Stream[LOCAL_c_input_stream].stream_getc(
|
||||
LOCAL_c_input_stream));
|
||||
return (
|
||||
GLOBAL_Stream[LOCAL_c_input_stream].stream_getc(LOCAL_c_input_stream));
|
||||
}
|
||||
|
||||
int Yap_PlGetWchar(void) {
|
||||
@ -1082,8 +1073,7 @@ int PlGetc(int sno) {
|
||||
}
|
||||
|
||||
bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
||||
encoding_t encoding, stream_flags_t flags,
|
||||
Atom open_mode) {
|
||||
encoding_t encoding, stream_flags_t flags, Atom open_mode) {
|
||||
StreamDesc *st = &GLOBAL_Stream[sno];
|
||||
st->status = flags;
|
||||
|
||||
@ -1175,8 +1165,8 @@ int PlGetc(int sno) {
|
||||
static const param_t open_defs[] = {OPEN_DEFS()};
|
||||
#undef PAR
|
||||
|
||||
static Int do_open(
|
||||
Term file_name, Term t2,
|
||||
static Int
|
||||
do_open(Term file_name, Term t2,
|
||||
Term tlist USES_REGS) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||
Atom open_mode;
|
||||
int sno;
|
||||
@ -1282,8 +1272,7 @@ int PlGetc(int sno) {
|
||||
|
||||
// Skip scripts that start with !#/.. or similar
|
||||
bool script =
|
||||
(args[OPEN_SCRIPT].used ? args[OPEN_SCRIPT].tvalue == TermTrue
|
||||
: false);
|
||||
(args[OPEN_SCRIPT].used ? args[OPEN_SCRIPT].tvalue == TermTrue : false);
|
||||
// binary type
|
||||
if (args[OPEN_TYPE].used) {
|
||||
Term t = args[OPEN_TYPE].tvalue;
|
||||
@ -1331,11 +1320,11 @@ int PlGetc(int sno) {
|
||||
fname = LOCAL_FileNameBuf;
|
||||
UNLOCK(st->streamlock);
|
||||
if (errno == ENOENT)
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s",
|
||||
fname, strerror(errno)));
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname,
|
||||
strerror(errno)));
|
||||
else {
|
||||
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name,
|
||||
"%s: %s", fname, strerror(errno)));
|
||||
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name, "%s: %s",
|
||||
fname, strerror(errno)));
|
||||
}
|
||||
}
|
||||
#if MAC
|
||||
@ -1344,11 +1333,9 @@ int PlGetc(int sno) {
|
||||
}
|
||||
#endif
|
||||
flags &= ~(Free_Stream_f);
|
||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags,
|
||||
open_mode))
|
||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags, open_mode))
|
||||
return false;
|
||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags,
|
||||
open_mode))
|
||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags, open_mode))
|
||||
return false;
|
||||
if (open_mode == AtomWrite) {
|
||||
if (needs_bom && !write_bom(sno, st))
|
||||
@ -1392,8 +1379,7 @@ int PlGetc(int sno) {
|
||||
|
||||
*/
|
||||
|
||||
static Int open3(
|
||||
USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||
static Int open3(USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
||||
}
|
||||
|
||||
@ -1475,13 +1461,11 @@ int PlGetc(int sno) {
|
||||
|
||||
|
||||
*/
|
||||
static Int open4(
|
||||
USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||
static Int open4(USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||
return do_open(Deref(ARG1), Deref(ARG2), Deref(ARG4) PASS_REGS);
|
||||
}
|
||||
|
||||
static Int p_file_expansion(
|
||||
USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
||||
static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
||||
Term file_name = Deref(ARG1);
|
||||
|
||||
/* we know file_name is bound */
|
||||
@ -1552,8 +1536,8 @@ int PlGetc(int sno) {
|
||||
#define CheckStream(arg, kind, msg) \
|
||||
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
||||
|
||||
static int CheckStream__(const char *file, const char *f, int line,
|
||||
Term arg, int kind, const char *msg) {
|
||||
static int CheckStream__(const char *file, const char *f, int line, Term arg,
|
||||
int kind, const char *msg) {
|
||||
int sno = -1;
|
||||
arg = Deref(arg);
|
||||
if (IsVarTerm(arg)) {
|
||||
@ -1615,8 +1599,8 @@ int PlGetc(int sno) {
|
||||
return CheckStream__(file, f, line, arg, kind, msg);
|
||||
}
|
||||
|
||||
int Yap_CheckTextStream__(const char *file, const char *f, int line,
|
||||
Term arg, int kind, const char *msg) {
|
||||
int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
|
||||
int kind, const char *msg) {
|
||||
int sno;
|
||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||
return -1;
|
||||
@ -1685,8 +1669,7 @@ int PlGetc(int sno) {
|
||||
|
||||
(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||
Int sno = CheckStream(
|
||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f),
|
||||
"close/2");
|
||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
||||
if (sno < 0)
|
||||
return (FALSE);
|
||||
if (sno <= StdErrStream) {
|
||||
@ -1724,8 +1707,7 @@ int PlGetc(int sno) {
|
||||
*/
|
||||
static Int close2(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||
Int sno = CheckStream(
|
||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f),
|
||||
"close/2");
|
||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
||||
Term tlist;
|
||||
if (sno < 0)
|
||||
return (FALSE);
|
||||
@ -1819,8 +1801,7 @@ int PlGetc(int sno) {
|
||||
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] = gethdir(TermDot);
|
||||
}
|
||||
if (args[ABSOLUTE_FILE_NAME_FILE_TYPE].used)
|
||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] =
|
||||
args[ABSOLUTE_FILE_NAME_FILE_TYPE].tvalue;
|
||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = args[ABSOLUTE_FILE_NAME_FILE_TYPE].tvalue;
|
||||
else
|
||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = TermTxt;
|
||||
if (args[ABSOLUTE_FILE_NAME_ACCESS].used)
|
||||
@ -1833,8 +1814,7 @@ int PlGetc(int sno) {
|
||||
else
|
||||
t[ABSOLUTE_FILE_NAME_FILE_ERRORS] = TermError;
|
||||
if (args[ABSOLUTE_FILE_NAME_SOLUTIONS].used)
|
||||
t[ABSOLUTE_FILE_NAME_SOLUTIONS] =
|
||||
args[ABSOLUTE_FILE_NAME_SOLUTIONS].tvalue;
|
||||
t[ABSOLUTE_FILE_NAME_SOLUTIONS] = args[ABSOLUTE_FILE_NAME_SOLUTIONS].tvalue;
|
||||
else
|
||||
t[ABSOLUTE_FILE_NAME_SOLUTIONS] = TermFirst;
|
||||
if (args[ABSOLUTE_FILE_NAME_EXPAND].used)
|
||||
@ -1851,8 +1831,7 @@ int PlGetc(int sno) {
|
||||
args[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH].tvalue;
|
||||
else
|
||||
t[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH] =
|
||||
(trueGlobalPrologFlag(VERBOSE_FILE_SEARCH_FLAG) ? TermTrue
|
||||
: TermFalse);
|
||||
(trueGlobalPrologFlag(VERBOSE_FILE_SEARCH_FLAG) ? TermTrue : TermFalse);
|
||||
tf = Yap_MkApplTerm(Yap_MkFunctor(AtomOpt, ABSOLUTE_FILE_NAME_END),
|
||||
ABSOLUTE_FILE_NAME_END, t);
|
||||
return (Yap_unify(ARG2, tf));
|
||||
|
Reference in New Issue
Block a user