Skip to content

Commit

Permalink
p2jx table generation - differentiate static variable name prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mete0r committed Mar 6, 2019
1 parent b86dc06 commit 95e4316
Show file tree
Hide file tree
Showing 3 changed files with 22,674 additions and 22,673 deletions.
19 changes: 10 additions & 9 deletions data2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def table_to_pack(table):
yield jamo_struct.pack(ord(uch))


def table_to_header(table):
def table_to_header(prefix, table):
pua_groups = make_groups(sorted(table.keys()))

for pua_start, pua_end in pua_groups:
Expand All @@ -59,22 +59,23 @@ def table_to_header(table):
['0x{:04X}'.format(len(jamo))] +
['0x{:04x}'.format(ord(uch)) for uch in jamo]
)
yield 'static const unsigned short pua2jamo_{:04X}[] = {{ {} }};'.format( # noqa
pua_code, codepoints
yield 'static const unsigned short {}_{:04X}[] = {{ {} }};'.format( # noqa
prefix, pua_code, codepoints
)

yield 'static const unsigned short *pua2jamo_group_{:04X}[] = {{'.format( # noqa
pua_start,
yield 'static const unsigned short *{}_group_{:04X}[] = {{'.format( # noqa
prefix, pua_start,
)
for pua_code in range(pua_start, pua_end + 1):
yield '\tpua2jamo_{:04X},'.format(pua_code)
yield '\t{}_{:04X},'.format(prefix, pua_code)
yield '};'

yield '#define lookup(code) \\'
for pua_start, pua_end in pua_groups:
yield (
'\t(0x{start:04X} <= code && code <= 0x{end:04X})?'
'(pua2jamo_group_{start:04X}[code - 0x{start:04X}]): \\'.format(
'({prefix}_group_{start:04X}[code - 0x{start:04X}]): \\'.format(
prefix=prefix,
start=pua_start,
end=pua_end
)
Expand Down Expand Up @@ -266,7 +267,7 @@ def tree_to_pack(tree):
fp.write(line.encode('utf-8'))
fp.write('\n')
with io.open('src/hypua2jamo-c/p2jc-table.h', 'wb') as fp:
for line in table_to_header(composed):
for line in table_to_header('p2jc', composed):
fp.write(line)
fp.write('\n')
with io.open('src/hypua2jamo/p2jc.bin', 'wb') as fp:
Expand All @@ -280,7 +281,7 @@ def tree_to_pack(tree):
'data/hypua2jamodecomposed.txt'
))
with io.open('src/hypua2jamo-c/p2jd-table.h', 'wb') as fp:
for line in table_to_header(decomposed):
for line in table_to_header('p2jd', decomposed):
fp.write(line)
fp.write('\n')
with io.open('src/hypua2jamo/p2jd.bin', 'wb') as fp:
Expand Down
Loading

0 comments on commit 95e4316

Please sign in to comment.