Index: src/OFStdIOStream+Private.h ================================================================== --- src/OFStdIOStream+Private.h +++ src/OFStdIOStream+Private.h @@ -17,14 +17,16 @@ OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFStdIOStream () -#ifndef OF_AMIGAOS -- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init); -#else +#if defined(OF_AMIGAOS) - (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable OF_METHOD_FAMILY(init); +#elif defined(OF_WII_U) +- (instancetype)of_init OF_METHOD_FAMILY(init); +#else +- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init); #endif @end OF_ASSUME_NONNULL_END Index: src/OFStdIOStream.h ================================================================== --- src/OFStdIOStream.h +++ src/OFStdIOStream.h @@ -36,19 +36,19 @@ */ #ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H OF_SUBCLASSING_RESTRICTED #endif @interface OFStdIOStream: OFStream -#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) +#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U) #endif { -#ifndef OF_AMIGAOS - int _fd; -#else +#if defined(OF_AMIGAOS) BPTR _handle; bool _closable; +#elif !defined(OF_WII_U) + int _fd; #endif bool _atEndOfStream; } /** Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -49,10 +49,16 @@ #ifdef OF_AMIGAOS # include # include # undef HAVE_ISATTY #endif + +#ifdef OF_WII_U +# define BOOL WUT_BOOL +# include +# undef BOOL +#endif /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFWin32ConsoleStdIOStream(void) @@ -106,11 +112,11 @@ date.microsecond / 1000, me, getpid(), msg]; objc_autoreleasePoolPop(pool); } -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) static int colorToANSI(OFColor *color) { if ([color isEqual: [OFColor black]]) return 30; @@ -154,22 +160,11 @@ + (void)load { if (self != [OFStdIOStream class]) return; -# ifndef OF_AMIGAOS - int fd; - - if ((fd = fileno(stdin)) >= 0) - OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; - if ((fd = fileno(stdout)) >= 0) - OFStdOut = [[OFStdIOStream alloc] - of_initWithFileDescriptor: fd]; - if ((fd = fileno(stderr)) >= 0) - OFStdErr = [[OFStdIOStream alloc] - of_initWithFileDescriptor: fd]; -# else +# if defined(OF_AMIGAOS) BPTR input, output, error; bool inputClosable = false, outputClosable = false, errorClosable = false; input = Input(); @@ -195,69 +190,112 @@ closable: inputClosable]; OFStdOut = [[OFStdIOStream alloc] of_initWithHandle: output closable: outputClosable]; OFStdErr = [[OFStdIOStream alloc] of_initWithHandle: error closable: errorClosable]; +# elif defined(OF_WII_U) + OFStdOut = [[OFStdIOStream alloc] of_init]; + OFStdErr = [[OFStdIOStream alloc] of_init]; +# else + int fd; + + if ((fd = fileno(stdin)) >= 0) + OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; + if ((fd = fileno(stdout)) >= 0) + OFStdOut = [[OFStdIOStream alloc] + of_initWithFileDescriptor: fd]; + if ((fd = fileno(stderr)) >= 0) + OFStdErr = [[OFStdIOStream alloc] + of_initWithFileDescriptor: fd]; # endif } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } -#ifndef OF_AMIGAOS -- (instancetype)of_initWithFileDescriptor: (int)fd -{ - self = [super init]; - - _fd = fd; - - return self; -} -#else +#if defined(OF_AMIGAOS) - (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable { self = [super init]; _handle = handle; _closable = closable; return self; } +#elif defined(OF_WII_U) +- (instancetype)of_init +{ + return [super init]; +} +#else +- (instancetype)of_initWithFileDescriptor: (int)fd +{ + self = [super init]; + + _fd = fd; + + return self; +} #endif - (void)dealloc { -#ifndef OF_AMIGAOS - if (_fd != -1) -#else +#if defined(OF_AMIGAOS) if (_handle != 0) -#endif + [self close]; +#elif !defined(OF_WII_U) + if (_fd != -1) [self close]; +#endif [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { -#ifndef OF_AMIGAOS - if (_fd == -1) -#else +#if defined(OF_AMIGAOS) if (_handle == 0) -#endif + @throw [OFNotOpenException exceptionWithObject: self]; +#elif !defined(OF_WII_U) + if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; +#endif return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { +#if defined(OF_AMIGAOS) + ssize_t ret; + + if (_handle == 0) + @throw [OFNotOpenException exceptionWithObject: self]; + + if (length > LONG_MAX) + @throw [OFOutOfRangeException exception]; + + if ((ret = Read(_handle, buffer, length)) < 0) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length + errNo: EIO]; + + if (ret == 0) + _atEndOfStream = true; + + return ret; +#elif defined(OF_WII_U) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length + errNo: EOPNOTSUPP]; +#else ssize_t ret; -#ifndef OF_AMIGAOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @@ -271,32 +309,41 @@ if ((ret = read(_fd, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; # endif -#else - if (_handle == 0) - @throw [OFNotOpenException exceptionWithObject: self]; - - if (length > LONG_MAX) - @throw [OFOutOfRangeException exception]; - - if ((ret = Read(_handle, buffer, length)) < 0) - @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length - errNo: EIO]; -#endif if (ret == 0) _atEndOfStream = true; return ret; +#endif } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { -#ifndef OF_AMIGAOS +#if defined(OF_AMIGAOS) + LONG bytesWritten; + + if (_handle == 0) + @throw [OFNotOpenException exceptionWithObject: self]; + + if (length > SSIZE_MAX) + @throw [OFOutOfRangeException exception]; + + if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length + bytesWritten: 0 + errNo: EIO]; + + return (size_t)bytesWritten; +#elif defined(OF_WII_U) + OSConsoleWrite(buffer, length); + + return length; +#else if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS ssize_t bytesWritten; @@ -319,30 +366,16 @@ @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; # endif -#else - LONG bytesWritten; - - if (_handle == 0) - @throw [OFNotOpenException exceptionWithObject: self]; - - if (length > SSIZE_MAX) - @throw [OFOutOfRangeException exception]; - - if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0) - @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length - bytesWritten: 0 - errNo: EIO]; -#endif return (size_t)bytesWritten; +#endif } -#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) +#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U) - (int)fileDescriptorForReading { return _fd; } @@ -352,24 +385,24 @@ } #endif - (void)close { -#ifndef OF_AMIGAOS - if (_fd == -1) - @throw [OFNotOpenException exceptionWithObject: self]; - - close(_fd); - _fd = -1; -#else +#if defined(OF_AMIGAOS) if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; if (_closable) Close(_handle); _handle = 0; +#elif !defined(OF_WII_U) + if (_fd == -1) + @throw [OFNotOpenException exceptionWithObject: self]; + + close(_fd); + _fd = -1; #endif [super close]; } @@ -392,20 +425,21 @@ return OFMaxRetainCount; } - (bool)hasTerminal { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) return isatty(_fd); #else return false; #endif } - (int)columns { -#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS) +#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \ + !defined(OF_AMIGAOS) && !defined(OF_WII_U) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; @@ -415,11 +449,12 @@ #endif } - (int)rows { -#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS) +#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \ + !defined(OF_AMIGAOS) && !defined(OF_WII_U) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; @@ -429,11 +464,11 @@ #endif } - (void)setForegroundColor: (OFColor *)color { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) int code; if (!isatty(_fd)) return; @@ -444,11 +479,11 @@ #endif } - (void)setBackgroundColor: (OFColor *)color { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) int code; if (!isatty(_fd)) return; @@ -459,41 +494,41 @@ #endif } - (void)reset { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; [self writeString: @"\033[0m"]; #endif } - (void)clear { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; [self writeString: @"\033[2J"]; #endif } - (void)eraseLine { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; [self writeString: @"\033[2K"]; #endif } - (void)setCursorColumn: (unsigned int)column { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; [self writeFormat: @"\033[%uG", column + 1]; #endif @@ -502,11 +537,11 @@ - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; [self writeFormat: @"\033[%u;%uH", (unsigned)position.y + 1, (unsigned)position.x + 1]; @@ -513,11 +548,11 @@ #endif } - (void)setRelativeCursorPosition: (OFPoint)position { -#ifdef HAVE_ISATTY +#if defined(HAVE_ISATTY) && !defined(OF_WII_U) if (!isatty(_fd)) return; if (position.x > 0) [self writeFormat: @"\033[%uC", (unsigned)position.x]; Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -36,16 +36,10 @@ # include # include # undef asm #endif -#ifdef OF_WII_U -# define BOOL WUT_BOOL -# include -# undef BOOL -#endif - #ifdef OF_NINTENDO_DS # define asm __asm__ # include # undef asm #endif @@ -170,12 +164,13 @@ # ifdef OF_HAVE_FILES [[OFFileManager defaultManager] changeCurrentDirectoryPath: @"romfs:/"]; # endif #endif -#if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \ - defined(OF_NINTENDO_3DS) || defined(OF_NINTENDO_SWITCH) +#if defined(OF_WII) || defined(OF_WII_U) || defined(OF_PSP) || \ + defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \ + defined(OF_NINTENDO_SWITCH) @try { return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); } @catch (id e) { OFString *string = [OFString stringWithFormat: @@ -232,74 +227,53 @@ abort(); # else abort(); # endif } -#elif defined(OF_WII_U) - @try { - return OFApplicationMain(&argc, &argv, - [[TestsAppDelegate alloc] init]); - } @catch (id e) { - OSReport("\nRuntime error: Unhandled exception:\n%s\n", - [[e description] UTF8String]); - OSReport("\nBacktrace:\n %s\n\n", - [[e backtrace] componentsJoinedByString: @"\n "] - .UTF8String); - abort(); - } #else return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); #endif } @implementation TestsAppDelegate - (void)outputTesting: (OFString *)test inModule: (OFString *)module { -#ifndef OF_WII_U if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor yellow]]; [OFStdOut writeFormat: @"[%@] %@: testing...", module, test]; } else [OFStdOut writeFormat: @"[%@] %@: ", module, test]; -#else - OSReport("[%s] %s: ", module.UTF8String, test.UTF8String); -#endif #ifdef OF_NINTENDO_SWITCH updateConsole(false); #endif } - (void)outputSuccess: (OFString *)test inModule: (OFString *)module { -#ifndef OF_WII_U if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut eraseLine]; [OFStdOut writeFormat: @"\r[%@] %@: ok\n", module, test]; } else [OFStdOut writeLine: @"ok"]; -#else - OSReport("ok\n"); -#endif #ifdef OF_NINTENDO_SWITCH updateConsole(false); #endif } - (void)outputFailure: (OFString *)test inModule: (OFString *)module { -#ifndef OF_WII_U if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut eraseLine]; [OFStdOut writeFormat: @"\r[%@] %@: failed\n", module, test]; } else [OFStdOut writeLine: @"failed"]; -# ifdef OF_WII +#ifdef OF_WII [OFStdOut reset]; [OFStdOut writeLine: @"Press A to continue!"]; for (;;) { WPAD_ScanPads(); @@ -307,12 +281,12 @@ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) return; VIDEO_WaitVSync(); } -# endif -# ifdef OF_PSP +#endif +#ifdef OF_PSP [OFStdOut reset]; [OFStdOut writeLine: @"Press X to continue!"]; for (;;) { SceCtrlData pad; @@ -324,23 +298,23 @@ if (!(pad.Buttons & PSP_CTRL_CROSS)) return; } } } -# endif -# ifdef OF_NINTENDO_DS +#endif +#ifdef OF_NINTENDO_DS [OFStdOut reset]; [OFStdOut writeString: @"Press A to continue!"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_A) break; } -# endif -# ifdef OF_NINTENDO_3DS +#endif +#ifdef OF_NINTENDO_3DS [OFStdOut reset]; [OFStdOut writeString: @"Press A to continue!"]; for (;;) { hidScanInput(); @@ -348,12 +322,12 @@ if (hidKeysDown() & KEY_A) break; gspWaitForVBlank(); } -# endif -# ifdef OF_NINTENDO_SWITCH +#endif +#ifdef OF_NINTENDO_SWITCH [OFStdOut reset]; [OFStdOut writeString: @"Press A to continue!"]; while (appletMainLoop()) { PadState pad; @@ -362,20 +336,17 @@ updateConsole(true); if (padGetButtonsDown(&pad) & HidNpadButton_A) break; } -# endif +#endif if (OFStdOut.hasTerminal) { [OFStdOut writeString: @"\r"]; [OFStdOut reset]; [OFStdOut eraseLine]; } -#else - OSReport("failed\n"); -#endif } - (void)applicationDidFinishLaunching { #if defined(OF_IOS) && defined(OF_HAVE_FILES)