diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2016-05-10 05:15:59 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2016-05-10 05:15:59 +0200 |
commit | e706cbe5496e1829d1ddbe4d5bb0a6728204e510 (patch) | |
tree | c72d1848ac6aef07703848d0ffbe80f1336a81cd /src/gperf_unfold_key_conv.py | |
parent | 69ab3addbc2dbbc90c311b2845cd25a2159435cd (diff) | |
parent | 5e01a4852b31d537307994248869caf38b4023cc (diff) |
new upstream release
Diffstat (limited to 'src/gperf_unfold_key_conv.py')
-rwxr-xr-x | src/gperf_unfold_key_conv.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gperf_unfold_key_conv.py b/src/gperf_unfold_key_conv.py new file mode 100755 index 0000000..dcd8587 --- /dev/null +++ b/src/gperf_unfold_key_conv.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import sys +import re + +REG_LINE_GPERF = re.compile('#line .+gperf"') +REG_HASH_FUNC = re.compile('hash\s*\(register\s+const\s+char\s*\*\s*str,\s*register\s+unsigned\s+int\s+len\s*\)') +REG_STR_AT = re.compile('str\[(\d+)\]') +REG_UNFOLD_KEY = re.compile('unicode_unfold_key\s*\(register\s+const\s+char\s*\*\s*str,\s*register\s+unsigned\s+int\s+len\)') +REG_ENTRY = re.compile('\{".+?",\s*/\*(.+?)\*/\s*(-?\d+),\s*(\d)\}') +REG_EMPTY_ENTRY = re.compile('\{"",\s*(-?\d+),\s*(\d)\}') +REG_IF_LEN = re.compile('if\s*\(\s*len\s*<=\s*MAX_WORD_LENGTH.+') +REG_GET_HASH = re.compile('(?:register\s+)?(?:unsigned\s+)?int\s+key\s*=\s*hash\s*\(str,\s*len\);') +REG_GET_CODE = re.compile('(?:register\s+)?const\s+char\s*\*\s*s\s*=\s*wordlist\[key\]\.name;') +REG_CODE_CHECK = re.compile('if\s*\(\*str\s*==\s*\*s\s*&&\s*!strncmp.+\)') + +def parse_line(s): + s = s.rstrip() + + r = re.sub(REG_LINE_GPERF, '', s) + if r != s: return r + r = re.sub(REG_HASH_FUNC, 'hash(OnigCodePoint codes[])', s) + if r != s: return r + r = re.sub(REG_STR_AT, 'onig_codes_byte_at(codes, \\1)', s) + if r != s: return r + r = re.sub(REG_UNFOLD_KEY, 'unicode_unfold_key(OnigCodePoint code)', s) + if r != s: return r + r = re.sub(REG_ENTRY, '{\\1, \\2, \\3}', s) + if r != s: return r + r = re.sub(REG_EMPTY_ENTRY, '{0xffffffff, \\1, \\2}', s) + if r != s: return r + r = re.sub(REG_IF_LEN, 'if (0 == 0)', s) + if r != s: return r + r = re.sub(REG_GET_HASH, 'int key = hash(&code);', s) + if r != s: return r + r = re.sub(REG_GET_CODE, 'OnigCodePoint gcode = wordlist[key].code;', s) + if r != s: return r + r = re.sub(REG_CODE_CHECK, 'if (code == gcode)', s) + if r != s: return r + + return s + +def parse_file(f): + print "/* This file was converted by gperf_unfold_key_conv.py\n from gperf output file. */" + + line = f.readline() + while line: + s = parse_line(line) + print s + line = f.readline() + + +# main +parse_file(sys.stdin) |