[1047] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r1030 - in branches/barnowl_sqlite: . owl owl/perl/modules/Jabber/lib/BarnOwl/Module owl/perl/modules/Jabber/lib/Net/Jabber

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:12:29 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 19:20:21 -0400 (EDT)

Author: nelhage
Date: 2008-04-29 19:20:21 -0400 (Tue, 29 Apr 2008)
New Revision: 1030

Removed:
   branches/barnowl_sqlite/owl/stylefunc.c
Modified:
   branches/barnowl_sqlite/
   branches/barnowl_sqlite/owl/
   branches/barnowl_sqlite/owl/Makefile.in
   branches/barnowl_sqlite/owl/aim.c
   branches/barnowl_sqlite/owl/commands.c
   branches/barnowl_sqlite/owl/functions.c
   branches/barnowl_sqlite/owl/keys.c
   branches/barnowl_sqlite/owl/owl.c
   branches/barnowl_sqlite/owl/owl.h
   branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
   branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm
   branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm
   branches/barnowl_sqlite/owl/perlconfig.c
   branches/barnowl_sqlite/owl/perlglue.xs
   branches/barnowl_sqlite/owl/perlwrap.pm
   branches/barnowl_sqlite/owl/style.c
   branches/barnowl_sqlite/owl/variable.c
Log:
Merged revisions 1002-1029 via svnmerge from 
svn+ssh://lunatique.mit.edu/mit/barnowl/src/svn/trunk

........
  r1015 | nelhage | 2008-04-04 14:58:45 -0400 (Fri, 04 Apr 2008) | 3 lines
  
  Bind the combinations the iPhone sends for arrow keys [probably other
  terminals, too]
........
  r1018 | shadow | 2008-04-08 13:57:49 -0400 (Tue, 08 Apr 2008) | 2 lines
  
  avoid null pointer dereference if msg is NULL (or a 0 length is claimed)
........
  r1019 | nelhage | 2008-04-09 18:08:26 -0400 (Wed, 09 Apr 2008) | 2 lines
  
  Fix some stupid typos
........
  r1020 | chmrr | 2008-04-09 18:16:02 -0400 (Wed, 09 Apr 2008) | 3 lines
  
   r29300@kohr-ah:  chmrr | 2008-04-09 18:14:37 -0400
    * It's apparently a popular typo
........
  r1022 | asedeno | 2008-04-16 17:05:36 -0400 (Wed, 16 Apr 2008) | 2 lines
  
  Jabber reply bugfix.
  Reported by several people, resolved by arolfe.
........
  r1023 | nelhage | 2008-04-28 23:33:03 -0400 (Mon, 28 Apr 2008) | 3 lines
  
  Initialized merge tracking via "svnmerge" with revisions "735" from 
  svn+ssh://lunatique.mit.edu/mit/barnowl/src/svn/branches/barnowl_unicode
........
  r1024 | nelhage | 2008-04-28 23:33:12 -0400 (Mon, 28 Apr 2008) | 3 lines
  
  Initialized merge tracking via "svnmerge" with revisions "735" from 
  svn+ssh://lunatique.mit.edu/mit/barnowl/src/svn/branches/barnowl_sqlite
........
  r1025 | nelhage | 2008-04-29 01:21:12 -0400 (Tue, 29 Apr 2008) | 2 lines
  
  Clone owl_perl from the sqlite branch because I'm about to make use of it.
........
  r1026 | nelhage | 2008-04-29 01:21:13 -0400 (Tue, 29 Apr 2008) | 4 lines
  
  Initial step of moving styles from the current mishmash of different
  options to a unified object interface.
  No backwards-compatibility support yet.
........
  r1027 | nelhage | 2008-04-29 01:21:15 -0400 (Tue, 29 Apr 2008) | 2 lines
  
  Implement back-compat with old-style owl::format_msg() styles
........
  r1028 | nelhage | 2008-04-29 01:21:16 -0400 (Tue, 29 Apr 2008) | 2 lines
  
  Remove nearly all references to the "basic" style.
