YAP
7.1.0
YapStreams.h
1
/**************************************************************************
2
* *
3
* File: iopreds.h *
4
* Last rev: 5/2/88 *
5
* mods: *
6
* comments: Input/Output C implemented predicates *
7
* *
8
*************************************************************************/
9
10
#ifndef YAPSTREAMS_H
11
#define YAPSTREAMS_H 1
12
13
#if HAVE_SYS_TYPES_H
14
#include <sys/types.h>
15
#endif
16
#if HAVE_SYS_SOCKET_H
17
#include <sys/socket.h>
18
#endif
19
20
#define YAP_ERROR NIL
21
22
#define MaxStreams 64
23
24
#define EXPAND_FILENAME 0x000080
25
26
#define StdInStream 0
27
#define StdOutStream 1
28
#define StdErrStream 2
29
30
#define ALIASES_BLOCK_SIZE 8
31
32
#if _WIN32
33
#ifndef USE_SOCKET
34
#define USE_SOCKET 1
35
#endif
36
#define HAVE_SOCKET 1
37
#endif
38
39
//#include "Atoms.h"
40
//#include "Yap.h"
41
#include <stdlib.h>
42
43
/*
44
* This file defines main data-structure for stream management,
45
*
46
*/
47
48
#if defined(_MSC_VER) || defined(__MINGW32__)
49
50
#include <windows.h>
51
52
#endif
53
54
#include <wchar.h>
55
56
/************ SWI compatible support for unicode representations ************/
57
typedef
struct
yap_io_position
{
58
int64_t byteno;
/* byte-position in file */
59
int64_t charno;
/* character position in file */
60
long
int
lineno;
/* lineno in file */
61
long
int
linepos;
/* position in line */
62
intptr_t reserved[2];
/* future extensions */
63
}
yapIOPOS
;
64
65
typedef
struct
yapchlookahead
{
66
intptr_t charcount;
/* character position in file */
67
intptr_t linecount;
/* lineno in file */
68
intptr_t linepos;
/* position in line */
69
intptr_t ch;
/* future extensions */
70
struct
yapchlookahead
*next;
71
}
yapStreamLookahead
;
72
73
extern
int
PopCode(
int
sno);
74
75
#ifndef _PL_STREAM_H
76
typedef
struct
{
77
YAP_Atom file;
/* current source file */
78
yapIOPOS
position;
/* Line, line pos, char and byte */
79
}
yapSourceLocation
;
80
#endif
81
82
#define RD_MAGIC 0xefebe128
83
84
typedef
struct
vlist_struct_t
{
85
struct
VARSTRUCT
*ve;
86
struct
vlist_struct_t
*next;
87
}
vlist_t
;
88
89
typedef
struct
qq_struct_t
{
90
unsigned
char
*text;
91
yapIOPOS
start, mid, end;
92
vlist_t
*vlist;
93
struct
qq_struct_t
*next;
94
}
qq_t
;
95
96
typedef
struct
read_data_t
{
97
unsigned
char
*here;
/* current character */
98
unsigned
char
*base;
/* base of clause */
99
unsigned
char
*end;
/* end of the clause */
100
unsigned
char
*token_start;
/* start of most recent read token */
101
102
int
magic;
/* RD_MAGIC */
103
struct
stream_desc
*stream;
104
FILE *f;
/* file. of known */
105
YAP_Term position;
/* Line, line pos, char and byte */
106
void
*posp;
/* position pointer */
107
size_t
posi;
/* position number */
108
109
YAP_Term subtpos;
/* Report Subterm positions */
110
bool
cycles;
/* Re-establish cycles */
111
yapSourceLocation
start_of_term;
/* Position of start of term */
112
struct
mod_entry
*module;
/* Current source module */
113
unsigned
int
flags
;
/* Module syntax flags */
114
int
styleCheck;
/* style-checking mask */
115
bool
backquoted_string;
/* Read `hello` as string */
116
117
int
*char_conversion_table;
/* active conversion table */
118
119
YAP_Atom on_error;
/* Handling of syntax errors */
120
int
has_exception;
/* exception is raised */
121
122
YAP_Term exception;
/* raised exception */
123
YAP_Term variables;
/* report variables */
124
YAP_Term singles;
/* Report singleton variables */
125
YAP_Term varnames;
/* Report variables+names */
126
int
strictness;
/* Strictness level */
127
128
#ifdef O_QUASIQUOTATIONS
129
YAP_Term quasi_quotations;
/* User option quasi_quotations(QQ) */
130
YAP_Term qq;
/* Quasi quoted list */
131
YAP_Term qq_tail;
/* Tail of the quoted stuff */
132
#endif
133
134
YAP_Term comments;
/* Report comments */
135
136
}
read_data
, *
ReadData
;
137
138
#if __APPLE__ && !PY4YAP_H
139
#include "fmemopen.h"
140
#define HAVE_FMEMOPEN 1
141
#define HAVE_OPEN_MEMSTREAM 1
142
FILE *open_memstream(
char
**buf,
size_t
*len);
143
#endif
144
145
#if __ANDROID__
146
//extern FILE * fmemopen(void *buf, size_t size, const char *mode);
147
#define HAVE_FMEMOPEN 1
148
#define HAVE_OPEN_MEMSTREAM 1
149
#endif
150
151
#if HAVE_FMEMOPEN
152
#define MAY_READ 1
153
#endif
154
155
#if HAVE_OPEN_MEMSTREAM
156
#define MAY_READ 1
157
#define MAY_WRITE 1
158
#endif
159
160
#if _WIN32
161
#undef MAY_WRITE
162
#undef MAY_READ
163
#endif
164
165
typedef
struct
mem_desc
{
166
char
*buf;
/* where the file is being read from/written to */
167
int
src;
/* where the space comes from, 0 code space, 1 malloc */
168
YAP_Int max_size;
/* maximum buffer size (may be changed dynamically) */
169
YAP_UInt pos;
/* cursor */
170
volatile
void
*error_handler;
171
}
memHandle
;
172
173
#if HAVE_SOCKET
174
typedef
enum
{
/* in YAP, sockets may be in one of 4 possible status */
175
new_socket,
176
server_socket,
177
client_socket,
178
server_session_socket,
179
closed_socket
180
} socket_info;
181
182
typedef
enum
{
/* we accept two domains for the moment, IPV6 may follow */
183
af_inet,
/* IPV4 */
184
af_unix
/* or AF_FILE */
185
} socket_domain;
186
187
#endif
188
189
#define Quote_illegal_f 0x01
190
#define Ignore_ops_f 0x02
191
#define Handle_vars_f 0x04
192
#define Use_portray_f 0x08
193
#define To_heap_f 0x10
194
#define Handle_cyclics_f 0x20
195
#define Use_SWI_Stream_f 0x40
196
#define BackQuote_String_f 0x80
197
#define AttVar_None_f 0x100
198
#define AttVar_Dots_f 0x200
199
#define AttVar_Portray_f 0x400
200
#define Blob_Portray_f 0x800
201
#define No_Escapes_f 0x1000
202
#define No_Brace_Terms_f 0x2000
203
#define Fullstop_f 0x4000
204
#define New_Line_f 0x8000
205
#define Number_vars_f 0x10000
206
#define Singleton_vars_f 0x20000
207
#define Named_vars_f 0x40000
208
209
typedef
struct
stream_desc
{
210
YAP_Atom name;
211
YAP_Term user_name;
212
FILE *file;
213
// useful in memory streams
214
char
*nbuf;
215
size_t
nsize;
216
struct
{
217
struct
{
218
#define PLGETC_BUF_SIZE 4096
219
unsigned
char
*buf, *ptr;
220
int
left;
221
} file;
222
memHandle
mem_string;
223
struct
{
224
int
fd;
225
} pipe;
226
#if HAVE_SOCKET
227
struct
{
228
socket_domain domain;
229
socket_info flags;
230
int
fd;
231
} socket;
232
#endif
233
struct
{
234
const
unsigned
char
*buf, *ptr;
235
} irl;
236
struct
{
237
unsigned
char
*buf, *ptr;
238
} w_irl;
239
void
*private_data;
240
} u;
241
struct
{
242
bool
on;
243
int
ch;
244
intptr_t pos, line, lpos;
245
} buf;
246
247
YAP_Int charcount, linecount, linestart;
248
stream_flags_t status;
249
#if defined(YAPOR) || defined(THREADS)
250
lockvar streamlock;
/* protect stream access */
251
#endif
252
int (*stream_putc)(
253
int, int);
254
int (*
stream_wputc
)(
255
int, wchar_t);
256
int (*
stream_getc
)(int);
257
int (*
stream_wgetc
)(
258
int);
259
struct
vfs
*
vfs
;
260
void
*
vfs_handle
;
261
int (*
stream_wgetc_for_read
)(int);
263
int (*
stream_peek
)(int);
264
int (*
stream_wpeek
)(int);
265
encoding_t
encoding
;
266
}
StreamDesc
;
267
268
269
270
extern
bool
Yap_set_stream_to_buf(
StreamDesc
*st,
const
char
*bufi,
271
size_t
nchars
272
#ifdef USES_REGS
273
USES_REGS
274
#endif
275
);
276
277
#endif
VARSTRUCT
Definition:
ScannerTypes.h:24
mem_desc
Definition:
YapStreams.h:165
mod_entry
Module property: low-level data used to manage modes.
Definition:
Yatom.h:209
mod_entry::flags
unsigned int flags
module's owner file
Definition:
Yatom.h:219
qq_struct_t
Definition:
YapStreams.h:89
read_data_t
Definition:
YapStreams.h:96
stream_desc
Definition:
YapStreams.h:209
stream_desc::stream_getc
int(* stream_getc)(int)
function the stream uses for writing a character
Definition:
YapStreams.h:256
stream_desc::stream_wputc
int(* stream_wputc)(int, wchar_t)
function the stream uses for writing a single octet
Definition:
YapStreams.h:254
stream_desc::vfs_handle
void * vfs_handle
stream belongs to a space
Definition:
YapStreams.h:260
stream_desc::encoding
encoding_t encoding
check if the next wide character is available
Definition:
YapStreams.h:265
stream_desc::stream_wgetc
int(* stream_wgetc)(int)
function the stream uses for reading an octet
Definition:
YapStreams.h:257
stream_desc::stream_wpeek
int(* stream_wpeek)(int)
check if the next character is available
Definition:
YapStreams.h:264
stream_desc::vfs
struct vfs * vfs
function the stream uses for reading a character
Definition:
YapStreams.h:259
stream_desc::stream_wgetc_for_read
int(* stream_wgetc_for_read)(int)
direct handle to stream in that space
Definition:
YapStreams.h:261
stream_desc::stream_peek
int(* stream_peek)(int)
function the stream uses for parser
Definition:
YapStreams.h:263
vfs
Definition:
VFS.h:74
vlist_struct_t
Definition:
YapStreams.h:84
yapSourceLocation
Definition:
YapStreams.h:76
yap_io_position
Definition:
YapStreams.h:57
yapchlookahead
Definition:
YapStreams.h:65
include
YapStreams.h
Generated by
1.9.3