alias njau.enable {
if ( $istok( %njau. [ $+ [ $1 ] ] , $network $+ $active , 32 ) == $true ) {
set %njau. [ $+ [ $1 ] ] $remtok( %njau. [ $+ [ $1 ] ] , $network $+ $active , 1, 32)
}
else set %njau. [ $+ [ $1 ] ] $addtok( %njau. [ $+ [ $1 ] ] , $network $+ $active , 32)
}
alias njau.isenabled {
if ( $istok( %njau. [ $+ [ $1 ] ] , $network $+ $active , 32 ) == $true ) return 1
else return 0
}
menu channel {
$style( $njau.isenabled( jis ) ) Enable JIS:/njau.enable jis
}
on *:input:*:{
if ( $istok( %njau.jis , $network $+ $active , 32 ) == $true ) {
if ( $left($1-,2) == $chr(129) $+ E ) {
.describe $active $sjis2jis($right($1-,-2))
echo 3 -atn ** $me $right($1-,-2)
halt
}
elseif ( $left($1-,3) == /me ) {
.describe $active $sjis2jis($right($1-,-3))
echo 3 -atn ** $me $right($1-,-3)
halt
}
elseif ( $left($1-,1) != / ) {
.msg $active $sjis2jis($1-)
echo 3 -atn << $+ $me $+ >> $1-
halt
}
}
}
on ^1:text:*:#: if ( $istok( %njau.jis , $network $+ $chan , 32 ) == $true ) { haltdef | echo -mtl # << $+ $nick $+ >> $jis2sjis($1-) }
on ^1:action:*:#: if ( $istok( %njau.jis , $network $+ $chan , 32 ) == $true ) { haltdef | echo -mtl # ** $nick $jis2sjis($1-) }
alias -l sjis2jis {
var %x = 1, %y, %c, %word, %out, %insequence = 0
var %startsequence = $B
var %endsequence = (B
while ( %x <= $numtok($1-, 32)) {
%word = $gettok($1-, %x, 32)
%y = 1
set %o
while (%y <= $len(%word)) {
%c = $asc($mid(%word, %y, 1))
if ( ((%c >= 129) && (%c <= 159 )) || ((%c >= 224) && (%c <= 239)) ) {
if (%insequence == 0) { %o = %o $+ %startsequence | %insequence = 1 }
{ { { { {
var %a = $asc( $mid(%word, %y, 1) ), %b = $asc( $mid(%word, $calc(%y + 1),1) )
if (%a <= 159) %a = $calc(%a - 113)
else %a = $calc(%a - 177)
%a = $calc( %a * 2 + 1)
if (%b >= 127) %b = $calc(%b - 1)
if (%b >= 158) {
%b = $calc(%b - 125)
%a = $calc(%a + 1)
}
else %b = $calc(%b - 31)
%o = %o $+ $chr(%a) $+ $chr(%b)
} } } } }
%y = $calc( %y + 2 )
}
else {
if (%insequence == 1) { %o = %o $+ %endsequence | %insequence = 0 }
%o = %o $+ $mid(%word, %y, 1)
%y = $calc( %y + 1 )
}
}
if (%insequence == 1) %o = { %o $+ %endsequence | %insequence = 0 }
%out = %out %o
%x = $calc( %x + 1 )
}
return %out
}
alias -l jis2sjis {
var %jis = /\$B(.+?)\([BJ]/g
return $regsubex($1-, %jis, $_jis2sjis(\t))
}
alias -l _jis2sjis {
var %x = 1, %y, %z, %j1, %j2, %s1, %s2
while ( %x < $len($1-) ) {
%j1 = $asc( $mid( $1-, %x, 1 ) )
%j2 = $asc( $mid( $1-, $calc( %x + 1 ), 1 ) )
if ( ( 33 <= %j1 ) && ( %j1 <= 96 ) ) %s1 = $calc( $int( $calc( ( %j1 + 1 ) / 2)) + 112 )
if ( ( 97 <= %j1 ) && ( %j1 <= 126 ) ) %s1 = $calc( $int( $calc( ( %j1 + 1 ) / 2 )) + 176 )
if ( $calc( %j1 % 2 ) == 1 ) %s2 = $calc( %j2 + 31 + $int( $calc( %j2 / 96 ) ) )
else set %s2 $calc( %j2 + 126 )
set %x $calc( %x + 2 )
set %z %z $+ $chr( %s1 ) $+ $chr( %s2 )
}
return %z
}