[1042] in BarnOwl Developers
[D-O-H] r1027 - trunk/owl
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:12:25 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@MIT.EDU
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Tue, 29 Apr 2008 01:21:15 -0400 (EDT)
Author: nelhage
Date: 2008-04-29 01:21:15 -0400 (Tue, 29 Apr 2008)
New Revision: 1027
Modified:
trunk/owl/owl.c
trunk/owl/perlconfig.c
trunk/owl/perlglue.xs
trunk/owl/perlwrap.pm
Log:
Implement back-compat with old-style owl::format_msg() styles
Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c 2008-04-29 05:21:13 UTC (rev 1026)
+++ trunk/owl/owl.c 2008-04-29 05:21:15 UTC (rev 1027)
@@ -588,7 +588,7 @@
if(owl_message_is_direction_in(m)) {
/* let perl know about it*/
- owl_perlconfig_getmsg(m, 0, NULL);
+ owl_perlconfig_getmsg(m, NULL);
/* do we need to autoreply? */
if (owl_global_is_zaway(&g) && !owl_message_get_attribute_value(m, "isauto")) {
Modified: trunk/owl/perlconfig.c
===================================================================
--- trunk/owl/perlconfig.c 2008-04-29 05:21:13 UTC (rev 1026)
+++ trunk/owl/perlconfig.c 2008-04-29 05:21:15 UTC (rev 1027)
@@ -410,34 +410,14 @@
return(out);
}
-char *owl_perlconfig_getmsg(owl_message *m, int mode, char *subname)
-{
- /* if mode==1 we are doing message formatting. The returned
- * formatted message needs to be freed by the caller.
- *
- * if mode==0 we are just doing the message-has-been-received
- * thing.
- */
- if (!owl_global_have_config(&g)) return(NULL);
-
- /* run the procedure corresponding to the mode */
- if (mode==1) {
- char *ret = NULL;
- ret = owl_perlconfig_call_with_message(subname?subname
- :"BarnOwl::_format_msg_legacy_wrap", m);
- if (!ret) {
- ret = owl_sprintf("@b([Perl Message Formatting Failed!])\n");
- }
- return ret;
- } else {
- char *ptr = NULL;
- if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
- ptr = owl_perlconfig_call_with_message(subname?subname
- :"BarnOwl::_receive_msg_legacy_wrap", m);
- }
- if (ptr) owl_free(ptr);
- return(NULL);
+void owl_perlconfig_getmsg(owl_message *m, char *subname)
+{
+ char *ptr = NULL;
+ if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
+ ptr = owl_perlconfig_call_with_message(subname?subname
+ :"BarnOwl::_receive_msg_legacy_wrap", m);
}
+ if (ptr) owl_free(ptr);
}
char *owl_perlconfig_perlcmd(owl_cmd *cmd, int argc, char **argv)
Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs 2008-04-29 05:21:13 UTC (rev 1026)
+++ trunk/owl/perlglue.xs 2008-04-29 05:21:15 UTC (rev 1027)
@@ -255,12 +255,10 @@
}
void
-_create_style(name, object)
+create_style(name, object)
char *name
SV *object
PREINIT:
- /* This is to allow us to bootstrap the default style before the
- command architecture has been initialized */
owl_style *s;
CODE:
{
Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm 2008-04-29 05:21:13 UTC (rev 1026)
+++ trunk/owl/perlwrap.pm 2008-04-29 05:21:15 UTC (rev 1027)
@@ -154,13 +154,6 @@
$configfile ||= $ENV{HOME}."/.owlconf";
# populate global variable space for legacy owlconf files
-sub _format_msg_legacy_wrap {
- my ($m) = @_;
- $m->legacy_populate_global();
- return &BarnOwl::format_msg($m);
-}
-
-# populate global variable space for legacy owlconf files
sub _receive_msg_legacy_wrap {
my ($m) = @_;
$m->legacy_populate_global();
@@ -701,10 +694,12 @@
package BarnOwl;
if(*BarnOwl::format_msg{CODE}) {
# if the config defines a legacy formatting function, add 'perl' as a style
- # BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap",
- # "User-defined perl style that calls BarnOwl::format_msg"
- # . " with legacy global variable support");
- # BarnOwl::set("-q default_style perl");
+ BarnOwl::create_style("perl", BarnOwl::Style::Legacy->new(
+ "BarnOwl::format_msg",
+ "User-defined perl style that calls BarnOwl::format_msg"
+ . " with legacy global variable support",
+ 1));
+ BarnOwl::set("-q default_style perl");
}
}
}
@@ -778,7 +773,7 @@
sub description {"Default style";}
-BarnOwl::_create_style("default", "BarnOwl::Style::Default");
+BarnOwl::create_style("default", "BarnOwl::Style::Default");
################################################################################
@@ -868,7 +863,7 @@
sub description {"Compatability alias for the default style";}
-BarnOwl::_create_style("basic", "BarnOwl::Style::Basic");
+BarnOwl::create_style("basic", "BarnOwl::Style::Basic");
package BarnOwl::Style::OneLine;
################################################################################
@@ -895,7 +890,7 @@
sub description {"Formats for one-line-per-message"}
-BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine");
+BarnOwl::create_style("oneline", "BarnOwl::Style::OneLine");
################################################################################
@@ -995,7 +990,31 @@
}
}
+package BarnOwl::Style::Legacy;
+sub new {
+ my $class = shift;
+ my $func = shift;
+ my $desc = shift;
+ my $useglobals = shift;
+ $useglobals = 0 unless defined($useglobals);
+ return bless {function => $func,
+ description => $desc,
+ useglobals => $useglobals}, $class;
+}
+
+sub description {shift->{description}};
+
+sub format_message {
+ my $self = shift;
+ if($self->{useglobals}) {
+ $_[0]->legacy_populate_global();
+ }
+ no strict 'refs';
+ goto \&{$self->{function}};
+}
+
+
# switch to package main when we're done
package main;