2015-02-27 06:17:26 +01:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
2016-04-07 05:01:14 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
2016-07-08 04:32:53 +02:00
|
|
|
try:
|
|
|
|
from urllib2 import urlopen
|
|
|
|
from urllib2 import URLError
|
|
|
|
except ImportError:
|
|
|
|
from urllib.request import urlopen
|
|
|
|
from urllib.error import URLError
|
|
|
|
|
2015-02-27 06:17:26 +01:00
|
|
|
import sys
|
2016-06-09 07:22:31 +02:00
|
|
|
import os
|
2015-02-27 06:17:26 +01:00
|
|
|
from lxml import html
|
2016-04-07 05:01:14 +02:00
|
|
|
from six.moves import range
|
2015-02-27 06:17:26 +01:00
|
|
|
|
2016-06-09 07:22:31 +02:00
|
|
|
datafile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'list-unicodeset.html')
|
|
|
|
try:
|
2016-07-08 04:32:53 +02:00
|
|
|
fp = urlopen('http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[%3AGC%3DZs%3A][%3ADI%3A]&abb=on&ucd=on&esc=on&g')
|
2016-06-09 07:22:31 +02:00
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
2017-08-25 04:46:53 +02:00
|
|
|
# check before writing if data isn't corrupted.
|
|
|
|
dom = html.fromstring(data)
|
|
|
|
x = dom.xpath('/html/body/form/p/text()')
|
|
|
|
p = x[1]
|
2016-07-08 04:32:53 +02:00
|
|
|
fp = open(datafile, 'wb');
|
2016-06-09 07:22:31 +02:00
|
|
|
fp.write(data);
|
|
|
|
fp.close();
|
2017-08-25 04:46:53 +02:00
|
|
|
except (URLError, IndexError):
|
2016-06-09 07:22:31 +02:00
|
|
|
# fall back reading the static data in repo
|
|
|
|
try:
|
|
|
|
fp = open(datafile)
|
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
|
|
|
except IOError:
|
|
|
|
sys.stderr.write("Error: No static data to generate the blank data. please make sure the network connection is reachable to Unicode.org\n")
|
|
|
|
sys.exit(1)
|
2015-02-27 06:17:26 +01:00
|
|
|
|
|
|
|
dom = html.fromstring(data)
|
|
|
|
x = dom.xpath('/html/body/form/p/text()')
|
|
|
|
p = x[1]
|
|
|
|
if p[0] == '[' and p[-1] == ']':
|
|
|
|
p = p.replace('[', '').replace(']', '')
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
|
|
|
fescape = False
|
|
|
|
funicode = False
|
|
|
|
frange = False
|
|
|
|
fprocess = False
|
|
|
|
v = 0
|
|
|
|
vbegin = 0
|
|
|
|
vend = 0
|
|
|
|
n = 0
|
|
|
|
l = []
|
|
|
|
|
|
|
|
def insert(db, begin, end):
|
|
|
|
db.append([begin, end])
|
|
|
|
|
|
|
|
for i in p:
|
|
|
|
if i == '\\':
|
|
|
|
if n > 0:
|
|
|
|
if frange == True and funicode == True:
|
|
|
|
vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
fprocess = True
|
|
|
|
elif funicode == True:
|
|
|
|
vbegin = v
|
|
|
|
vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
fprocess = True
|
|
|
|
funicode = False
|
|
|
|
fescape = True
|
|
|
|
elif i.lower() == 'u' and fescape == True:
|
|
|
|
funicode = True
|
2015-02-27 07:48:54 +01:00
|
|
|
fescape = False
|
2015-02-27 06:17:26 +01:00
|
|
|
elif i >= '0' and i <= '9' or i.lower() >= 'a' and i.lower() <= 'f':
|
2015-02-27 07:48:54 +01:00
|
|
|
if fescape == True:
|
2016-04-07 05:01:14 +02:00
|
|
|
raise RuntimeError("Unexpected escape code")
|
2015-02-27 06:17:26 +01:00
|
|
|
if funicode == True:
|
|
|
|
v <<= 4
|
|
|
|
v += int(i, 16)
|
|
|
|
else:
|
2016-04-07 05:01:14 +02:00
|
|
|
raise RuntimeError("Unable to parse Unicode")
|
2015-02-27 06:17:26 +01:00
|
|
|
elif i == ' ':
|
2015-02-27 07:48:54 +01:00
|
|
|
if fescape == True:
|
|
|
|
funicode = True
|
|
|
|
fescape = False
|
|
|
|
v = 0x20
|
2015-02-27 06:17:26 +01:00
|
|
|
if frange == True and funicode == True:
|
|
|
|
vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
fprocess = True
|
|
|
|
elif funicode == True:
|
|
|
|
vbegin = v
|
|
|
|
vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
fprocess = True
|
|
|
|
funicode = False
|
|
|
|
frange = False
|
|
|
|
elif i == '-':
|
2015-02-27 07:48:54 +01:00
|
|
|
if fescape == True:
|
2016-04-07 05:01:14 +02:00
|
|
|
raise RuntimeError("Unexpected escape code")
|
2015-02-27 06:17:26 +01:00
|
|
|
vbegin = v
|
|
|
|
v = 0
|
|
|
|
funicode = False
|
|
|
|
frange = True
|
|
|
|
else:
|
2016-04-07 05:01:14 +02:00
|
|
|
raise RuntimeError("Unable to parse Unicode: %s" % i)
|
2015-02-27 06:17:26 +01:00
|
|
|
|
|
|
|
if fprocess == True:
|
|
|
|
vbegin = 0
|
|
|
|
vend = 0
|
|
|
|
v = 0
|
|
|
|
fprocess = False
|
|
|
|
funicode = False
|
|
|
|
frange = False
|
|
|
|
n += 1
|
|
|
|
|
|
|
|
if frange == True and funicode == True:
|
|
|
|
vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
elif funicode == True:
|
|
|
|
vbegin = vend = v
|
|
|
|
insert(l, vbegin, vend)
|
|
|
|
|
|
|
|
ncode = 0
|
|
|
|
for i in l:
|
|
|
|
ncode += (i[1] - i[0] + 1)
|
|
|
|
|
|
|
|
a = int(x[0].split(' ')[0].replace(',', ''))
|
|
|
|
if a != ncode:
|
|
|
|
sys.stderr.write("Unexpected the amount of code points: %d (expected %d)\n" % (ncode, a))
|
|
|
|
sys.exit(1)
|
2015-02-27 07:48:54 +01:00
|
|
|
|
|
|
|
# exception; BRAILLE PATTERN BLANK
|
2015-02-27 06:17:26 +01:00
|
|
|
insert(l, 0x2800, 0x2800)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
s = sys.stdin.readline().rstrip()
|
|
|
|
if s == "@@@":
|
|
|
|
break
|
2016-04-07 05:01:14 +02:00
|
|
|
print(s)
|
2015-02-27 06:17:26 +01:00
|
|
|
|
2016-04-07 05:01:14 +02:00
|
|
|
print("static FcChar32 _fcBlanks[%s] = {" % (ncode + 1))
|
2015-02-27 06:17:26 +01:00
|
|
|
k = 0
|
2016-04-07 05:01:14 +02:00
|
|
|
for i in sorted(l, key=lambda a: a[0]):
|
2015-02-27 06:17:26 +01:00
|
|
|
for j in range(i[0], i[1] + 1):
|
|
|
|
if k != 0:
|
2016-04-07 05:01:14 +02:00
|
|
|
print(",")
|
|
|
|
print(" 0x%04x" % j, end=' ')
|
2015-02-27 06:17:26 +01:00
|
|
|
k += 1
|
|
|
|
|
2016-04-07 05:01:14 +02:00
|
|
|
print("};")
|
|
|
|
print('''
|
2015-02-27 06:17:26 +01:00
|
|
|
static FcBlanks fcBlanks = {
|
|
|
|
%s,
|
|
|
|
-1,
|
|
|
|
_fcBlanks
|
|
|
|
};
|
2016-04-07 05:01:14 +02:00
|
|
|
''' % (ncode + 1))
|