........
  r1029 | nelhage | 2008-04-29 01:21:17 -0400 (Tue, 29 Apr 2008) | 2 lines
  
  Support the `style' command again. Note that it is deprecated.
........



Property changes on: branches/barnowl_sqlite
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk:1-1001
   + /trunk:1-1029


Property changes on: branches/barnowl_sqlite/owl
___________________________________________________________________
Name: svk:merge
   - 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:2008
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:20981
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/branches/par:19594
fe09232e-8620-0410-8e36-e6b4839e121d:/branches/par:688
   + 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:2008
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:29300
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/branches/par:19594
fe09232e-8620-0410-8e36-e6b4839e121d:/branches/par:688

Modified: branches/barnowl_sqlite/owl/Makefile.in
===================================================================
--- branches/barnowl_sqlite/owl/Makefile.in	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/Makefile.in	2008-04-29 23:20:21 UTC (rev 1030)
@@ -24,7 +24,7 @@
      perlconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
      regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
      keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
-     aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
+     aim.c buddy.c buddylist.c timer.c style.c errqueue.c \
      zbuddylist.c muxevents.c popexec.c obarray.c select.c
 OWL_SRC = owl.c
 TESTER_SRC = tester.c

Modified: branches/barnowl_sqlite/owl/aim.c
===================================================================
--- branches/barnowl_sqlite/owl/aim.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/aim.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -1451,7 +1451,8 @@
      * containing Smart Quotes.
      *
      */
-    strncpy(realmsg, args->msg, sizeof(realmsg));
+    if (args->msg && args->msglen)
+      strncpy(realmsg, args->msg, sizeof(realmsg));
   }
 
   owl_function_debugmsg("faimtest_parse_incoming_im_chan1: message from: %s", userinfo->sn?userinfo->sn:"");

Modified: branches/barnowl_sqlite/owl/commands.c
===================================================================
--- branches/barnowl_sqlite/owl/commands.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/commands.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -101,14 +101,6 @@
 	      "Use 'show keymaps' to see the existing keymaps.\n"
 	      "Key sequences may be things like M-C-t or NPAGE.\n"),
 
-  OWLCMD_ARGS("style", owl_command_style, OWL_CTX_ANY,
-	      "creates a new style",
-	      "style <name> perl <function_name>",
-	      "Creates a new style for formatting messages.\n"
-	      "A style named <name> will be created that will\n"
-	      "format messages using the perl function <function_name>.\n\n"
-	      "SEE ALSO: show styles, view -s, filter -s\n"),
-
   OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
 	      "send a zephyr",
 	      "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
@@ -179,7 +171,7 @@
 	      "print a variable value",
 	      "print <variable>\n"
 	      "print",
-	      "Print the value of the named variable.  If no arugments\n"
+	      "Print the value of the named variable.  If no arguments\n"
 	      "are used print the value of all variables.\n"),
 
   OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
@@ -598,7 +590,7 @@
 	      "view only messages similar to the current message",
 	      "smartnarrow [-i | --instance]",
 	      "If the curmsg is a personal message narrow\n"
-	      "   to the converstaion with that user.\n"
+	      "   to the conversation with that user.\n"
 	      "If the curmsg is a class message, instance foo, recip *\n"
 	      "   message, narrow to the class, inst.\n"
 	      "If the curmsg is a class message then narrow\n"
@@ -610,7 +602,7 @@
 	      "returns the name of a filter based on the current message",
 	      "smartfilter [-i | --instance]",
 	      "If the curmsg is a personal message, the filter is\n"
-	      "   the converstaion with that user.\n"
+	      "   the conversation with that user.\n"
 	      "If the curmsg is a class message, instance foo, recip *\n"
 	      "   message, the filter is the class, inst.\n"
 	      "If the curmsg is a class message, the filter is that class.\n"
@@ -1675,27 +1667,6 @@
   return NULL;
 }
 
-char *owl_command_style(int argc, char **argv, char *buff) {
-  owl_style *s;
-
-  /* Usage: style <name> perl <function> */
-  if (argc != 4 || strcmp(argv[2], "perl")) {
-    owl_function_makemsg("Usage: style <name> perl <function>");
-    return NULL;
-  }
-  if (!owl_perlconfig_is_function(argv[3])) {
-    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
-			 argv[1], argv[3]);
-    return NULL;
-  }
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_perl(s, argv[1], argv[3], NULL);
-  owl_global_add_style(&g, s);
-
-  return NULL;
-}
-
-
 void owl_command_quit()
 {
   owl_function_quit();

Modified: branches/barnowl_sqlite/owl/functions.c
===================================================================
--- branches/barnowl_sqlite/owl/functions.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/functions.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -257,7 +257,7 @@
   /* check the arguments */
   ret=owl_zwrite_create_from_line(&z, line);
   if (ret) {
-    owl_function_error("Error in zwrite arugments");
+    owl_function_error("Error in zwrite arguments");
     owl_zwrite_free(&z);
     return;
   }
@@ -1922,7 +1922,7 @@
   owl_fmtext_append_normal(&fm, OWL_VERSION_STRING);
   owl_fmtext_append_normal(&fm, "\n");
 
-  owl_fmtext_append_normal(&fm, "  Startup Arugments: ");
+  owl_fmtext_append_normal(&fm, "  Startup Arguments: ");
   owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g));
   owl_fmtext_append_normal(&fm, "\n");
 

Modified: branches/barnowl_sqlite/owl/keys.c
===================================================================
--- branches/barnowl_sqlite/owl/keys.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/keys.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -229,11 +229,15 @@
   BIND_CMD("?",   "start-command search -r ", "start a reverse search command");
 
   BIND_CMD("LEFT",   "recv:shiftleft", "");
+  BIND_CMD("M-[ D",  "recv:shiftleft", "");
   BIND_CMD("RIGHT",  "recv:shiftright","");
+  BIND_CMD("M-[ C",  "recv:shiftleft", "");
   BIND_CMD("DOWN",   "recv:next",      "");
   BIND_CMD("C-n",    "recv:next",      "");
+  BIND_CMD("M-[ B",  "recv:next",      "");
   BIND_CMD("M-C-n",  "recv:next --smart-filter", "move to next message matching the current one"); 
   BIND_CMD("UP",     "recv:prev",      "");
+  BIND_CMD("M-[ A",  "recv:prev",      "");
   BIND_CMD("n",      "recv:next-notdel", "");
   BIND_CMD("p",      "recv:prev-notdel", "");
   BIND_CMD("C-p",    "recv:prev",        "");

Modified: branches/barnowl_sqlite/owl/owl.c
===================================================================
--- branches/barnowl_sqlite/owl/owl.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/owl.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -266,13 +266,6 @@
 
   owl_global_complete_setup(&g);
 
-  /* setup the built-in styles */
-  owl_function_debugmsg("startup: creating built-in styles");
-
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting.");
-  owl_global_add_style(&g, s);
-
   /* setup the default filters */
   /* the personal filter will need to change again when AIM chat's are
    *  included.  Also, there should be an %aimme% */
@@ -406,12 +399,8 @@
   owl_function_debugmsg("startup: setting startup and default style");
   if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) {
     /* the style was set by the user: leave it alone */
-  } else if (owl_global_is_config_format(&g)) {
-    owl_global_set_default_style(&g, "perl");
-  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
-    owl_global_set_default_style(&g, "default");
   } else {
-    owl_global_set_default_style(&g, "basic");
+    owl_global_set_default_style(&g, "default");
   }
 
   /* zlog in if we need to */
@@ -606,7 +595,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: branches/barnowl_sqlite/owl/owl.h
===================================================================
--- branches/barnowl_sqlite/owl/owl.h	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/owl.h	2008-04-29 23:20:21 UTC (rev 1030)
@@ -144,9 +144,6 @@
 #define OWL_SCROLLMODE_PAGED       4
 #define OWL_SCROLLMODE_PAGEDCENTER 5
 
-#define OWL_STYLE_TYPE_INTERNAL  0
-#define OWL_STYLE_TYPE_PERL      1
-
 #define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
 #define OWL_TABSTR        "   "
 #define OWL_MSGTAB            7
@@ -354,10 +351,7 @@
 
 typedef struct _owl_style {
   char *name;
-  char *description;
-  int type;
-  char *perlfuncname;
-  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
+  SV *perlobj;
 } owl_style;
 
 typedef struct _owl_viewwin {

Modified: branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	2008-04-29 23:20:21 UTC (rev 1030)
@@ -24,7 +24,7 @@
 use Net::Jabber::MUC;
 use Net::DNS;
 use Getopt::Long;
-Getopt::Long::Configure(qw(no_getopt_compat prefix_pattern="-|--"));
+Getopt::Long::Configure(qw(no_getopt_compat prefix_pattern=-|--));
 
 our $VERSION = 0.1;
 

Modified: branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm	2008-04-29 23:20:21 UTC (rev 1030)
@@ -119,7 +119,7 @@
 In an effort to make maintaining this document easier, I am not going
 to go into full detail on each of these functions.  Rather I will
 present the functions in a list with a type in the first column to
-show what they return, or take as arugments.  Here is the list of
+show what they return, or take as arguments.  Here is the list of
 types I will use:
 
   string  - just a string

Modified: branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm	2008-04-29 23:20:21 UTC (rev 1030)
@@ -939,7 +939,7 @@
 
         if (!exists($funcHash{set}) && exists($funcHash{get}))
         {
-            croak("The DefineNamespace arugments have changed, and I cannot determine the\nnew values automatically for name($name).  Please read the man page\nfor Net::Jabber::Namespaces.  I apologize for this incompatability.\n");
+            croak("The DefineNamespace arguments have changed, and I cannot determine the\nnew values automatically for name($name).  Please read the man page\nfor Net::Jabber::Namespaces.  I apologize for this incompatability.\n");
         }
 
         if (exists($funcHash{type}) || exists($funcHash{path}) ||

Modified: branches/barnowl_sqlite/owl/perlconfig.c
===================================================================
--- branches/barnowl_sqlite/owl/perlconfig.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perlconfig.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -266,34 +266,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: branches/barnowl_sqlite/owl/perlglue.xs
===================================================================
--- branches/barnowl_sqlite/owl/perlglue.xs	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perlglue.xs	2008-04-29 23:20:21 UTC (rev 1030)
@@ -267,18 +267,15 @@
 	}
 
 void
-_create_style(name, function, description)
+create_style(name, object)
      char *name
-     char *function
-     char *description
+     SV  *object
      PREINIT:
-		/* This is to allow us to bootstrap the default style before the
-		command architecture has been initialized */
 		owl_style *s;
      CODE:
 	{
 		s = owl_malloc(sizeof(owl_style));
-		owl_style_create_perl(s, name, function, description);
+		owl_style_create_perl(s, name, object);
 		owl_global_add_style(&g, s);
 	}
 

Modified: branches/barnowl_sqlite/owl/perlwrap.pm
===================================================================
--- branches/barnowl_sqlite/owl/perlwrap.pm	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/perlwrap.pm	2008-04-29 23:20:21 UTC (rev 1030)
@@ -160,13 +160,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();
@@ -1105,6 +1098,20 @@
 
 # Internal startup/shutdown routines called by the C code
 
+sub _load_perl_commands {
+    # Load builtin perl commands
+    BarnOwl::new_command(style => \&BarnOwl::Style::style_command,
+                       {
+                           summary => "creates a new style",
+                           usage   => "style <name> perl <function_name>",
+                           description =>
+                           "A style named <name> will be created that will\n" .
+                           "format messages using the perl function <function_name>.\n\n" .
+                           "SEE ALSO: show styles, view -s, filter -s\n\n" .
+                           "DEPRECATED in favor of BarnOwl::create_style(NAME, OBJECT)",
+                          });
+}
+
 sub _load_owlconf {
     # load the config  file
     if ( -r $BarnOwl::configfile ) {
@@ -1115,10 +1122,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");
         }
     }
 }
@@ -1133,6 +1142,7 @@
     }
     @BarnOwl::__startup_errors = ();
     
+    _load_perl_commands();
     _load_owlconf();
 
     if(eval {require BarnOwl::ModuleLoader}) {
@@ -1182,21 +1192,24 @@
 ################################################################################
 sub format_message($)
 {
+    my $self = shift;
     my $m = shift;
 
     if ( $m->is_loginout) {
-        return format_login($m);
+        return $self->format_login($m);
     } elsif($m->is_ping && $m->is_personal) {
-        return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
+        return $self->format_ping($m);
     } elsif($m->is_admin) {
-        return "\@bold(OWL ADMIN)\n" . indentBody($m);
+        return $self->format_admin($m);
     } else {
-        return format_chat($m);
+        return $self->format_chat($m);
     }
 }
 
-BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style");
+sub description {"Default style";}
 
+BarnOwl::create_style("default", "BarnOwl::Style::Default");
+
 ################################################################################
 
 sub time_hhmm {
@@ -1206,6 +1219,7 @@
 }
 
 sub format_login($) {
+    my $self = shift;
     my $m = shift;
     return sprintf(
         '@b<%s%s> for @b(%s) (%s) %s',
@@ -1217,7 +1231,20 @@
        );
 }
 
+sub format_ping {
+    my $self = shift;
+    my $m = shift;
+    return "\@b(PING) from \@b(" . $m->pretty_sender . ")\n";
+}
+
+sub format_admin {
+    my $self = shift;
+    my $m = shift;
+    return "\@bold(OWL ADMIN)\n" . indentBody($m);
+}
+
 sub format_chat($) {
+    my $self = shift;
     my $m = shift;
     my $header;
     if ( $m->is_personal ) {
@@ -1265,36 +1292,45 @@
     return "    ".$body;
 }
 
+package BarnOwl::Style::Basic;
+
+our @ISA=qw(BarnOwl::Style::Default);
+
+sub description {"Compatability alias for the default style";}
+
+BarnOwl::create_style("basic", "BarnOwl::Style::Basic");
+
 package BarnOwl::Style::OneLine;
 ################################################################################
 # Branching point for various formatting functions in this style.
 ################################################################################
 use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s ';
 sub format_message($) {
+  my $self = shift;
   my $m = shift;
 
-#  if ( $m->is_zephyr ) {
-#    return format_zephyr($m);
-#  }
   if ( $m->is_loginout ) {
-    return format_login($m);
+    return $self->format_login($m);
   }
   elsif ( $m->is_ping) {
-    return format_ping($m);
+    return $self->format_ping($m);
   }
   elsif ( $m->is_admin || $m->is_loopback) {
-    return format_local($m);
+    return $self->format_local($m);
   }
   else {
-    return format_chat($m);
+    return $self->format_chat($m);
   }
 }
 
-BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message");
+sub description {"Formats for one-line-per-message"}
 
+BarnOwl::create_style("oneline", "BarnOwl::Style::OneLine");
+
 ################################################################################
 
 sub format_login($) {
+  my $self = shift;
   my $m = shift;
   return sprintf(
     BASE_FORMAT,
@@ -1317,6 +1353,7 @@
 
 sub format_chat($)
 {
+  my $self = shift;
   my $m = shift;
   my $dir = lc($m->{direction});
   my $dirsym = '-';
@@ -1357,6 +1394,7 @@
 # Format locally generated messages
 sub format_local($)
 {
+  my $self = shift;
   my $m = shift;
   my $type = uc($m->{type});
   my $line = sprintf(BASE_FORMAT, '<', $type, '', '');
@@ -1387,7 +1425,52 @@
     }
 }
 
+sub style_command {
+    my $command = shift;
+    if(scalar @_ != 3 || $_[1] ne 'perl') {
+        die("Usage: style <name> perl <function>\n");
+    }
+    my $name = shift;
+    my $perl = shift;
+    my $fn   = shift;
+    {
+        no strict 'refs';
+        unless(*{$fn}{CODE}) {
+            die("Unable to create style '$name': no perl function '$fn'\n");
+        }
+    }
+    BarnOwl::create_style($name, BarnOwl::Style::Legacy->new($fn));
+}
 
+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 {
+    my $self = shift;
+    return $self->{description} ||
+    ("User-defined perl style that calls " . $self->{function});
+};
+
+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;
 

Modified: branches/barnowl_sqlite/owl/style.c
===================================================================
--- branches/barnowl_sqlite/owl/style.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/style.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -1,3 +1,4 @@
+#define OWL_PERL
 #include "owl.h"
 
 static const char fileIdent[] = "$Id$";
@@ -2,29 +3,8 @@
 
-void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)
+void owl_style_create_perl(owl_style *s, char *name, SV *obj)
 {
-  s->type=OWL_STYLE_TYPE_INTERNAL;
   s->name=owl_strdup(name);
-  if (description) {
-    s->description=owl_strdup(description);
-  } else {
-    s->description=owl_sprintf("Owl internal style %s", name);
-  }
-  s->perlfuncname=NULL;
-  s->formatfunc=formatfunc;
+  s->perlobj = SvREFCNT_inc(obj);
 }
 
-void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description)
-{
-  s->type=OWL_STYLE_TYPE_PERL;
-  s->name=owl_strdup(name);
-  s->perlfuncname=owl_strdup(perlfuncname);
-  if (description) {
-    s->description=owl_strdup(description);
-  } else {
-    s->description=owl_sprintf("User-defined perl style that calls %s", 
-			       perlfuncname);
-  }
-  s->formatfunc=NULL;
-}
-
 int owl_style_matches_name(owl_style *s, char *name)
@@ -42,7 +22,19 @@
 
 char *owl_style_get_description(owl_style *s)
 {
-  return(s->description);
+  SV *sv = NULL;
+  OWL_PERL_CALL_METHOD(s->perlobj,
+                       "description",
+                       /* no args */,
+                       "Error in style_get_description: %s",
+                       0,
+                       sv = SvREFCNT_inc(POPs);
+                       );
+  if(sv) {
+    return SvPV_nolen(sv_2mortal(sv));
+  } else {
+    return "[error getting description]";
+  }
 }
 
 /* Use style 's' to format message 'm' into fmtext 'fm'.
@@ -50,55 +42,52 @@
  */
 void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
 {
-  if (s->type==OWL_STYLE_TYPE_INTERNAL) {
-    (* s->formatfunc)(fm, m);
-  } else if (s->type==OWL_STYLE_TYPE_PERL) {
-    char *body, *indent;
-    int curlen;
+  char *body, *indent;
+  int curlen;
 
-    /* run the perl function */
-    body=owl_perlconfig_getmsg(m, 1, s->perlfuncname);
-    if (!strcmp(body, "")) {
-      owl_free(body);
-      body=owl_strdup("<unformatted message>");
-    }
-    
-    /* indent and ensure ends with a newline */
-    indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
-    owl_text_indent(indent, body, OWL_TAB);
-    curlen = strlen(indent);
-    if (curlen==0 || indent[curlen-1] != '\n') {
-      indent[curlen] = '\n';
-      indent[curlen+1] = '\0';
-    }
+  SV *sv = NULL;
+  
+  /* Call the perl object */
+  OWL_PERL_CALL_METHOD(s->perlobj,
+                       "format_message",
+                       XPUSHs(owl_perlconfig_message2hashref(m));,
+                       "Error in format_message: %s",
+                       0,
+                       sv = SvREFCNT_inc(POPs);
+                       );
 
-    /* fmtext_append.  This needs to change */
-    owl_fmtext_append_ztext(fm, indent);
-    
-    owl_free(indent);
-    owl_free(body);
+  if(sv) {
+    body = SvPV_nolen(sv);
+  } else {
+    body = "<unformatted message>";
   }
+
+  /* indent and ensure ends with a newline */
+  indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
+  owl_text_indent(indent, body, OWL_TAB);
+  curlen = strlen(indent);
+  if (curlen==0 || indent[curlen-1] != '\n') {
+    indent[curlen] = '\n';
+    indent[curlen+1] = '\0';
+  }
+
+  /* fmtext_append.  This needs to change */
+  owl_fmtext_append_ztext(fm, indent);
+
+  owl_free(indent);
+  if(sv)
+    SvREFCNT_dec(body);
 }
 
 int owl_style_validate(owl_style *s) {
-  if (!s) {
+  if (!s || !s->perlobj || !SvOK(s->perlobj)) {
     return -1;
-  } else if (s->type==OWL_STYLE_TYPE_INTERNAL) {
-    return 0;
-  } else if (s->type==OWL_STYLE_TYPE_PERL 
-	     && s->perlfuncname 
-	     && owl_perlconfig_is_function(s->perlfuncname)) {
-    return 0;
-  } else {
-    return -1;
   }
+  return 0;
 }
 
 void owl_style_free(owl_style *s)
 {
   if (s->name) owl_free(s->name);
-  if (s->description) owl_free(s->description);
-  if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) {
-    owl_free(s->perlfuncname);
-  }
+  SvREFCNT_dec(s->perlobj);
 }

Deleted: branches/barnowl_sqlite/owl/stylefunc.c
===================================================================
--- branches/barnowl_sqlite/owl/stylefunc.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/stylefunc.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -1,219 +0,0 @@
-#include "owl.h"
-
-static const char fileIdent[] = "$Id$";
-
-/* In all of these functions, 'fm' is expected to already be
- * initialized.
- */
-
-void owl_style_basic_format_body(owl_fmtext *fm, owl_message *m) {
-  char *indent, *body;
-  owl_filter *f;
-  int wrap = 0;
-
-  /* get the body */
-  body=owl_strdup(owl_message_get_body(m));
-
-  f = owl_global_get_filter(&g, "wordwrap");
-  if(f && owl_filter_message_match(f, m)) 
-    wrap = 1;
-
-  if(wrap) {
-    int cols, i, width, word;
-    char *tab, *tok, *ws = " \t\n\r";
-    cols = owl_global_get_cols(&g) - OWL_MSGTAB - 1;
-
-    tab = owl_malloc(OWL_MSGTAB+1);
-    for(i = 0; i < OWL_MSGTAB; i++) {
-      tab[i] = ' ';
-    }
-    tab[OWL_MSGTAB] = 0;
-
-    tok = strtok(body, ws);
-    tab[OWL_MSGTAB-1] = 0;
-    owl_fmtext_append_normal(fm, tab);
-    tab[OWL_MSGTAB-1] = ' ';
-    width = 0;
-
-    while(tok) {
-      word = strlen(tok);
-      if(word + width + 1 < cols) {
-        owl_fmtext_append_normal(fm, " ");
-        owl_fmtext_append_normal(fm, tok);
-        width += word + 1;
-      } else {
-        owl_fmtext_append_normal(fm, "\n");
-        owl_fmtext_append_normal(fm, tab);
-        owl_fmtext_append_normal(fm, tok);
-        width = word;
-      }
-      tok = strtok(NULL, ws);
-    }
-    owl_fmtext_append_normal(fm, "\n");
-
-    owl_free(tab);
-  } else {
-    /* do the indenting into indent */
-    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
-    owl_text_indent(indent, body, OWL_MSGTAB);
-    owl_fmtext_append_ztext(fm, indent);
-    if(body[strlen(body)-1] != '\n')
-      owl_fmtext_append_ztext(fm, "\n");
-    owl_free(indent);
-  }
-
-  owl_free(body);
-}
- 
-void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
-{
-#ifdef HAVE_LIBZEPHYR
-  char *ptr, *zsigbuff, frombuff[LINE];
-#endif
-
-  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
-#ifdef HAVE_LIBZEPHYR
-
-    /* edit the from addr for printing */
-    strcpy(frombuff, owl_message_get_sender(m));
-    ptr=strchr(frombuff, '@');
-    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
-      *ptr='\0';
-    }
-    
-    /* set the message for printing */
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    
-    if (owl_message_is_ping(m)) {
-      owl_fmtext_append_bold(fm, "PING");
-      owl_fmtext_append_normal(fm, " from ");
-      owl_fmtext_append_bold(fm, frombuff);
-      owl_fmtext_append_normal(fm, "\n");
-    } else if (owl_message_is_loginout(m)) {
-      char *host, *tty;
-
-      host=owl_message_get_attribute_value(m, "loginhost");
-      tty=owl_message_get_attribute_value(m, "logintty");
-      
-      if (owl_message_is_login(m)) {
-	owl_fmtext_append_bold(fm, "LOGIN");
-      } else if (owl_message_is_logout(m)) {
-	owl_fmtext_append_bold(fm, "LOGOUT");
-      }
-      if (owl_message_is_pseudo(m)) {
-	owl_fmtext_append_bold(fm, " (PSEUDO)");
-      }
-      owl_fmtext_append_normal(fm, " for ");
-      ptr=short_zuser(owl_message_get_instance(m));
-      owl_fmtext_append_bold(fm, ptr);
-      owl_free(ptr);
-      owl_fmtext_append_normal(fm, " at ");
-      owl_fmtext_append_normal(fm, host ? host : "");
-      owl_fmtext_append_normal(fm, " ");
-      owl_fmtext_append_normal(fm, tty ? tty : "");
-      owl_fmtext_append_normal(fm, "\n");
-    } else {
-      owl_fmtext_append_normal(fm, "From: ");
-      if (strcasecmp(owl_message_get_class(m), "message")) {
-	owl_fmtext_append_normal(fm, "Class ");
-	owl_fmtext_append_normal(fm, owl_message_get_class(m));
-	owl_fmtext_append_normal(fm, " / Instance ");
-	owl_fmtext_append_normal(fm, owl_message_get_instance(m));
-	owl_fmtext_append_normal(fm, " / ");
-      }
-      owl_fmtext_append_normal(fm, frombuff);
-      if (strcasecmp(owl_message_get_realm(m), owl_zephyr_get_realm())) {
-	owl_fmtext_append_normal(fm, " {");
-	owl_fmtext_append_normal(fm, owl_message_get_realm(m));
-	owl_fmtext_append_normal(fm, "} ");
-      }
-      
-      /* stick on the zsig */
-      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
-      owl_message_pretty_zsig(m, zsigbuff);
-      owl_fmtext_append_normal(fm, "    (");
-      owl_fmtext_append_ztext(fm, zsigbuff);
-      owl_fmtext_append_normal(fm, ")");
-      owl_fmtext_append_normal(fm, "\n");
-      owl_free(zsigbuff);
-      
-      /* then the indented message */
-      owl_style_basic_format_body(fm, m);
-      
-      /* make personal messages bold for smaat users */
-      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
-	if (owl_message_is_personal(m)) {
-	  owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
-	}
-      }
-    }
-    
-#endif
-  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
-    char *zsigbuff, *foo;
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_normal(fm, "To: ");
-    foo=short_zuser(owl_message_get_recipient(m));
-    owl_fmtext_append_normal(fm, foo);
-    owl_free(foo);
-    owl_fmtext_append_normal(fm, "  (Zsig: ");
-    
-    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
-    owl_message_pretty_zsig(m, zsigbuff);
-    owl_fmtext_append_ztext(fm, zsigbuff);
-    owl_free(zsigbuff);
-    
-    owl_fmtext_append_normal(fm, ")");
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-  } else if (owl_message_is_type_aim(m)) {
-    if (owl_message_is_loginout(m)) {
-      owl_fmtext_append_normal(fm, OWL_TABSTR);
-      if (owl_message_is_login(m)) {
-	owl_fmtext_append_bold(fm, "AIM LOGIN");
-      } else {
-	owl_fmtext_append_bold(fm, "AIM LOGOUT");
-      }
-      owl_fmtext_append_normal(fm, " for ");
-      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
-      owl_fmtext_append_normal(fm, "\n");
-    } else if (owl_message_is_direction_in(m)) {
-      owl_fmtext_append_bold(fm, OWL_TABSTR);
-      owl_fmtext_append_bold(fm, "AIM from ");
-      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
-      owl_fmtext_append_bold(fm, "\n");
-      owl_style_basic_format_body(fm, m);
-    } else if (owl_message_is_direction_out(m)) {
-      owl_fmtext_append_normal(fm, OWL_TABSTR);
-      owl_fmtext_append_normal(fm, "AIM sent to ");
-      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
-      owl_fmtext_append_normal(fm, "\n");
-      owl_style_basic_format_body(fm, m);
-    }
-  } else if (owl_message_is_type_admin(m)) {
-    char *text, *header;
-    
-    text=owl_message_get_body(m);
-    header=owl_message_get_attribute_value(m, "adminheader");
-
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_bold(fm, "OWL ADMIN ");
-    owl_fmtext_append_ztext(fm, header);
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-  } else {
-    char *header;
-
-    header=owl_sprintf("%s from: %s to: %s",
-		       owl_message_get_type(m),
-		       owl_message_get_sender(m),
-		       owl_message_get_recipient(m));
-
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_normal(fm, header);
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-    
-    owl_free(header);
-  }
-}

Modified: branches/barnowl_sqlite/owl/variable.c
===================================================================
--- branches/barnowl_sqlite/owl/variable.c	2008-04-29 05:21:17 UTC (rev 1029)
+++ branches/barnowl_sqlite/owl/variable.c	2008-04-29 23:20:21 UTC (rev 1030)
@@ -272,7 +272,6 @@
 		 "Styles may be created with the 'style' command.\n"
 		 "Some built-in styles include:\n"
 		 "   default  - the default owl formatting\n"
-		 "   basic    - simple formatting\n"
 		 "   oneline  - one line per-message\n"
 		 "   perl     - legacy perl interface\n"
 		 "\nSEE ALSO: style, show styles, view -s <style>\n"


home help back first fref pref prev next nref lref last post