html/accent.pl


   1 #to run it if it is here (but in this case it will run automagically when
   2 #irssi will start):
   3 #
   4 #/script load ~/.irssi/scripts/autorun/accent.pl
   5 #
   6 #you can simply remove the script:
   7 #
   8 #/script unload accent
   9 #
  10 #and it will strips your incoming and outgoing hungarian accents
  11 #but you can:
  12 #
  13 #/set accent_strip_in  <on|off> -- strips the incoming accents (on) or not (off)
  14 #/set accent_strip_out <on|off> -- strips the outgoing accents (on) or not (off)
  15 #
  16 #/set accent_tag_in  <string, default: [A]> indicates the incoming msg filtered 
  17 #/set accent_tag_out <string, default: [A]> indicates the outgoing msg filtered
  18 #
  19 #/set accent_latin <string, default: iso 8859-2: A',a',E',e',I',i',O',o',O:,o:,O",o",U',u',U:,u:,U",u"> which to strip
  20 #/set accent_ascii <string, default: AaEeIiOoOoOoUuUuUu> will be the stripped
  21 #
  22 #be careful, accent_latin and accent_latin must be charlist and must have
  23 #the same length to be matched as a pair.
  24 #
  25 #/set accent_debug <on|off> -- if you have a problem try to turn this on
  26 
  27 use strict;
  28 use vars qw($VERSION %IRSSI);
  29 
  30 use Irssi;
  31 $VERSION = '$Id: accent.pl,v 1.34 2003/03/27 15:54:25 toma Exp $';
  32 %IRSSI = (
  33 	authors     => 'Tamas SZERB',
  34 	contact     => 'toma@rulez.org',
  35 	name        => 'accent',
  36 	description => 'This script strips the hungarian accents.',
  37 	license     => 'GPL',
  38 );
  39 
  40 my $stripped_out = 0;
  41 my $stripped_in  = 0;
  42 
  43 sub accent_out {
  44 	if(Irssi::settings_get_bool('accent_strip_out') && !$stripped_out) {
  45 		my $accent_tag = Irssi::settings_get_str('accent_tag_out');
  46 
  47 		my $debug=Irssi::settings_get_bool('accent_debug');
  48 		
  49 		my $accent_latin = Irssi::settings_get_str('accent_latin');
  50 		my $accent_ascii = Irssi::settings_get_str('accent_ascii');
  51 		if (length($accent_latin) != length($accent_ascii)) {
  52 			if ($debug) {
  53 				Irssi::print("`$accent_latin' and `$accent_ascii' hasn't same length");
  54 			}
  55 		}
  56 		else {
  57 			my $emitted_signal = Irssi::signal_get_emitted();
  58 			my ($msg, $dummy1, $dummy2) = @_;
  59 
  60 			if ($debug) {
  61 				Irssi::print("signal emitted: $emitted_signal");
  62 			}
  63 
  64 			if ( $msg =~ /[$accent_latin]/ ) {
  65 				if ($debug) {
  66 					Irssi::print("outgoing contains accent: $msg");
  67 				}
  68 				eval "\$msg =~ tr/$accent_latin/$accent_ascii/;";
  69 				$msg = $msg . ' ' . $accent_tag;
  70 				$stripped_out=1;
  71 				
  72 				Irssi::signal_emit("$emitted_signal", $msg, $dummy1, $dummy2 );
  73 				Irssi::signal_stop();
  74 				$stripped_out=0;
  75 			}
  76 		}
  77 	}
  78 }
  79 
  80 sub accent_in {
  81 	if(Irssi::settings_get_bool('accent_strip_in') && !$stripped_in) {
  82 		my $accent_tag = Irssi::settings_get_str('accent_tag_in');
  83 
  84 		my $debug=Irssi::settings_get_bool('accent_debug');
  85 		
  86 		my $accent_latin = Irssi::settings_get_str('accent_latin');
  87 		my $accent_ascii = Irssi::settings_get_str('accent_ascii');
  88 		if (length($accent_latin) != length($accent_ascii)) {
  89 			if ($debug) {
  90 				Irssi::print("`$accent_latin' and `$accent_ascii' hasn't same length");
  91 			}
  92 		}
  93 		else {
  94 			my $emitted_signal = Irssi::signal_get_emitted();
  95 
  96 			my ($dummy0, $text, $dummy3, $dummy4, $dummy5) = @_;
  97 			if ($debug) {
  98 				Irssi::print("signal emitted: $emitted_signal");
  99 			}
 100 			if ( $text =~ /[$accent_latin]/ ) {
 101 				if ($debug) {
 102 					Irssi::print("incoming contains accent: $text");
 103 				}
 104 				if ($debug) {
 105 					Irssi::print("text=$text");
 106 				}
 107 				#no idea why w/o eval doesn't work:
 108 				eval "\$text =~ tr/$accent_latin/$accent_ascii/;";
 109 				$text = $text . ' ' . $accent_tag;
 110 				$stripped_in=1;
 111 
 112 				if ($debug) {
 113 					Irssi::print("text=$text");
 114 				}
 115 				Irssi::signal_emit("$emitted_signal", $dummy0, $text, $dummy3, $dummy4, $dummy5 );
 116 				Irssi::signal_stop();
 117 				$stripped_in=0;
 118 			}
 119 		}
 120 	}
 121 }
 122 
 123 #main():
 124 
 125 #default settings /set accent_in && accent_out ON:
 126 Irssi::settings_add_bool('lookandfeel', 'accent_strip_in', 1);
 127 Irssi::settings_add_bool('lookandfeel', 'accent_strip_out', 1);
 128 
 129 #define the default tags for the filtered text:
 130 Irssi::settings_add_str('lookandfeel', 'accent_tag_in', '[Ai]');
 131 Irssi::settings_add_str('lookandfeel', 'accent_tag_out', '[Ao]');
 132 
 133 #define which chars will be changed:
 134 #iso 8859-2: A',a',E',e',I',i',O',o',O:,o:,O",o",U',u',U:,u:,U",u"
 135 Irssi::settings_add_str('lookandfeel', 'accent_latin', "\301\341\311\351\315\355\323\363\326\366\325\365\332\372\334\374\333\373");
 136 Irssi::settings_add_str('lookandfeel', 'accent_ascii', "AaEeIiOoOoOoUuUuUu");
 137 
 138 #define wheather debug or not (default OFF):
 139 Irssi::settings_add_bool('lookandfeel', 'accent_debug', 0);
 140 
 141 #filters:
 142 #incoming filters:
 143 Irssi::signal_add_first('server event', 'accent_in');
 144 
 145 #output filters:
 146 Irssi::signal_add_first('send command', 'accent_out');
 147 #Irssi::signal_add_first('message own_public', 'accent_out');
 148 #Irssi::signal_add_first('message own_private', 'accent_out');
 149 
 150 #startup info:
 151 Irssi::print("Hungarian accent stripper by toma * http://scripts.irssi.org/scripts/accent.pl");
 152 Irssi::print("Version: $VERSION");
 153