-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake8bitcs.py
executable file
·133 lines (98 loc) · 2.87 KB
/
make8bitcs.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
#!/usr/bin/env python
# Python script to process a Unicode mapping table for an 8-bit
# character set into an omniORB code set object definition.
# Lines beginning # are comments
# Data lines are of the form:
#
# 0xXX <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 = [0] * 256
fr_u = {}
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
fr_u[u] = c
bank[u >> 8] = 1
sys.stdout.write("""\
// -*- Mode: C++; -+-
//
// Code set table automatically generated from:
//
// %s
//
#include <omniORB4/CORBA.h>
#include <omniORB4/linkHacks.h>
#include <codeSetUtil.h>
OMNI_NAMESPACE_BEGIN(omni)
static const omniCodeSet::UniChar toUCS[] = {""" % sys.argv[1])
for i in range(256):
if i % 8 == 0:
sys.stdout.write("\n ")
sys.stdout.write(" 0x%04x," % to_u[i])
print "\n};\n"
for i in range(256):
if bank[i]:
sys.stdout.write("static const _CORBA_Char frUCS%02x[] = {" % i)
add = i << 8
for j in range(256):
if j % 8 == 0:
sys.stdout.write("\n ")
sys.stdout.write(" 0x%02x," % fr_u.get(add + j, 0))
print "\n};\n"
sys.stdout.write("""\
#ifdef E_T
# undef E_T
#endif
#define E_T omniCodeSet::empty8BitTable
static const _CORBA_Char* frUCS[] = {""")
for i in range(256):
if i % 8 == 0:
sys.stdout.write("\n ")
if bank[i]:
sys.stdout.write(" frUCS%02x," % i)
else:
sys.stdout.write(" E_T,")
print "\n};\n"
spacer = " " * len(csid)
print """\
static omniCodeSet::NCS_C_8bit _NCS_C_%(csid)s(%(dceid)s,
%(spacer)s"%(name)s",
%(spacer)stoUCS, frUCS);
static omniCodeSet::TCS_C_8bit _TCS_C_%(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_C(&_NCS_C_%(csid)s);
omniCodeSet::registerTCS_C(&_TCS_C_%(csid)s);
}
};
static CS_%(csid)s_init _CS_%(csid)s_init_;
OMNI_NAMESPACE_END(omni)
OMNI_EXPORT_LINK_FORCE_SYMBOL(CS_%(csid)s);
""" % vars()