YAP 7.1.0
VFS.h
1/*************************************************************************
2 * *
3 * YAP Prolog *
4 * *
5 * Yap Prolog was developed at NCCUP - Universidade do Porto *
6 * *
7 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8 * *
9 **************************************************************************
10 * *
11 * File: VFS.h *
12 * Last rev: 5/2/88 *
13 * mods: *
14 * comments: Virtual File System Access for YAP *
15 * *
16 *************************************************************************/
17#ifndef VFS_H
18#define VFS_H 1
19#include <string.h>
20#if HAVE_SYS_STAT_H
21#include <sys/stat.h>
22#endif
23
24#ifdef _WIN32
25#include <stdint.h>
26#ifndef uid_t
27#define uid_t int
28#endif
29#ifndef gid_t
30#define gid_t int
31#endif
32#endif
33
34#include <YapEncoding.h>
35
36typedef struct {
37 dev_t st_dev; /* ID of device containing file */
38 mode_t st_mode; /* Mode of file (see below) */
39 uid_t st_uid; /* User ID of the file */
40 gid_t st_gid; /* Group ID of the file */
41 struct timespec st_atimespec; /* time of last access */
42 struct timespec st_mtimespec; /* time of last data modification */
43 struct timespec st_ctimespec; /* time of last status change */
44 struct timespec st_birthtimespec; /* time of file creation(birth) */
45#if __ANDROID__
46 off64_t st_size; /* file size, in bytes */
47#else
48 off_t st_size; /* file size, in bytes */
49#endif
50} vfs_stat;
51
52typedef enum vfs_flags {
53 VFS_CAN_READ = 0x1,
54 VFS_CAN_WRITE = 0x2,
55 VFS_CAN_EXEC = 0x4,
56 VFS_CAN_SEEK = 0x8,
57 VFS_HAS_PREFIX = 0x10,
58 VFS_HAS_SUFFIX = 0x20,
59 VFS_HAS_FUNCTION = 0x40
60} vfs_flags_t;
61
62typedef union {
63 struct vfs *vfs;
64 uintptr_t cell;
65 size_t sz;
66 void *pt;
67 uintptr_t scalar;
68#if __ANDROID__0
69 AAssetManager *mgr;
70 AAsset *asset;
71#endif
73
74typedef struct vfs {
75 const char *name;
76 uintptr_t vflags;
78 const char *prefix;
79 const char *suffix;
80 bool (*chDir)(struct vfs *me, const char *s);
82 void *(*open)(struct vfs *, const char *fname,
83 const char *io_mode,
84 int sno);
86 bool (*close)(int sno);
87 int (*get_char)(int sno);
88 int (*get_wchar)(int sno);
89 int (*peek_char)(int sno);
90 int (*peek_wchar)(int sno);
91 int (*put_char)(int sno, int ch);
92 int (*put_wchar)(int sno, int ch);
93 void (*flush)(int sno);
94 int64_t (*seek)(int sno, int64_t offset,
95 int whence);
96 void *(*opendir)(struct vfs *,
97 const char *s);
98 const char *(*nextdir)(
99 void *d);
100 bool (*closedir)(void *d);
101 ;
102 bool (*stat)(struct vfs *, const char *s,
103 vfs_stat *);
104 bool (*isdir)(struct vfs *, const char *s);
105 bool (*exists)(struct vfs *, const char *s);
106 bool (*chdir)(struct vfs *,
107 const char *s);
108 encoding_t enc;
109 YAP_Term (*parsers)(int sno); // a set of parsers that can read the
110 // stream and generate a YAP_Term
111 int (*writers)(int ch, int sno);
114 void *priv;
115 struct vfs *next;
116} VFS_t;
117
118extern VFS_t *GLOBAL_VFS;
119
120extern void init_android_stream(void);
121
122extern void Yap_InitStdStream(int sno, unsigned int flags, FILE *file,
123 VFS_t *vfsp);
124
125static inline VFS_t *vfs_owner(const char *fname) {
126 VFS_t *me = GLOBAL_VFS;
127 int d;
128 size_t sz0 = strlen(fname), sz;
129
130 while (me) {
131 bool p = true;
132 if ((me->vflags & VFS_HAS_PREFIX) && p) {
133 if (strstr(fname,me->prefix)==fname)
134 return me;
135 }
136 if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) &&
137 (d = (sz0 - sz)) >= 0 && strcmp(fname + d, me->suffix) == 0) {
138 return me;
139 }
140 me = me->next;
141 }
142 return NULL;
143}
144
145#endif
146
Definition: VFS.h:36
Definition: VFS.h:74
bool(* stat)(struct vfs *, const char *s, vfs_stat *)
close access a directory object
Definition: VFS.h:102
int64_t(* seek)(int sno, int64_t offset, int whence)
flush a stream
Definition: VFS.h:94
bool(* close)(int sno)
open an object
Definition: VFS.h:86
YAP_Term(* parsers)(int sno)
default file encoded
Definition: VFS.h:109
const char * prefix
the main flags describing the operation of the Fs
Definition: VFS.h:78
bool(* exists)(struct vfs *, const char *s)
verify whether is directory
Definition: VFS.h:105
void * priv
VFS dep endent area.
Definition: VFS.h:114
int(* peek_char)(int sno)
get an octet from the stream
Definition: VFS.h:89
int(* put_char)(int sno, int ch)
unget an octet from the stream
Definition: VFS.h:91
bool(* chdir)(struct vfs *, const char *s)
verify whether a file exists
Definition: VFS.h:106
int(* get_wchar)(int sno)
get an octet from the stream
Definition: VFS.h:88
int(* peek_wchar)(int sno)
unget an octet from the stream
Definition: VFS.h:90
void(* flush)(int sno)
output a character to the stream
Definition: VFS.h:93
int(* get_char)(int sno)
close the object
Definition: VFS.h:87
uintptr_t vflags
A text that explains the file system.
Definition: VFS.h:76
int(* put_wchar)(int sno, int ch)
output an octet to the stream
Definition: VFS.h:92
bool(* isdir)(struct vfs *, const char *s)
obtain size, age, permissions of a file
Definition: VFS.h:104
bool(* closedir)(void *d)
walk to the next entry in a directory object
Definition: VFS.h:100
encoding_t enc
set working directory (may be virtual)
Definition: VFS.h:108