Index: owl.c
===================================================================
--- owl.c	(revision 687c674874f17f0db99a8604cf835df4b5dbe651)
+++ owl.c	(revision b6c067afcb43b49fd77c87be23190b4a18bd3c16)
@@ -227,9 +227,20 @@
   }
 
+  /* Initialize perl */
+  owl_function_debugmsg("startup: processing config file");
+  owl_context_set_readconfig(owl_global_get_context(&g));
+  perlerr=owl_perlconfig_initperl(configfile);
+  if (perlerr) {
+    endwin();
+    owl_function_error("Internal perl error: %s\n", perlerr);
+    fprintf(stderr, "Internal perl error: %s\n", perlerr);
+    fflush(stderr);
+    printf("Internal perl error: %s\n", perlerr);
+    fflush(stdout);
+    exit(1);
+  }
+
   /* setup the built-in styles */
   owl_function_debugmsg("startup: creating built-in styles");
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_internal(s, "default", &owl_stylefunc_default, "Default message formatting");
-  owl_global_add_style(&g, s);
 
   s=owl_malloc(sizeof(owl_style));
@@ -304,18 +315,4 @@
   owl_function_debugmsg("startup: doing AIM initialization");
   owl_aim_init();
-
-  /* read the config file */
-  owl_function_debugmsg("startup: processing config file");
-  owl_context_set_readconfig(owl_global_get_context(&g));
-  perlerr=owl_perlconfig_readconfig(configfile);
-  if (perlerr) {
-    endwin();
-    owl_function_error("Error parsing configfile: %s\n", perlerr);
-    fprintf(stderr, "\nError parsing configfile: %s\n", perlerr);
-    fflush(stderr);
-    printf("\nError parsing configfile: %s\n", perlerr);
-    fflush(stdout);
-    exit(1);
-  }
 
   /* if the config defines a formatting function, add 'perl' as a style */
Index: perlconfig.c
===================================================================
--- perlconfig.c	(revision 8fba2eedba1c587ee4b4a752dda819a1fe24bd59)
+++ perlconfig.c	(revision b6c067afcb43b49fd77c87be23190b4a18bd3c16)
@@ -270,5 +270,5 @@
 
 
-char *owl_perlconfig_readconfig(char * file)
+char *owl_perlconfig_initperl(char * file)
 {
   int ret;
@@ -276,5 +276,4 @@
   char *err;
   char *args[4] = {"", "-e", "0;", NULL};
-
 
   /* create and initialize interpreter */
Index: perlglue.xs
===================================================================
--- perlglue.xs	(revision 0ff2528921e3999e59eba0829babdc839fa45a99)
+++ perlglue.xs	(revision b6c067afcb43b49fd77c87be23190b4a18bd3c16)
@@ -246,2 +246,18 @@
 		owl_function_error("%s", text);
 	}
+
+void
+_create_style(name, function, description)
+     char *name
+     char *function
+     char *description
+     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_global_add_style(&g, s);
+	}
Index: perlwrap.pm
===================================================================
--- perlwrap.pm	(revision 16138b00a34da062eee6d351c8f00413edaa0f92)
+++ perlwrap.pm	(revision b6c067afcb43b49fd77c87be23190b4a18bd3c16)
@@ -5,4 +5,9 @@
 #####################################################################
 #####################################################################
+# XXX NOTE: This file is sourced before almost any barnowl
+# architecture is loaded. This means, for example, that it cannot
+# execute any owl commands. Any code that needs to do so, should
+# create a function wrapping it and push it onto @onStartSubs
+
 
 use strict;
@@ -293,5 +298,5 @@
 #####################################################################
 ################################################################################
-package owl;
+package BarnOwl;
 
 ################################################################################
@@ -326,5 +331,5 @@
       BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
   }
-
+    
   @BarnOwl::Hooks::onMainLoop = ();
   @BarnOwl::Hooks::onStartSubs = ();
@@ -335,8 +340,8 @@
       undef $@;
       do $BarnOwl::configfile;
-      owl::error("Error reloading $BarnOwl::configfile: $@") if $@;
+      BarnOwl::error("Error reloading $BarnOwl::configfile: $@") if $@;
   }
   BarnOwl::reload_hook(@_);
-  package owl;
+  package BarnOwl;
 }
 
@@ -372,4 +377,17 @@
 }
 
+sub _load_owlconf {
+    # Only do this the first time
+    return if $BarnOwl::reload;
+    # load the config  file
+    if ( -r $BarnOwl::configfile ) {
+        undef $@;
+        do $BarnOwl::configfile;
+        die $@ if $@;
+    }
+}
+
+push @BarnOwl::Hooks::onStartSubs, \&_load_owlconf;
+
 package BarnOwl::Hooks;
 
@@ -453,4 +471,169 @@
     return runHook_accumulate(\@onGetBuddyList);
 }
