From dff380f2847a030ae1e2db4c26c2316cf70fa7ca Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 8 Sep 2015 15:34:08 +0800 Subject: write generateheader.py --- scripts2/bopomofotable.py | 15 ------ scripts2/doublepinyintable.py | 11 ---- scripts2/generateheader.py | 113 ++++++++++++++++++++++++++++++++++++++++++ scripts2/utils.py | 19 ------- 4 files changed, 113 insertions(+), 45 deletions(-) create mode 100644 scripts2/generateheader.py (limited to 'scripts2') diff --git a/scripts2/bopomofotable.py b/scripts2/bopomofotable.py index 2db5e49..e9beb1d 100644 --- a/scripts2/bopomofotable.py +++ b/scripts2/bopomofotable.py @@ -101,21 +101,6 @@ def gen_chewing_tones(scheme): return ",\n".join(entries) -''' -def get_table_content(tablename): - (scheme, part) = tablename.split('_', 1) - if part == "SYMBOLS": - return gen_chewing_symbols(scheme) - if part == "INITIALS": - return gen_chewing_initials(scheme) - if part == "MIDDLES": - return gen_chewing_middles(scheme) - if part == "FINALS": - return gen_chewing_finals(scheme) - if part == "TONES": - return gen_chewing_tones(scheme) -''' - ### main function ### if __name__ == "__main__": print(gen_chewing_symbols("HSU"), os.linesep) diff --git a/scripts2/doublepinyintable.py b/scripts2/doublepinyintable.py index 710c6f1..ff991b7 100644 --- a/scripts2/doublepinyintable.py +++ b/scripts2/doublepinyintable.py @@ -118,17 +118,6 @@ def gen_fallback_table3(scheme): return ',\n'.join(entries) - -''' -def get_table_content(tablename): - (scheme, part) = tablename.split('_', 1) - if part == "SHENG": - return gen_shengmu_table(scheme) - if part == "YUN": - return gen_yunmu_table(scheme) -''' - - ### main function ### if __name__ == "__main__": print(gen_fallback_table2("PYJJ"), os.linesep) diff --git a/scripts2/generateheader.py b/scripts2/generateheader.py new file mode 100644 index 0000000..901d682 --- /dev/null +++ b/scripts2/generateheader.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# vim:set et sts=4 sw=4: +# +# libpinyin - Library to deal with pinyin. +# +# Copyright (C) 2011 Peng Wu +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +from argparse import ArgumentParser +from chewing import gen_initials, gen_middles, gen_finals, gen_tones +from fullpinyintable import gen_content_table, gen_pinyin_index, gen_luoma_pinyin_index, gen_secondary_zhuyin_index, gen_zhuyin_index, gen_hsu_zhuyin_index, gen_eten26_zhuyin_index, gen_divided_table, gen_resplit_table, gen_chewing_key_table +from doublepinyintable import gen_shengmu_table, gen_yunmu_table +from bopomofotable import gen_chewing_symbols, gen_chewing_initials, gen_chewing_middles, gen_chewing_finals, gen_chewing_tones + + +header = '''/* This file is generated by python scripts. Don't edit this file directly. + */ +''' + + +def get_table_content(tablename): + #chewing enums + if tablename == 'CHEWING_INITIAL': + return gen_initials() + if tablename == 'CHEWING_MIDDLE': + return gen_middles() + if tablename == 'CHEWING_FINAL': + return gen_finals() + if tablename == 'CHEWING_TONE': + return gen_tones() + + #pinyin table + if tablename == 'CONTENT_TABLE': + return gen_content_table() + if tablename == 'PINYIN_INDEX': + return gen_pinyin_index() + if tablename == 'LUOMA_PINYIN_INDEX': + return gen_luoma_pinyin_index() + if tablename == 'SECONDARY_ZHUYIN_INDEX': + return gen_secondary_zhuyin_index() + if tablename == 'ZHUYIN_INDEX': + return gen_zhuyin_index() + if tablename == 'HSU_ZHUYIN_INDEX': + return gen_hsu_zhuyin_index() + if tablename == 'ETEN26_ZHUYIN_INDEX': + return gen_eten26_zhuyin_index() + if tablename == 'DIVIDED_TABLE': + return gen_divided_table() + if tablename == 'RESPLIT_TABLE': + return gen_resplit_table() + if tablename == 'TABLE_INDEX': + return gen_chewing_key_table() + + #double pinyin table + (scheme, part) = tablename.split('_', 1) + if part == "SHENG": + return gen_shengmu_table(scheme) + if part == "YUN": + return gen_yunmu_table(scheme) + + #zhuyin table + (scheme, part) = tablename.split('_', 1) + if part == "SYMBOLS": + return gen_chewing_symbols(scheme) + if part == "INITIALS": + return gen_chewing_initials(scheme) + if part == "MIDDLES": + return gen_chewing_middles(scheme) + if part == "FINALS": + return gen_chewing_finals(scheme) + if part == "TONES": + return gen_chewing_tones(scheme) + + +def expand_file(filename): + infile = open(filename, "r") + print(header) + for line in infile.readlines(): + line = line.rstrip(os.linesep) + if len(line) < 3: + print(line) + continue + if line[0] == '@' and line[-1] == '@': + tablename = line[1:-1] + print(get_table_content(tablename)) + else: + print(line) + + +### main function ### +if __name__ == "__main__": + parser = ArgumentParser(description='Generate header file from template.') + parser.add_argument('infile', action='store', \ + help='input file.') + + args = parser.parse_args() + print(args) + expand_file(args.infile) + diff --git a/scripts2/utils.py b/scripts2/utils.py index e33ed25..c90dd83 100644 --- a/scripts2/utils.py +++ b/scripts2/utils.py @@ -23,25 +23,6 @@ import os -header = '''/* This file is generated by python scripts. Don't edit this file directly. - */ -''' - - -def expand_file(filename, get_table_content): - infile = open(filename, "r") - print(header) - for line in infile.readlines(): - line = line.rstrip(os.linesep) - if len(line) < 3: - print(line) - continue - if line[0] == '@' and line[-1] == '@': - tablename = line[1:-1] - print(get_table_content(tablename)) - else: - print(line) - def shuffle_all(instr): for output in shuffle_recur(instr): -- cgit