ObjFW  Check-in [adb82c292c]

Overview
Comment:TableGenerator: Use new async OFHTTPClient API
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: adb82c292c80b0738e03ab9cc490a9875fe2a2eafedbd8b153a925aa85617b2e
User & Date: js on 2017-09-25 21:31:06
Other Links: manifest | tags
Context
2017-09-25
23:15
ObjFW.xcodeproj: Use ./autogen.sh check-in: f8f4c733b8 user: js tags: trunk
21:31
TableGenerator: Use new async OFHTTPClient API check-in: adb82c292c user: js tags: trunk
00:02
OFHTTPClient: Add support for passing a context check-in: c35ba05bbc user: js tags: trunk
Changes

Modified generators/TableGenerator.h from [ed3760d524] to [21727ea245].

11
12
13
14
15
16
17

18
19
20
21

22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45

46
47
48
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51







+



-
+

+




















-
-
+
+

+



 * Alternatively, it may be distributed under the terms of the GNU General
 * 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 "OFObject.h"
#import "OFHTTPClient.h"

@class OFString;

@interface TableGenerator: OFObject
@interface TableGenerator: OFObject <OFHTTPClientDelegate>
{
	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];
	OFString *_decompositionCompatTable[0x110000];
	char _uppercaseTableUsed[0x1100];
	char _lowercaseTableUsed[0x1100];
	char _titlecaseTableUsed[0x1100];
	char _casefoldingTableUsed[0x1100];
	char _decompositionTableUsed[0x1100];
	char _decompositionCompatTableUsed[0x1100];
	size_t _uppercaseTableSize;
	size_t _lowercaseTableSize;
	size_t _titlecaseTableSize;
	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

Modified generators/TableGenerator.m from [c7bfffe23c] to [1cc19838af].

41
42
43
44
45
46
47




48
49
50
51
52
53










54
55
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
84
85
86
87
88
89

90
91
92




93
94



























95
96
97
98
99
100
101
41
42
43
44
45
46
47
48
49
50
51






52
53
54
55
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110







+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-

-
+
-


+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







OF_APPLICATION_DELEGATE(TableGenerator)

@implementation TableGenerator
- init
{
	self = [super init];

	@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;
		_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]];
	[_HTTPClient asyncPerformRequest: request
				 context: @"UnicodeData"];
}

	client = [OFHTTPClient client];
	response = [client performRequest: request];
-      (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;

		if ([line length] == 0)
150
151
152
153
154
155
156



157
158




159

160
161
162

163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177

178
179




180
181

182





183
184
185
186
187
188
189







+
+
+


+
+
+
+
-
+


-
+

-
-
-
-


-
+
-
-
-
-
-







				_decompositionTable[codePoint] = [string copy];
			_decompositionCompatTable[codePoint] = [string copy];
		}

		objc_autoreleasePoolPop(pool2);
	}

	[self applyDecompositionRecursivelyForTable: _decompositionTable];
	[self applyDecompositionRecursivelyForTable: _decompositionCompatTable];

	[of_stdout writeLine: @" done"];

	[of_stdout writeString: @"Downloading CaseFolding.txt…"];
	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: CASE_FOLDING_URL]];
	[_HTTPClient asyncPerformRequest: request
	objc_autoreleasePoolPop(pool);
				 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…"];
	[of_stdout writeString: @"Parsing CaseFolding.txt…"];

	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: CASE_FOLDING_URL]];
	client = [OFHTTPClient client];
	response = [client performRequest: request];

	while ((line = [response readLine]) != nil) {
		void *pool2;
		OFArray OF_GENERIC(OFString *) *components;
		of_unichar_t codePoint;

		if ([line length] == 0 || [line hasPrefix: @"#"])
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225







-
+







		    [[components objectAtIndex: 2] hexadecimalValue];

		objc_autoreleasePoolPop(pool2);
	}

	[of_stdout writeLine: @" done"];

	objc_autoreleasePoolPop(pool);
	[self writeFiles];
}

- (void)applyDecompositionRecursivelyForTable: (OFString *[0x110000])table
{
	bool done;

	do {
256
257
258
259
260
261
262



















263
264
265
266
267
268
269
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				table[i] = [replacement copy];

				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
				       mode: @"w"];