add const modifiers for chewing table
[platform/upstream/libpinyin.git] / scripts / utils.py
1 # -*- coding: utf-8 -*-
2 # vim:set et sts=4 sw=4:
3 #
4 # libpinyin - Library to deal with pinyin.
5 #
6 # Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22
23 import os
24
25 header = '''/* This file is generated by python scripts. Don't edit this file directly.
26  */
27 '''
28
29 def expand_file(filename, get_table_content):
30     infile = open(filename, "r")
31     print(header)
32     for line in infile.readlines():
33         line = line.rstrip(os.linesep)
34         if len(line) < 3 :
35             print(line)
36             continue
37         if line[0] == '@' and line[-1] == '@':
38             tablename = line[1:-1]
39             print(get_table_content(tablename))
40         else:
41             print(line)