From f80271e2c758729f58e23bc2f7f4064c64eb6d9c Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Tue, 2 Sep 2008 02:01:07 -0400 Subject: [PATCH] Teach MasterCoder to look at both ends, and allow IrssiInterface to switch. This is an investigative effort to see if we can solve some irssi format mangling wrt highlighting. darcs-hash:20080902060107-2ee1a-6536c558ee2bfb34b55947dd631363b164878f0a.gz --- IrssiInterface.pl | 28 +++++++++++++++++++-------- MasterCoder.pm | 48 ++++++++++++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/IrssiInterface.pl b/IrssiInterface.pl index 8298b6f..7a5f763 100644 --- a/IrssiInterface.pl +++ b/IrssiInterface.pl @@ -202,10 +202,18 @@ sub get_instance_label ($$) { return $instlabel; } -sub generate_prefix($) { - $mc->tlvs_to_message([$mc->tlv_wrap( +sub generate_outgoing($$) { + my ($text, $instlabel) = @_; + + my $framedlabel = $mc->tlvs_to_message([$mc->tlv_wrap( $known_types{'InstanceLabelHuffman1'}, - @_)]); + $instlabel)]); + + if (Irssi::settings_get_bool("instance_tlvs_at_start")) { + $text = $framedlabel . $text . $instance_suffix; + } else { + $text = $text . $instance_suffix . $framedlabel; + } } my $suppress_out = 0; @@ -224,7 +232,8 @@ sub inst_filter_out { my $instlabel = get_instance_label($$server{'address'}, $$channel{'name'}); - $text = generate_prefix($instlabel) . $text . $instance_suffix if "" ne $instlabel; + + $text = generate_outgoing($text, $instlabel) if "" ne $instlabel; $suppress_out = 1; my $emitted_signal = Irssi::signal_get_emitted(); @@ -340,10 +349,7 @@ sub cmd_inst_say { return; } - $text = $mc->tlvs_to_message([$mc->tlv_wrap( - $known_types{'InstanceLabelHuffman1'}, - $instenc) - ] ) . $text . $instance_suffix if "" ne $inst; + $text = generate_outgoing($text, $instenc) if "" ne $inst; $suppress_out = 1; Irssi::signal_emit("send text", $text, $server, $witem); @@ -362,6 +368,12 @@ Irssi::command_bind('instsay', 'cmd_inst_say'); Irssi::command_bind('punt', 'cmd_punt'); Irssi::command_bind('unpunt', 'cmd_unpunt'); +# NOTICE: This is transitional for experimentation with the protocol and may +# disappear soon. MasterCoder is aware to look at both ends of strings +# passed to tlv_run_callbacks, so this option controls which position we use +# when generating. +Irssi::settings_add_bool('instance','instance_tlvs_at_start', 1); + # The old way of storing these... #Irssi::settings_add_str('lookandfeel', 'current_instance', "default"); #Irssi::settings_add_str('lookandfeel', 'punt_list', ""); diff --git a/MasterCoder.pm b/MasterCoder.pm index a4695f3..c487f86 100644 --- a/MasterCoder.pm +++ b/MasterCoder.pm @@ -177,29 +177,43 @@ sub tlv_run_callbacks($$$) { . (join ("",@{$$self{'code_chars'}})) ."]+)".$$self{'msg_suffix'}."(.*)\$"; - my $rest; + # This regex is a little different. It nongreedly consumes the + # ordinary text and will repeatedly backtrack in the presence of + # multiple message prefix sigils. + my $regex2 = "^(.*?)" + . $$self{'msg_prefix'}."([" + . (join ("",@{$$self{'code_chars'}})) + ."]+)".$$self{'msg_suffix'}."\$"; + + my ($tlvstr, $rest) = (undef, undef); if ( $msg =~ /$regex/ ) { + $tlvstr = $1; $rest = $2; - # That's meta-l, not the conductive solid. - my ($metal, $metallen) = $self->ldecode($1); - return (0, $msg) if (length $1) < $metallen + $metal; - # So here's an interesting connundrum. It might be that - # the additional text we insert after ours looks like a - # message end. Therefore, once we have extracted metal, - # we need to check that there's a msg_suffix where there - # should be. - if ((length $1) > $metallen + $metal) { - my $ssws = substr($1, $metallen + $metal); - return (0, $msg) if (index $ssws, $$self{'msg_suffix'}); - - # Now put what should be on $rest back on it. - $rest = substr($1, $metallen + $metal) . $rest; - } - $msg = substr($1, $metallen, $metal); + } elsif ( $msg =~ /$regex2/ ) { + $tlvstr = $2; + $rest = $1; } else { return (0, $msg); } + # That's meta-l, not the conductive solid. + my ($metal, $metallen) = $self->ldecode($tlvstr); + return (0, $msg) if (length $tlvstr) < $metallen + $metal; + # So here's an interesting connundrum. It might be that + # the additional text we insert after ours looks like a + # message end. Therefore, once we have extracted metal, + # we need to check that there's a msg_suffix where there + # should be. + if ((length $tlvstr) > $metallen + $metal) { + my $ssws = substr($tlvstr, $metallen + $metal); + return (0, $msg) if (index $ssws, $$self{'msg_suffix'}); + + # Now put what should be on $rest back on it. + $rest = substr($tlvstr, $metallen + $metal) . $rest; + } + $msg = substr($tlvstr, $metallen, $metal); + + while( $msg ne "" ) { last if length $msg < 2; -- 2.50.1