Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
274 lines (238 sloc) 9.27 KB
#!/usr/bin/perl -w
#
# Copyright (c) 2002 Victor Ivanov <v0rbiz@yahoo.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = '1.0b3';
%IRSSI = (
authors => 'Victor Ivanov',
contact => 'v0rbiz@yahoo.com',
name => 'romaji',
description => 'translates romaji to hiragana or katakana in text enclosed in ^R',
license => 'BSD 2-clause',
url => 'http://irssi.org/scripts/'
);
my(%hira) = (
"a" => "", "i" => "", "u" => "", "e" => "", "o" => "",
"ka" => "", "ki" => "", "ku" => "", "ke" => "", "ko" => "",
"sa" => "", "shi" => "", "su" => "", "se" => "", "so" => "",
"ta" => "", "chi" => "", "tsu" => "", "te" => "", "to" => "",
"na" => "", "ni" => "", "nu" => "", "ne" => "", "no" => "",
"ha" => "", "hi" => "", "hu" => "", "he" => "", "ho" => "", "fu" => "",
"ma" => "", "mi" => "", "mu" => "", "me" => "", "mo" => "",
"ya" => "", "yu" => "", "yo" => "",
"ra" => "", "ri" => "", "ru" => "", "re" => "", "ro" => "",
"wa" => "", "wi" => "", "we" => "", "wo" => "",
"n" => "",
"m" => "",
"ga" => "", "gi" => "", "gu" => "", "ge" => "", "go" => "",
"za" => "", "ji" => "", "zu" => "", "ze" => "", "zo" => "",
"da" => "", "dzi" => "", "dzu" => "", "de" => "", "do" => "",
"ba" => "", "bi" => "", "bu" => "", "be" => "", "bo" => "",
"pa" => "", "pi" => "", "pu" => "", "pe" => "", "po" => "",
"fa" => "ふぁ", "fi" => "ふぃ", "fe" => "ふぇ", "fo" => "ふぉ",
"di" => "でぃ",
"kya" => "きゃ", "kyu" => "きゅ", "kyo" => "きょ",
"sha" => "しゃ", "shu" => "しゅ", "sho" => "しょ",
"cha" => "ちゃ", "chu" => "ちゅ", "cho" => "ちょ",
"nya" => "にゃ", "nyu" => "にゅ", "nyo" => "にょ",
"hya" => "ひゃ", "hyu" => "ひゅ", "hyo" => "ひょ",
"mya" => "みゃ", "myu" => "みゅ", "myo" => "みょ",
"rya" => "りゃ", "ryu" => "りゅ", "ryo" => "りょ",
"gya" => "ぎゃ", "gyu" => "ぎゅ", "gyo" => "ぎょ",
"ja" => "じゃ", "ju" => "じゅ", "jo" => "じょ",
"jya" => "じゃ", "jyu" => "じゅ", "jyo" => "じょ",
"dza" => "ぢゃ", "dju" => "ぢゅ", "dzo" => "ぢょ",
"dja" => "ぢゃ", "djo" => "ぢょ",
"bya" => "びゃ", "byu" => "びゅ", "byo" => "びょ",
"pya" => "ぴゃ", "pyu" => "ぴゅ", "pyo" => "ぴょ",
"TSU" => ""
);
my(%kata) = (
"a" => "", "i" => "", "u" => "", "e" => "", "o" => "",
"ka" => "", "ki" => "", "ku" => "", "ke" => "", "ko" => "",
"sa" => "", "shi" => "", "su" => "", "se" => "", "so" => "",
"ta" => "", "chi" => "", "tsu" => "", "te" => "", "to" => "",
"na" => "", "ni" => "", "nu" => "", "ne" => "", "no" => "",
"ha" => "", "hi" => "", "hu" => "", "he" => "", "ho" => "", "fu" => "",
"ma" => "", "mi" => "", "mu" => "", "me" => "", "mo" => "",
"ya" => "", "yu" => "", "yo" => "", "ye" => "",
"ra" => "", "ri" => "", "ru" => "", "re" => "", "ro" => "",
"wa" => "", "wi" => "", "we" => "", "wo" => "",
"n" => "",
"m" => "",
"ga" => "", "gi" => "", "gu" => "", "ge" => "", "go" => "",
"za" => "", "ji" => "", "zu" => "", "ze" => "", "zo" => "",
"da" => "", "dzi" => "", "dzu" => "", "de" => "", "do" => "",
"ba" => "", "bi" => "", "bu" => "", "be" => "", "bo" => "",
"pa" => "", "pi" => "", "pu" => "", "pe" => "", "po" => "",
"va" => "ヴァ", "vi" => "ヴィ", "vu" => "", "ve" => "ヴェ", "vo" => "ヴォ",
"fa" => "ファ", "fi" => "フィ", "fe" => "フェ", "fo" => "フォ",
"di" => "ディ",
"dje" => "ヂェ", "dze" => "ヂェ",
"kya" => "キャ", "kyu" => "キュ", "kyo" => "キョ",
"sha" => "シャ", "shu" => "シュ", "sho" => "ショ",
"cha" => "チャ", "chu" => "チュ", "cho" => "チョ",
"nya" => "ニャ", "nyu" => "ニュ", "nyo" => "ニョ",
"hya" => "ヒャ", "hyu" => "ヒュ", "hyo" => "ヒョ",
"mya" => "ミャ", "myu" => "ミュ", "myo" => "ミョ",
"rya" => "リャ", "ryu" => "リュ", "ryo" => "リョ",
"gya" => "ギャ", "gyu" => "ギュ", "gyo" => "ギョ",
"ja" => "ジャ", "ju" => "ジュ", "jo" => "ジョ",
"jya" => "ジャ", "jyu" => "ジュ", "jyo" => "ジョ",
"dza" => "ヂャ", "dju" => "ヂュ", "dzo" => "ヂョ",
"dja" => "ヂャ", "djo" => "ヂョ",
"bya" => "ビャ", "byu" => "ビュ", "byo" => "ビョ",
"pya" => "ピャ", "pyu" => "ピュ", "pyo" => "ピョ",
"TSU" => ""
);
my(%comn) = (
"-" => "",
"." => "",
"," => "",
"!" => "",
"?" => "",
"~" => "",
" " => " ",
"[" => "", "]" => "",
"{" => "", "}" => "",
"(" => "", ")" => "",
"0" => "", "1" => "", "2" => "", "3" => "", "4" => "",
"5" => "", "6" => "", "7" => "", "8" => "", "9" => "",
"*" => "", # ☆ is uglier :P
# where to put ♪ ?
);
my(@squot) = ( "", "" );
my($squoti) = 0;
my(@dquot) = ( "", "" );
my($dquoti) = 0;
sub r2hk ($$) {
my($str) = "";
my($pos) = 0;
my($inlen) = length($_[0]);
my($last) = "";
my($href) = $_[1];
my($inp) = lc($_[0]);
while ($pos < $inlen) {
my($len);
my($p) = substr($inp, $pos, 3);
my($h) = ${$href}{$p};
# this could be done with another cycle, but this way's faster i guess
if ($h) {
$len = 3;
} else {
$p = substr($inp, $pos, 2);
$h = ${$href}{$p};
if ($h) {
$len = 2;
} else {
$p = substr($inp, $pos, 1);
$h = ${$href}{$p};
if (!$h) {
if ($p eq "'") {
$h = $squot[$squoti];
$squoti = 1 - $squoti;
} elsif ($p eq "\"") {
$h = $dquot[$dquoti];
$dquoti = 1 - $dquoti;
} else {
$h = $p;
}
}
$len = 1;
}
}
if ($h ne $p) {
if ($last) {
if ($last eq substr($p, 0, 1)) {
$str .= ${$href}{"TSU"};
} else {
$str .= $last;
}
$last = "";
}
} else {
$str .= $last;
$last = $p;
$h = "";
}
$str .= $h;
$pos += $len;
}
$str .= $last;
return $str;
}
my($lock_ev) = 0;
sub event1 {
my ($line, $server, $witem) = @_;
return unless ref $witem;
if ($lock_ev) { return };
$squoti = 0;
$dquoti = 0;
my ($str) = "";
my (@p) = split(//, $line);
my ($i);
my ($inside) = 0;
my ($empty) = 0;
for ($i = 0; $i <= $#p; $i++) {
if ($inside) {
if (!$p[$i]) {
$empty++;
} else {
if ($empty == 0) {
$str .= r2hk($p[$i], \%hira);
} else {
$str .= r2hk($p[$i], \%kata);
}
$empty = 0;
$inside = 0;
}
} else {
$str .= $p[$i];
$inside = 1;
}
}
$lock_ev = 1;
Irssi::signal_emit('send command', $str, $server, $witem);
Irssi::signal_stop();
$lock_ev = 0;
}
sub cmd_romaji {
Irssi::print('%BRomaji (with ひらがな and カタカナ support) version '.$VERSION);
Irssi::print('(this is amateur product and comes with %Wno warranty%n, see the source)');
Irssi::print('Text enclosed in Ctrl-Rs (like this) will be converted to hiragana.');
Irssi::print('If the opening ^R is doubled, it will be converted to katakana.');
Irssi::print('Example: genki -> げんき and genki -> ゲンキ');
}
Irssi::signal_add('send command', "event1");
Irssi::command_bind('romaji', \&cmd_romaji);
Irssi::print('%B'.$IRSSI{name}.' '.$VERSION.'%n loaded; type /romaji for more info');
# Add the common hash to hiragana and kitakana hashes
my($k, $v);
while (($k, $v) = each %comn) {
$hira{$k} = $v;
$kata{$k} = $v;
}