Debian Codegraph @

terps/tads/tads3/lib/file.t

raw
1 #charset "us-ascii"
2
3 /*
4 * Copyright (c) 2001, 2006 Michael J. Roberts
5 *
6 * This file is part of TADS 3.
7 *
8 * This module defines classes and constants related to the File
9 * intrinsic class. In particular, this module defines the Exception
10 * subclasses thrown by File methods.
11 */
12
13 #include <tads.h>
14 #include <file.h>
15
16
17 /* ------------------------------------------------------------------------ */
18 /*
19 * File status information. This is returned from file.getFileInfo().
20 */
21 class FileInfo: object
22 construct(typ, siz, ctime, mtime, atime, target, attrs, ...)
23 {
24 fileType = typ;
25 fileSize = siz;
26 fileCreateTime = ctime;
27 fileModifyTime = mtime;
28 fileAccessTime = atime;
29 fileLinkTarget = target;
30 fileAttrs = attrs;
31
32 /* for convenience, note if it's a directory and/or special link */
33 isDir = (typ & FileTypeDir) != 0;
34 specialLink = (typ & (FileTypeSelfLink | FileTypeParentLink));
35 }
36
37 /* is this file a directory? */
38 isDir = nil
39
40 /*
41 * Is this a special link directory? This is FileTypeSelfLink for a
42 * directory link to itself; it's FileTypeParentLink for a directory
43 * link to the parent; it's zero for all other files. On Windows and
44 * Unix, these flags will be set for the special "." and ".."
45 * directories, respectively. These flags only apply to the
46 * *system-defined* special links; they aren't set for user-created
47 * links that happen to point to self or parent. This is zero for
48 * all other files.
49 */
50 specialLink = 0
51
52 /*
53 * Link target. If the file is a symbolic link, this contains a
54 * string giving the target file's path. This is the direct target
55 * of this link, which might itself be another link.
56 */
57 fileLinkTarget = nil
58
59 /*
60 * type of the file, as a combination of FileTypeXxx bit flags (see
61 * filename.h)
62 */
63 fileType = 0
64
65 /*
66 * file attributes, as a combination of FileAttrXxx bit flags (see
67 * filename.h)
68 */
69 fileAttrs = 0
70
71 /* size of the file in bytes */
72 fileSize = 0
73
74 /*
75 * The file's time of creation, last modification, and last access,
76 * as Date objects. On some systems, these timestamps might not all
77 * be available; an item that's not available is set to nil.
78 */
79 fileCreateTime = nil
80 fileModifyTime = nil
81 fileAccessTime = nil
82 ;
83
84 export FileInfo 'File.FileInfo';
85
86 /* ------------------------------------------------------------------------ */
87 /*
88 * File Exception classes. All File exceptions derive from FileException,
89 * to allow for generic 'catch' clauses which catch any file-related
90 * error.
91 */
92 class FileException: Exception
93 displayException() { "file error"; }
94 ;
95
96 /*
97 * File not found - this is thrown when attempting to open a file for
98 * reading and the file doesn't exist or can't be opened (because the user
99 * doesn't have privileges to read the file, or the file is already being
100 * used by another user, for example).
101 */
102 class FileNotFoundException: FileException
103 displayException() { "file not found"; }
104 ;
105
106 /*
107 * File creation error - this is thrown when attempting to open a file for
108 * writing and the file can't be created; this can happen because the disk
109 * or the directory is full, due to privilege failures, or due to sharing
110 * violations, among other reasons.
111 */
112 class FileCreationException: FileException
113 displayException() { "cannot create file"; }
114 ;
115
116 /*
117 * File cannot be opened - this is thrown when attempting to open a file
118 * for reading and writing but the file can't be opened. This can happen
119 * for numerous reasons: sharing violations, privilege failures, lack of
120 * space on the disk or in the directory.
121 */
122 class FileOpenException: FileException
123 displayException() { "cannot open file"; }
124 ;
125
126 /*
127 * File synchronization exception. This is thrown when an operation
128 * (such as a read or write) is attempted during normal execution on a
129 * file object that was originally opened during pre-initialization. A
130 * file object created during pre-initialization can't be used to access
131 * the file during ordinary execution, since the state of the external
132 * file might have changed since the pre-init session ended. In such
133 * cases, a new file object must be created instead.
134 */
135 class FileSyncException: FileException
136 displayException() { "file synchronization error"; }
137 ;
138
139 /*
140 * File closed - this is thrown when an operation is attempted on a file
141 * that has already been explicitly closed.
142 */
143 class FileClosedException: FileException
144 displayException() { "operation attempted on closed file"; }
145 ;
146
147 /*
148 * File I/O exception - this is thrown when a read or write operation on a
149 * file fails. This can indicate, for example, that the device containing
150 * the file is full, or that a physical media error occurred.
151 */
152 class FileIOException: FileException
153 displayException() { "file I/O error"; }
154 ;
155
156 /*
157 * File mode error - this is thrown when an attempted operation is
158 * incompatible with the file's mode. This is thrown under these
159 * conditions:
160 *
161 * - writing to a file opened for read-only access
162 *. - reading from a file opened for write-only access
163 *. - calling readFile or writeFile on a raw-mode file
164 *. - calling readBytes or writeBytes on a non-raw-mode file
165 */
166 class FileModeException: FileException
167 displayException() { "invalid file mode"; }
168 ;
169
170 /*
171 * File safety error - this is thrown when an attempted "open" operation
172 * is prohibited by the current file safety level set by the user.
173 */
174 class FileSafetyException: FileException
175 displayException()
176 {
177 "access to file blocked by user-specified file safety level";
178 }
179 ;
180
181
182 /* export the file exceptions for use by the intrinsic class */
183 export FileNotFoundException 'File.FileNotFoundException';
184 export FileCreationException 'File.FileCreationException';
185 export FileOpenException 'File.FileOpenException';
186 export FileIOException 'File.FileIOException';
187 export FileSyncException 'File.FileSyncException';
188 export FileClosedException 'File.FileClosedException';
189 export FileModeException 'File.FileModeException';
190 export FileSafetyException 'File.FileSafetyException';
191