15569331642446be05292e3e1f8a51218827168cdclairehoimport sys
25569331642446be05292e3e1f8a51218827168cdclairehofrom unicode_parse_common import *
35569331642446be05292e3e1f8a51218827168cdclaireho
45569331642446be05292e3e1f8a51218827168cdclaireho# http://www.unicode.org/Public/5.1.0/ucd/extracted/DerivedCombiningClass.txt
55569331642446be05292e3e1f8a51218827168cdclaireho
65569331642446be05292e3e1f8a51218827168cdclairehoclass IdentityMap(object):
75569331642446be05292e3e1f8a51218827168cdclaireho  def __getitem__(_, key):
85569331642446be05292e3e1f8a51218827168cdclaireho    return key
95569331642446be05292e3e1f8a51218827168cdclaireho
105569331642446be05292e3e1f8a51218827168cdclairehodef main(infile, outfile):
115569331642446be05292e3e1f8a51218827168cdclaireho  ranges = unicode_file_parse(infile, IdentityMap(), '0')
125569331642446be05292e3e1f8a51218827168cdclaireho  ranges = sort_and_merge(ranges)
135569331642446be05292e3e1f8a51218827168cdclaireho
145569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '// Generated from Unicode tables\n'
155569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '#ifndef COMBINING_PROPERTIES_H_'
165569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '#define COMBINING_PROPERTIES_H_\n'
175569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '#include <stdint.h>'
185569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, 'struct combining_property {'
195569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '  uint32_t range_start;'
205569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '  uint32_t range_end;'
215569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '  uint8_t klass;'
225569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '};\n'
235569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, 'static const struct combining_property combining_properties[] = {'
245569331642446be05292e3e1f8a51218827168cdclaireho  for (start, end, value) in ranges:
255569331642446be05292e3e1f8a51218827168cdclaireho    print >>outfile, '  {0x%x, 0x%x, %s},' % (start, end, value)
265569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '};\n'
275569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, 'static const unsigned combining_properties_count = %d;\n' % len(ranges)
285569331642446be05292e3e1f8a51218827168cdclaireho  print >>outfile, '#endif  // COMBINING_PROPERTIES_H_'
295569331642446be05292e3e1f8a51218827168cdclaireho
305569331642446be05292e3e1f8a51218827168cdclairehoif __name__ == '__main__':
315569331642446be05292e3e1f8a51218827168cdclaireho  if len(sys.argv) != 3:
325569331642446be05292e3e1f8a51218827168cdclaireho    print 'Usage: %s <input .txt> <output .h>' % sys.argv[0]
335569331642446be05292e3e1f8a51218827168cdclaireho  else:
345569331642446be05292e3e1f8a51218827168cdclaireho    main(file(sys.argv[1], 'r'), file(sys.argv[2], 'w+'))
35