[595] in BarnOwl Developers

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

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

daemon@ATHENA.MIT.EDU (hartmans@MIT.EDU)
Thu Oct 29 18:07:46 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: hartmans@MIT.EDU
Reply-To: dirty-owl-hackers@MIT.EDU
Date: Sun, 29 Apr 2007 18:27:31 -0400 (EDT)

Author: hartmans
Date: 2007-04-29 18:27:30 -0400 (Sun, 29 Apr 2007)
New Revision: 708

Modified:
   trunk/owl/perlconfig.c
   trunk/owl/perlglue.xs
   trunk/owl/perlwrap.pm
Log:
Implement hackish support for the wordwrap filter in the perl styles.
Note that while I think the user-visible parts of this are reasonably
OK the implementation needs cleanup.


* perlconfig.c: Add should_wordwrap attribute to message hashes.  This
   is a hack; a better solution is to expose an arbitrary interface for
   doing filter matches from perl.  That proved to be more than I had
   time for.
* perlglue.xs: expose owl_text_wordwrap
* perlwrap.pm: use in the default style


Modified: trunk/owl/perlconfig.c
===================================================================
--- trunk/owl/perlconfig.c	2007-04-29 22:24:45 UTC (rev 707)
+++ trunk/owl/perlconfig.c	2007-04-29 22:27:30 UTC (rev 708)
@@ -32,8 +32,15 @@
   char *ptr, *blessas, *type;
   int i, j;
   owl_pair *pair;
+  owl_filter *wrap;
 
   if (!m) return &PL_sv_undef;
+  wrap = owl_global_get_filter(&g, "wordwrap");
+  if(!wrap) {
+      owl_function_error("wrap filter is not defined");
+      return &PL_sv_undef;
+  }
+
   h = newHV();
 
 #define MSG2H(h,field) hv_store(h, #field, strlen(#field), \
@@ -84,6 +91,9 @@
   hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
   hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);
   hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
+  hv_store(h, "should_wordwrap",
+	   strlen("should_wordwrap"), newSViv(
+					      owl_filter_message_match(wrap, m)),0);
 
   type = owl_message_get_type(m);
   if(!type || !*type) type = "generic";

Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs	2007-04-29 22:24:45 UTC (rev 707)
+++ trunk/owl/perlglue.xs	2007-04-29 22:27:30 UTC (rev 708)
@@ -314,3 +314,17 @@
 			owl_global_remove_filter(&g,filterName);
 		}
 	}
+
+char *
+wordwrap(in, cols)
+	char *in
+	int cols
+	PREINIT:
+		char *rv = NULL;
+	CODE:
+rv = owl_text_wordwrap(in, cols);
+		RETVAL = rv;	
+	OUTPUT:
+		RETVAL
+	CLEANUP:
+		if (rv) owl_free(rv);

Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm	2007-04-29 22:24:45 UTC (rev 707)
+++ trunk/owl/perlwrap.pm	2007-04-29 22:27:30 UTC (rev 708)
@@ -417,7 +417,10 @@
         eval {
             BarnOwl::ModuleLoader->load_all;
         };
-        BarnOwl::error("Error loading modules: $@") if $@;
+        BarnOwl::error("$@") if $@;
+open TMP, ">/tmp/error";
+print TMP $@;
+
     } else {
         BarnOwl::error("Can't load BarnOwl::ModuleLoader, loadable module support disabled:\n$@");
     }
@@ -527,6 +530,9 @@
     my $m = shift;
 
     my $body = $m->body;
+    if ($m->{should_wordwrap}) {
+      $body = BarnOwl::wordwrap($body, BarnOwl::getnumcols()-8);
+    }
     # replace newline followed by anything with
     # newline plus four spaces and that thing.
     $body =~ s/\n(.)/\n    $1/g;


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