1 import sys 2 from unicode_parse_common import * 3 4 # http://www.unicode.org/Public/5.1.0/ucd/extracted/DerivedCombiningClass.txt 5 6 class IdentityMap(object): 7 def __getitem__(_, key): 8 return key 9 10 def main(infile, outfile): 11 ranges = unicode_file_parse(infile, IdentityMap(), '0') 12 ranges = sort_and_merge(ranges) 13 14 print >>outfile, '// Generated from Unicode tables\n' 15 print >>outfile, '#ifndef COMBINING_PROPERTIES_H_' 16 print >>outfile, '#define COMBINING_PROPERTIES_H_\n' 17 print >>outfile, '#include <stdint.h>' 18 print >>outfile, 'struct combining_property {' 19 print >>outfile, ' uint32_t range_start;' 20 print >>outfile, ' uint32_t range_end;' 21 print >>outfile, ' uint8_t klass;' 22 print >>outfile, '};\n' 23 print >>outfile, 'static const struct combining_property combining_properties[] = {' 24 for (start, end, value) in ranges: 25 print >>outfile, ' {0x%x, 0x%x, %s},' % (start, end, value) 26 print >>outfile, '};\n' 27 print >>outfile, 'static const unsigned combining_properties_count = %d;\n' % len(ranges) 28 print >>outfile, '#endif // COMBINING_PROPERTIES_H_' 29 30 if __name__ == '__main__': 31 if len(sys.argv) != 3: 32 print 'Usage: %s <input .txt> <output .h>' % sys.argv[0] 33 else: 34 main(file(sys.argv[1], 'r'), file(sys.argv[2], 'w+')) 35