3 // Copyright (c) 1999-2006 by Digital Mars
5 // written by Walter Bright
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, September 2004
27 typedef size_t hash_t
;
31 char *wchar2ascii(wchar_t *);
32 int wcharIsAscii(wchar_t *);
33 char *wchar2ascii(wchar_t *, unsigned len
);
34 int wcharIsAscii(wchar_t *, unsigned len
);
36 int bstrcmp(unsigned char *s1
, unsigned char *s2
);
37 char *bstr2str(unsigned char *b
);
39 void error(const char *format
, ...);
40 void error(const wchar_t *format
, ...);
41 void warning(const char *format
, ...);
48 typedef __int64 longlong
;
49 typedef unsigned __int64 ulonglong
;
51 typedef long long longlong
;
52 typedef unsigned long long ulonglong
;
60 * Root of our class library.
71 virtual int equals(Object
*o
);
74 * Returns a hash code, useful for things like building hash tables of Objects.
76 virtual hash_t
hashCode();
79 * Return <0, ==0, or >0 if this is less than, equal to, or greater than obj.
80 * Useful for sorting Objects.
82 virtual int compare(Object
*obj
);
85 * Pretty-print an Object. Useful for debugging the old-fashioned way.
89 virtual char *toChars();
90 virtual dchar
*toDchars();
91 virtual void toBuffer(OutBuffer
*buf
);
94 * Used as a replacement for dynamic_cast. Returns a unique number
95 * defined by the library user. For Object, the return value is 0.
97 virtual int dyncast();
100 * Marks pointers for garbage collector by calling mem.mark() for all pointers into heap.
102 /*virtual*/ // not used, disable for now
106 struct String
: Object
108 int ref
; // != 0 if this is a reference to someone else's string
109 char *str
; // the string itself
111 String(char *str
, int ref
= 1);
115 static hash_t
calcHash(const char *str
, size_t len
);
116 static hash_t
calcHash(const char *str
);
119 int equals(Object
*obj
);
120 int compare(Object
*obj
);
126 struct FileName
: String
128 FileName(char *str
, int ref
);
129 FileName(char *path
, char *name
);
131 int equals(Object
*obj
);
132 int compare(Object
*obj
);
133 static int absolute(const char *name
);
134 static char *ext(const char *);
136 static char *removeExt(const char *str
);
137 static char *name(const char *);
139 static char *path(const char *);
140 static char *replaceName(char *path
, char *name
);
142 static char *combine(char *path
, char *name
);
143 static Array
*splitPath(const char *path
);
144 static FileName
*defaultExt(const char *name
, const char *ext
);
145 static FileName
*forceExt(const char *name
, const char *ext
);
146 int equalsExt(const char *ext
);
148 void CopyTo(FileName
*to
);
149 static char *searchPath(Array
*path
, char *name
, int cwd
);
150 static int exists(const char *name
);
151 static void ensurePathExists(const char *path
);
156 int ref
; // != 0 if this is a reference to someone else's buffer
157 unsigned char *buffer
; // data for our file
158 unsigned len
; // amount of data in buffer[]
159 void *touchtime
; // system time to use for file
161 FileName
*name
; // name of our file
171 /* Read file, return !=0 if error
176 /* Write file, either succeed or fail
177 * with error message & exit.
182 /* Read file, return !=0 if error
187 /* Write file, either succeed or fail
188 * with error message & exit.
193 /* Write file, return !=0 if error
198 /* Write file, either succeed or fail
199 * with error message & exit.
204 /* Return !=0 if file exists.
205 * 0: file doesn't exist
210 /* Append to file, return !=0 if error
215 /* Append to file, either succeed or fail
216 * with error message & exit.
221 /* Return !=0 if file exists.
222 * 0: file doesn't exist
229 /* Given wildcard filespec, return an array of
233 static Array
*match(char *);
234 static Array
*match(FileName
*);
236 // Compare file times.
237 // Return <0 this < f
240 int compareTime(File
*f
);
242 // Read system file statistics
248 void setbuffer(void *buffer
, unsigned len
)
250 this->buffer
= (unsigned char *)buffer
;
254 void checkoffset(size_t offset
, size_t nbytes
);
256 void remove(); // delete file
259 struct OutBuffer
: Object
270 void reserve(unsigned nbytes
);
271 void setsize(unsigned size
);
273 void write(const void *data
, unsigned nbytes
);
274 void writebstring(unsigned char *string
);
275 void writestring(const char *string
);
276 void writedstring(const char *string
);
277 void writedstring(const wchar_t *string
);
278 void prependstring(char *string
);
279 void writenl(); // write newline
280 void writeByte(unsigned b
);
281 void writebyte(unsigned b
) { writeByte(b
); }
282 void writeUTF8(unsigned b
);
283 void writedchar(unsigned b
);
284 void prependbyte(unsigned b
);
285 void writeword(unsigned w
);
286 void writeUTF16(unsigned w
);
287 void write4(unsigned w
);
288 void write(OutBuffer
*buf
);
289 void write(Object
*obj
);
290 void fill0(unsigned nbytes
);
291 void align(unsigned size
);
292 void vprintf(const char *format
, va_list args
);
293 void printf(const char *format
, ...);
295 void vprintf(const unsigned short *format
, va_list args
);
296 void printf(const unsigned short *format
, ...);
298 void bracket(char left
, char right
);
299 unsigned bracket(unsigned i
, char *left
, unsigned j
, char *right
);
300 void spread(unsigned offset
, unsigned nbytes
);
301 unsigned insert(unsigned offset
, const void *data
, unsigned nbytes
);
302 void remove(unsigned offset
, unsigned nbytes
);
304 char *extractString();
307 struct Array
: Object
318 void reserve(unsigned nentries
);
319 void setDim(unsigned newdim
);
321 void push(void *ptr
);
323 void shift(void *ptr
);
324 void insert(unsigned index
, void *ptr
);
325 void insert(unsigned index
, Array
*a
);
326 void append(Array
*a
);
327 void remove(unsigned i
);
344 void resize(unsigned bitdim
);
346 void set(unsigned bitnum
);
347 void clear(unsigned bitnum
);
348 int test(unsigned bitnum
);
352 void copy(Bits
*from
);