Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -19,12 +19,10 @@ DerivedData docs extra.mk generators/gen_tables generators/gen_tables.exe -generators/CaseFolding.txt -generators/UnicodeData.txt Info.plist ObjFW.xcodeproj/*.mode1v3 ObjFW.xcodeproj/*.pbxuser ObjFW.xcodeproj/project.xcworkspace ObjFW.xcodeproj/xcuserdata Index: generators/Makefile ================================================================== --- generators/Makefile +++ generators/Makefile @@ -2,11 +2,11 @@ PROG_NOINST = gen_tables${PROG_SUFFIX} SRCS = TableGenerator.m .PHONY: run -run: all UnicodeData.txt CaseFolding.txt +run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f libobjfw.dll libobjfw.dylib if test -f ../src/libobjfw.so; then \ ${LN_S} ../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ @@ -30,16 +30,10 @@ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} libobjfw.dll \ rm -f libobjfw.dylib; \ exit $$EXIT -UnicodeData.txt: - wget http://unicode.org/Public/UNIDATA/UnicodeData.txt - -CaseFolding.txt: - wget http://www.unicode.org/Public/UNIDATA/CaseFolding.txt - include ../buildsys.mk CPPFLAGS += -I../src -I../src/runtime -I.. LIBS := -L../src -lobjfw ${LIBS} LD = ${OBJC} Index: generators/TableGenerator.h ================================================================== --- generators/TableGenerator.h +++ generators/TableGenerator.h @@ -12,14 +12,17 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFString.h" +#import "OFObject.h" + +@class OFString; @interface TableGenerator: OFObject { + OFString *unicodeData, *caseFolding; of_unichar_t uppercaseTable[0x110000]; of_unichar_t lowercaseTable[0x110000]; of_unichar_t titlecaseTable[0x110000]; of_unichar_t casefoldingTable[0x110000]; BOOL uppercaseTableUsed[0x1100]; @@ -30,10 +33,11 @@ size_t lowercaseTableSize; size_t titlecaseTableSize; size_t casefoldingTableSize; } -- (void)readUnicodeDataFileAtPath: (OFString*)path; -- (void)readCaseFoldingFileAtPath: (OFString*)path; -- (void)writeTablesToFileAtPath: (OFString*)path; -- (void)writeHeaderToFileAtPath: (OFString*)path; +- (void)downloadFiles; +- (void)parseUnicodeData; +- (void)parseCaseFolding; +- (void)writeTablesToFile: (OFString*)path; +- (void)writeHeaderToFile: (OFString*)path; @end Index: generators/TableGenerator.m ================================================================== --- generators/TableGenerator.m +++ generators/TableGenerator.m @@ -18,17 +18,24 @@ #include #import "OFString.h" #import "OFArray.h" +#import "OFApplication.h" +#import "OFURL.h" #import "OFFile.h" -#import "OFAutoreleasePool.h" -#import "OFApplication.h" + +#import "autorelease.h" #import "TableGenerator.h" #import "copyright.h" +#define UNICODE_DATA_URL \ + @"http://unicode.org/Public/UNIDATA/UnicodeData.txt" +#define CASE_FOLDING_URL \ + @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt" + OF_APPLICATION_DELEGATE(TableGenerator) @implementation TableGenerator - init { @@ -42,34 +49,61 @@ return self; } - (void)applicationDidFinishLaunching { - TableGenerator *generator = [[[TableGenerator alloc] init] autorelease]; + [self downloadFiles]; - [generator readUnicodeDataFileAtPath: @"UnicodeData.txt"]; - [generator readCaseFoldingFileAtPath: @"CaseFolding.txt"]; + [self parseUnicodeData]; + [self parseCaseFolding]; - [generator writeTablesToFileAtPath: @"../src/unicode.m"]; - [generator writeHeaderToFileAtPath: @"../src/unicode.h"]; + [of_stdout writeString: @"Writing files..."]; + + [self writeTablesToFile: @"../src/unicode.m"]; + [self writeHeaderToFile: @"../src/unicode.h"]; + + [of_stdout writeLine: @" done"]; [OFApplication terminate]; } -- (void)readUnicodeDataFileAtPath: (OFString*)path +- (void)downloadFiles +{ + [of_stdout writeString: @"Downloading " UNICODE_DATA_URL @"..."]; + unicodeData = [[OFString alloc] initWithContentsOfURL: + [OFURL URLWithString: UNICODE_DATA_URL]]; + [of_stdout writeLine: @" done"]; + + [of_stdout writeString: @"Downloading " CASE_FOLDING_URL @"..."]; + caseFolding = [[OFString alloc] initWithContentsOfURL: + [OFURL URLWithString: CASE_FOLDING_URL]]; + [of_stdout writeLine: @" done"]; +} + +- (void)parseUnicodeData { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; - OFFile *file = [OFFile fileWithPath: path - mode: @"rb"]; + void *pool = objc_autoreleasePoolPush(); + OFArray *lines; + OFEnumerator *enumerator; OFString *line; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((line = [file readLine])) { + [of_stdout writeString: @"Parsing UnicodeData.txt..."]; + + lines = [unicodeData componentsSeparatedByString: @"\n"]; + enumerator = [lines objectEnumerator]; + + while ((line = [enumerator nextObject]) != nil) { + void *pool2; OFArray *split; OFString **splitObjects; of_unichar_t codep; + if ([line length] == 0) + continue; + + pool2 = objc_autoreleasePoolPush(); + split = [line componentsSeparatedByString: @";"]; if ([split count] != 15) { of_log(@"Invalid line: %@\n", line); [OFApplication terminateWithStatus: 1]; } @@ -81,31 +115,40 @@ lowercaseTable[codep] = (of_unichar_t)[splitObjects[13] hexadecimalValue]; titlecaseTable[codep] = (of_unichar_t)[splitObjects[14] hexadecimalValue]; - [pool2 releaseObjects]; - } - - [pool release]; -} - -- (void)readCaseFoldingFileAtPath: (OFString*)path -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; - OFFile *file = [OFFile fileWithPath: path - mode: @"rb"]; - OFString *line; - - pool2 = [[OFAutoreleasePool alloc] init]; - while ((line = [file readLine]) != nil) { + objc_autoreleasePoolPop(pool2); + } + + [of_stdout writeLine: @" done"]; + + objc_autoreleasePoolPop(pool); +} + +- (void)parseCaseFolding +{ + void *pool = objc_autoreleasePoolPush(); + OFArray *lines; + OFEnumerator *enumerator; + OFString *line; + + [of_stdout writeString: @"Parsing CaseFolding.txt..."]; + + lines = [caseFolding componentsSeparatedByString: @"\n"]; + enumerator = [lines objectEnumerator]; + + while ((line = [enumerator nextObject]) != nil) { + void *pool2; OFArray *split; OFString **splitObjects; of_unichar_t codep; if ([line length] == 0 || [line hasPrefix: @"#"]) continue; + + pool2 = objc_autoreleasePoolPush(); split = [line componentsSeparatedByString: @"; "]; if ([split count] != 4) { of_log(@"Invalid line: %s\n", line); [OFApplication terminateWithStatus: 1]; @@ -118,32 +161,31 @@ codep = (of_unichar_t)[splitObjects[0] hexadecimalValue]; casefoldingTable[codep] = (of_unichar_t)[splitObjects[2] hexadecimalValue]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; + [of_stdout writeLine: @" done"]; + + objc_autoreleasePoolPop(pool); } -- (void)writeTablesToFileAtPath: (OFString*)path +- (void)writeTablesToFile: (OFString*)path { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; - - of_unichar_t i, j; + void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; + of_unichar_t i, j; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"OFString.h\"\n\n" @"static const of_unichar_t nop_page[0x100] = {};\n\n"]; - pool2 = [[OFAutoreleasePool alloc] init]; - /* Write uppercase_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { BOOL isEmpty = YES; for (j = i; j < i + 0x100; j++) { @@ -154,10 +196,12 @@ break; } } if (!isEmpty) { + void *pool2 = objc_autoreleasePoolPush(); + [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"uppercase_page_%u[0x100] = {\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) @@ -172,11 +216,11 @@ uppercaseTable[j + 6], uppercaseTable[j + 7]]]; [file writeString: @"};\n\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } } /* Write lowercase_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { @@ -190,10 +234,12 @@ break; } } if (!isEmpty) { + void *pool2 = objc_autoreleasePoolPush(); + [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"lowercase_page_%u[0x100] = {\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) @@ -208,11 +254,11 @@ lowercaseTable[j + 6], lowercaseTable[j + 7]]]; [file writeString: @"};\n\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } } /* Write titlecase_page_%u if it does NOT match uppercase_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { @@ -229,10 +275,12 @@ break; } } if (!isEmpty) { + void *pool2 = objc_autoreleasePoolPush(); + [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"titlecase_page_%u[0x100] = {\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) @@ -247,11 +295,11 @@ titlecaseTable[j + 6], titlecaseTable[j + 7]]]; [file writeString: @"};\n\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } } /* Write casefolding_page_%u if it does NOT match lowercase_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { @@ -268,10 +316,12 @@ break; } } if (!isEmpty) { + void *pool2 = objc_autoreleasePoolPush(); + [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"casefolding_page_%u[0x100] = {\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) @@ -286,11 +336,11 @@ casefoldingTable[j + 6], casefoldingTable[j + 7]]]; [file writeString: @"};\n\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } } /* * Those are currently set to the last index. @@ -308,11 +358,10 @@ for (i = 0; i < uppercaseTableSize; i++) { if (uppercaseTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"uppercase_page_%u", i]]; - [pool2 releaseObjects]; } else [file writeString: @"nop_page"]; if (i + 1 < uppercaseTableSize) { if ((i + 1) % 4 == 0) @@ -331,11 +380,10 @@ for (i = 0; i < lowercaseTableSize; i++) { if (lowercaseTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"lowercase_page_%u", i]]; - [pool2 releaseObjects]; } else [file writeString: @"nop_page"]; if (i + 1 < lowercaseTableSize) { if ((i + 1) % 4 == 0) @@ -354,11 +402,10 @@ for (i = 0; i < titlecaseTableSize; i++) { if (titlecaseTableUsed[i] == 1) { [file writeString: [OFString stringWithFormat: @"titlecase_page_%u", i]]; - [pool2 releaseObjects]; } else if (titlecaseTableUsed[i] == 2) { [file writeString: [OFString stringWithFormat: @"uppercase_page_%u", i]]; } else [file writeString: @"nop_page"]; @@ -380,11 +427,10 @@ for (i = 0; i < casefoldingTableSize; i++) { if (casefoldingTableUsed[i] == 1) { [file writeString: [OFString stringWithFormat: @"casefolding_page_%u", i]]; - [pool2 releaseObjects]; } else if (casefoldingTableUsed[i] == 2) { [file writeString: [OFString stringWithFormat: @"lowercase_page_%u", i]]; } else [file writeString: @"nop_page"]; @@ -397,16 +443,16 @@ } } [file writeString: @"\n};\n"]; - [pool release]; + objc_autoreleasePoolPop(pool); } -- (void)writeHeaderToFileAtPath: (OFString*)path +- (void)writeHeaderToFile: (OFString*)path { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; @@ -437,8 +483,8 @@ @"OF_UNICODE_CASEFOLDING_TABLE_SIZE];\n" @"#ifdef __cplusplus\n" @"}\n" @"#endif\n"]; - [pool release]; + objc_autoreleasePoolPop(pool); } @end