-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake16bitcs.py
executable file
·151 lines (112 loc) · 3.33 KB
/
make16bitcs.py
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
#!/usr/bin/env python
# Python script to process a Unicode mapping table for a 16-bit
# character set into an omniORB code set object definition.
# Lines beginning # are comments
# Data lines are of the form:
#
# 0xXXXX <tab> 0xXXXX <tab> # <unicode name>
import sys, string
if len(sys.argv) >= 4:
file = open(sys.argv[1], "r")
csid = sys.argv[2]
name = sys.argv[3]
if len(sys.argv) == 4:
dceid = "omniCodeSet::ID_" + csid
else:
dceid = sys.argv[4]
else:
sys.stderr.write("Usage: %s <file> <csid> <name> [dce id]\n" % sys.argv[0])
sys.exit(1)
to_u = {}
fr_u = {}
to_bank = [0] * 256
fr_bank = [0] * 256
while 1:
line = file.readline()
if not line:
break
if line[0] == "#":
continue
sl = string.split(line)
if (len(sl) < 2 or sl[0][:2] != "0x" or sl[1][:2] != "0x"):
sys.stderr.write("Don't understand line: " +
string.join(sl, "\t") + "\n")
continue
c = string.atoi(sl[0], 0)
u = string.atoi(sl[1], 0)
to_u[c] = u
to_bank[c >> 8] = 1
fr_u[u] = c
fr_bank[u >> 8] = 1
sys.stdout.write("""\
// -*- Mode: C++; -+-
//
// Code set table automatically generated from:
//
// %s
//
#include <omniORB4/CORBA.h>
#include <codeSetUtil.h>
""" % sys.argv[1])
for i in range(256):
if to_bank[i]:
sys.stdout.write("static const omniCodeSet::UniChar toUCS%02x[] = {"%i)
add = i << 8
for j in range(256):
if j % 8 == 0:
sys.stdout.write("\n ")
sys.stdout.write(" 0x%04x," % to_u.get(add + j, 0))
print "\n};\n"
for i in range(256):
if fr_bank[i]:
sys.stdout.write("static const _CORBA_UShort frUCS%02x[] = {" % i)
add = i << 8
for j in range(256):
if j % 8 == 0:
sys.stdout.write("\n ")
sys.stdout.write(" 0x%04x," % fr_u.get(add + j, 0))
print "\n};\n"
sys.stdout.write("""\
#ifdef E_T
# undef E_T
#endif
#define E_T (omniCodeSet::UniChar*)omniCodeSet::empty16BitTable
static const omniCodeSet::UniChar* toUCS[] = {""")
for i in range(256):
if i % 8 == 0:
sys.stdout.write("\n ")
if to_bank[i]:
sys.stdout.write(" toUCS%02x," % i)
else:
sys.stdout.write(" E_T,")
print "\n};\n"
sys.stdout.write("""\
#undef E_T
#define E_T (_CORBA_UShort*)omniCodeSet::empty16BitTable
static const _CORBA_UShort* frUCS[] = {""")
for i in range(256):
if i % 8 == 0:
sys.stdout.write("\n ")
if fr_bank[i]:
sys.stdout.write(" frUCS%02x," % i)
else:
sys.stdout.write(" E_T,")
print "\n};\n"
spacer = " " * len(csid)
print """\
static omniCodeSet::NCS_W_16bit _NCS_W_%(csid)s(%(dceid)s,
%(spacer)s"%(name)s",
%(spacer)stoUCS, frUCS);
static omniCodeSet::TCS_W_16bit _TCS_W_%(csid)s(%(dceid)s,
%(spacer)s"%(name)s",
%(spacer)somniCodeSetUtil::GIOP12,
%(spacer)stoUCS, frUCS);
class CS_%(csid)s_init {
public:
CS_%(csid)s_init() {
omniCodeSet::registerNCS_W(&_NCS_W_%(csid)s);
omniCodeSet::registerTCS_W(&_TCS_W_%(csid)s);
}
};
static CS_%(csid)s_init _CS_%(csid)s_init_;
""" % vars()