comparison mupdf-source/thirdparty/gumbo-parser/genperf.py @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 import sys, re
2
3 gperf_output = sys.stdin.read()
4
5 hash_func = re.search(
6 "static unsigned int\s+hash\s+\((.*?)\)\s{(.*?)\n}",
7 gperf_output, re.DOTALL)
8
9 if not hash_func:
10 raise "Failed to detect hash function in GPerf output"
11
12 wordlist = re.search(
13 "wordlist\[\]\s+=\s+{(.*?)}",
14 gperf_output, re.DOTALL)
15
16 if not wordlist:
17 raise "Failed to detect word list in GPerf output"
18
19 def process_wordlist(text):
20 wordlist = [w.strip().replace('"', '') for w in text.split(',')]
21 taglist = [
22 "\tGUMBO_TAG_" + (w.upper().replace('-', '_') if w else 'LAST')
23 for w in wordlist]
24 return taglist
25
26 print "static unsigned int tag_hash(%s)\n{%s\n}" % (
27 hash_func.group(1), hash_func.group(2))
28 print ""
29 print "static const unsigned char kGumboTagMap[] = {\n%s\n};" % (
30 ',\n'.join(process_wordlist(wordlist.group(1))))