/[pcre]/code/trunk/maint/GenerateUtt.py
ViewVC logotype

Contents of /code/trunk/maint/GenerateUtt.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1050 - (show annotations)
Sun Sep 30 18:20:10 2012 UTC (7 years ago) by chpe
File MIME type: text/x-python
File size: 4481 byte(s)
unicode: Update to Unicode 6.2
1 #! /usr/bin/python
2
3 # Generate utt tables.
4
5 # The source file pcre_tables.c contains (amongst other things), a table that
6 # is indexed by script name. In order to reduce the number of relocations when
7 # loading the library, the names are held as a single large string, with
8 # offsets in the table. This is tedious to maintain by hand. Therefore, this
9 # script is used to generate the table. The output is sent to stdout; usually
10 # that should be directed to a temporary file. Then pcre_tables.c can be edited
11 # by replacing the relevant definitions and table therein with the temporary
12 # file.
13
14 # Modified by PH 17-March-2009 to generate the more verbose form that works
15 # for UTF-support in EBCDIC as well as ASCII environments.
16 # Modified by PH 01-March-2010 to add new scripts for Unicode 5.2.0.
17 # Modified by PH 04-May-2010 to add new "X.." special categories.
18 # Modified by PH 30-April-2011 to add new scripts for Unicode 6.0.0
19 # Modified by ChPe 30-September-2012 to add this note; no other changes were
20 # necessary for Unicode 6.2.0 support.
21
22 script_names = ['Arabic', 'Armenian', 'Bengali', 'Bopomofo', 'Braille', 'Buginese', 'Buhid', 'Canadian_Aboriginal', \
23 'Cherokee', 'Common', 'Coptic', 'Cypriot', 'Cyrillic', 'Deseret', 'Devanagari', 'Ethiopic', 'Georgian', \
24 'Glagolitic', 'Gothic', 'Greek', 'Gujarati', 'Gurmukhi', 'Han', 'Hangul', 'Hanunoo', 'Hebrew', 'Hiragana', \
25 'Inherited', 'Kannada', 'Katakana', 'Kharoshthi', 'Khmer', 'Lao', 'Latin', 'Limbu', 'Linear_B', 'Malayalam', \
26 'Mongolian', 'Myanmar', 'New_Tai_Lue', 'Ogham', 'Old_Italic', 'Old_Persian', 'Oriya', 'Osmanya', 'Runic', \
27 'Shavian', 'Sinhala', 'Syloti_Nagri', 'Syriac', 'Tagalog', 'Tagbanwa', 'Tai_Le', 'Tamil', 'Telugu', 'Thaana', \
28 'Thai', 'Tibetan', 'Tifinagh', 'Ugaritic', 'Yi', \
29 # New for Unicode 5.0
30 'Balinese', 'Cuneiform', 'Nko', 'Phags_Pa', 'Phoenician', \
31 # New for Unicode 5.1
32 'Carian', 'Cham', 'Kayah_Li', 'Lepcha', 'Lycian', 'Lydian', 'Ol_Chiki', 'Rejang', 'Saurashtra', 'Sundanese', 'Vai', \
33 # New for Unicode 5.2
34 'Avestan', 'Bamum', 'Egyptian_Hieroglyphs', 'Imperial_Aramaic', \
35 'Inscriptional_Pahlavi', 'Inscriptional_Parthian', \
36 'Javanese', 'Kaithi', 'Lisu', 'Meetei_Mayek', \
37 'Old_South_Arabian', 'Old_Turkic', 'Samaritan', 'Tai_Tham', 'Tai_Viet', \
38 # New for Unicode 6.0.0
39 'Batak', 'Brahmi', 'Mandaic', \
40 # New for Unicode 6.1.0
41 'Chakma', 'Meroitic_Cursive', 'Meroitic_Hieroglyphs', 'Miao', 'Sharada', 'Sora_Sompeng', 'Takri'
42 ]
43
44 category_names = ['Cc', 'Cf', 'Cn', 'Co', 'Cs', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu',
45 'Mc', 'Me', 'Mn', 'Nd', 'Nl', 'No', 'Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po', 'Ps',
46 'Sc', 'Sk', 'Sm', 'So', 'Zl', 'Zp', 'Zs' ]
47
48 general_category_names = ['C', 'L', 'M', 'N', 'P', 'S', 'Z']
49
50 # First add the Unicode script and category names.
51
52 utt_table = zip(script_names, ['PT_SC'] * len(script_names))
53 utt_table += zip(category_names, ['PT_PC'] * len(category_names))
54 utt_table += zip(general_category_names, ['PT_GC'] * len(general_category_names))
55
56 # Now add our own specials.
57
58 utt_table.append(('Any', 'PT_ANY'))
59 utt_table.append(('L&', 'PT_LAMP'))
60 utt_table.append(('Xan', 'PT_ALNUM'))
61 utt_table.append(('Xps', 'PT_PXSPACE'))
62 utt_table.append(('Xsp', 'PT_SPACE'))
63 utt_table.append(('Xwd', 'PT_WORD'))
64
65 # Sort the table.
66
67 utt_table.sort()
68
69 # We have to use STR_ macros to define the strings so that it all works in
70 # UTF-8 mode on EBCDIC platforms.
71
72 for utt in utt_table:
73 print '#define STRING_%s0' % (utt[0].replace('&', '_AMPERSAND')),
74 for c in utt[0]:
75 if c == '_':
76 print 'STR_UNDERSCORE',
77 elif c == '&':
78 print 'STR_AMPERSAND',
79 else:
80 print 'STR_%s' % c,;
81 print '"\\0"'
82
83 # Print the actual table, using the string names
84
85 print ''
86 print 'const char PRIV(utt_names)[] =';
87 last = ''
88 for utt in utt_table:
89 if utt == utt_table[-1]:
90 last = ';'
91 print ' STRING_%s0%s' % (utt[0].replace('&', '_AMPERSAND'), last)
92 # This was how it was done before the EBCDIC-compatible modification.
93 # print ' "%s\\0"%s' % (utt[0], last)
94
95 print '\nconst ucp_type_table PRIV(utt)[] = {'
96 offset = 0
97 last = ','
98 for utt in utt_table:
99 if utt[1] in ('PT_ANY', 'PT_LAMP', 'PT_ALNUM', 'PT_PXSPACE',
100 'PT_SPACE', 'PT_WORD'):
101 value = '0'
102 else:
103 value = 'ucp_' + utt[0]
104 if utt == utt_table[-1]:
105 last = ''
106 print ' { %3d, %s, %s }%s' % (offset, utt[1], value, last)
107 offset += len(utt[0]) + 1
108 print '};'

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5