Index: src/OFConstString.m ================================================================== --- src/OFConstString.m +++ src/OFConstString.m @@ -10,10 +10,11 @@ */ #include "config.h" #import "OFConstString.h" +#import "OFExceptions.h" #ifndef __objc_INCLUDE_GNU void *_OFConstStringClassReference; #endif @@ -23,10 +24,15 @@ { objc_setFutureClass((Class)&_OFConstStringClassReference, "OFConstString"); } #endif + +- autorelease +{ + return self; +} - retain { return self; } @@ -38,10 +44,12 @@ - (size_t)retainCount { return SIZE_MAX; } -- autorelease +- (void)dealloc { - return self; + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; + [super dealloc]; /* Get rid of stupid warning */ } @end Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -34,10 +34,26 @@ * \param mode The mode in which the file should be opened as a string * \return A new autoreleased OFFile */ + fileWithPath: (OFString*)path andMode: (OFString*)mode; + +/** + * \return An OFFile singleton for stdin + */ ++ standardInput; + +/** + * \return An OFFile singleton for stdout + */ ++ standardOutput; + +/** + * \return An OFFile singleton for stderr + */ ++ standardError; + /** * Changes the mode of a file. * * Not available on Windows. * @@ -130,5 +146,9 @@ */ - (size_t)writeNItems: (size_t)nitems ofSize: (size_t)size fromBuffer: (const char*)buf; @end + +@interface OFFileSingleton: OFFile +- initWithFilePointer: (FILE*)fp; +@end Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -21,17 +21,48 @@ #endif #import "OFFile.h" #import "OFExceptions.h" +static OFFileSingleton *of_file_stdin = nil; +static OFFileSingleton *of_file_stdout = nil; +static OFFileSingleton *of_file_stderr = nil; + @implementation OFFile + fileWithPath: (OFString*)path andMode: (OFString*)mode { return [[[self alloc] initWithPath: path andMode: mode] autorelease]; } + ++ standardInput +{ + if (of_file_stdin == nil) + of_file_stdin = [[OFFileSingleton alloc] + initWithFilePointer: stdin]; + + return of_file_stdin; +} + ++ standardOutput +{ + if (of_file_stdout == nil) + of_file_stdout = [[OFFileSingleton alloc] + initWithFilePointer: stdout]; + + return of_file_stdout; +} + ++ standardError +{ + if (of_file_stderr == nil) + of_file_stderr = [[OFFileSingleton alloc] + initWithFilePointer: stderr]; + + return of_file_stderr; +} + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode { /* @@ -172,5 +203,42 @@ fp = NULL; return self; } @end + +@implementation OFFileSingleton +- initWithFilePointer: (FILE*)fp_ +{ + self = [super init]; + + fp = fp_; + + return self; +} + +- autorelease +{ + return self; +} + +- retain +{ + return self; +} + +- (void)release +{ +} + +- (size_t)retainCount +{ + return SIZE_MAX; +} + +- (void)dealloc +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; + [super dealloc]; /* Get rid of stupid warning */ +} +@end