[894] in BarnOwl Developers

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

[D-O-H] r881 - trunk/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:10:52 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed, 16 Jan 2008 02:59:07 -0500 (EST)

Author: nelhage
Date: 2008-01-16 02:59:06 -0500 (Wed, 16 Jan 2008)
New Revision: 881

Modified:
   trunk/owl/owl.c
   trunk/owl/perlwrap.pm
   trunk/owl/stylefunc.c
Log:
Move oneline style to perl. closes 43

Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c	2008-01-16 03:19:43 UTC (rev 880)
+++ trunk/owl/owl.c	2008-01-16 07:59:06 UTC (rev 881)
@@ -253,9 +253,6 @@
   s=owl_malloc(sizeof(owl_style));
   owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting.");
   owl_global_add_style(&g, s);
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline, "Formats for one-line-per-message");
-  owl_global_add_style(&g, s);
 
   /* setup the default filters */
   /* the personal filter will need to change again when AIM chat's are

Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm	2008-01-16 03:19:43 UTC (rev 880)
+++ trunk/owl/perlwrap.pm	2008-01-16 07:59:06 UTC (rev 881)
@@ -830,11 +830,111 @@
     # replace newline followed by anything with
     # newline plus four spaces and that thing.
     $body =~ s/\n(.)/\n    $1/g;
-
+    # Trim trailing newlines.
+    $body =~ s/\n*$//;
     return "    ".$body;
 }
 
+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 $m = shift;
 
+#  if ( $m->is_zephyr ) {
+#    return format_zephyr($m);
+#  }
+  if ( $m->is_login ) {
+    return format_login($m);
+  }
+  elsif ( $m->is_ping) {
+    return format_ping($m);
+  }
+  elsif ( $m->is_admin || $m->is_loopback) {
+    return format_local($m);
+  }
+  else {
+    return format_chat($m);
+  }
+}
+
+BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message");
+
+################################################################################
+
+sub format_login($) {
+  my $m = shift;
+  return sprintf(
+    BASE_FORMAT,
+    '<',
+    $m->type,
+    uc( $m->login ),
+    $m->pretty_sender)
+    . ($m->login_extra ? "at ".$m->login_extra : '');
+}
+
+sub format_ping($) {
+  my $m = shift;
+  return sprintf(
+    BASE_FORMAT,
+    '<',
+    $m->type,
+    'PING',
+    $m->pretty_sender)
+}
+
+sub format_chat($)
+{
+  my $m = shift;
+  my $dir = lc($m->{direction});
+  my $dirsym = '-';
+  if ($dir eq 'in') {
+    $dirsym = '<';
+  }
+  elsif ($dir eq 'out') {
+    $dirsym = '>';
+  }
+
+  my $line;
+  if ($m->is_personal) {
+    $line= sprintf(BASE_FORMAT,
+		   $dirsym,
+		   $m->type,
+		   '',
+		   ($dir eq 'out'
+		      ? $m->pretty_recipient
+		      : $m->pretty_sender));
+  }
+  else {
+    $line = sprintf(BASE_FORMAT,
+		    $dirsym,
+		    $m->context,
+		    $m->subcontext,
+		    ($dir eq 'out'
+		       ? $m->pretty_recipient
+		       : $m->pretty_sender));
+  }
+
+  my $body = $m->{body};
+  $body =~ tr/\n/ /;
+  $line .= $body;
+  $line = BarnOwl::Style::boldify($line) if ($m->is_personal && lc($m->direction) eq 'in');
+  return $line;
+}
+
+# Format locally generated messages
+sub format_local($)
+{
+  my $m = shift;
+  my $type = uc($m->{type});
+  my $line = sprintf(BASE_FORMAT, '<', $type, '', '');
+  my $body = $m->{body};
+  $body =~ tr/\n/ /;
+  return $line.$body;
+}
+
 package BarnOwl::Style;
 
 # This takes a zephyr to be displayed and modifies it to be displayed

Modified: trunk/owl/stylefunc.c
===================================================================
--- trunk/owl/stylefunc.c	2008-01-16 03:19:43 UTC (rev 880)
+++ trunk/owl/stylefunc.c	2008-01-16 07:59:06 UTC (rev 881)
@@ -219,133 +219,3 @@
     owl_free(header);
   }
 }
-
-void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
-{
-  char *tmp;
-  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
-  char *sender, *recip;
-#ifdef HAVE_LIBZEPHYR
-  ZNotice_t *n;
-#endif
-
-  sender=short_zuser(owl_message_get_sender(m));
-  recip=short_zuser(owl_message_get_recipient(m));
-  
-  if (owl_message_is_type_zephyr(m)) {
-#ifdef HAVE_LIBZEPHYR
-    n=owl_message_get_notice(m);
-    
-    owl_fmtext_append_spaces(fm, OWL_TAB);
-
-    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)) {
-	tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGIN-P":"LOGIN", "", sender);
-	owl_fmtext_append_normal(fm, tmp);
-	owl_free(tmp);
-      } else if (owl_message_is_logout(m)) {
-	tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGOUT-P":"LOGOUT", "", sender);
-	owl_fmtext_append_normal(fm, tmp);
-	owl_free(tmp);
-      }
-
-      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 if (owl_message_is_ping(m)) {
-      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
-      owl_fmtext_append_normal(fm, tmp);
-      owl_fmtext_append_normal(fm, "\n");
-      owl_free(tmp);
-
-    } else {
-      if (owl_message_is_direction_in(m)) {
-	tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
-      } else if (owl_message_is_direction_out(m)) {
-	tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
-      } else {
-	tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
-      }
-      owl_fmtext_append_normal(fm, tmp);
-      if (tmp) owl_free(tmp);
-      
-      tmp=owl_strdup(owl_message_get_body(m));
-      owl_text_tr(tmp, '\n', ' ');
-      owl_fmtext_append_ztext(fm, tmp);
-      owl_fmtext_append_normal(fm, "\n");
-      if (tmp) owl_free(tmp);
-    }
-      
-    /* make personal messages bold for smaat users */
-    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
-	owl_message_is_personal(m) &&
-	owl_message_is_direction_in(m)) {
-      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
-    }
-
-    owl_free(sender);
-    owl_free(recip);
-#endif
-  } else if (owl_message_is_type_aim(m)) {
-    owl_fmtext_append_spaces(fm, OWL_TAB);
-    if (owl_message_is_login(m)) {
-      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
-      owl_fmtext_append_normal(fm, tmp);
-      owl_fmtext_append_normal(fm, "\n");
-      if (tmp) owl_free(tmp);
-    } else if (owl_message_is_logout(m)) {
-      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
-      owl_fmtext_append_normal(fm, tmp);
-      owl_fmtext_append_normal(fm, "\n");
-      if (tmp) owl_free(tmp);
-    } else {
-      if (owl_message_is_direction_in(m)) {
-	tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
-	owl_fmtext_append_normal(fm, tmp);
-	if (tmp) owl_free(tmp);
-      } else if (owl_message_is_direction_out(m)) {
-	tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
-	owl_fmtext_append_normal(fm, tmp);
-	if (tmp) owl_free(tmp);
-      }
-      
-      tmp=owl_strdup(owl_message_get_body(m));
-      owl_text_tr(tmp, '\n', ' ');
-      owl_fmtext_append_normal(fm, tmp);
-      owl_fmtext_append_normal(fm, "\n");
-      if (tmp) owl_free(tmp);
-
-      /* make personal messages bold for smaat users */
-      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
-	owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
-      }
-    }
-  } else if (owl_message_is_type_admin(m)) {
-    owl_fmtext_append_spaces(fm, OWL_TAB);
-    owl_fmtext_append_normal(fm, "< ADMIN                                  ");
-    
-    tmp=owl_strdup(owl_message_get_body(m));
-    owl_text_tr(tmp, '\n', ' ');
-    owl_fmtext_append_normal(fm, tmp);
-    owl_fmtext_append_normal(fm, "\n");
-    if (tmp) owl_free(tmp);
-  } else {
-    owl_fmtext_append_spaces(fm, OWL_TAB);
-    owl_fmtext_append_normal(fm, "< LOOPBACK                               ");
-    
-    tmp=owl_strdup(owl_message_get_body(m));
-    owl_text_tr(tmp, '\n', ' ');
-    owl_fmtext_append_normal(fm, tmp);
-    owl_fmtext_append_normal(fm, "\n");
-    if (tmp) owl_free(tmp);
-  }    
-
-}


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