ObjFW  Check-in [160b3ac744]

Overview
Comment:Adjust table generator to new ivar naming convention.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 160b3ac7442fb260adcbf050e01db44f78b0e198a0ef079f5b2f76e195e0917c
User & Date: js on 2010-04-18 01:17:17
Other Links: manifest | tags
Context
2010-04-18
01:22
Move objfw-config.in and objfw-compile into utils subdir. check-in: eba6fdcf3c user: js tags: trunk
01:17
Adjust table generator to new ivar naming convention. check-in: 160b3ac744 user: js tags: trunk
00:08
Require overriding of -[applicationDidFinishLaunching]. check-in: 400552fa28 user: js tags: trunk
Changes

Modified generators/TableGenerator.h from [01e4424f24] to [06ba02e944].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24









25
26
27
28
29
30




31
9
10
11
12
13
14
15









16
17
18
19
20
21
22
23
24
25
26




27
28
29
30
31







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


-
-
-
-
+
+
+
+

 * the packaging of this file.
 */

#import "OFString.h"

@interface TableGenerator: OFObject
{
	of_unichar_t upper[0x110000];
	of_unichar_t lower[0x110000];
	of_unichar_t casefolding[0x110000];
	BOOL upper_table_used[0x1100];
	BOOL lower_table_used[0x1100];
	char casefolding_table_used[0x1100];
	size_t upper_size;
	size_t lower_size;
	size_t casefolding_size;
	of_unichar_t upperTable[0x110000];
	of_unichar_t lowerTable[0x110000];
	of_unichar_t casefoldingTable[0x110000];
	BOOL upperTableUsed[0x1100];
	BOOL lowerTableUsed[0x1100];
	char casefoldingTableUsed[0x1100];
	size_t upperTableSize;
	size_t lowerTableSize;
	size_t casefoldingTableSize;
}

- (void)readUnicodeDataFile: (OFString*)path;
- (void)readCaseFoldingFile: (OFString*)path;
- (void)writeTablesToFile: (OFString*)file;
- (void)writeHeaderToFile: (OFString*)file;
- (void)readUnicodeDataFileAtPath: (OFString*)path;
- (void)readCaseFoldingFileAtPath: (OFString*)path;
- (void)writeTablesToFileAtPath: (OFString*)file;
- (void)writeHeaderToFileAtPath: (OFString*)file;
@end

Modified generators/TableGenerator.m from [b3c2322eeb] to [124b72162e].

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
52
53
54
55
56
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
52
53
54
55
56







-
-
-
+
+
+







-
-
-
-
+
+
+
+


-
+







OF_APPLICATION_DELEGATE(TableGenerator)

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

	upper_size = SIZE_MAX;
	lower_size = SIZE_MAX;
	casefolding_size = SIZE_MAX;
	upperTableSize = SIZE_MAX;
	lowerTableSize = SIZE_MAX;
	casefoldingTableSize = SIZE_MAX;

	return self;
}

- (void)applicationDidFinishLaunching
{
	TableGenerator *tgen = [[[TableGenerator alloc] init] autorelease];
	[tgen readUnicodeDataFile: @"UnicodeData.txt"];
	[tgen readCaseFoldingFile: @"CaseFolding.txt"];
	[tgen writeTablesToFile: @"../src/unicode.m"];
	[tgen writeHeaderToFile: @"../src/unicode.h"];
	[tgen readUnicodeDataFileAtPath: @"UnicodeData.txt"];
	[tgen readCaseFoldingFileAtPath: @"CaseFolding.txt"];
	[tgen writeTablesToFileAtPath: @"../src/unicode.m"];
	[tgen writeHeaderToFileAtPath: @"../src/unicode.h"];
}

- (void)readUnicodeDataFile: (OFString*)path
- (void)readUnicodeDataFileAtPath: (OFString*)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
	OFFile *file = [OFFile fileWithPath: path
				       mode: @"rb"];
	OFString *line;

	pool2 = [[OFAutoreleasePool alloc] init];
