Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
libxml2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
libraries
libxml2
Commits
ef97e48c5b5a
Commit
ef97e48c5b5a
authored
3 years ago
by
Nick Wellnhofer
Browse files
Options
Downloads
Patches
Plain Diff
Port genUnicode.py to Python 3
parent
c18d080261e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
genUnicode.py
+40
-40
40 additions, 40 deletions
genUnicode.py
with
40 additions
and
40 deletions
genUnicode.py
+
40
−
40
View file @
ef97e48c
...
...
@@ -31,7 +31,7 @@
# number, inline comparisons are generated
minTableSize
=
8
(
blockfile
,
catfile
)
=
s
tring
.
split
(
sources
)
(
blockfile
,
catfile
)
=
s
ources
.
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
=
str
in
g
.
strip
(
line
)
line
=
l
in
e
.
strip
()
if
line
==
''
:
continue
try
:
...
...
@@ -53,9 +53,9 @@
if
line
==
''
:
continue
try
:
fields
=
str
in
g
.
split
(
line
,
'
;
'
)
range
=
string
.
strip
(
fields
[
0
])
(
start
,
end
)
=
stri
ng
.
split
(
range
,
"
..
"
)
name
=
string
.
strip
(
fields
[
1
])
name
=
string
.
replace
(
name
,
'
'
,
''
)
fields
=
l
in
e
.
split
(
'
;
'
)
range
=
fields
[
0
]
.
strip
(
)
(
start
,
end
)
=
ra
ng
e
.
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
=
str
in
g
.
strip
(
line
)
line
=
l
in
e
.
strip
()
if
line
==
''
:
continue
try
:
...
...
@@ -108,8 +108,8 @@
if
line
==
''
:
continue
try
:
fields
=
str
in
g
.
split
(
line
,
'
;
'
)
point
=
string
.
strip
(
fields
[
0
])
fields
=
l
in
e
.
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
+
"
};
\n
static xmlChRangeGroup xml%sG = {%s,%s,%s,%s};
\n\n
"
output
.
write
(
pline
+
"
};
\n
static
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
"
%
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment