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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 391 - (show annotations)
Tue Mar 17 21:16:01 2009 UTC (10 years, 7 months ago) by ph10
File MIME type: text/x-python
File size: 3270 byte(s)
Add support for UTF-8 in EBCDIC environments.
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.
10
11 # Modified by PH 17-March-2009 to generate the more verbose form that works
12 # for UTF-support in EBCDIC as well as ASCII environments.
13
14 script_names = ['Arabic', 'Armenian', 'Bengali', 'Bopomofo', 'Braille', 'Buginese', 'Buhid', 'Canadian_Aboriginal', \
15 'Cherokee', 'Common', 'Coptic', 'Cypriot', 'Cyrillic', 'Deseret', 'Devanagari', 'Ethiopic', 'Georgian', \
16 'Glagolitic', 'Gothic', 'Greek', 'Gujarati', 'Gurmukhi', 'Han', 'Hangul', 'Hanunoo', 'Hebrew', 'Hiragana', \
17 'Inherited', 'Kannada', 'Katakana', 'Kharoshthi', 'Khmer', 'Lao', 'Latin', 'Limbu', 'Linear_B', 'Malayalam', \
18 'Mongolian', 'Myanmar', 'New_Tai_Lue', 'Ogham', 'Old_Italic', 'Old_Persian', 'Oriya', 'Osmanya', 'Runic', \
19 'Shavian', 'Sinhala', 'Syloti_Nagri', 'Syriac', 'Tagalog', 'Tagbanwa', 'Tai_Le', 'Tamil', 'Telugu', 'Thaana', \
20 'Thai', 'Tibetan', 'Tifinagh', 'Ugaritic', 'Yi', \
21 # New for Unicode 5.0
22 'Balinese', 'Cuneiform', 'Nko', 'Phags_Pa', 'Phoenician', \
23 # New for Unicode 5.1
24 'Carian', 'Cham', 'Kayah_Li', 'Lepcha', 'Lycian', 'Lydian', 'Ol_Chiki', 'Rejang', 'Saurashtra', 'Sundanese', 'Vai'
25 ]
26
27 category_names = ['Cc', 'Cf', 'Cn', 'Co', 'Cs', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu',
28 'Mc', 'Me', 'Mn', 'Nd', 'Nl', 'No', 'Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po', 'Ps',
29 'Sc', 'Sk', 'Sm', 'So', 'Zl', 'Zp', 'Zs' ]
30
31 general_category_names = ['C', 'L', 'M', 'N', 'P', 'S', 'Z']
32
33 utt_table = zip(script_names, ['PT_SC'] * len(script_names))
34 utt_table += zip(category_names, ['PT_PC'] * len(category_names))
35 utt_table += zip(general_category_names, ['PT_GC'] * len(general_category_names))
36 utt_table.append(('L&', 'PT_LAMP'))
37 utt_table.append(('Any', 'PT_ANY'))
38
39 utt_table.sort()
40
41 # We have to use STR_ macros to define the strings so that it all works in
42 # UTF-8 mode on EBCDIC platforms.
43
44 for utt in utt_table:
45 print '#define STRING_%s0' % (utt[0].replace('&', '_AMPERSAND')),
46 for c in utt[0]:
47 if c == '_':
48 print 'STR_UNDERSCORE',
49 elif c == '&':
50 print 'STR_AMPERSAND',
51 else:
52 print 'STR_%s' % c,;
53 print '"\\0"'
54
55 # Print the actual table, using the string names
56
57 print ''
58 print 'const char _pcre_utt_names[] = ';
59 last = ''
60 for utt in utt_table:
61 if utt == utt_table[-1]:
62 last = ';'
63 print ' STRING_%s0%s' % (utt[0].replace('&', '_AMPERSAND'), last)
64 # This was how it was done before the EBCDIC-compatible modification.
65 # print ' "%s\\0"%s' % (utt[0], last)
66
67 print '\nconst ucp_type_table _pcre_utt[] = { '
68 offset = 0
69 last = ','
70 for utt in utt_table:
71 if utt[1] in ('PT_ANY', 'PT_LAMP'):
72 value = '0'
73 else:
74 value = 'ucp_' + utt[0]
75 if utt == utt_table[-1]:
76 last = ''
77 print ' { %3d, %s, %s }%s ' % (offset, utt[1], value, last)
78 offset += len(utt[0]) + 1
79 print '};'

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5