/usr/bin/ibus-skk-convert-jisyo is in ibus-skk 1.3.9-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ibus-skk - The SKK engine for IBus
#
# Copyright (C) 2009-2010 Daiki Ueno <ueno@unixuser.org>
#
# 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
# of the License, 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 __future__ import with_statement
from optparse import OptionParser
import sys, os, re
parser = OptionParser()
parser.add_option("-f", "--from-file", dest="src_path",
help="read user dictionary from FILE",
metavar="FILE")
parser.add_option("-F", "--from-encoding", dest="src_encoding",
help="assume the encoding of the input as ENCODING",
metavar="ENCODING")
parser.add_option("-t", "--to-file", dest="dst_path",
help="write user dictionary to FILE",
metavar="FILE")
parser.add_option("-T", "--to-encoding", dest="dst_encoding",
help="assume the encoding of the output as ENCODING",
metavar="ENCODING")
(options, args) = parser.parse_args()
src_path = options.src_path or os.path.expanduser('~/.skk-ibus-jisyo')
dst_path = options.dst_path or os.path.expanduser('~/.skk-ibus-jisyo')
src_encoding = options.src_encoding
dst_encoding = options.dst_encoding or 'UTF-8'
coding_cookie_pattern = \
re.compile('\A\s*;+\s*-\*-\s*coding:\s*(\S+?)\s*-\*-')
encoding_to_coding_system = {
'UTF-8': 'utf-8',
'EUC-JP': 'euc-jp',
'Shift_JIS': 'shift_jis',
'ISO-2022-JP': 'iso-2022-jp'
}
coding_system_to_encoding = dict()
for encoding, coding_system in encoding_to_coding_system.items():
coding_system_to_encoding[coding_system] = encoding
if src_encoding is None:
with open(src_path, 'r') as fp:
line = fp.readline()
if line:
match = re.match(coding_cookie_pattern, line)
if match:
encoding = coding_system_to_encoding.get(match.group(1))
if encoding:
src_encoding = encoding
if src_encoding is None:
print >> sys.stderr, "Can't determine input encoding"
exit(1)
tmp_path = dst_path
if src_path == dst_path:
if src_encoding == dst_encoding:
print >> sys.stderr, "No need to convert"
exit(0)
tmp_path += '.tmp'
ok = raw_input("Convert from %s (%s) to %s (%s) (y/N) " % (src_path,
src_encoding,
dst_path,
dst_encoding))
if ok != 'y':
exit(1)
with open(src_path, 'r') as sp:
line = sp.readline()
if not (line and re.match(coding_cookie_pattern, line)):
sp.seek(0)
with open(tmp_path, 'a') as tp:
tp.write(';; -*- coding: %s -*-\n' % \
encoding_to_coding_system.get(dst_encoding))
for line in sp:
line = line.decode(src_encoding)
tp.write(line.encode(dst_encoding))
if src_path == dst_path:
os.rename(tmp_path, dst_path)
|