This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/include/VFS.h

146 lines
4.9 KiB
C
Raw Normal View History

2016-07-31 15:55:50 +01:00
/*************************************************************************
* *
* 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
#include <string.h>
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef _WIN32
#include <stdint.h>
#ifndef uid_t
#define uid_t int
#endif
#ifndef gid_t
#define gid_t int
#endif
2016-07-31 15:55:50 +01:00
#endif
2017-07-25 01:10:44 +01:00
#include <encoding.h>
2016-07-31 15:55:50 +01:00
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 {
2018-02-14 14:17:57 +00:00
VFS_CAN_READ = 0x1, /// we can write to files in this space
VFS_CAN_WRITE = 0x2, /// we can write to files in this space
VFS_CAN_EXEC = 0x4, /// we can execute files in this space
VFS_CAN_SEEK = 0x8, /// we can seek within files in this space
VFS_HAS_PREFIX = 0x10, /// has a prefix that identifies a file in this space
VFS_HAS_SUFFIX = 0x20, /// has a suffix that describes the file.
VFS_HAS_FUNCTION = 0x40 /// has a suffix that describes the file.
2016-07-31 15:55:50 +01:00
} vfs_flags_t;
typedef union {
struct vfs *vfs;
uintptr_t cell;
size_t sz;
void *pt;
uintptr_t scalar;
2017-07-25 01:10:44 +01:00
#if __ANDROID__0
2016-07-31 15:55:50 +01:00
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;
2017-11-21 15:44:43 +00:00
bool (*chDir)(struct vfs *me, const char *s);
2016-07-31 15:55:50 +01:00
/** operations */
2018-03-17 10:38:56 +00:00
void *(*open)(struct vfs *, const char *fname,
const char *io_mode,
int sno); /// open an object
2016-07-31 15:55:50 +01:00
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
2018-01-05 16:57:38 +00:00
bool (*close)(int sno); /// close the object
int (*get_char)(int sno); /// get an octet from the stream
2018-10-17 16:51:29 +01:00
int (*get_wchar)(int sno); /// get an octet from the stream
2018-01-18 14:47:27 +00:00
int (*peek_char)(int sno); /// unget an octet from the stream
int (*peek_wchar)(int sno); /// unget an octet from the stream
2017-06-12 18:00:47 +01:00
int (*put_char)(int sno, int ch); /// output an octet to the stream
2018-09-26 01:14:14 +01:00
int (*put_wchar)(int sno, int ch); /// output a character to the stream
2018-01-05 16:57:38 +00:00
void (*flush)(int sno); /// flush a stream
2017-05-27 22:54:00 +01:00
int64_t (*seek)(int sno, int64_t offset,
2016-07-31 15:55:50 +01:00
int whence); /// jump around the stream
2018-01-05 16:57:38 +00:00
void *(*opendir)(struct vfs *,
const char *s); /// open a directory object, if one exists
const char *(*nextdir)(
void *d); /// walk to the next entry in a directory object
2017-11-21 15:44:43 +00:00
bool (*closedir)(void *d);
2016-07-31 15:55:50 +01:00
; /// close access a directory object
2018-01-05 16:57:38 +00:00
bool (*stat)(struct vfs *, const char *s,
2016-07-31 15:55:50 +01:00
vfs_stat *); /// obtain size, age, permissions of a file.
2018-01-05 16:57:38 +00:00
bool (*isdir)(struct vfs *, const char *s); /// verify whether is directory.
2017-11-21 15:44:43 +00:00
bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.
2018-01-05 16:57:38 +00:00
bool (*chdir)(struct vfs *,
const char *s); /// set working directory (may be virtual).
encoding_t enc; /// default file encoded.
2017-05-27 22:54:00 +01:00
YAP_Term (*parsers)(int sno); // a set of parsers that can read the
2018-01-05 16:57:38 +00:00
// stream and generate a YAP_Term
int (*writers)(int ch, int sno);
2016-07-31 15:55:50 +01:00
/** VFS dep
endent area */
2018-06-15 13:55:31 +01:00
void *priv;
2016-07-31 15:55:50 +01:00
struct vfs *next;
} VFS_t;
extern VFS_t *GLOBAL_VFS;
2017-07-25 01:10:44 +01:00
extern void init_android_stream(void);
2018-01-05 16:57:38 +00:00
extern void Yap_InitStdStream(int sno, unsigned int flags, FILE *file,
VFS_t *vfsp);
2017-07-25 01:10:44 +01:00
2016-07-31 15:55:50 +01:00
static inline VFS_t *vfs_owner(const char *fname) {
VFS_t *me = GLOBAL_VFS;
int d;
2017-05-27 22:54:00 +01:00
size_t sz0 = strlen(fname), sz;
2016-07-31 15:55:50 +01:00
while (me) {
2017-11-21 15:44:43 +00:00
bool p = true;
if ((me->vflags & VFS_HAS_PREFIX) && p) {
2018-02-14 00:13:13 +00:00
if (strstr(fname,me->prefix)==fname)
2018-01-05 16:57:38 +00:00
return me;
2017-11-21 15:44:43 +00:00
}
2018-01-05 16:57:38 +00:00
if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) &&
(d = (sz0 - sz)) >= 0 && strcmp(fname + d, me->suffix) == 0) {
2016-07-31 15:55:50 +01:00
return me;
}
me = me->next;
}
return NULL;
}
#endif