diff options
author | Karl Berry <karl@freefriends.org> | 2017-02-21 23:54:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-02-21 23:54:15 +0000 |
commit | 216791a94d49b9c2142dcb14d7d7ff639b9e2e5b (patch) | |
tree | 5af1781eb56ff157c7e0ff6346b5cbc3b4e152ed /Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py | |
parent | 91c9b5dc1e480401f79c7ea64bd98754e1eab170 (diff) |
dvisvgm-2.1.3
git-svn-id: svn://tug.org/texlive/trunk@43293 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py')
-rwxr-xr-x | Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py b/Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py index bc93ef064f5..d53ad22938e 100755 --- a/Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py +++ b/Build/source/texk/dvisvgm/dvisvgm-src/tests/genhashcheck.py @@ -8,24 +8,27 @@ import re import sys def extract_hashes (fname): - with open(fname) as f: - lines = f.readlines() - found = False - for line in lines: - if ' hash2unicode = {{\n' in line: - found = True - elif found: - match = re.search(r'^\s*{(0x[0-9a-f]{8}),\s*0x[0-9a-f]{4}}, //\s*(.+)\s*$', line) - if match: - print '\t{%s, "%s"},' % (match.group(1), match.group(2)) - else: - found = False + with open(fname) as f: + lines = f.readlines() + found = False + for line in lines: + if ' hash2unicode = {{\n' in line: + found = True + elif found: + match = re.match(r'\s*{(0x[0-9a-f]{8}),\s*0x[0-9a-f]{4}}, //\s*(.+)\s*$', line) + if match: + hashval = match.group(1) + name = match.group(2) + print('\t{}{}, "{}"{},'.format('{', hashval, name, '}')) + else: + found = False if (len(sys.argv) < 2): - sys.exit(1) + sys.exit(1) -print """\ +print("""\ #include <xxhash.h> +#include <cstdint> #include <iomanip> #include <iostream> #include <string> @@ -33,39 +36,38 @@ print """\ using namespace std; struct NameHash { - unsigned hash; - string name; -} nameHashes[] = { -""" + uint32_t hash; + string name; +} nameHashes[] = {\ +""") extract_hashes(sys.argv[1]) -print """\ -}; +print(r"""}; int main () { - unsigned prev_hash=0; - size_t size = sizeof(nameHashes)/sizeof(NameHash); - if (size == 0) { - cout << "hash table is empty\\n"; - return 1; - } - for (unsigned i=0; i < size; i++) { - const string &name = nameHashes[i].name; - const unsigned hash = nameHashes[i].hash; - if (XXH32(&name[0], name.length(), 0) != hash) { - cout << "hash of '" << name << "' doesn't match\\n"; - return 1; - } - if (hash < prev_hash) { - cout << "misplaced hash value " << hex << setw(8) << setfill('0') << hash << "\\n"; - return 1; - } - if (hash == prev_hash) { - cout << "colliding hash values " << hex << setw(8) << setfill('0') << hash << "\\n"; - return 1; - } - prev_hash = hash; - } - cout << "hash check passed\\n"; - return 0; + uint32_t prev_hash=0; + size_t size = sizeof(nameHashes)/sizeof(NameHash); + if (size == 0) { + cout << "hash table is empty\n"; + return 1; + } + for (size_t i=0; i < size; i++) { + const string &name = nameHashes[i].name; + const uint32_t hash = nameHashes[i].hash; + if (XXH32(&name[0], name.length(), 0) != hash) { + cout << "hash of '" << name << "' doesn't match\n"; + return 1; + } + if (hash < prev_hash) { + cout << "misplaced hash value " << hex << setw(8) << setfill('0') << hash << "\n"; + return 1; + } + if (hash == prev_hash) { + cout << "colliding hash values " << hex << setw(8) << setfill('0') << hash << "\n"; + return 1; + } + prev_hash = hash; + } + cout << "hash check passed\n"; + return 0; } -""" +""") |