+
+################################################################################
+# Built-in perl styles
+################################################################################
+package BarnOwl::Style::Default;
+################################################################################
+# Branching point for various formatting functions in this style.
+################################################################################
+sub format_message($)
+{
+    my $m = shift;
+
+    if ( $m->is_zephyr ) {
+        return format_zephyr($m);
+    }
+    elsif ( $m->is_admin ) {
+        return "\@bold(OWL ADMIN)\n" . indentBody($m);
+    }
+    elsif ( $m->is_aim ) {
+        return format_aim($m);
+    }
+    elsif ( lc( $m->type ) eq 'loopback' ) {
+        return format_loopback($m);
+    }
+    else {
+        return "Unexpected message type.";
+    }
+}
+
+BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style");
+
+################################################################################
+sub format_zephyr($)
+{
+    my $m = shift;
+
+    # Extract time from message
+    my ($time) = $m->time =~ /(\d\d:\d\d)/;
+
+    # Deal with PING messages, assuming owl's rxping variable is true.
+    if ( $m->is_ping && $m->recipient ne "" ) {
+        return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
+    }
+
+    # Deal with login/logout messages
+    elsif ( $m->is_loginout ) {
+        return sprintf(
+            '@b<%s%s> for @b(%s) at %s %s %s',
+            uc( $m->login ),
+
+            # This is a hack, owl does not export "pseudo"-ness
+            ( $m->zsig ) ? "" : " (PSEUDO)",
+            $m->pretty_sender,
+            lc( $m->host ),
+            $m->login_tty,
+            $time
+        );
+    }
+
+    # Deal with outbound zephyrs (personal, we don't see outbound non-personal)
+    elsif ( lc( $m->direction ) eq 'out' ) {
+        my $user = $m->recipient;
+        $user =~ s/\@ATHENA[.]MIT[.]EDU$//;
+
+        my $zsig = $m->zsig;
+        $zsig =~ s/\n.*$//s;
+
+        return sprintf( "Zephyr sent to %s  %s  (Zsig: %s)\n%s",
+            $user, $time, $zsig, indentBody($m) );
+    }
+
+    # Deal with everything else
+    else {
+        my $zsig = $m->zsig;
+        $zsig =~ s/\n.*$//s;
+
+        my $msg = sprintf(
+            "%s / %s / \@b<%s>%s  %s    (%s)\n%s",
+            $m->class, $m->instance, $m->pretty_sender,
+            ( $m->opcode ? " [@{[$m->opcode]}]" : "" ),
+            $time, $zsig, indentBody($m)
+        );
+        return BarnOwl::Style::boldify($msg) if ( $m->is_private );
+        return $msg;
+    }
+}
+
+
+sub format_aim($)
+{
+    my $m = shift;
+
+    # Extract time from message
+    my ($time) = $m->time =~ /(\d\d:\d\d)/;
+
+    # Deal with login/logout messages
+    if ( $m->is_loginout ) {
+        return
+          sprintf( "\@b(AIM %s) for %s %s",
+                   uc( $m->login ),
+                   $m->sender,
+                   $time );
+    }
+    elsif ( lc( $m->direction ) eq 'out' ) {
+        return sprintf( "AIM sent to %s  %s\n%s",
+                        $m->recipient,
+                        $time,
+                        indentBody($m) );
+    }
+    else {
+        return sprintf( "\@b(AIM from %s)  %s\n%s",
+                        $m->sender,
+                        $time,
+                        BarnOwl::Style::boldify( indentBody($m) ) );
+    }
+}
+
+
+sub format_loopback($)
+{
+    my $m = shift;
+
+    # Extract time from message
+    my ($time) = $m->time =~ /(\d\d:\d\d)/;
+
+    return sprintf( "loopback from: %s to: %s  %s\n%s",
+        $m->sender, $m->recipient, $time, indentBody($m) );
+}
+
+
+sub indentBody($)
+{
+    my $m = shift;
+    
+    my $body = $m->body;
+    # replace newline followed by anything with 
+    # newline plus four spaces and that thing.
+    $body =~ s/\n(.)/\n    $1/g;
+
+    return "    ".$body;
+}
+
+
+package BarnOwl::Style;
+
+# This takes a zephyr to be displayed and modifies it to be displayed
+# entirely in bold.
+sub boldify($)
+{
+    local $_ = shift;
+    if ( !(/\)/) ) {
+        return '@b(' . $_ . ')';
+    } elsif ( !(/\>/) ) {
+        return '@b<' . $_ . '>';
+    } elsif ( !(/\}/) ) {
+        return '@b{' . $_ . '}';
+    } elsif ( !(/\]/) ) {
+        return '@b[' . $_ . ']';
+    } else {
+        my $txt = "\@b($_";
+        $txt =~ s/\)/\)\@b\[\)\]\@b\(/g;
+        return $txt . ')';
+    }
+}
+
 
 # switch to package main when we're done
@@ -468,10 +651,3 @@
 }
 
-# load the config  file
-if (-r $BarnOwl::configfile) {
-    undef $@;
-    do $BarnOwl::configfile;
-    die $@ if $@;
-}
-
 1;
