hope it is useful
This commit is contained in:
parent
a382ca43fa
commit
2b9b92dac7
130
include/VFS.h
Normal file
130
include/VFS.h
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/*************************************************************************
|
||||||
|
* *
|
||||||
|
* YAP Prolog *
|
||||||
|
* *
|
||||||
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
|
* *
|
||||||
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||||
|
* *
|
||||||
|
**************************************************************************
|
||||||
|
* *
|
||||||
|
* File: VFS.h *
|
||||||
|
* Last rev: 5/2/88 *
|
||||||
|
* mods: *
|
||||||
|
* comments: Virtual File System Access for YAP *
|
||||||
|
* *
|
||||||
|
*************************************************************************/
|
||||||
|
#ifndef VFS_H
|
||||||
|
#define VFS_H 1
|
||||||
|
#if HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYS_STAT_H
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
dev_t st_dev; /* ID of device containing file */
|
||||||
|
mode_t st_mode; /* Mode of file (see below) */
|
||||||
|
uid_t st_uid; /* User ID of the file */
|
||||||
|
gid_t st_gid; /* Group ID of the file */
|
||||||
|
struct timespec st_atimespec; /* time of last access */
|
||||||
|
struct timespec st_mtimespec; /* time of last data modification */
|
||||||
|
struct timespec st_ctimespec; /* time of last status change */
|
||||||
|
struct timespec st_birthtimespec; /* time of file creation(birth) */
|
||||||
|
#if __ANDROID__
|
||||||
|
off64_t st_size; /* file size, in bytes */
|
||||||
|
#else
|
||||||
|
off_t st_size; /* file size, in bytes */
|
||||||
|
#endif
|
||||||
|
} vfs_stat;
|
||||||
|
|
||||||
|
typedef enum vfs_flags {
|
||||||
|
VFS_CAN_WRITE = 0x1, /// we can write to files in this space
|
||||||
|
VFS_CAN_EXEC = 0x2, /// we can execute files in this space
|
||||||
|
VFS_CAN_SEEK = 0x4, /// we can seek within files in this space
|
||||||
|
VFS_HAS_PREFIX = 0x8, /// has a prefix that identifies a file in this space
|
||||||
|
VFS_HAS_SUFFIX = 0x10, /// has a suffix that describes the file.
|
||||||
|
VFS_HAS_FUNCTION = 0x10, /// has a suffix that describes the file.
|
||||||
|
} vfs_flags_t;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct vfs *vfs;
|
||||||
|
uintptr_t cell;
|
||||||
|
size_t sz;
|
||||||
|
void *pt;
|
||||||
|
uintptr_t scalar;
|
||||||
|
#if __ANDROID__
|
||||||
|
AAssetManager *mgr;
|
||||||
|
AAsset *asset;
|
||||||
|
#endif
|
||||||
|
} cell_size_t;
|
||||||
|
|
||||||
|
typedef struct vfs {
|
||||||
|
const char *name; /// A text that explains the file system
|
||||||
|
uintptr_t vflags; /// the main flags describing the operation of the Fs.
|
||||||
|
/// a way to identify a file in this VFS: two special cases, prefix and suffix
|
||||||
|
const char *prefix;
|
||||||
|
const char *suffix;
|
||||||
|
bool (*id)(struct vfs *me, const char *s);
|
||||||
|
/** operations */
|
||||||
|
bool (*open)(struct vfs *me, struct stream_desc *st, const char *s,
|
||||||
|
const char *io_mode);
|
||||||
|
; /// open an object
|
||||||
|
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
|
||||||
|
bool (*close)(struct stream_desc *stream); /// close the object
|
||||||
|
int (*get_char)(struct stream_desc *stream); /// get an octet to the stream
|
||||||
|
int (*putc)(int ch,
|
||||||
|
struct stream_desc *stream); /// output an octet to the stream
|
||||||
|
int64_t (*seek)(struct stream_desc *stream, int64_t offset,
|
||||||
|
int whence); /// jump around the stream
|
||||||
|
void *(*opendir)(struct vfs *me,
|
||||||
|
const char *s); /// open a directory object, if one exists
|
||||||
|
const char *(*nextdir)(
|
||||||
|
void *d); /// walk to the next entry in a directory object
|
||||||
|
void (*closedir)(void *d);
|
||||||
|
; /// close access a directory object
|
||||||
|
bool (*stat)(struct vfs *me, const char *s,
|
||||||
|
vfs_stat *); /// obtain size, age, permissions of a file.
|
||||||
|
bool (*isdir)(struct vfs *me, const char *s); /// verify whether is directory.
|
||||||
|
bool (*exists)(struct vfs *me,
|
||||||
|
const char *s); /// verify whether a file exists.
|
||||||
|
bool (*chdir)(struct vfs *me,
|
||||||
|
const char *s); /// set working directory (may be virtual).
|
||||||
|
encoding_t enc; /// how the file is encoded.
|
||||||
|
YAP_Term (*parsers)(void *stream); // a set of parsers that can read the
|
||||||
|
// stream and generate a YAP_Term
|
||||||
|
int (*writers)(int ch, void *stream);
|
||||||
|
; /// convert a YAP_Term into this space
|
||||||
|
const char *virtual_cwd;
|
||||||
|
/** VFS dep
|
||||||
|
endent area */
|
||||||
|
cell_size_t priv[4];
|
||||||
|
struct vfs *next;
|
||||||
|
} VFS_t;
|
||||||
|
|
||||||
|
extern VFS_t *GLOBAL_VFS;
|
||||||
|
|
||||||
|
static inline VFS_t *vfs_owner(const char *fname) {
|
||||||
|
return NULL;
|
||||||
|
VFS_t *me = GLOBAL_VFS;
|
||||||
|
int d;
|
||||||
|
YAP_Int sz0 = strlen(fname);
|
||||||
|
|
||||||
|
while (me) {
|
||||||
|
if (me->vflags & VFS_HAS_PREFIX && strstr(fname, me->prefix))
|
||||||
|
return me;
|
||||||
|
YAP_Int sz = strlen(me->suffix);
|
||||||
|
;
|
||||||
|
if (me->vflags & VFS_HAS_SUFFIX && (d = (sz0 - sz)) >= 0 &&
|
||||||
|
strcmp(fname + d, me->suffix) == 0)
|
||||||
|
return me;
|
||||||
|
if (me->vflags & VFS_HAS_FUNCTION && (me->id(me, fname))) {
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
me = me->next;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
285
include/YAPStreams.h
Normal file
285
include/YAPStreams.h
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
* *
|
||||||
|
* File: iopreds.h *
|
||||||
|
* Last rev: 5/2/88 *
|
||||||
|
* mods: *
|
||||||
|
* comments: Input/Output C implemented predicates *
|
||||||
|
* *
|
||||||
|
*************************************************************************/
|
||||||
|
#ifdef SCCS
|
||||||
|
static char SccsId[] = "%W% %G%";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef YAPSTREAMS_H
|
||||||
|
#define YAPSTREAMS_H 1
|
||||||
|
|
||||||
|
#if HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYS_SOCKET_H
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define YAP_ERROR NIL
|
||||||
|
|
||||||
|
#define MaxStreams 64
|
||||||
|
|
||||||
|
#define EXPAND_FILENAME 0x000080
|
||||||
|
|
||||||
|
#define StdInStream 0
|
||||||
|
#define StdOutStream 1
|
||||||
|
#define StdErrStream 2
|
||||||
|
|
||||||
|
#define ALIASES_BLOCK_SIZE 8
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
#define USE_SOCKET 1
|
||||||
|
#define HAVE_SOCKET 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//#include "Atoms.h"
|
||||||
|
//#include "Yap.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file defines main data-structure for stream management,
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
|
||||||
|
/************ SWI compatible support for unicode representations ************/
|
||||||
|
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 */
|
||||||
|
} yapIOPOS;
|
||||||
|
|
||||||
|
#ifndef _PL_STREAM_H
|
||||||
|
typedef struct {
|
||||||
|
YAP_Atom file; /* current source file */
|
||||||
|
yapIOPOS position; /* Line, line pos, char and byte */
|
||||||
|
} 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;
|
||||||
|
|
||||||
|
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 */
|
||||||
|
YAP_Term position; /* Line, line pos, char and byte */
|
||||||
|
void *posp; /* position pointer */
|
||||||
|
size_t posi; /* position number */
|
||||||
|
|
||||||
|
YAP_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 */
|
||||||
|
|
||||||
|
YAP_Atom on_error; /* Handling of syntax errors */
|
||||||
|
int has_exception; /* exception is raised */
|
||||||
|
|
||||||
|
YAP_Term exception; /* raised exception */
|
||||||
|
YAP_Term variables; /* report variables */
|
||||||
|
YAP_Term singles; /* Report singleton variables */
|
||||||
|
YAP_Term varnames; /* Report variables+names */
|
||||||
|
int strictness; /* Strictness level */
|
||||||
|
|
||||||
|
#ifdef O_QUASIQUOTATIONS
|
||||||
|
YAP_Term quasi_quotations; /* User option quasi_quotations(QQ) */
|
||||||
|
YAP_Term qq; /* Quasi quoted list */
|
||||||
|
YAP_Term qq_tail; /* Tail of the quoted stuff */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
YAP_Term comments; /* Report comments */
|
||||||
|
|
||||||
|
} read_data, *ReadData;
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
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 */
|
||||||
|
YAP_Int max_size; /* maximum buffer size (may be changed dynamically) */
|
||||||
|
YAP_UInt pos; /* cursor */
|
||||||
|
volatile void *error_handler;
|
||||||
|
} memHandle;
|
||||||
|
|
||||||
|
#if HAVE_SOCKET
|
||||||
|
typedef enum { /* in YAP, sockets may be in one of 4 possible status */
|
||||||
|
new_socket,
|
||||||
|
server_socket,
|
||||||
|
client_socket,
|
||||||
|
server_session_socket,
|
||||||
|
closed_socket
|
||||||
|
} socket_info;
|
||||||
|
|
||||||
|
typedef enum { /* we accept two domains for the moment, IPV6 may follow */
|
||||||
|
af_inet, /* IPV4 */
|
||||||
|
af_unix /* or AF_FILE */
|
||||||
|
} socket_domain;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define Quote_illegal_f 0x01
|
||||||
|
#define Ignore_ops_f 0x02
|
||||||
|
#define Handle_vars_f 0x04
|
||||||
|
#define Use_portray_f 0x08
|
||||||
|
#define To_heap_f 0x10
|
||||||
|
#define Unfold_cyclics_f 0x20
|
||||||
|
#define Use_SWI_Stream_f 0x40
|
||||||
|
#define BackQuote_String_f 0x80
|
||||||
|
#define AttVar_None_f 0x100
|
||||||
|
#define AttVar_Dots_f 0x200
|
||||||
|
#define AttVar_Portray_f 0x400
|
||||||
|
#define Blob_Portray_f 0x800
|
||||||
|
#define No_Escapes_f 0x1000
|
||||||
|
#define No_Brace_Terms_f 0x2000
|
||||||
|
#define Fullstop_f 0x4000
|
||||||
|
#define New_Line_f 0x8000
|
||||||
|
|
||||||
|
typedef struct stream_desc {
|
||||||
|
YAP_Atom name;
|
||||||
|
YAP_Term user_name;
|
||||||
|
FILE *file;
|
||||||
|
// useful in memory streams
|
||||||
|
char *nbuf;
|
||||||
|
size_t nsize;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
#define PLGETC_BUF_SIZE 4096
|
||||||
|
unsigned char *buf, *ptr;
|
||||||
|
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 {
|
||||||
|
const unsigned char *buf, *ptr;
|
||||||
|
} irl;
|
||||||
|
} u;
|
||||||
|
|
||||||
|
YAP_Int charcount, linecount, linepos;
|
||||||
|
stream_flags_t status;
|
||||||
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
|
lockvar streamlock; /* protect stream access */
|
||||||
|
#endif
|
||||||
|
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. */
|
||||||
|
struct vfs *vfs; /** stream belongs to a space */
|
||||||
|
void *vfs_handle; /** direct handle to stream in that space. */
|
||||||
|
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 */
|
||||||
|
encoding_t encoding; /** current encoding for stream */
|
||||||
|
} StreamDesc;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user