2015-06-18 01:39:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* *
|
2016-02-18 12:10:58 +00:00
|
|
|
* File: iopreds.h *
|
2015-06-18 01:39:03 +01:00
|
|
|
* Last rev: 5/2/88 *
|
2016-02-18 12:10:58 +00:00
|
|
|
* mods: *
|
2015-06-18 01:39:03 +01:00
|
|
|
* comments: Input/Output C implemented predicates *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef IOPREDS_H
|
|
|
|
#define IOPREDS_H 1
|
|
|
|
|
2016-01-31 10:39:15 +00:00
|
|
|
#if _WIN32
|
|
|
|
#define USE_SOCKET 1
|
|
|
|
#define HAVE_SOCKET 1
|
|
|
|
#endif
|
|
|
|
|
2015-07-28 04:22:44 +01:00
|
|
|
#include "Atoms.h"
|
2016-04-05 02:53:39 +01:00
|
|
|
#include "Yap.h"
|
|
|
|
#include <stdlib.h>
|
2015-07-28 04:22:44 +01:00
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
/*
|
2015-07-28 04:22:44 +01:00
|
|
|
* This file defines main data-structure for stream management,
|
2015-06-18 01:39:03 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern size_t Yap_page_size;
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
#define Yap_CheckStream(arg, kind, msg) \
|
|
|
|
Yap_CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
|
|
|
extern int Yap_CheckStream__(const char *, const char *, int, Term, int,
|
|
|
|
const char *);
|
|
|
|
#define Yap_CheckTextStream(arg, kind, msg) \
|
|
|
|
Yap_CheckTextStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
|
|
|
extern int Yap_CheckTextStream__(const char *, const char *, int, Term, int,
|
|
|
|
const char *);
|
2016-04-19 23:30:02 +01:00
|
|
|
#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 *);
|
2016-01-31 10:39:15 +00:00
|
|
|
|
|
|
|
extern bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
2016-02-18 12:10:58 +00:00
|
|
|
encoding_t encoding, stream_flags_t flags,
|
|
|
|
Atom open_mode);
|
2016-01-31 10:39:15 +00:00
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
#if HAVE_SOCKET
|
|
|
|
extern int Yap_sockets_io;
|
|
|
|
|
|
|
|
/****************** defines for sockets *********************************/
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef enum { /* in YAP, sockets may be in one of 4 possible status */
|
|
|
|
new_socket,
|
|
|
|
server_socket,
|
|
|
|
client_socket,
|
|
|
|
server_session_socket,
|
|
|
|
closed_socket
|
2015-06-18 01:39:03 +01:00
|
|
|
} socket_info;
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef enum { /* we accept two domains for the moment, IPV6 may follow */
|
|
|
|
af_inet, /* IPV4 */
|
|
|
|
af_unix /* or AF_FILE */
|
2015-06-18 01:39:03 +01:00
|
|
|
} socket_domain;
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
extern Term Yap_InitSocketStream(int, socket_info, socket_domain);
|
|
|
|
extern int Yap_CheckSocketStream(Term, const char *);
|
|
|
|
extern socket_domain Yap_GetSocketDomain(int);
|
|
|
|
extern socket_info Yap_GetSocketStatus(int);
|
|
|
|
extern void Yap_UpdateSocketStream(int, socket_info, socket_domain);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
/* routines in ypsocks.c */
|
|
|
|
Int Yap_CloseSocket(int, socket_info, socket_domain);
|
|
|
|
|
|
|
|
#endif /* USE_SOCKET */
|
|
|
|
|
|
|
|
/************ SWI compatible support for unicode representations ************/
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef struct yap_io_position {
|
|
|
|
int64_t byteno; /* byte-position in file */
|
|
|
|
int64_t charno; /* character position in file */
|
|
|
|
long int lineno; /* lineno in file */
|
|
|
|
long int linepos; /* position in line */
|
|
|
|
intptr_t reserved[2]; /* future extensions */
|
2015-06-18 01:39:03 +01:00
|
|
|
} yapIOPOS;
|
|
|
|
|
|
|
|
#ifndef _PL_STREAM_H
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef struct {
|
|
|
|
Atom file; /* current source file */
|
|
|
|
yapIOPOS position; /* Line, line pos, char and byte */
|
2015-06-18 01:39:03 +01:00
|
|
|
} yapSourceLocation;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RD_MAGIC 0xefebe128
|
|
|
|
|
|
|
|
typedef struct vlist_struct_t {
|
|
|
|
struct VARSTRUCT *ve;
|
|
|
|
struct vlist_struct_t *next;
|
|
|
|
} vlist_t;
|
|
|
|
|
|
|
|
typedef struct qq_struct_t {
|
|
|
|
unsigned char *text;
|
|
|
|
yapIOPOS start, mid, end;
|
|
|
|
vlist_t *vlist;
|
|
|
|
struct qq_struct_t *next;
|
|
|
|
} qq_t;
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef struct read_data_t {
|
|
|
|
unsigned char *here; /* current character */
|
|
|
|
unsigned char *base; /* base of clause */
|
|
|
|
unsigned char *end; /* end of the clause */
|
|
|
|
unsigned char *token_start; /* start of most recent read token */
|
|
|
|
|
|
|
|
int magic; /* RD_MAGIC */
|
|
|
|
struct stream_desc *stream;
|
|
|
|
FILE *f; /* file. of known */
|
|
|
|
Term position; /* Line, line pos, char and byte */
|
|
|
|
void *posp; /* position pointer */
|
|
|
|
size_t posi; /* position number */
|
|
|
|
|
|
|
|
Term subtpos; /* Report Subterm positions */
|
|
|
|
bool cycles; /* Re-establish cycles */
|
|
|
|
yapSourceLocation start_of_term; /* Position of start of term */
|
|
|
|
struct mod_entry *module; /* Current source module */
|
|
|
|
unsigned int flags; /* Module syntax flags */
|
|
|
|
int styleCheck; /* style-checking mask */
|
|
|
|
bool backquoted_string; /* Read `hello` as string */
|
|
|
|
|
|
|
|
int *char_conversion_table; /* active conversion table */
|
|
|
|
|
|
|
|
Atom on_error; /* Handling of syntax errors */
|
|
|
|
int has_exception; /* exception is raised */
|
|
|
|
|
|
|
|
Term exception; /* raised exception */
|
|
|
|
Term variables; /* report variables */
|
|
|
|
Term singles; /* Report singleton variables */
|
|
|
|
Term varnames; /* Report variables+names */
|
|
|
|
int strictness; /* Strictness level */
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
#ifdef O_QUASIQUOTATIONS
|
2016-02-18 12:10:58 +00:00
|
|
|
Term quasi_quotations; /* User option quasi_quotations(QQ) */
|
|
|
|
Term qq; /* Quasi quoted list */
|
|
|
|
Term qq_tail; /* Tail of the quoted stuff */
|
2015-06-18 01:39:03 +01:00
|
|
|
#endif
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
Term comments; /* Report comments */
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
} read_data, *ReadData;
|
|
|
|
|
|
|
|
Term Yap_read_term(int inp_stream, Term opts, int nargs);
|
2016-04-10 14:21:17 +01:00
|
|
|
Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
void init_read_data(ReadData _PL_rd, struct stream_desc *s);
|
|
|
|
|
|
|
|
typedef int (*GetsFunc)(int, UInt, char *);
|
|
|
|
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
2016-04-08 09:22:27 +01:00
|
|
|
#if __APPLE__
|
|
|
|
#include "fmemopen.h"
|
|
|
|
#define HAVE_FMEMOPEN 1
|
|
|
|
#define HAVE_OPEN_MEMSTREAM 1
|
|
|
|
FILE *open_memstream(char **buf, size_t *len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __ANDROID__
|
|
|
|
#undef HAVE_FMEMOPEN
|
|
|
|
#undef HAVE_OPEN_MEMSTREAM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_FMEMOPEN
|
|
|
|
#define MAY_READ 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_OPEN_MEMSTREAM
|
|
|
|
#define MAY_READ 1
|
|
|
|
#define MAY_WRITE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _WIN32
|
|
|
|
#undef MAY_WRITE
|
|
|
|
#undef MAY_READ
|
|
|
|
#endif
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef struct mem_desc {
|
|
|
|
char *buf; /* where the file is being read from/written to */
|
|
|
|
int src; /* where the space comes from, 0 code space, 1 malloc */
|
|
|
|
Int max_size; /* maximum buffer size (may be changed dynamically) */
|
|
|
|
UInt pos; /* cursor */
|
2015-06-18 01:39:03 +01:00
|
|
|
volatile void *error_handler;
|
|
|
|
} memHandle;
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
typedef struct stream_desc {
|
2015-06-18 01:39:03 +01:00
|
|
|
Atom name;
|
|
|
|
Term user_name;
|
2016-02-18 12:10:58 +00:00
|
|
|
FILE *file;
|
2015-07-23 01:33:30 +01:00
|
|
|
// useful in memory streams
|
|
|
|
char *nbuf;
|
|
|
|
size_t nsize;
|
2015-06-18 01:39:03 +01:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
#define PLGETC_BUF_SIZE 4096
|
2016-02-18 12:10:58 +00:00
|
|
|
unsigned char *buf, *ptr;
|
2015-06-18 01:39:03 +01:00
|
|
|
int left;
|
|
|
|
} file;
|
|
|
|
memHandle mem_string;
|
|
|
|
struct {
|
|
|
|
int fd;
|
|
|
|
} pipe;
|
|
|
|
#if HAVE_SOCKET
|
|
|
|
struct {
|
|
|
|
socket_domain domain;
|
|
|
|
socket_info flags;
|
|
|
|
int fd;
|
|
|
|
} socket;
|
|
|
|
#endif
|
|
|
|
struct {
|
2016-02-18 12:10:58 +00:00
|
|
|
const unsigned char *buf, *ptr;
|
2015-06-18 01:39:03 +01:00
|
|
|
} irl;
|
|
|
|
} u;
|
|
|
|
Int charcount, linecount, linepos;
|
|
|
|
stream_flags_t status;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2016-02-18 12:10:58 +00:00
|
|
|
lockvar streamlock; /* protect stream access */
|
2015-06-18 01:39:03 +01:00
|
|
|
#endif
|
2016-04-05 02:53:39 +01:00
|
|
|
int (*stream_putc)(
|
|
|
|
int, int); /** function the stream uses for writing a single octet */
|
|
|
|
int (*stream_wputc)(
|
|
|
|
int, wchar_t); /** function the stream uses for writing a character */
|
|
|
|
int (*stream_getc)(int); /** function the stream uses for reading an octet. */
|
|
|
|
int (*stream_wgetc)(
|
|
|
|
int); /** function the stream uses for reading a character. */
|
|
|
|
|
|
|
|
int (*stream_wgetc_for_read)(
|
|
|
|
int); /* function the stream uses for parser. It may be different
|
|
|
|
from above if the ISO character conversion is on */
|
2016-02-21 19:06:25 +00:00
|
|
|
encoding_t encoding; /** current encoding for stream */
|
2016-02-18 12:10:58 +00:00
|
|
|
} StreamDesc;
|
2015-08-07 22:57:53 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
static inline bool IsStreamTerm(Term t) {
|
2015-06-18 01:39:03 +01:00
|
|
|
return !IsVarTerm(t) &&
|
2016-02-18 12:10:58 +00:00
|
|
|
(IsAtomTerm(t) ||
|
|
|
|
(IsApplTerm(t) && (FunctorOfTerm(t) == FunctorStream)));
|
2015-06-18 01:39:03 +01:00
|
|
|
}
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
static inline StreamDesc *Yap_GetStreamHandle(Term t) {
|
|
|
|
int sno = Yap_CheckStream(t, 0, "stream search");
|
2015-06-18 01:39:03 +01:00
|
|
|
if (sno < 0)
|
|
|
|
return NULL;
|
2016-02-18 12:10:58 +00:00
|
|
|
return GLOBAL_Stream + sno;
|
2015-06-18 01:39:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define YAP_ERROR NIL
|
|
|
|
|
|
|
|
#define MaxStreams 64
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
#define EXPAND_FILENAME 0x000080
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
#define StdInStream 0
|
|
|
|
#define StdOutStream 1
|
|
|
|
#define StdErrStream 2
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
#define ALIASES_BLOCK_SIZE 8
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_InitStdStreams(void);
|
|
|
|
Term Yap_StreamPosition(int);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-04-10 14:21:17 +01:00
|
|
|
static inline Int GetCurInpPos(StreamDesc *inp_stream) {
|
2015-06-18 01:39:03 +01:00
|
|
|
return (inp_stream->linecount);
|
|
|
|
}
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
#define PlIOError(type, culprit, ...) \
|
|
|
|
PlIOError__(__FILE__, __FUNCTION__, __LINE__, type, culprit, __VA_ARGS__)
|
2015-09-29 23:44:11 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
Int PlIOError__(const char *, const char *, int, yap_error_number, Term, ...);
|
2015-09-29 23:44:11 +01:00
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
int GetFreeStreamD(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
Term Yap_MkStream(int n);
|
2015-07-06 12:03:16 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
bool Yap_PrintWarning(Term twarning);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_plwrite(Term, struct stream_desc *, int, int, int);
|
|
|
|
void Yap_WriteAtom(struct stream_desc *s, Atom atom);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
Term Yap_scan_num(struct stream_desc *);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_DefaultStreamOps(StreamDesc *st);
|
|
|
|
void Yap_PipeOps(StreamDesc *st);
|
|
|
|
void Yap_MemOps(StreamDesc *st);
|
|
|
|
bool Yap_CloseMemoryStream(int sno);
|
|
|
|
void Yap_ConsolePipeOps(StreamDesc *st);
|
|
|
|
void Yap_SocketOps(StreamDesc *st);
|
|
|
|
void Yap_ConsoleSocketOps(StreamDesc *st);
|
|
|
|
bool Yap_ReadlineOps(StreamDesc *st);
|
2016-04-05 02:53:39 +01:00
|
|
|
int Yap_OpenBufWriteStream(USES_REGS1);
|
2016-04-10 14:21:17 +01:00
|
|
|
void Yap_ConsoleOps(StreamDesc *s);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_InitRandomPreds(void);
|
|
|
|
void Yap_InitSignalPreds(void);
|
|
|
|
void Yap_InitTimePreds(void);
|
2015-11-05 16:57:24 +00:00
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
void Yap_init_socks(char *host, long interface_port);
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_InitPipes(void);
|
|
|
|
void Yap_InitMem(void);
|
|
|
|
void Yap_InitSockets(void);
|
2015-06-18 01:39:03 +01:00
|
|
|
void Yap_InitSocketLayer(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_InitMems(void);
|
|
|
|
void Yap_InitConsole(void);
|
|
|
|
void Yap_InitReadlinePreds(void);
|
|
|
|
bool Yap_InitReadline(Term);
|
2015-06-18 01:39:03 +01:00
|
|
|
void Yap_InitChtypes(void);
|
|
|
|
void Yap_InitCharsio(void);
|
|
|
|
void Yap_InitFormat(void);
|
|
|
|
void Yap_InitFiles(void);
|
|
|
|
void Yap_InitIOStreams(void);
|
|
|
|
void Yap_InitWriteTPreds(void);
|
|
|
|
void Yap_InitReadTPreds(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_socketStream(StreamDesc *s);
|
|
|
|
void Yap_ReadlineFlush(int sno);
|
|
|
|
Int Yap_ReadlinePeekChar(int sno);
|
2015-06-18 01:39:03 +01:00
|
|
|
int Yap_ReadlineForSIGINT(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
bool Yap_ReadlinePrompt(StreamDesc *s);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
Int Yap_peek(int sno);
|
2015-10-11 04:23:16 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
Term Yap_syntax_error(TokEntry *tokptr, int sno);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
int console_post_process_read_char(int, StreamDesc *);
|
|
|
|
int console_post_process_eof(StreamDesc *);
|
2016-02-28 19:32:55 +00:00
|
|
|
int post_process_read_wchar(int, size_t, StreamDesc *);
|
2016-02-18 12:10:58 +00:00
|
|
|
int post_process_weof(StreamDesc *);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
bool is_same_tty(FILE *f1, FILE *f2);
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
int ISOWGetc(int sno);
|
|
|
|
int GetUTF8(int sno);
|
2015-06-18 01:39:03 +01:00
|
|
|
Term read_line(int sno);
|
2016-02-18 12:10:58 +00:00
|
|
|
int PlGets(int sno, UInt size, char *buf);
|
2015-06-18 01:39:03 +01:00
|
|
|
GetsFunc PlGetsFunc(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
int PlGetc(int sno);
|
|
|
|
int FilePutc(int sno, int c);
|
|
|
|
int DefaultGets(int, UInt, char *);
|
2015-06-18 01:39:03 +01:00
|
|
|
int put_wchar(int sno, wchar_t ch);
|
|
|
|
Int GetStreamFd(int sno);
|
|
|
|
int ResetEOF(StreamDesc *s);
|
2015-12-15 09:14:15 +00:00
|
|
|
int EOFPeek(int sno);
|
|
|
|
int EOFWPeek(int sno);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_SetAlias(Atom arg, int sno);
|
|
|
|
bool Yap_AddAlias(Atom arg, int sno);
|
|
|
|
int Yap_CheckAlias(Atom arg);
|
|
|
|
int Yap_RemoveAlias(Atom arg, int snoinline);
|
|
|
|
void Yap_SetAlias(Atom arg, int sno);
|
2015-06-18 01:39:03 +01:00
|
|
|
void Yap_InitAliases(void);
|
2016-02-18 12:10:58 +00:00
|
|
|
void Yap_DeleteAliases(int sno);
|
|
|
|
bool Yap_FindStreamForAlias(Atom al);
|
|
|
|
bool Yap_FetchStreamAlias(int sno, Term t2 USES_REGS);
|
2015-06-18 01:39:03 +01:00
|
|
|
|
|
|
|
INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s);
|
|
|
|
|
2015-07-06 12:03:16 +01:00
|
|
|
Term Yap_StreamUserName(int sno);
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s) {
|
|
|
|
if (ch == '\n') {
|
2015-06-18 01:39:03 +01:00
|
|
|
#if MPWSHELL
|
2016-02-18 12:10:58 +00:00
|
|
|
if (mpwshell && (sno == StdOutStream || sno == StdErrStream) &&
|
|
|
|
!(s->status & Null_Stream_f)) {
|
|
|
|
putc(MPWSEP, s->file);
|
|
|
|
if (!(GLOBAL_Stream[LOCAL_output_stream].status & Null_Stream_f))
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2015-06-18 01:39:03 +01:00
|
|
|
#endif
|
2016-02-18 12:10:58 +00:00
|
|
|
/* Inform that we have written a newline */
|
|
|
|
++s->charcount;
|
|
|
|
++s->linecount;
|
|
|
|
s->linepos = 0;
|
|
|
|
} else {
|
2015-06-18 01:39:03 +01:00
|
|
|
#if MAC
|
2016-02-18 12:10:58 +00:00
|
|
|
if ((sno == StdOutStream || sno == StdErrStream) && s->linepos > 200)
|
2015-06-18 01:39:03 +01:00
|
|
|
sno->stream_putc(sno, '\n');
|
|
|
|
#endif
|
|
|
|
++s->charcount;
|
|
|
|
++s->linepos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
|
2015-06-18 01:39:03 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
inline static Atom StreamFullName(int i) { return (GLOBAL_Stream[i].name); }
|
2015-09-29 23:44:11 +01:00
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
inline static void console_count_output_char(int ch, StreamDesc *s) {
|
|
|
|
CACHE_REGS
|
|
|
|
if (ch == '\n') {
|
2015-06-18 01:39:03 +01:00
|
|
|
#if MPWSHELL
|
2016-02-18 12:10:58 +00:00
|
|
|
if (mpwshell && (sno == StdOutStream || sno == StdErrStream) &&
|
|
|
|
!(s->status & Null_Stream_f)) {
|
|
|
|
putc(MPWSEP, s->file);
|
|
|
|
if (!(GLOBAL_Stream[LOCAL_output_stream].status & Null_Stream_f))
|
|
|
|
fflush(stdout);
|
2015-06-18 01:39:03 +01:00
|
|
|
}
|
2016-02-18 12:10:58 +00:00
|
|
|
#endif
|
|
|
|
++s->charcount;
|
|
|
|
++s->linecount;
|
|
|
|
s->linepos = 0;
|
|
|
|
LOCAL_newline = TRUE;
|
|
|
|
/* Inform we are not at the start of a newline */
|
|
|
|
} else {
|
2015-06-18 01:39:03 +01:00
|
|
|
LOCAL_newline = FALSE;
|
|
|
|
#if MAC
|
2016-02-18 12:10:58 +00:00
|
|
|
if ((sno == StdOutStream || sno == StdErrStream) && s->linepos > 200)
|
2015-06-18 01:39:03 +01:00
|
|
|
sno->stream_putc(sno, '\n');
|
|
|
|
#endif
|
|
|
|
++s->charcount;
|
|
|
|
++s->linepos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
inline static Term StreamPosition(int sno) {
|
2015-10-05 10:34:32 +01:00
|
|
|
CACHE_REGS
|
2015-06-18 01:39:03 +01:00
|
|
|
Term sargs[5];
|
|
|
|
Int cpos;
|
|
|
|
cpos = GLOBAL_Stream[sno].charcount;
|
2016-02-18 12:10:58 +00:00
|
|
|
sargs[0] = MkIntegerTerm(LOCAL_StartCharCount = cpos);
|
|
|
|
sargs[1] = MkIntegerTerm(LOCAL_StartLineCount = GLOBAL_Stream[sno].linecount);
|
|
|
|
sargs[2] = MkIntegerTerm(LOCAL_StartLinePos = GLOBAL_Stream[sno].linepos);
|
|
|
|
sargs[3] = sargs[4] = MkIntTerm(0);
|
|
|
|
return Yap_MkApplTerm(FunctorStreamPos, 5, sargs);
|
2015-06-18 01:39:03 +01:00
|
|
|
}
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
inline static Term CurrentPositionToTerm(void) {
|
2015-10-05 10:34:32 +01:00
|
|
|
CACHE_REGS
|
|
|
|
Term sargs[5];
|
2016-02-18 12:10:58 +00:00
|
|
|
sargs[0] = MkIntegerTerm(LOCAL_StartCharCount);
|
|
|
|
sargs[1] = MkIntegerTerm(LOCAL_StartLineCount);
|
|
|
|
sargs[2] = MkIntegerTerm(LOCAL_StartLinePos);
|
|
|
|
sargs[3] = sargs[4] = MkIntTerm(0);
|
|
|
|
return Yap_MkApplTerm(FunctorStreamPos, 5, sargs);
|
2015-10-05 10:34:32 +01:00
|
|
|
}
|
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
extern FILE *Yap_stdin;
|
|
|
|
extern FILE *Yap_stdout;
|
|
|
|
extern FILE *Yap_stderr;
|
|
|
|
|
2016-02-18 12:10:58 +00:00
|
|
|
char *Yap_MemExportStreamPtr(int sno);
|
2016-04-18 01:09:10 +01:00
|
|
|
|
|
|
|
bool Yap_Exists(const char *f);
|
|
|
|
|
2015-06-18 01:39:03 +01:00
|
|
|
#endif
|