64
65
66
67
68
69
70

71
72



73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
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







+
-
-
+
+
+







-
+







			[of_stderr writeFormat: @"Invalid line: %s\n",
						[line cString]];
			[OFApplication terminateWithStatus: 1];
		}
		splitted_carray = [splitted cArray];

		codep = [splitted_carray[0] hexadecimalValueAsInteger];
		upperTable[codep] =
		upper[codep] = [splitted_carray[12] hexadecimalValueAsInteger];
		lower[codep] = [splitted_carray[13] hexadecimalValueAsInteger];
		    [splitted_carray[12] hexadecimalValueAsInteger];
		lowerTable[codep] =
		    [splitted_carray[13] hexadecimalValueAsInteger];

		[pool2 releaseObjects];
	}

	[pool release];
}

- (void)readCaseFoldingFile: (OFString*)path
- (void)readCaseFoldingFileAtPath: (OFString*)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
	OFFile *file = [OFFile fileWithPath: path
				       mode: @"rb"];
	OFString *line;

	pool2 = [[OFAutoreleasePool alloc] init];
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+








-
+







		splitted_carray = [splitted cArray];

		if (![splitted_carray[1] isEqual: @"S"] &&
		    ![splitted_carray[1] isEqual: @"C"])
			continue;

		codep = [splitted_carray[0] hexadecimalValueAsInteger];
		casefolding[codep] =
		casefoldingTable[codep] =
		    [splitted_carray[2] hexadecimalValueAsInteger];

		[pool2 releaseObjects];
	}

	[pool release];
}

- (void)writeTablesToFile: (OFString*)file
- (void)writeTablesToFileAtPath: (OFString*)file
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;

	of_unichar_t i, j;
	OFFile *f = [OFFile fileWithPath: file
				    mode: @"wb"];

134
135
136
137
138
139
140
141

142
143
144


145
146
147
148
149
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
183
184
185
186
187
188
189
190
191
192




193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208



209
210
211


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228








229
230
231
232
233
234
235
236
237
238
239
240
241
242



243
244
245
246
247

248
249
250


251
252
253
254
255
256
257

258
259
260
261
262
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
296


297
298
299
300

301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340
341
342
343
344
345
136
137
138
139
140
141
142

143
144


145
146
147
148
149
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
183
184
185
186
187
188
189
190
191
192



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210


211
212
213
214


215
216
217
218
219
220
221
222
223
224
225
226
227
228
229




230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248



249
250
251
252
253
254
255

256
257


258
259
260
261
262
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
296
297
298
299
300
301

302
303


304
305
306
307
308

309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353
354







-
+

-
-
+
+












-
-
-
+
+
+
+














-
+

-
-
+
+












-
-
-
+
+
+
+














-
-
+
+
+

-
-
+
+













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











-
-
-
+
+
+




-
+

-
-
+
+






-
+












-
+

-
-
+
+






-
+












-
+

-
-
+
+



-
+





-
+












-
+












-
+













	/* Write upper_page_%u */
	for (i = 0; i < 0x110000; i += 0x100) {
		BOOL empty;

		empty = YES;

		for (j = i; j < i + 0x100; j++) {
			if (upper[j] != 0) {
			if (upperTable[j] != 0) {
				empty = NO;
				upper_size = i >> 8;
				upper_table_used[upper_size] = YES;
				upperTableSize = i >> 8;
				upperTableUsed[upperTableSize] = YES;
				break;
			}
		}

		if (!empty) {
			[f writeString: [OFString stringWithFormat:
			    @"static const of_unichar_t upper_page_%u[0x100] = "
			    @"{\n", i >> 8]];

			for (j = i; j < i + 0x100; j += 8)
				[f writeString: [OFString stringWithFormat:
				    @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
				    upper[j], upper[j + 1], upper[j + 2],
				    upper[j + 3], upper[j + 4], upper[j + 5],
				    upper[j + 6], upper[j + 7]]];
				    upperTable[j], upperTable[j + 1],
				    upperTable[j + 2], upperTable[j + 3],
				    upperTable[j + 4], upperTable[j + 5],
				    upperTable[j + 6], upperTable[j + 7]]];

			[f writeString: @"};\n\n"];

			[pool2 releaseObjects];
		}
	}

	/* Write lower_page_%u */
	for (i = 0; i < 0x110000; i += 0x100) {
		BOOL empty;

		empty = YES;

		for (j = i; j < i + 0x100; j++) {
			if (lower[j] != 0) {
			if (lowerTable[j] != 0) {
				empty = NO;
				lower_size = i >> 8;
				lower_table_used[lower_size] = YES;
				lowerTableSize = i >> 8;
				lowerTableUsed[lowerTableSize] = YES;
				break;
			}
		}

		if (!empty) {
			[f writeString: [OFString stringWithFormat:
			    @"static const of_unichar_t lower_page_%u[0x100] = "
			    @"{\n", i >> 8]];

			for (j = i; j < i + 0x100; j += 8)
				[f writeString: [OFString stringWithFormat:
				    @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
				    lower[j], lower[j + 1], lower[j + 2],
				    lower[j + 3], lower[j + 4], lower[j + 5],
				    lower[j + 6], lower[j + 7]]];
				    lowerTable[j], lowerTable[j + 1],
				    lowerTable[j + 2], lowerTable[j + 3],
				    lowerTable[j + 4], lowerTable[j + 5],
				    lowerTable[j + 6], lowerTable[j + 7]]];

			[f writeString: @"};\n\n"];

			[pool2 releaseObjects];
		}
	}

	/* Write cf_page_%u if it does NOT match lower_page_%u */
	for (i = 0; i < 0x110000; i += 0x100) {
		BOOL empty;

		empty = YES;

		for (j = i; j < i + 0x100; j++) {
			if (casefolding[j] != 0) {
				empty = (memcmp(lower + i, casefolding + i,
			if (casefoldingTable[j] != 0) {
				empty = (memcmp(lowerTable + i,
				    casefoldingTable + i,
				    256 * sizeof(of_unichar_t)) ? NO : YES);
				casefolding_size = i >> 8;
				casefolding_table_used[casefolding_size] =
				casefoldingTableSize = i >> 8;
				casefoldingTableUsed[casefoldingTableSize] =
				    (empty ? 2 : 1);
				break;
			}
		}

		if (!empty) {
			[f writeString: [OFString stringWithFormat:
			    @"static const of_unichar_t cf_page_%u[0x100] = {"
			    @"\n", i >> 8]];

			for (j = i; j < i + 0x100; j += 8)
				[f writeString: [OFString stringWithFormat:
				    @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
				    casefolding[j], casefolding[j + 1],
				    casefolding[j + 2], casefolding[j + 3],
				    casefolding[j + 4], casefolding[j + 5],
				    casefolding[j + 6], casefolding[j + 7]]];
				    casefoldingTable[j],
				    casefoldingTable[j + 1],
				    casefoldingTable[j + 2],
				    casefoldingTable[j + 3],
				    casefoldingTable[j + 4],
				    casefoldingTable[j + 5],
				    casefoldingTable[j + 6],
				    casefoldingTable[j + 7]]];

			[f writeString: @"};\n\n"];

			[pool2 releaseObjects];
		}
	}

	/*
	 * Those are currently set to the last index.
	 * But from now on, we need the size.
	 */
	upper_size++;
	lower_size++;
	casefolding_size++;
	upperTableSize++;
	lowerTableSize++;
	casefoldingTableSize++;

	/* Write of_unicode_upper_table */
	[f writeString: [OFString stringWithFormat:
	    @"const of_unichar_t* const of_unicode_upper_table[0x%X] = {\n\t",
	    upper_size]];
	    upperTableSize]];

	for (i = 0; i < upper_size; i++) {
		if (upper_table_used[i]) {
	for (i = 0; i < upperTableSize; i++) {
		if (upperTableUsed[i]) {
			[f writeString: [OFString stringWithFormat:
			    @"upper_page_%u", i]];
			[pool2 releaseObjects];
		} else
			[f writeString: @"nop_page"];

		if (i + 1 < upper_size) {
		if (i + 1 < upperTableSize) {
			if ((i + 1) % 4 == 0)
				[f writeString: @",\n\t"];
			else
				[f writeString: @", "];
		}
	}

	[f writeString: @"\n};\n\n"];

	/* Write of_unicode_lower_table */
	[f writeString: [OFString stringWithFormat:
	    @"const of_unichar_t* const of_unicode_lower_table[0x%X] = {\n\t",
	    lower_size]];
	    lowerTableSize]];

	for (i = 0; i < lower_size; i++) {
		if (lower_table_used[i]) {
	for (i = 0; i < lowerTableSize; i++) {
		if (lowerTableUsed[i]) {
			[f writeString: [OFString stringWithFormat:
			    @"lower_page_%u", i]];
			[pool2 releaseObjects];
		} else
			[f writeString: @"nop_page"];

		if (i + 1 < lower_size) {
		if (i + 1 < lowerTableSize) {
			if ((i + 1) % 4 == 0)
				[f writeString: @",\n\t"];
			else
				[f writeString: @", "];
		}
	}

	[f writeString: @"\n};\n\n"];

	/* Write of_unicode_casefolding_table */
	[f writeString: [OFString stringWithFormat:
	    @"const of_unichar_t* const of_unicode_casefolding_table[0x%X] = {"
	    @"\n\t", casefolding_size]];
	    @"\n\t", casefoldingTableSize]];

	for (i = 0; i < casefolding_size; i++) {
		if (casefolding_table_used[i] == 1) {
	for (i = 0; i < casefoldingTableSize; i++) {
		if (casefoldingTableUsed[i] == 1) {
			[f writeString: [OFString stringWithFormat:
			    @"cf_page_%u", i]];
			[pool2 releaseObjects];
		} else if (casefolding_table_used[i] == 2) {
		} else if (casefoldingTableUsed[i] == 2) {
			[f writeString: [OFString stringWithFormat:
			    @"lower_page_%u", i]];
		} else
			[f writeString: @"nop_page"];

		if (i + 1 < casefolding_size) {
		if (i + 1 < casefoldingTableSize) {
			if ((i + 1) % 4 == 0)
				[f writeString: @",\n\t"];
			else
				[f writeString: @", "];
		}
	}

	[f writeString: @"\n};\n"];

	[pool release];
}

- (void)writeHeaderToFile: (OFString*)file
- (void)writeHeaderToFileAtPath: (OFString*)file
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFFile *f = [OFFile fileWithPath: file
				    mode: @"wb"];

	[f writeString: COPYRIGHT
	    @"#import \"OFString.h\"\n\n"];

	[f writeString: [OFString stringWithFormat:
	    @"#define OF_UNICODE_UPPER_TABLE_SIZE 0x%X\n"
	    @"#define OF_UNICODE_LOWER_TABLE_SIZE 0x%X\n"
	    @"#define OF_UNICODE_CASEFOLDING_TABLE_SIZE 0x%X\n\n",
	    upper_size, lower_size, casefolding_size]];
	    upperTableSize, lowerTableSize, casefoldingTableSize]];

	[f writeString:
	    @"extern const of_unichar_t* const\n"
	    @"    of_unicode_upper_table[OF_UNICODE_UPPER_TABLE_SIZE];\n"
	    @"extern const of_unichar_t* const\n"
	    @"    of_unicode_lower_table[OF_UNICODE_LOWER_TABLE_SIZE];\n"
	    @"extern const of_unichar_t* const\n"
	    @"    of_unicode_casefolding_table["
	    @"OF_UNICODE_CASEFOLDING_TABLE_SIZE];\n"];

	[pool release];
}
@end