 |
Changeset 3891
- Timestamp:
- 08/18/08 19:45:53
(4 months ago)
- Author:
- keinfarbton
- Message:
Fix more compile errors. Files still not compiling:
tango/sys/Environment.d
tango/net/http/HttpTokens.d
tango/net/ftp/FtpClient.d
tango/text/Regex.d
tango/text/stream/RegexIterator.d
tango/io/vfs/VirtualFolder.d
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3888 |
r3891 |
|
| 37 | 37 | class File |
|---|
| 38 | 38 | { |
|---|
| 39 | | private char[] path_; |
|---|
| | 39 | private Cutf8 path_; |
|---|
| 40 | 40 | |
|---|
| 41 | 41 | /*********************************************************************** |
|---|
| r3890 |
r3891 |
|
| 26 | 26 | private import tango.io.Path; |
|---|
| 27 | 27 | |
|---|
| 28 | | private import tango.io.model.IFile : FileConst; |
|---|
| | 28 | private import tango.io.model.IFile/+ : FileConst+/; |
|---|
| 29 | 29 | |
|---|
| 30 | 30 | private import tango.core.Exception : IllegalArgumentException; |
|---|
| r3888 |
r3891 |
|
| 20 | 20 | private import tango.io.FilePath; |
|---|
| 21 | 21 | |
|---|
| | 22 | private import tango.io.device.FileConduit; |
|---|
| | 23 | |
|---|
| 22 | 24 | private import tango.core.Exception; |
|---|
| 23 | 25 | |
|---|
| … | … | |
| 33 | 35 | private import tango.stdc.posix.unistd; |
|---|
| 34 | 36 | |
|---|
| 35 | | private import tango.io.device.FileConduit; |
|---|
| | 37 | //private import tango.io.device.FileConduit; |
|---|
| 36 | 38 | private import Integer = tango.text.convert.Integer; |
|---|
| 37 | 39 | } |
|---|
| … | … | |
| 58 | 60 | ***********************************************************************/ |
|---|
| 59 | 61 | |
|---|
| 60 | | static FilePath toAbsolute (FilePath target, char[] prefix=null) |
|---|
| | 62 | static FilePath toAbsolute (FilePath target, Cutf8 prefix=null) |
|---|
| 61 | 63 | { |
|---|
| 62 | 64 | if (! target.isAbsolute) |
|---|
| … | … | |
| 73 | 75 | |
|---|
| 74 | 76 | Convert the provided path to an absolute path, using the |
|---|
| 75 | | current working directory where prefix is not provided. |
|---|
| 76 | | If the given path is already an absolute path, return it |
|---|
| | 77 | current working directory where prefix is not provided. |
|---|
| | 78 | If the given path is already an absolute path, return it |
|---|
| 77 | 79 | intact. |
|---|
| 78 | 80 | |
|---|
| … | … | |
| 81 | 83 | ***********************************************************************/ |
|---|
| 82 | 84 | |
|---|
| 83 | | static char[] toAbsolute (char[] path, char[] prefix=null) |
|---|
| | 85 | static Cutf8 toAbsolute (Cutf8 path, Cutf8 prefix=null) |
|---|
| 84 | 86 | { |
|---|
| 85 | 87 | scope target = new FilePath (path); |
|---|
| … | … | |
| 98 | 100 | ***********************************************************************/ |
|---|
| 99 | 101 | |
|---|
| 100 | | static bool equals (char[] path1, char[] path2, char[] prefix=null) |
|---|
| | 102 | static bool equals (Cutf8 path1, Cutf8 path2, Cutf8 prefix=null) |
|---|
| 101 | 103 | { |
|---|
| 102 | 104 | scope p1 = new FilePath (path1); |
|---|
| … | … | |
| 126 | 128 | ***************************************************************/ |
|---|
| 127 | 129 | |
|---|
| 128 | | static void setDirectory (char[] path) |
|---|
| | 130 | static void setDirectory (Cutf8 path) |
|---|
| 129 | 131 | { |
|---|
| 130 | 132 | version (Win32SansUnicode) |
|---|
| … | … | |
| 143 | 145 | assert (path.length < tmp.length); |
|---|
| 144 | 146 | auto i = MultiByteToWideChar (CP_UTF8, 0, |
|---|
| 145 | | cast(PCHAR)path.ptr, path.length, |
|---|
| | 147 | cast(PCHAR)path.ptr, path.length, |
|---|
| 146 | 148 | tmp.ptr, tmp.length); |
|---|
| 147 | 149 | tmp[i] = 0; |
|---|
| … | … | |
| 158 | 160 | ***************************************************************/ |
|---|
| 159 | 161 | |
|---|
| 160 | | static char[] getDirectory () |
|---|
| | 162 | static Cutf8 getDirectory () |
|---|
| 161 | 163 | { |
|---|
| 162 | 164 | char[] path; |
|---|
| … | … | |
| 169 | 171 | if (len) |
|---|
| 170 | 172 | { |
|---|
| 171 | | dir[len-1] = '/'; |
|---|
| | 173 | dir[len-1] = '/'; |
|---|
| 172 | 174 | path = standard (dir); |
|---|
| 173 | 175 | } |
|---|
| … | … | |
| 198 | 200 | |
|---|
| 199 | 201 | /*************************************************************** |
|---|
| 200 | | |
|---|
| | 202 | |
|---|
| 201 | 203 | List the set of root devices (C:, D: etc) |
|---|
| 202 | 204 | |
|---|
| … | … | |
| 235 | 237 | ***************************************************************/ |
|---|
| 236 | 238 | |
|---|
| 237 | | static void setDirectory (char[] path) |
|---|
| | 239 | static void setDirectory (Cutf8 path) |
|---|
| 238 | 240 | { |
|---|
| 239 | 241 | char[512] tmp = void; |
|---|
| … | … | |
| 251 | 253 | ***************************************************************/ |
|---|
| 252 | 254 | |
|---|
| 253 | | static char[] getDirectory () |
|---|
| | 255 | static Cutf8 getDirectory () |
|---|
| 254 | 256 | { |
|---|
| 255 | 257 | char[512] tmp = void; |
|---|
| … | … | |
| 270 | 272 | ***************************************************************/ |
|---|
| 271 | 273 | |
|---|
| 272 | | static char[][] roots () |
|---|
| | 274 | static Cutf8[] roots () |
|---|
| 273 | 275 | { |
|---|
| 274 | 276 | version(darwin) |
|---|
| … | … | |
| 278 | 280 | else |
|---|
| 279 | 281 | { |
|---|
| 280 | | char[] path = ""; |
|---|
| 281 | | char[][] list; |
|---|
| | 282 | Cutf8 path; |
|---|
| | 283 | Cutf8[] list; |
|---|
| 282 | 284 | int spaces; |
|---|
| 283 | 285 | |
|---|
| … | … | |
| 285 | 287 | scope (exit) |
|---|
| 286 | 288 | fc.close; |
|---|
| 287 | | |
|---|
| | 289 | |
|---|
| 288 | 290 | auto content = new char[cast(int) fc.length]; |
|---|
| 289 | 291 | fc.input.read (content); |
|---|
| 290 | | |
|---|
| | 292 | |
|---|
| 291 | 293 | for(int i = 0; i < content.length; i++) |
|---|
| 292 | 294 | { |
|---|
| … | … | |
| 296 | 298 | spaces = 0; |
|---|
| 297 | 299 | list ~= path; |
|---|
| 298 | | path = ""; |
|---|
| | 300 | path = null; |
|---|
| 299 | 301 | } |
|---|
| 300 | 302 | else if(spaces == 1) |
|---|
| … | … | |
| 308 | 310 | } |
|---|
| 309 | 311 | } |
|---|
| 310 | | |
|---|
| | 312 | |
|---|
| 311 | 313 | return list; |
|---|
| 312 | 314 | } |
|---|
| r3890 |
r3891 |
|
| 53 | 53 | private import tango.sys.Common; |
|---|
| 54 | 54 | |
|---|
| 55 | | private import tango.io.model.IFile : FileConst; |
|---|
| | 55 | private import tango.io.model.IFile/+ : FileConst+/; |
|---|
| 56 | 56 | |
|---|
| 57 | 57 | public import tango.time.Time : Time, TimeSpan; |
|---|
| 58 | 58 | |
|---|
| 59 | | public import tango.core.Exception : IOException, IllegalArgumentException; |
|---|
| | 59 | public import tango.core.Exception/+ : IOException, IllegalArgumentException+/; |
|---|
| 60 | 60 | |
|---|
| 61 | 61 | |
|---|
| r3888 |
r3891 |
|
| 76 | 76 | wchar[MAX_PATH+1] tmp = void; |
|---|
| 77 | 77 | assert (fn.length < tmp.length); |
|---|
| 78 | | auto i = MultiByteToWideChar (CP_UTF8, 0, cast(PCHAR) fn.ptr, |
|---|
| | 78 | auto i = MultiByteToWideChar (CP_UTF8, 0, cast(PCHAR) fn.ptr, |
|---|
| 79 | 79 | fn.length, tmp.ptr, tmp.length); |
|---|
| 80 | 80 | tmp[i] = 0; |
|---|
| … | … | |
| 94 | 94 | |
|---|
| 95 | 95 | auto dir = new char [len * 3]; |
|---|
| 96 | | auto i = WideCharToMultiByte (CP_UTF8, 0, result.ptr, len, |
|---|
| | 96 | auto i = WideCharToMultiByte (CP_UTF8, 0, result.ptr, len, |
|---|
| 97 | 97 | cast(PCHAR) dir.ptr, dir.length, null, null); |
|---|
| 98 | 98 | return Path.standard (dir[0..i]); |
|---|
| … | … | |
| 128 | 128 | import tango.stdc.posix.unistd : access, getuid, lseek, unlink, W_OK; |
|---|
| 129 | 129 | import tango.stdc.posix.sys.stat : stat, stat_t; |
|---|
| 130 | | |
|---|
| | 130 | |
|---|
| 131 | 131 | import tango.sys.Environment : Environment; |
|---|
| 132 | 132 | |
|---|
| … | … | |
| 181 | 181 | * { |
|---|
| 182 | 182 | * scope temp = new TempFile; |
|---|
| 183 | | * |
|---|
| | 183 | * |
|---|
| 184 | 184 | * // Use temp as a normal conduit; it will be automatically closed when |
|---|
| 185 | 185 | * // it goes out of scope. |
|---|
| … | … | |
| 217 | 217 | |
|---|
| 218 | 218 | /************************************************************************** |
|---|
| 219 | | * |
|---|
| | 219 | * |
|---|
| 220 | 220 | * This enumeration is used to control whether the temporary file should |
|---|
| 221 | 221 | * persist after the TempFile object has been destroyed. |
|---|
| … | … | |
| 266 | 266 | |
|---|
| 267 | 267 | /************************************************************************** |
|---|
| 268 | | * |
|---|
| | 268 | * |
|---|
| 269 | 269 | * This structure is used to determine how the temporary files should be |
|---|
| 270 | 270 | * opened and used. |
|---|
| … | … | |
| 294 | 294 | |
|---|
| 295 | 295 | // Path to the temporary file |
|---|
| 296 | | private char[] _path; |
|---|
| | 296 | private Cutf8 _path; |
|---|
| 297 | 297 | |
|---|
| 298 | 298 | // Style we've opened with |
|---|
| … | … | |
| 309 | 309 | |
|---|
| 310 | 310 | /// |
|---|
| 311 | | this(char[] prefix, Style style = Style.init) |
|---|
| | 311 | this(Cutf8 prefix, Style style = Style.init) |
|---|
| 312 | 312 | { |
|---|
| 313 | 313 | create (prefix, style); |
|---|
| … | … | |
| 332 | 332 | * |
|---|
| 333 | 333 | **************************************************************************/ |
|---|
| 334 | | char[] path() |
|---|
| | 334 | Cutf8 path() |
|---|
| 335 | 335 | { |
|---|
| 336 | 336 | return _path; |
|---|
| … | … | |
| 347 | 347 | } |
|---|
| 348 | 348 | |
|---|
| 349 | | override char[] toString() |
|---|
| | 349 | override Cutf8 toString() |
|---|
| 350 | 350 | { |
|---|
| 351 | 351 | if( path.length > 0 ) |
|---|
| … | … | |
| 387 | 387 | } |
|---|
| 388 | 388 | |
|---|
| 389 | | private void create(char[] prefix, Style style) |
|---|
| | 389 | private void create(Cutf8 prefix, Style style) |
|---|
| 390 | 390 | { |
|---|
| 391 | 391 | for( size_t i=0; i<style.attempts; ++i ) |
|---|
| … | … | |
| 404 | 404 | private static const DEFAULT_SUFFIX = ".tmp"; |
|---|
| 405 | 405 | |
|---|
| 406 | | private static const JUNK_CHARS = |
|---|
| | 406 | private static const JUNK_CHARS = |
|---|
| 407 | 407 | "abcdefghijklmnopqrstuvwxyz0123456789"; |
|---|
| 408 | 408 | |
|---|
| … | … | |
| 410 | 410 | * Returns the path to the temporary directory. |
|---|
| 411 | 411 | */ |
|---|
| 412 | | public static char[] tempPath() |
|---|
| | 412 | public static Cutf8 tempPath() |
|---|
| 413 | 413 | { |
|---|
| 414 | 414 | return GetTempPath; |
|---|
| … | … | |
| 419 | 419 | * style. |
|---|
| 420 | 420 | */ |
|---|
| 421 | | private bool create_path(char[] path, Style style) |
|---|
| | 421 | private bool create_path(Cutf8 path, Style style) |
|---|
| 422 | 422 | { |
|---|
| 423 | 423 | // TODO: Check permissions directly and throw an exception; |
|---|
| … | … | |
| 463 | 463 | { |
|---|
| 464 | 464 | LONG high = cast(LONG) (offset >> 32); |
|---|
| 465 | | long result = SetFilePointer (handle, cast(LONG) offset, |
|---|
| | 465 | long result = SetFilePointer (handle, cast(LONG) offset, |
|---|
| 466 | 466 | &high, anchor); |
|---|
| 467 | 467 | |
|---|
| 468 | | if (result is -1 && |
|---|
| | 468 | if (result is -1 && |
|---|
| 469 | 469 | GetLastError() != ERROR_SUCCESS) |
|---|
| 470 | 470 | error(); |
|---|
| … | … | |
| 481 | 481 | private static const DEFAULT_SUFFIX = "~"; |
|---|
| 482 | 482 | |
|---|
| 483 | | private static const JUNK_CHARS = |
|---|
| | 483 | private static const JUNK_CHARS = |
|---|
| 484 | 484 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|---|
| 485 | 485 | "abcdefghijklmnopqrstuvwxyz0123456789"; |
|---|
| … | … | |
| 488 | 488 | * Returns the path to the temporary directory. |
|---|
| 489 | 489 | */ |
|---|
| 490 | | public static char[] tempPath() |
|---|
| | 490 | public static Cutf8 tempPath() |
|---|
| 491 | 491 | { |
|---|
| 492 | 492 | // Check for TMPDIR; failing that, use /tmp |
|---|
| … | … | |
| 501 | 501 | * style. |
|---|
| 502 | 502 | */ |
|---|
| 503 | | private bool create_path(char[] path, Style style) |
|---|
| | 503 | private bool create_path(Cutf8 path, Style style) |
|---|
| 504 | 504 | { |
|---|
| 505 | 505 | // Check suitability |
|---|
| … | … | |
| 521 | 521 | if( pwe is null ) error("could not get root's uid"); |
|---|
| 522 | 522 | auto root_uid = pwe.pw_uid; |
|---|
| 523 | | |
|---|
| | 523 | |
|---|
| 524 | 524 | // Make sure either we or root are the owner |
|---|
| 525 | 525 | if( !(sb.st_uid == root_uid || sb.st_uid == getuid) ) |
|---|
| … | … | |
| 575 | 575 | { |
|---|
| 576 | 576 | /********************************************************************** |
|---|
| 577 | | * |
|---|
| | 577 | * |
|---|
| 578 | 578 | * Seeks the temporary file's cursor to the given location. |
|---|
| 579 | 579 | * |
|---|
| … | … | |
| 582 | 582 | |
|---|
| 583 | 583 | /********************************************************************** |
|---|
| 584 | | * |
|---|
| | 584 | * |
|---|
| 585 | 585 | * Returns the path to the directory where temporary files will be |
|---|
| 586 | 586 | * created. The returned path is safe to mutate. |
|---|
| … | … | |
| 597 | 597 | * Generates a new random file name, sans directory. |
|---|
| 598 | 598 | */ |
|---|
| 599 | | private char[] randomName(uint length=DEFAULT_LENGTH, |
|---|
| 600 | | char[] prefix=DEFAULT_PREFIX, |
|---|
| 601 | | char[] suffix=DEFAULT_SUFFIX) |
|---|
| | 599 | private Cutf8 randomName(uint length=DEFAULT_LENGTH, |
|---|
| | 600 | Cutf8 prefix=DEFAULT_PREFIX, |
|---|
| | 601 | Cutf8 suffix=DEFAULT_SUFFIX) |
|---|
| 602 | 602 | { |
|---|
| 603 | 603 | auto junk = new char[length]; |
|---|
| … | … | |
| 609 | 609 | return prefix~junk~suffix; |
|---|
| 610 | 610 | } |
|---|
| 611 | | |
|---|
| | 611 | |
|---|
| 612 | 612 | override void detach() |
|---|
| 613 | 613 | { |
|---|
| r3890 |
r3891 |
|
| 105 | 105 | static assert( Data.sizeof == 26 ); |
|---|
| 106 | 106 | |
|---|
| 107 | | char[] file_name; |
|---|
| | 107 | Cutf8 file_name; |
|---|
| 108 | 108 | ubyte[] extra_field; |
|---|
| 109 | 109 | |
|---|
| … | … | |
| 264 | 264 | static assert( Data.sizeof == 42 ); |
|---|
| 265 | 265 | |
|---|
| 266 | | char[] file_name; |
|---|
| | 266 | Cutf8 file_name; |
|---|
| 267 | 267 | ubyte[] extra_field; |
|---|
| 268 | | char[] file_comment; |
|---|
| | 268 | Cutf8 file_comment; |
|---|
| 269 | 269 | |
|---|
| 270 | 270 | bool usingDataDescriptor() |
|---|
| … | … | |
| 341 | 341 | //debug(Zip) data.dump; |
|---|
| 342 | 342 | |
|---|
| 343 | | char[] function(ubyte[]) conv_fn; |
|---|
| | 343 | Cutf8 function(ubyte[]) conv_fn; |
|---|
| 344 | 344 | if( usingUtf8 ) |
|---|
| 345 | 345 | conv_fn = &cp437_to_utf8; |
|---|
| … | … | |
| 409 | 409 | static assert( data.sizeof == 18 ); |
|---|
| 410 | 410 | |
|---|
| 411 | | char[] file_comment; |
|---|
| | 411 | Cutf8 file_comment; |
|---|
| 412 | 412 | |
|---|
| 413 | 413 | void[] data_arr() |
|---|
| … | … | |
| 445 | 445 | //data.dump; |
|---|
| 446 | 446 | |
|---|
| 447 | | file_comment = cast(char[]) src[0..data.file_comment_length].dup; |
|---|
| | 447 | file_comment = cast(Cutf8) src[0..data.file_comment_length].dup; |
|---|
| 448 | 448 | } |
|---|
| 449 | 449 | } |
|---|
| … | … | |
| 542 | 542 | { |
|---|
| 543 | 543 | void finish(); |
|---|
| 544 | | void putFile(ZipEntryInfo info, char[] path); |
|---|
| | 544 | void putFile(ZipEntryInfo info, Cutf8 path); |
|---|
| 545 | 545 | deprecated void putFile(ZipEntryInfo info, PathView path); |
|---|
| 546 | | void putFile(ZipEntryInfo info, char[] path); |
|---|
| | 546 | void putFile(ZipEntryInfo info, Cutf8 path); |
|---|
| 547 | 547 | void putStream(ZipEntryInfo info, InputStream source); |
|---|
| 548 | 548 | void putEntry(ZipEntryInfo info, ZipEntry entry); |
|---|
| … | … | |
| 595 | 595 | |
|---|
| 596 | 596 | /// ditto |
|---|
| 597 | | this(char[] path) |
|---|
| | 597 | this(Cutf8 path) |
|---|
| 598 | 598 | { |
|---|
| 599 | 599 | file_source = new FileConduit(path); |
|---|
| … | … | |
| 1000 | 1000 | |
|---|
| 1001 | 1001 | /// ditto |
|---|
| 1002 | | this(char[] path) |
|---|
| | 1002 | this(Cutf8 path) |
|---|
| 1003 | 1003 | { |
|---|
| 1004 | 1004 | file_output = new FileConduit(path, FileConduit.WriteCreate); |
|---|
| … | … | |
| 1048 | 1048 | |
|---|
| 1049 | 1049 | /// ditto |
|---|
| 1050 | | void putFile(ZipEntryInfo info, char[] path) |
|---|
| | 1050 | void putFile(ZipEntryInfo info, Cutf8 path) |
|---|
| 1051 | 1051 | { |
|---|
| 1052 | 1052 | scope file = new FileConduit(path); |
|---|
| … | … | |
| 1102 | 1102 | FileHeaderData data; |
|---|
| 1103 | 1103 | long header_position; |
|---|
| 1104 | | char[] filename; |
|---|
| 1105 | | char[] comment; |
|---|
| | 1104 | Cutf8 filename; |
|---|
| | 1105 | Cutf8 comment; |
|---|
| 1106 | 1106 | ubyte[] extra; |
|---|
| 1107 | 1107 | } |
|---|
| … | … | |
| 1330 | 1330 | */ |
|---|
| 1331 | 1331 | void put_local_header(LocalFileHeaderData data, |
|---|
| 1332 | | char[] file_name) |
|---|
| | 1332 | Cutf8 file_name) |
|---|
| 1333 | 1333 | { |
|---|
| 1334 | 1334 | auto f_name = PathUtil.normalize(file_name); |
|---|
| … | … | |
| 1545 | 1545 | { |
|---|
| 1546 | 1546 | /// Full path and file name of this file. |
|---|
| 1547 | | char[] name; |
|---|
| | 1547 | Cutf8 name; |
|---|
| 1548 | 1548 | /// Modification timestamp. If this is left uninitialised when passed to |
|---|
| 1549 | 1549 | /// a ZipWriter, it will be reset to the current system time. |
|---|
| 1550 | 1550 | Time modified = Time.min; |
|---|
| 1551 | 1551 | /// Comment on the file. |
|---|
| 1552 | | char[] comment; |
|---|
| | 1552 | Cutf8 comment; |
|---|
| 1553 | 1553 | } |
|---|
| 1554 | 1554 | |
|---|
| … | … | |
| 1566 | 1566 | class ZipException : Exception |
|---|
| 1567 | 1567 | { |
|---|
| 1568 | | this(char[] msg) { super(msg); } |
|---|
| | 1568 | this(Cutf8 msg) { super(msg); } |
|---|
| 1569 | 1569 | |
|---|
| 1570 | 1570 | private: |
|---|
| 1571 | 1571 | alias typeof(this) thisT; |
|---|
| 1572 | | static void opCall(char[] msg) { throw new ZipException(msg); } |
|---|
| | 1572 | static void opCall(Cutf8 msg) { throw new ZipException(msg); } |
|---|
| 1573 | 1573 | |
|---|
| 1574 | 1574 | static void badsig() |
|---|
| … | … | |
| 1577 | 1577 | } |
|---|
| 1578 | 1578 | |
|---|
| 1579 | | static void badsig(char[] type) |
|---|
| | 1579 | static void badsig(Cutf8 type) |
|---|
| 1580 | 1580 | { |
|---|
| 1581 | 1581 | thisT("corrupt "~type~" signature or unexpected section found"); |
|---|
| 1582 | 1582 | } |
|---|
| 1583 | 1583 | |
|---|
| 1584 | | static void incons(char[] name) |
|---|
| | 1584 | static void incons(Cutf8 name) |
|---|
| 1585 | 1585 | { |
|---|
| 1586 | 1586 | thisT("inconsistent headers for file \""~name~"\"; " |
|---|
| … | … | |
| 1646 | 1646 | class ZipChecksumException : ZipException |
|---|
| 1647 | 1647 | { |
|---|
| 1648 | | this(char[] name) |
|---|
| | 1648 | this(Cutf8 name) |
|---|
| 1649 | 1649 | { |
|---|
| 1650 | 1650 | super("checksum failed on zip entry \""~name~"\""); |
|---|
| … | … | |
| 1652 | 1652 | |
|---|
| 1653 | 1653 | private: |
|---|
| 1654 | | static void opCall(char[] name) { throw new ZipChecksumException(name); } |
|---|
| | 1654 | static void opCall(Cutf8 name) { throw new ZipChecksumException(name); } |
|---|
| 1655 | 1655 | } |
|---|
| 1656 | 1656 | |
|---|
| … | … | |
| 1673 | 1673 | class ZipNotSupportedException : ZipException |
|---|
| 1674 | 1674 | { |
|---|
| 1675 | | this(char[] msg) { super(msg); } |
|---|
| | 1675 | this(Cutf8 msg) { super(msg); } |
|---|
| 1676 | 1676 | |
|---|
| 1677 | 1677 | private: |
|---|
| 1678 | 1678 | alias ZipNotSupportedException thisT; |
|---|
| 1679 | 1679 | |
|---|
| 1680 | | static void opCall(char[] msg) |
|---|
| | 1680 | static void opCall(Cutf8 msg) |
|---|
| 1681 | 1681 | { |
|---|
| 1682 | 1682 | throw new thisT(msg ~ " not supported"); |
|---|
| … | … | |
| 1709 | 1709 | { |
|---|
| 1710 | 1710 | // Cheat here and work out what the method *actually* is |
|---|
| 1711 | | char[] ms; |
|---|
| | 1711 | Cutf8 ms; |
|---|
| 1712 | 1712 | switch( m ) |
|---|
| 1713 | 1713 | { |
|---|
| … | … | |
| 1746 | 1746 | // Convenience methods |
|---|
| 1747 | 1747 | |
|---|
| 1748 | | void createArchive(char[] archive, Method method, char[][] files...) |
|---|
| | 1748 | void createArchive(Cutf8 archive, Method method, Cutf8[] files...) |
|---|
| 1749 | 1749 | { |
|---|
| 1750 | 1750 | scope zw = new ZipBlockWriter(archive); |
|---|
| … | … | |
| 1768 | 1768 | } |
|---|
| 1769 | 1769 | |
|---|
| 1770 | | deprecated void extractArchive(FilePath archive, char[] folder) |
|---|
| | 1770 | deprecated void extractArchive(FilePath archive, Cutf8 folder) |
|---|
| 1771 | 1771 | { |
|---|
| 1772 | 1772 | extractArchive(archive, folder); |
|---|
| … | … | |
| 1778 | 1778 | } |
|---|
| 1779 | 1779 | |
|---|
| 1780 | | void extractArchive(char[] archive, char[] dest) |
|---|
| | 1780 | void extractArchive(Cutf8 archive, Cutf8 dest) |
|---|
| 1781 | 1781 | { |
|---|
| 1782 | 1782 | scope zr = new ZipBlockReader(archive); |
|---|
| … | … | |
| 1910 | 1910 | * Really, seriously, write some bytes. |
|---|
| 1911 | 1911 | */ |
|---|
| 1912 | | void writeExact(OutputStream s, void[] src) |
|---|
| | 1912 | void writeExact(OutputStream s, const(void)[] src) |
|---|
| 1913 | 1913 | { |
|---|
| 1914 | 1914 | while( src.length > 0 ) |
|---|
| … | … | |
| 1968 | 1968 | // |
|---|
| 1969 | 1969 | |
|---|
| 1970 | | const char[][] cp437_to_utf8_map_low = [ |
|---|
| | 1970 | const Cutf8[] cp437_to_utf8_map_low = [ |
|---|
| 1971 | 1971 | "\u0000"[], "\u263a", "\u263b", "\u2665", |
|---|
| 1972 | 1972 | "\u2666", "\u2663", "\u2660", "\u2022", |
|---|
| … | … | |
| 1980 | 1980 | ]; |
|---|
| 1981 | 1981 | |
|---|
| 1982 | | const char[][] cp437_to_utf8_map_high = [ |
|---|
| | 1982 | const Cutf8[] cp437_to_utf8_map_high = [ |
|---|
| 1983 | 1983 | "\u00c7"[], "\u00fc", "\u00e9", "\u00e2", |
|---|
| 1984 | 1984 | "\u00e4", "\u00e0", "\u00e5", "\u00e7", |
|---|
| … | … | |
| 2021 | 2021 | ]; |
|---|
| 2022 | 2022 | |
|---|
| 2023 | | char[] cp437_to_utf8(ubyte[] s) |
|---|
| | 2023 | Cutf8 cp437_to_utf8(ubyte[] s) |
|---|
| 2024 | 2024 | { |
|---|
| 2025 | 2025 | foreach( i,c ; s ) |
|---|
| … | … | |
| 2034 | 2034 | */ |
|---|
| 2035 | 2035 | auto r = new char[i+2*(s.length-i)]; |
|---|
| 2036 | | r[0..i] = cast(char[]) s[0..i]; |
|---|
| | 2036 | r[0..i] = cast(Cutf8) s[0..i]; |
|---|
| 2037 | 2037 | size_t k=i; // current length |
|---|
| 2038 | 2038 | |
|---|
| … | … | |
| 2047 | 2047 | else if( 1 <= d && d <= 31 ) |
|---|
| 2048 | 2048 | { |
|---|
| 2049 | | char[] repl = cp437_to_utf8_map_low[d]; |
|---|
| | 2049 | Cutf8 repl = cp437_to_utf8_map_low[d]; |
|---|
| 2050 | 2050 | r[k..k+repl.length] = repl[]; |
|---|
| 2051 | 2051 | k += repl.length; |
|---|
| … | … | |
| 2053 | 2053 | else if( d == 127 ) |
|---|
| 2054 | 2054 | { |
|---|
| 2055 | | char[] repl = "\u2302"; |
|---|
| | 2055 | Cutf8 repl = "\u2302"; |
|---|
| 2056 | 2056 | r[k..k+repl.length] = repl[]; |
|---|
| 2057 | 2057 | k += repl.length; |
|---|
| … | … | |
| 2059 | 2059 | else if( d > 127 ) |
|---|
| 2060 | 2060 | { |
|---|
| 2061 | | char[] repl = cp437_to_utf8_map_high[d-128]; |
|---|
| | 2061 | Cutf8 repl = cp437_to_utf8_map_high[d-128]; |
|---|
| 2062 | 2062 | r[k..k+repl.length] = repl[]; |
|---|
| 2063 | 2063 | k += repl.length; |
|---|
| … | … | |
| 2074 | 2074 | * means it's also valid UTF-8; return the string unmodified. |
|---|
| 2075 | 2075 | */ |
|---|
| 2076 | | return cast(char[]) s; |
|---|
| | 2076 | return cast(Cutf8) s; |
|---|
| 2077 | 2077 | } |
|---|
| 2078 | 2078 | |
|---|
| … | … | |
| 2081 | 2081 | unittest |
|---|
| 2082 | 2082 | { |
|---|
| 2083 | | char[] c(char[] s) { return cp437_to_utf8(cast(ubyte[]) s); } |
|---|
| | 2083 | Cutf8 c(Cutf8 s) { return cp437_to_utf8(cast(ubyte[]) s); } |
|---|
| 2084 | 2084 | |
|---|
| 2085 | 2085 | auto s = c("Hi there \x01 old \x0c!"); |
|---|
| … | … | |
| 2151 | 2151 | } |
|---|
| 2152 | 2152 | |
|---|
| 2153 | | ubyte[] utf8_to_cp437(char[] s) |
|---|
| | 2153 | ubyte[] utf8_to_cp437(Cutf8 s) |
|---|
| 2154 | 2154 | { |
|---|
| 2155 | 2155 | foreach( i,dchar c ; s ) |
|---|
| … | … | |
| 2234 | 2234 | * This is here to simplify the code elsewhere. |
|---|
| 2235 | 2235 | */ |
|---|
| 2236 | | char[] utf8_to_utf8(ubyte[] s) { return cast(char[]) s; } |
|---|
| 2237 | | ubyte[] utf8_to_utf8(char[] s) { return cast(ubyte[]) s; } |
|---|
| | 2236 | Cutf8 utf8_to_utf8(ubyte[] s) { return cast(Cutf8) s; } |
|---|
| | 2237 | ubyte[] utf8_to_utf8(Cutf8 s) { return cast(ubyte[]) s; } |
|---|
| 2238 | 2238 | |
|---|
| 2239 | 2239 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| … | … | |
| 2389 | 2389 | } |
|---|
| 2390 | 2390 | |
|---|
| 2391 | | override uint write(void[] dst) |
|---|
| | 2391 | override uint write(const(void)[] dst) |
|---|
| 2392 | 2392 | { |
|---|
| 2393 | 2393 | auto wrote = output.write(dst); |
|---|
| … | … | |
| 2667 | 2667 | } |
|---|
| 2668 | 2668 | |
|---|
| 2669 | | uint write(void[] src) |
|---|
| | 2669 | override uint write(const(void)[] src) |
|---|
| 2670 | 2670 | { |
|---|
| 2671 | 2671 | // If we're at the end of the slice, return eof |
|---|
| … | … | |
| 2904 | 2904 | } |
|---|
| 2905 | 2905 | |
|---|
| 2906 | | uint write(void[] src) |
|---|
| | 2906 | override uint write(const(void)[] src) |
|---|
| 2907 | 2907 | { |
|---|
| 2908 | 2908 | if( seeker.seek(0, Anchor.Current) != _position ) |
|---|
| r3888 |
r3891 |
|
| 5 | 5 | license: BSD style: $(LICENSE) |
|---|
| 6 | 6 | |
|---|
| 7 | | version: Mar 2004: Initial release |
|---|
| | 7 | version: Mar 2004: Initial release |
|---|
| 8 | 8 | Dec 2006: Outback release |
|---|
| 9 | | |
|---|
| 10 | | author: Kris, |
|---|
| 11 | | John Reimer, |
|---|
| | 9 | |
|---|
| | 10 | author: Kris, |
|---|
| | 11 | John Reimer, |
|---|
| 12 | 12 | Anders F Bjorklund (Darwin patches), |
|---|
| 13 | 13 | Chris Sauls (Win95 file support) |
|---|
| … | … | |
| 44 | 44 | are the primary means of accessing external data and FileConduit |
|---|
| 45 | 45 | extends the basic pattern by providing file-specific methods to |
|---|
| 46 | | set the file size, seek to a specific file position and so on. |
|---|
| 47 | | |
|---|
| | 46 | set the file size, seek to a specific file position and so on. |
|---|
| | 47 | |
|---|
| 48 | 48 | Serial input and output is straightforward. In this example we |
|---|
| 49 | 49 | copy a file directly to the console: |
|---|
| … | … | |
| 64 | 64 | to.output.copy (new FileConduit("test.txt")); |
|---|
| 65 | 65 | --- |
|---|
| 66 | | |
|---|
| | 66 | |
|---|
| 67 | 67 | To load a file directly into memory one might do this: |
|---|
| 68 | 68 | --- |
|---|
| … | … | |
| 111 | 111 | --- |
|---|
| 112 | 112 | |
|---|
| 113 | | See File, FilePath, FileScan, and FileSystem for |
|---|
| 114 | | additional functionality related to file manipulation. |
|---|
| 115 | | |
|---|
| 116 | | Compile with -version=Win32SansUnicode to enable Win95 & Win32s file |
|---|
| | 113 | See File, FilePath, FileScan, and FileSystem for |
|---|
| | 114 | additional functionality related to file manipulation. |
|---|
| | 115 | |
|---|
| | 116 | Compile with -version=Win32SansUnicode to enable Win95 & Win32s file |
|---|
| 117 | 117 | support. |
|---|
| 118 | | |
|---|
| | 118 | |
|---|
| 119 | 119 | *******************************************************************************/ |
|---|
| 120 | 120 | |
|---|
| 121 | 121 | class FileConduit : DeviceConduit, DeviceConduit.Seek |
|---|
| 122 | 122 | { |
|---|
| 123 | | /*********************************************************************** |
|---|
| 124 | | |
|---|
| 125 | | Fits into 32 bits ... |
|---|
| 126 | | |
|---|
| 127 | | ***********************************************************************/ |
|---|
| 128 | | |
|---|
| 129 | | struct Style |
|---|
| 130 | | { |
|---|
| 131 | | align (1): |
|---|
| 132 | | |
|---|
| 133 | | Access access; /// access rights |
|---|
| 134 | | Open open; /// how to open |
|---|
| 135 | | Share share; /// how to share |
|---|
| 136 | | Cache cache; /// how to cache |
|---|
| 137 | | } |
|---|
| 138 | | |
|---|
| 139 | 123 | /*********************************************************************** |
|---|
| 140 | 124 | |
|---|
| … | … | |
| 148 | 132 | |
|---|
| 149 | 133 | /*********************************************************************** |
|---|
| 150 | | |
|---|
| | 134 | |
|---|
| 151 | 135 | ***********************************************************************/ |
|---|
| 152 | 136 | |
|---|
| … | … | |
| 159 | 143 | |
|---|
| 160 | 144 | /*********************************************************************** |
|---|
| 161 | | |
|---|
| | 145 | |
|---|
| 162 | 146 | ***********************************************************************/ |
|---|
| 163 | 147 | |
|---|
| … | … | |
| 169 | 153 | |
|---|
| 170 | 154 | /*********************************************************************** |
|---|
| 171 | | |
|---|
| | 155 | |
|---|
| 172 | 156 | ***********************************************************************/ |
|---|
| 173 | 157 | |
|---|
| … | … | |
| 181 | 165 | /*********************************************************************** |
|---|
| 182 | 166 | |
|---|
| | 167 | Fits into 32 bits ... |
|---|
| | 168 | |
|---|
| | 169 | ***********************************************************************/ |
|---|
| | 170 | |
|---|
| | 171 | struct Style |
|---|
| | 172 | { |
|---|
| | 173 | align (1): |
|---|
| | 174 | |
|---|
| | 175 | Access access; /// access rights |
|---|
| | 176 | Open open; /// how to open |
|---|
| | 177 | Share share; /// how to share |
|---|
| | 178 | Cache cache; /// how to cache |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | /*********************************************************************** |
|---|
| | 182 | |
|---|
| 183 | 183 | Read an existing file |
|---|
| 184 | | |
|---|
| | 184 | |
|---|
| 185 | 185 | ***********************************************************************/ |
|---|
| 186 | 186 | |
|---|
| … | … | |
| 188 | 188 | |
|---|
| 189 | 189 | /*********************************************************************** |
|---|
| 190 | | |
|---|
| | 190 | |
|---|
| 191 | 191 | Write on an existing file. Do not create |
|---|
| 192 | 192 | |
|---|
| … | … | |
| 196 | 196 | |
|---|
| 197 | 197 | /*********************************************************************** |
|---|
| 198 | | |
|---|
| | 198 | |
|---|
| 199 | 199 | Write on a clean file. Create if necessary |
|---|
| 200 | 200 | |
|---|
| … | … | |
| 204 | 204 | |
|---|
| 205 | 205 | /*********************************************************************** |
|---|
| 206 | | |
|---|
| | 206 | |
|---|
| 207 | 207 | Write at the end of the file |
|---|
| 208 | 208 | |
|---|
| … | … | |
| 212 | 212 | |
|---|
| 213 | 213 | /*********************************************************************** |
|---|
| 214 | | |
|---|
| | 214 | |
|---|
| 215 | 215 | Read and write an existing file |
|---|
| 216 | 216 | |
|---|
| 217 | 217 | ***********************************************************************/ |
|---|
| 218 | 218 | |
|---|
| 219 | | const Style ReadWriteExisting = {Access.ReadWrite, Open.Exists}; |
|---|
| 220 | | |
|---|
| 221 | | /*********************************************************************** |
|---|
| 222 | | |
|---|
| | 219 | const Style ReadWriteExisting = {Access.ReadWrite, Open.Exists}; |
|---|
| | 220 | |
|---|
| | 221 | /*********************************************************************** |
|---|
| | 222 | |
|---|
| 223 | 223 | Read & write on a clean file. Create if necessary |
|---|
| 224 | 224 | |
|---|
| 225 | 225 | ***********************************************************************/ |
|---|
| 226 | 226 | |
|---|
| 227 | | const Style ReadWriteCreate = {Access.ReadWrite, Open.Create}; |
|---|
| 228 | | |
|---|
| 229 | | /*********************************************************************** |
|---|
| 230 | | |
|---|
| | 227 | const Style ReadWriteCreate = {Access.ReadWrite, Open.Create}; |
|---|
| | 228 | |
|---|
| | 229 | /*********************************************************************** |
|---|
| | 230 | |
|---|
| 231 | 231 | Read and Write. Use existing file if present |
|---|
| 232 | 232 | |
|---|
| 233 | 233 | ***********************************************************************/ |
|---|
| 234 | 234 | |
|---|
| 235 | | const Style ReadWriteOpen = {Access.ReadWrite, Open.Sedate}; |
|---|
| 236 | | |
|---|
| 237 | | |
|---|
| 238 | | |
|---|
| 239 | | |
|---|
| 240 | | // the file we're working with |
|---|
| | 235 | const Style ReadWriteOpen = {Access.ReadWrite, Open.Sedate}; |
|---|
| | 236 | |
|---|
| | 237 | |
|---|
| | 238 | |
|---|
| | 239 | |
|---|
| | 240 | // the file we're working with |
|---|
| 241 | 241 | private char[] path_; |
|---|
| 242 | 242 | |
|---|
| … | … | |
| 245 | 245 | |
|---|
| 246 | 246 | /*********************************************************************** |
|---|
| 247 | | |
|---|
| | 247 | |
|---|
| 248 | 248 | Create a FileConduit for use with open() |
|---|
| 249 | 249 | |
|---|
| … | … | |
| 255 | 255 | |
|---|
| 256 | 256 | /*********************************************************************** |
|---|
| 257 | | |
|---|
| | 257 | |
|---|
| 258 | 258 | Create a FileConduit with the provided path and style. |
|---|
| 259 | 259 | |
|---|
| 260 | 260 | ***********************************************************************/ |
|---|
| 261 | 261 | |
|---|
| 262 | | this (char[] path, Style style = ReadExisting) |
|---|
| | 262 | this (Cutf8 path, Style style = ReadExisting) |
|---|
| 263 | 263 | { |
|---|
| 264 | 264 | open (path, style); |
|---|
| … | … | |
| 266 | 266 | |
|---|
| 267 | 267 | /*********************************************************************** |
|---|
| 268 | | |
|---|
| | 268 | |
|---|
| 269 | 269 | Create a FileConduit with the provided path and style. |
|---|
| 270 | 270 | |
|---|
| … | … | |
| 276 | 276 | { |
|---|
| 277 | 277 | this (path.toString, style); |
|---|
| 278 | | } |
|---|
| 279 | | |
|---|
| 280 | | /*********************************************************************** |
|---|
| 281 | | |
|---|
| | 278 | } |
|---|
| | 279 | |
|---|
| | 280 | /*********************************************************************** |
|---|
| | 281 | |
|---|
| 282 | 282 | Return the PathView used by this file. |
|---|
| 283 | 283 | |
|---|
| … | … | |
| 290 | 290 | // return something useful in the interim |
|---|
| 291 | 291 | return new FilePath (path_); |
|---|
| 292 | | } |
|---|
| 293 | | |
|---|
| 294 | | /*********************************************************************** |
|---|
| 295 | | |
|---|
| | 292 | } |
|---|
| | 293 | |
|---|
| | 294 | /************************************************ |
|---|
|