Skip to content
Snippets Groups Projects
Commit ef97e48c5b5a authored by Nick Wellnhofer's avatar Nick Wellnhofer
Browse files

Port genUnicode.py to Python 3

parent c18d080261e3
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@
# number, inline comparisons are generated
minTableSize = 8
(blockfile, catfile) = string.split(sources)
(blockfile, catfile) = sources.split()
#
......@@ -43,9 +43,9 @@
try:
blocks = open(blockfile, "r")
except:
print "Missing %s, aborting ..." % blockfile
print("Missing %s, aborting ..." % blockfile)
sys.exit(1)
for line in blocks.readlines():
if line[0] == '#':
continue
......@@ -47,9 +47,9 @@
sys.exit(1)
for line in blocks.readlines():
if line[0] == '#':
continue
line = string.strip(line)
line = line.strip()
if line == '':
continue
try:
......@@ -53,9 +53,9 @@
if line == '':
continue
try:
fields = string.split(line, ';')
range = string.strip(fields[0])
(start, end) = string.split(range, "..")
name = string.strip(fields[1])
name = string.replace(name, ' ', '')
fields = line.split(';')
range = fields[0].strip()
(start, end) = range.split("..")
name = fields[1].strip()
name = name.replace(' ', '')
except:
......@@ -61,5 +61,5 @@
except:
print "Failed to process line: %s" % (line)
print("Failed to process line: %s" % (line))
continue
start = "0x" + start
end = "0x" + end
......@@ -68,6 +68,6 @@
except:
BlockNames[name] = [(start, end)]
blocks.close()
print "Parsed %d blocks descriptions" % (len(BlockNames.keys()))
print("Parsed %d blocks descriptions" % (len(BlockNames.keys())))
for block in blockAliases:
......@@ -72,5 +72,5 @@
for block in blockAliases:
alias = string.split(block,':')
alist = string.split(alias[1],',')
alias = block.split(':')
alist = alias[1].split(',')
for comp in alist:
......@@ -76,7 +76,7 @@
for comp in alist:
if BlockNames.has_key(comp):
if comp in BlockNames:
if alias[0] not in BlockNames:
BlockNames[alias[0]] = []
for r in BlockNames[comp]:
BlockNames[alias[0]].append(r)
else:
......@@ -78,9 +78,9 @@
if alias[0] not in BlockNames:
BlockNames[alias[0]] = []
for r in BlockNames[comp]:
BlockNames[alias[0]].append(r)
else:
print "Alias %s: %s not in Blocks" % (alias[0], comp)
print("Alias %s: %s not in Blocks" % (alias[0], comp))
continue
#
......@@ -96,7 +96,7 @@
try:
data = open(catfile, "r")
except:
print "Missing %s, aborting ..." % catfile
print("Missing %s, aborting ..." % catfile)
sys.exit(1)
nbchar = 0;
......@@ -104,7 +104,7 @@
for line in data.readlines():
if line[0] == '#':
continue
line = string.strip(line)
line = line.strip()
if line == '':
continue
try:
......@@ -108,8 +108,8 @@
if line == '':
continue
try:
fields = string.split(line, ';')
point = string.strip(fields[0])
fields = line.split(';')
point = fields[0].strip()
value = 0
while point != '':
value = value * 16
......@@ -122,7 +122,7 @@
point = point[1:]
name = fields[2]
except:
print "Failed to process line: %s" % (line)
print("Failed to process line: %s" % (line))
continue
nbchar = nbchar + 1
......@@ -133,7 +133,7 @@
try:
Categories[name] = [value]
except:
print "Failed to process line: %s" % (line)
print("Failed to process line: %s" % (line))
# update "general category" name
try:
Categories[name[0]].append(value)
......@@ -141,6 +141,6 @@
try:
Categories[name[0]] = [value]
except:
print "Failed to process line: %s" % (line)
print("Failed to process line: %s" % (line))
blocks.close()
......@@ -145,6 +145,6 @@
blocks.close()
print "Parsed %d char generating %d categories" % (nbchar, len(Categories.keys()))
print("Parsed %d char generating %d categories" % (nbchar, len(Categories.keys())))
#
# The data is now all read. Time to process it into a more useful form.
......@@ -184,6 +184,5 @@
# Assure all data is in alphabetic order, since we will be doing binary
# searches on the tables.
#
bkeys = BlockNames.keys()
bkeys.sort()
bkeys = sorted(BlockNames.keys())
......@@ -189,6 +188,5 @@
ckeys = Categories.keys()
ckeys.sort()
ckeys = sorted(Categories.keys())
#
# Generate the resulting files
......@@ -196,9 +194,9 @@
try:
header = open("include/libxml/xmlunicode.h", "w")
except:
print "Failed to open include/libxml/xmlunicode.h"
print("Failed to open include/libxml/xmlunicode.h")
sys.exit(1)
try:
output = open("xmlunicode.c", "w")
except:
......@@ -200,9 +198,9 @@
sys.exit(1)
try:
output = open("xmlunicode.c", "w")
except:
print "Failed to open xmlunicode.c"
print("Failed to open xmlunicode.c")
sys.exit(1)
date = time.asctime(time.localtime(time.time()))
......@@ -272,10 +270,10 @@
} xmlUnicodeNameTable;
static xmlIntFunc *xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname);
static xmlIntFunc *xmlUnicodeLookup(const xmlUnicodeNameTable *tptr, const char *tname);
static const xmlUnicodeRange xmlUnicodeBlocks[] = {
""" % (webpage, date, sources));
flag = 0
for block in bkeys:
......@@ -276,10 +274,10 @@
static const xmlUnicodeRange xmlUnicodeBlocks[] = {
""" % (webpage, date, sources));
flag = 0
for block in bkeys:
name = string.replace(block, '-', '')
name = block.replace('-', '')
if flag:
output.write(',\n')
else:
......@@ -287,7 +285,7 @@
output.write(' {"%s", xmlUCSIs%s}' % (block, name))
output.write('};\n\n')
output.write('static xmlUnicodeRange xmlUnicodeCats[] = {\n')
output.write('static const xmlUnicodeRange xmlUnicodeCats[] = {\n')
flag = 0;
for name in ckeys:
if flag:
......@@ -329,4 +327,6 @@
if len(pline) > 60:
output.write(pline + "\n")
pline = " "
elif pline[-1:] == ",":
pline += " "
pline += "{%s, %s}" % (hex(low), hex(high))
......@@ -332,6 +332,6 @@
pline += "{%s, %s}" % (hex(low), hex(high))
output.write(pline + " };\nstatic xmlChRangeGroup xml%sG = {%s,%s,%s,%s};\n\n"
output.write(pline + " };\nstatic const xmlChRangeGroup xml%sG = {%s,%s,%s,%s};\n\n"
% (name, numshort, numlong, sptr, lptr))
output.write(
......@@ -334,9 +334,9 @@
% (name, numshort, numlong, sptr, lptr))
output.write(
"""static xmlUnicodeNameTable xmlUnicodeBlockTbl = {xmlUnicodeBlocks, %s};
static xmlUnicodeNameTable xmlUnicodeCatTbl = {xmlUnicodeCats, %s};
"""static const xmlUnicodeNameTable xmlUnicodeBlockTbl = {xmlUnicodeBlocks, %s};
static const xmlUnicodeNameTable xmlUnicodeCatTbl = {xmlUnicodeCats, %s};
/**
* xmlUnicodeLookup:
......@@ -348,5 +348,5 @@
* Returns pointer to range function if found, otherwise NULL
*/
static xmlIntFunc
*xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname) {
*xmlUnicodeLookup(const xmlUnicodeNameTable *tptr, const char *tname) {
int low, high, mid, cmp;
......@@ -352,5 +352,5 @@
int low, high, mid, cmp;
xmlUnicodeRange *sptr;
const xmlUnicodeRange *sptr;
if ((tptr == NULL) || (tname == NULL)) return(NULL);
......@@ -372,7 +372,7 @@
""" % (len(BlockNames), len(Categories)) )
for block in bkeys:
name = string.replace(block, '-', '')
name = block.replace('-', '')
header.write("XMLPUBFUN int XMLCALL xmlUCSIs%s\t(int code);\n" % name)
output.write("/**\n * xmlUCSIs%s:\n * @code: UCS code point\n" % (name))
output.write(" *\n * Check whether the character is part of %s UCS Block\n"%
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment