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
265a979b5b49
Commit
265a979b5b49
authored
2 years ago
by
Nick Wellnhofer
Browse files
Options
Downloads
Patches
Plain Diff
Port genChRanges.py to Python 3
parent
26176bd5bb02
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
genChRanges.py
+279
-281
279 additions, 281 deletions
genChRanges.py
with
279 additions
and
281 deletions
genChRanges.py
+
279
−
281
View file @
265a979b
...
...
@@ -16,7 +16,6 @@
#
import
sys
import
string
import
time
#
...
...
@@ -57,7 +56,7 @@
try
:
defines
=
open
(
"
chvalid.def
"
,
"
r
"
)
except
:
print
"
Missing chvalid.def, aborting ...
"
print
(
"
Missing chvalid.def, aborting ...
"
)
sys
.
exit
(
1
)
#
...
...
@@ -72,8 +71,8 @@
# ignore blank lines, or lines beginning with '#'
if
line
[
0
]
==
'
#
'
:
continue
line
=
str
in
g
.
strip
(
line
)
line
=
l
in
e
.
strip
()
if
line
==
''
:
continue
# split line into space-separated fields, then split on type
try
:
...
...
@@ -76,8 +75,8 @@
if
line
==
''
:
continue
# split line into space-separated fields, then split on type
try
:
fields
=
str
in
g
.
split
(
line
,
'
'
)
fields
=
l
in
e
.
split
(
'
'
)
#
# name line:
# validate any previous function block already ended
...
...
@@ -88,7 +87,7 @@
if
fields
[
0
]
==
'
name
'
:
name
=
fields
[
1
]
if
state
!=
0
:
print
"'
name
'
%s found before previous name
"
\
"
completed
"
%
(
fields
[
1
])
print
(
"'
name
'
%s found before previous name
"
\
"
completed
"
%
(
fields
[
1
])
)
continue
state
=
1
...
...
@@ -93,8 +92,8 @@
continue
state
=
1
if
Functs
.
has_key
(
name
)
:
print
"
name
'
%s
'
already present - may give
"
\
"
wrong results
"
%
(
name
)
if
name
in
Functs
:
print
(
"
name
'
%s
'
already present - may give
"
\
"
wrong results
"
%
(
name
)
)
else
:
# dict entry with two list elements (chdata, rangedata)
Functs
[
name
]
=
[
[],
[]
]
...
...
@@ -107,7 +106,7 @@
#
elif
fields
[
0
]
==
'
end
'
:
if
state
==
0
:
print
"'
end
'
found outside of function block
"
print
(
"'
end
'
found outside of function block
"
)
continue
state
=
0
...
...
@@ -119,5 +118,5 @@
#
elif
fields
[
0
]
==
'
ur
'
:
if
state
!=
1
:
raise
ValidationError
,
"'
ur
'
found outside of
'
name
'
block
"
raise
Exception
(
"'
ur
'
found outside of
'
name
'
block
"
)
for
el
in
fields
[
1
:]:
...
...
@@ -123,5 +122,5 @@
for
el
in
fields
[
1
:]:
pos
=
string
.
find
(
el
,
'
..
'
)
pos
=
el
.
find
(
'
..
'
)
# pos <=0 means not a range, so must be individual value
if
pos
<=
0
:
# cheap handling of hex or decimal values
...
...
@@ -132,8 +131,8 @@
else
:
value
=
int
(
el
)
if
((
value
<
0
)
|
(
value
>
0x1fffff
)):
raise
ValidationError
,
'
Illegal value (%s) in ch for
'
\
'
name %s
'
%
(
el
,
name
)
raise
Exception
(
'
Illegal value (%s) in ch for
'
\
'
name %s
'
%
(
el
,
name
)
)
# for ur we have only ranges (makes things simpler),
# so convert val to range
currange
=
(
value
,
value
)
...
...
@@ -141,7 +140,7 @@
# the interval
else
:
# split the range into it's first-val, last-val
(
first
,
last
)
=
string
.
split
(
el
,
"
..
"
)
(
first
,
last
)
=
el
.
split
(
"
..
"
)
# convert values from text into binary
if
first
[
0
:
2
]
==
'
0x
'
:
start
=
int
(
first
[
2
:],
16
)
...
...
@@ -156,7 +155,7 @@
else
:
end
=
int
(
last
)
if
(
start
<
0
)
|
(
end
>
0x1fffff
)
|
(
start
>
end
):
raise
ValidationError
,
"
Invalid range
'
%s
'"
%
el
raise
Exception
(
"
Invalid range
'
%s
'"
%
el
)
currange
=
(
start
,
end
)
# common path - 'currange' has the range, now take care of it
# We split on single-byte values vs. multibyte
...
...
@@ -165,7 +164,7 @@
# validate that value not previously defined
if
Functs
[
name
][
0
][
ch
]:
msg
=
"
Duplicate ch value
'
%s
'
for name
'
%s
'"
%
(
el
,
name
)
raise
ValidationError
,
msg
raise
Exception
(
msg
)
Functs
[
name
][
0
][
ch
]
=
1
else
:
# multi-byte
if
currange
in
Functs
[
name
][
1
]:
...
...
@@ -169,9 +168,9 @@
Functs
[
name
][
0
][
ch
]
=
1
else
:
# multi-byte
if
currange
in
Functs
[
name
][
1
]:
raise
ValidationError
,
"
range already defined in
"
\
"
function
"
raise
Exception
(
"
range already defined in
"
\
"
function
"
)
else
:
Functs
[
name
][
1
].
append
(
currange
)
except
:
...
...
@@ -174,8 +173,8 @@
else
:
Functs
[
name
][
1
].
append
(
currange
)
except
:
print
"
Failed to process line: %s
"
%
(
line
)
print
(
"
Failed to process line: %s
"
%
(
line
)
)
raise
#
# At this point, the entire definition file has been processed. Now we
...
...
@@ -194,9 +193,9 @@
try
:
header
=
open
(
"
include/libxml/chvalid.h
"
,
"
w
"
)
except
:
print
"
Failed to open include/libxml/chvalid.h
"
print
(
"
Failed to open include/libxml/chvalid.h
"
)
sys
.
exit
(
1
)
try
:
output
=
open
(
"
chvalid.c
"
,
"
w
"
)
except
:
...
...
@@ -198,9 +197,9 @@
sys
.
exit
(
1
)
try
:
output
=
open
(
"
chvalid.c
"
,
"
w
"
)
except
:
print
"
Failed to open chvalid.c
"
print
(
"
Failed to open chvalid.c
"
)
sys
.
exit
(
1
)
date
=
time
.
asctime
(
time
.
localtime
(
time
.
time
()))
...
...
@@ -236,10 +235,10 @@
typedef struct _xmlChSRange xmlChSRange;
typedef xmlChSRange *xmlChSRangePtr;
struct _xmlChSRange {
unsigned short
low;
unsigned short
high;
unsigned short
\t
low;
unsigned short
\t
high;
};
typedef struct _xmlChLRange xmlChLRange;
typedef xmlChLRange *xmlChLRangePtr;
struct _xmlChLRange {
...
...
@@ -241,12 +240,12 @@
};
typedef struct _xmlChLRange xmlChLRange;
typedef xmlChLRange *xmlChLRangePtr;
struct _xmlChLRange {
unsigned int
low;
unsigned int
high;
unsigned int
\t
low;
unsigned int
\t
high;
};
typedef struct _xmlChRangeGroup xmlChRangeGroup;
typedef xmlChRangeGroup *xmlChRangeGroupPtr;
struct _xmlChRangeGroup {
...
...
@@ -248,15 +247,15 @@
};
typedef struct _xmlChRangeGroup xmlChRangeGroup;
typedef xmlChRangeGroup *xmlChRangeGroupPtr;
struct _xmlChRangeGroup {
int
nbShortRange;
int
nbLongRange;
const xmlChSRange
*shortRange;
/* points to an array of ranges */
const xmlChLRange
*longRange;
int
\t\t\t
nbShortRange;
int
\t\t\t
nbLongRange;
const xmlChSRange
\t
*shortRange;
\t
/* points to an array of ranges */
const xmlChLRange
\t
*longRange;
};
/**
* Range checking routine
*/
XMLPUBFUN int XMLCALL
...
...
@@ -257,11 +256,11 @@
};
/**
* Range checking routine
*/
XMLPUBFUN int XMLCALL
xmlCharInRange(unsigned int val, const xmlChRangeGroup *group);
\t\t
xmlCharInRange(unsigned int val, const xmlChRangeGroup *group);
"""
%
(
date
,
sources
));
output
.
write
(
"""
/*
...
...
@@ -264,9 +263,9 @@
"""
%
(
date
,
sources
));
output
.
write
(
"""
/*
* chvalid.c:
this module implements the character range
*
validation APIs
* chvalid.c:
\t
this module implements the character range
*
\t\t
validation APIs
*
* This file is automatically generated from the cvs source
* definition files using the genChRanges.py Python script
...
...
@@ -299,8 +298,7 @@
# compares, otherwise we output a 256-byte table and a macro to use it.
#
fkeys
=
Functs
.
keys
()
# Dictionary of all defined functions
fkeys
.
sort
()
# Put some order to our output
fkeys
=
sorted
(
Functs
.
keys
())
for
f
in
fkeys
:
...
...
@@ -354,7 +352,7 @@
# okay, I'm tired of the messy lineup - let's automate it!
pline
=
"
#define %s_ch(c)
"
%
f
# 'ntab' is number of tabs needed to position to col. 33 from name end
ntab
=
4
-
(
len
(
pline
))
/
8
ntab
=
4
-
(
len
(
pline
))
/
/
8
if
ntab
<
0
:
ntab
=
0
just
=
""
...
...
@@ -387,7 +385,7 @@
*/
"""
%
f
)
pline
=
"
#define %sQ(c)
"
%
f
ntab
=
4
-
(
len
(
pline
))
/
8
ntab
=
4
-
(
len
(
pline
))
/
/
8
if
ntab
<
0
:
ntab
=
0
just
=
""
...
...
@@ -495,22 +493,22 @@
const xmlChLRange *lptr;
if (rptr == NULL) return(0);
if (val < 0x10000) {
/* is val in
'
short
'
or
'
long
'
array? */
if (rptr->nbShortRange == 0)
return 0;
low = 0;
high = rptr->nbShortRange - 1;
sptr = rptr->shortRange;
while (low <= high) {
mid = (low + high) / 2;
if ((unsigned short) val < sptr[mid].low) {
high = mid - 1;
} else {
if ((unsigned short) val > sptr[mid].high) {
low = mid + 1;
} else {
return 1;
}
}
}
if (val < 0x10000) {
\t
/* is val in
'
short
'
or
'
long
'
array? */
\t
if (rptr->nbShortRange == 0)
\t
return 0;
\t
low = 0;
\t
high = rptr->nbShortRange - 1;
\t
sptr = rptr->shortRange;
\t
while (low <= high) {
\t
mid = (low + high) / 2;
\t
if ((unsigned short) val < sptr[mid].low) {
\t\t
high = mid - 1;
\t
} else {
\t\t
if ((unsigned short) val > sptr[mid].high) {
\t\t
low = mid + 1;
\t\t
} else {
\t\t
return 1;
\t\t
}
\t
}
\t
}
} else {
...
...
@@ -516,22 +514,22 @@
} else {
if (rptr->nbLongRange == 0) {
return 0;
}
low = 0;
high = rptr->nbLongRange - 1;
lptr = rptr->longRange;
while (low <= high) {
mid = (low + high) / 2;
if (val < lptr[mid].low) {
high = mid - 1;
} else {
if (val > lptr[mid].high) {
low = mid + 1;
} else {
return 1;
}
}
}
\t
if (rptr->nbLongRange == 0) {
\t
return 0;
\t
}
\t
low = 0;
\t
high = rptr->nbLongRange - 1;
\t
lptr = rptr->longRange;
\t
while (low <= high) {
\t
mid = (low + high) / 2;
\t
if (val < lptr[mid].low) {
\t\t
high = mid - 1;
\t
} else {
\t\t
if (val > lptr[mid].high) {
\t\t
low = mid + 1;
\t\t
} else {
\t\t
return 1;
\t\t
}
\t
}
\t
}
}
return 0;
}
...
...
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