Overview
Comment: | Enhance Unicode table generator so it produces smaller output. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ef0c1ebc6843244943958bc00de4fee0 |
User & Date: | js on 2009-11-02 10:11:32 |
Other Links: | manifest | tags |
Context
2009-11-02
| ||
10:18 | Update Unicode tables to those from the enhanced generator. check-in: fe8c3ac93f user: js tags: trunk | |
10:11 | Enhance Unicode table generator so it produces smaller output. check-in: ef0c1ebc68 user: js tags: trunk | |
2009-11-01
| ||
19:51 | Fix a typo in the tests Makefile. check-in: 70f1d07a37 user: js tags: trunk | |
Changes
Deleted generators/CaseFoldingGenerator.h version [d3e4620949].
|
| < < < < < < < < < < < < < < < < < < < < < < < |
Deleted generators/CaseFoldingGenerator.m version [3fb8e54484].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified generators/Makefile from [12f632ea2d] to [d66cc078f4].
1 | PROG_NOINST = gen_tables${PROG_SUFFIX} | | | < | 1 2 3 4 5 6 7 8 9 10 | PROG_NOINST = gen_tables${PROG_SUFFIX} SRCS = main.o \ TableGenerator.m .PHONY: run run: all UnicodeData.txt CaseFolding.txt rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib if test -f ../src/libobjfw.so; then \ ln -s ../src/libobjfw.so libobjfw.so.0; \ ln -s ../src/libobjfw.so libobjfw.so.0.1; \ |
︙ | ︙ |
Added generators/TableGenerator.h version [e697d6dce6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /* * Copyright (c) 2008 - 2009 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * 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]; size_t upper_size; size_t lower_size; size_t casefolding_size; } - (void)readUnicodeDataFile: (OFString*)path; - (void)readCaseFoldingFile: (OFString*)path; - (void)writeTablesToFile: (OFString*)file; - (void)writeHeaderToFile: (OFString*)file; @end |
Added generators/TableGenerator.m version [55267c683a].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 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 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | /* * Copyright (c) 2008 - 2009 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #import "OFFile.h" #import "OFAutoreleasePool.h" #import "TableGenerator.h" #import "copyright.h" @implementation TableGenerator - init { self = [super init]; upper_size = SIZE_MAX; lower_size = SIZE_MAX; casefolding_size = SIZE_MAX; return self; } - (void)readUnicodeDataFile: (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])) { OFArray *splitted; OFString **splitted_carray; of_unichar_t codep; splitted = [line splitWithDelimiter: @";"]; if ([splitted count] != 15) { fprintf(stderr, "Invalid line: %s\n", [line cString]); exit(1); } splitted_carray = [splitted cArray]; codep = [splitted_carray[0] hexadecimalValueAsInteger]; upper[codep] = [splitted_carray[12] hexadecimalValueAsInteger]; lower[codep] = [splitted_carray[13] hexadecimalValueAsInteger]; [pool2 releaseObjects]; } [pool release]; } - (void)readCaseFoldingFile: (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])) { OFArray *splitted; OFString **splitted_carray; of_unichar_t codep; if ([line characterAtIndex: 0] == '#') continue; splitted = [line splitWithDelimiter: @"; "]; if ([splitted count] != 4) { fprintf(stderr, "Invalid line: %s\n", [line cString]); exit(1); } splitted_carray = [splitted cArray]; if (![splitted_carray[1] isEqual: @"S"] && ![splitted_carray[1] isEqual: @"C"]) continue; codep = [splitted_carray[0] hexadecimalValueAsInteger]; casefolding[codep] = [splitted_carray[2] hexadecimalValueAsInteger]; [pool2 releaseObjects]; } [pool release]; } - (void)writeTablesToFile: (OFString*)file { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; of_unichar_t i, j; BOOL *upper_table_used; BOOL *lower_table_used; char *casefolding_table_used; OFFile *f = [OFFile fileWithPath: file mode: @"wb"]; upper_table_used = [self allocMemoryWithSize: 0x1100]; lower_table_used = [self allocMemoryWithSize: 0x1100]; casefolding_table_used = [self allocMemoryWithSize: 0x1100]; memset(upper_table_used, 0, 0x1100); memset(lower_table_used, 0, 0x1100); memset(casefolding_table_used, 0, 0x1100); [f 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 upper_page_%d */ for (i = 0; i < 0x110000; i += 0x100) { BOOL empty; empty = YES; for (j = i; j < i + 0x100; j++) { if (upper[j] != 0) { empty = NO; upper_size = i >> 8; upper_table_used[upper_size] = 1; } } if (!empty) { [f writeString: [OFString stringWithFormat: @"static const of_unichar_t upper_page_%d[0x100] = " @"{\n", i >> 8]]; for (j = i; j < i + 0x100; j += 4) [f writeString: [OFString stringWithFormat: @"\t0x%06X, 0x%06X, 0x%06X, 0x%06X,\n", upper[j], upper[j + 1], upper[j + 2], upper[j + 3]]]; [f writeString: @"};\n\n"]; [pool2 releaseObjects]; } } /* Write lower_page_%d */ for (i = 0; i < 0x110000; i += 0x100) { BOOL empty; empty = YES; for (j = i; j < i + 0x100; j++) { if (lower[j] != 0) { empty = NO; lower_size = i >> 8; lower_table_used[lower_size] = 1; } } if (!empty) { [f writeString: [OFString stringWithFormat: @"static const of_unichar_t lower_page_%d[0x100] = " @"{\n", i >> 8]]; for (j = i; j < i + 0x100; j += 4) [f writeString: [OFString stringWithFormat: @"\t0x%06X, 0x%06X, 0x%06X, 0x%06X,\n", lower[j], lower[j + 1], lower[j + 2], lower[j + 3]]]; [f writeString: @"};\n\n"]; [pool2 releaseObjects]; } } /* Write cf_page_%d if it does NOT match lower_page_%d */ for (i = 0; i < 0x110000; i += 0x100) { BOOL empty; empty = YES; for (j = i; j < i + 0x100; j++) { if (casefolding[j] != 0) { empty = NO; casefolding_size = i >> 8; casefolding_table_used[casefolding_size] = (memcmp(lower + i, casefolding + i, 256) ? 1 : 2); } } if (!empty) { if (!memcmp(lower + i, casefolding + i, 256)) continue; [f writeString: [OFString stringWithFormat: @"static const of_unichar_t cf_page_%d[0x100] = {" @"\n", i >> 8]]; for (j = i; j < i + 0x100; j += 4) [f writeString: [OFString stringWithFormat: @"\t0x%06X, 0x%06X, 0x%06X, 0x%06X,\n", casefolding[j], casefolding[j + 1], casefolding[j + 2], casefolding[j + 3]]]; [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++; /* Write of_unicode_upper_table */ [f writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_upper_table[0x%X] = {\n\t", upper_size]]; for (i = 0; i < upper_size; i++) { if (upper_table_used[i]) { [f writeString: [OFString stringWithFormat: @"upper_page_%d", i]]; [pool2 releaseObjects]; } else [f writeString: @"nop_page"]; if ((i + 1) % 4 == 0) [f writeString: @",\n\t"]; else if (i + 1 < upper_size) [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]]; for (i = 0; i < lower_size; i++) { if (lower_table_used[i]) { [f writeString: [OFString stringWithFormat: @"lower_page_%d", i]]; [pool2 releaseObjects]; } else [f writeString: @"nop_page"]; if ((i + 1) % 4 == 0) [f writeString: @",\n\t"]; else if (i + 1 < lower_size) [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]]; for (i = 0; i < casefolding_size; i++) { switch (casefolding_table_used[i]) { case 0: [f writeString: @"nop_page"]; break; case 1: [f writeString: [OFString stringWithFormat: @"cf_page_%d", i]]; [pool2 releaseObjects]; break; case 2: [f writeString: [OFString stringWithFormat: @"lower_page_%d", i]]; [pool2 releaseObjects]; break; } if ((i + 1) % 4 == 0) [f writeString: @",\n\t"]; else if (i + 1 < casefolding_size) [f writeString: @", "]; } [f writeString: @"\n};\n"]; [self freeMemory: upper_table_used]; [self freeMemory: lower_table_used]; [self freeMemory: casefolding_table_used]; [pool release]; } - (void)writeHeaderToFile: (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]]; [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_lower_table[" @"OF_UNICODE_CASEFOLDING_TABLE_SIZE];\n"]; [pool release]; } @end |
Deleted generators/UpperLowerGenerator.h version [75752449a4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted generators/UpperLowerGenerator.m version [6e8155bc72].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified generators/main.m from [dbb1dcb480] to [6d44cafe2e].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * the packaging of this file. */ #include "config.h" #import "OFAutoreleasePool.h" | | < | < | | < < < < < | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * the packaging of this file. */ #include "config.h" #import "OFAutoreleasePool.h" #import "TableGenerator.h" int main() { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; TableGenerator *tgen; tgen = [[[TableGenerator alloc] init] autorelease]; [tgen readUnicodeDataFile: @"UnicodeData.txt"]; [tgen readCaseFoldingFile: @"CaseFolding.txt"]; [tgen writeTablesToFile: @"../src/unicode.m"]; [tgen writeHeaderToFile: @"../src/unicode.h"]; [pool release]; return 0; } |