Index: generators/TableGenerator.h ================================================================== --- generators/TableGenerator.h +++ generators/TableGenerator.h @@ -13,15 +13,17 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" +#import "OFHTTPClient.h" @class OFString; -@interface TableGenerator: OFObject +@interface TableGenerator: OFObject { + OFHTTPClient *_HTTPClient; of_unichar_t _uppercaseTable[0x110000]; of_unichar_t _lowercaseTable[0x110000]; of_unichar_t _titlecaseTable[0x110000]; of_unichar_t _casefoldingTable[0x110000]; OFString *_decompositionTable[0x110000]; @@ -38,11 +40,12 @@ size_t _casefoldingTableSize; size_t _decompositionTableSize; size_t _decompositionCompatTableSize; } -- (void)parseUnicodeData; -- (void)parseCaseFolding; +- (void)parseUnicodeData: (OFHTTPResponse *)response; +- (void)parseCaseFolding: (OFHTTPResponse *)response; - (void)applyDecompositionRecursivelyForTable: (OFString *[0x110000])table; +- (void)writeFiles; - (void)writeTablesToFile: (OFString *)path; - (void)writeHeaderToFile: (OFString *)path; @end Index: generators/TableGenerator.m ================================================================== --- generators/TableGenerator.m +++ generators/TableGenerator.m @@ -43,57 +43,66 @@ @implementation TableGenerator - init { self = [super init]; - _uppercaseTableSize = SIZE_MAX; - _lowercaseTableSize = SIZE_MAX; - _titlecaseTableSize = SIZE_MAX; - _casefoldingTableSize = SIZE_MAX; - _decompositionTableSize = SIZE_MAX; - _decompositionCompatTableSize = SIZE_MAX; + @try { + _HTTPClient = [[OFHTTPClient alloc] init]; + [_HTTPClient setDelegate: self]; + + _uppercaseTableSize = SIZE_MAX; + _lowercaseTableSize = SIZE_MAX; + _titlecaseTableSize = SIZE_MAX; + _casefoldingTableSize = SIZE_MAX; + _decompositionTableSize = SIZE_MAX; + _decompositionCompatTableSize = SIZE_MAX; + } @catch (id e) { + @throw e; + [self release]; + } return self; } - (void)applicationDidFinishLaunching { - OFString *path; - [self parseUnicodeData]; - [self parseCaseFolding]; - [self applyDecompositionRecursivelyForTable: _decompositionTable]; - [self applyDecompositionRecursivelyForTable: _decompositionCompatTable]; - - [of_stdout writeString: @"Writing files…"]; - - path = [OFString pathWithComponents: [OFArray arrayWithObjects: - OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.m", nil]]; - [self writeTablesToFile: path]; - - path = [OFString pathWithComponents: [OFArray arrayWithObjects: - OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.h", nil]]; - [self writeHeaderToFile: path]; - - [of_stdout writeLine: @" done"]; - - [OFApplication terminate]; -} - -- (void)parseUnicodeData -{ - void *pool = objc_autoreleasePoolPush(); OFHTTPRequest *request; - OFHTTPClient *client; - OFHTTPResponse *response; - OFString *line; - [of_stdout writeString: @"Downloading and parsing UnicodeData.txt…"]; - + [of_stdout writeString: @"Downloading UnicodeData.txt…"]; request = [OFHTTPRequest requestWithURL: [OFURL URLWithString: UNICODE_DATA_URL]]; - client = [OFHTTPClient client]; - response = [client performRequest: request]; + [_HTTPClient asyncPerformRequest: request + context: @"UnicodeData"]; +} + +- (void)client: (OFHTTPClient *)client + didPerformRequest: (OFHTTPRequest *)request + response: (OFHTTPResponse *)response + context: (id)context +{ + [of_stdout writeLine: @" done"]; + + if ([context isEqual: @"UnicodeData"]) + [self parseUnicodeData: response]; + else if ([context isEqual: @"CaseFolding"]) + [self parseCaseFolding: response]; +} + +- (void)client: (OFHTTPClient *)client + didEncounterException: (id)exception + forRequest: (OFHTTPRequest *)request + context: (id)context +{ + @throw exception; +} + +- (void)parseUnicodeData: (OFHTTPResponse *)response +{ + OFString *line; + OFHTTPRequest *request; + + [of_stdout writeString: @"Parsing UnicodeData.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; of_unichar_t codePoint; @@ -152,29 +161,27 @@ } objc_autoreleasePoolPop(pool2); } + [self applyDecompositionRecursivelyForTable: _decompositionTable]; + [self applyDecompositionRecursivelyForTable: _decompositionCompatTable]; + [of_stdout writeLine: @" done"]; - objc_autoreleasePoolPop(pool); + [of_stdout writeString: @"Downloading CaseFolding.txt…"]; + request = [OFHTTPRequest requestWithURL: + [OFURL URLWithString: CASE_FOLDING_URL]]; + [_HTTPClient asyncPerformRequest: request + context: @"CaseFolding"]; } -- (void)parseCaseFolding +- (void)parseCaseFolding: (OFHTTPResponse *)response { - void *pool = objc_autoreleasePoolPush(); - OFHTTPRequest *request; - OFHTTPClient *client; - OFHTTPResponse *response; OFString *line; - [of_stdout writeString: @"Downloading and parsing CaseFolding.txt…"]; - - request = [OFHTTPRequest requestWithURL: - [OFURL URLWithString: CASE_FOLDING_URL]]; - client = [OFHTTPClient client]; - response = [client performRequest: request]; + [of_stdout writeString: @"Parsing CaseFolding.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; of_unichar_t codePoint; @@ -206,11 +213,11 @@ objc_autoreleasePoolPop(pool2); } [of_stdout writeLine: @" done"]; - objc_autoreleasePoolPop(pool); + [self writeFiles]; } - (void)applyDecompositionRecursivelyForTable: (OFString *[0x110000])table { bool done; @@ -258,10 +265,29 @@ done = false; } } } while (!done); } + +- (void)writeFiles +{ + OFString *path; + + [of_stdout writeString: @"Writing files…"]; + + path = [OFString pathWithComponents: [OFArray arrayWithObjects: + OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.m", nil]]; + [self writeTablesToFile: path]; + + path = [OFString pathWithComponents: [OFArray arrayWithObjects: + OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.h", nil]]; + [self writeHeaderToFile: path]; + + [of_stdout writeLine: @" done"]; + + [OFApplication terminate]; +} - (void)writeTablesToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path