import fileinput, re, os, sys, operator, math
+# The directory in which this file resides.
+fdir = os.path.dirname(os.path.realpath(__file__)) + "/"
+
preamble = '''// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
surrogate_codepoints = (0xd800, 0xdfff)
def fetch(f):
- if not os.path.exists(os.path.basename(f)):
+ path = fdir + os.path.basename(f)
+ if not os.path.exists(path):
os.system("curl -O http://www.unicode.org/Public/UNIDATA/%s"
% f)
- if not os.path.exists(os.path.basename(f)):
+ if not os.path.exists(path):
sys.stderr.write("cannot load %s" % f)
exit(1)
udict = {}
range_start = -1
- for line in fileinput.input(f):
+ for line in fileinput.input(fdir + f):
data = line.split(';')
if len(data) != 15:
continue
def load_special_casing(f, to_upper, to_lower, to_title):
fetch(f)
- for line in fileinput.input(f):
+ for line in fileinput.input(fdir + f):
data = line.split('#')[0].split(';')
if len(data) == 5:
code, lower, title, upper, _comment = data
re1 = re.compile("^ *([0-9A-F]+) *; *(\w+)")
re2 = re.compile("^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)")
- for line in fileinput.input(os.path.basename(f)):
+ for line in fileinput.input(fdir + os.path.basename(f)):
prop = None
d_lo = 0
d_hi = 0
canon_comp_keys = sorted(canon_comp.keys())
if __name__ == "__main__":
- r = "tables.rs"
+ r = fdir + "tables.rs"
if os.path.exists(r):
os.remove(r)
with open(r, "w") as rf:
# download and parse all the data
fetch("ReadMe.txt")
- with open("ReadMe.txt") as readme:
+ with open(fdir + "ReadMe.txt") as readme:
pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode"
unicode_version = re.search(pattern, readme.read()).groups()
rf.write("""