56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#import "OFInvalidEncodingException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
static of_string_encoding_t
codepageToEncoding(UINT codepage)
{
switch (codepage) {
case 437:
return OF_STRING_ENCODING_CODEPAGE_437;
case 850:
return OF_STRING_ENCODING_CODEPAGE_850;
case 858:
return OF_STRING_ENCODING_CODEPAGE_858;
case 1251:
return OF_STRING_ENCODING_WINDOWS_1251;
case 1252:
return OF_STRING_ENCODING_WINDOWS_1252;
default:
@throw [OFInvalidEncodingException exception];
}
}
@implementation OFWin32ConsoleStdIOStream
+ (void)load
|
|
|
|
|
|
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#import "OFInvalidEncodingException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
static OFStringEncoding
codepageToEncoding(UINT codepage)
{
switch (codepage) {
case 437:
return OFStringEncodingCodepage437;
case 850:
return OFStringEncodingCodepage850;
case 858:
return OFStringEncodingCodepage858;
case 1251:
return OFStringEncodingWindows1251;
case 1252:
return OFStringEncodingWindows1252;
default:
@throw [OFInvalidEncodingException exception];
}
}
@implementation OFWin32ConsoleStdIOStream
+ (void)load
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
if (!ReadConsoleW(_handle, UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2
errNo: EIO];
} else {
of_string_encoding_t encoding;
OFString *string;
size_t stringLen;
if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
|
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
if (!ReadConsoleW(_handle, UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2
errNo: EIO];
} else {
OFStringEncoding encoding;
OFString *string;
size_t stringLen;
if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
|
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString
stringWithUTF16String: UTF16
length: UTF16Len];
of_string_encoding_t encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString
stringWithUTF16String: UTF16
length: UTF16Len];
OFStringEncoding encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
requestedLength: j * 2
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString stringWithUTF16String: tmp
length: j];
of_string_encoding_t encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
requestedLength: j * 2
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString stringWithUTF16String: tmp
length: j];
OFStringEncoding encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|