[2653] in BarnOwl Developers

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

[PATCH] add a random zsig function

daemon@ATHENA.MIT.EDU (Kevin Riggle)
Sun Sep 19 03:07:34 2010

From: Kevin Riggle <kevinr@free-dissociation.com>
To: barnowl-dev@mit.edu
Cc: Kevin Riggle <kevinr@free-dissociation.com>
Date: Sun, 19 Sep 2010 03:07:06 -0400
In-Reply-To: <1284879898-sup-5985@black-opal.free-dissociation.com>

---
 perl/lib/BarnOwl.pm |   20 ++++++++++++++++++++
 variable.c          |    3 ++-
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/perl/lib/BarnOwl.pm b/perl/lib/BarnOwl.pm
index b097cdd..db4f665 100644
--- a/perl/lib/BarnOwl.pm
+++ b/perl/lib/BarnOwl.pm
@@ -560,6 +560,26 @@ sub default_zephyr_signature
   return $zsig;
 }
 
+=head3 random_zephyr_signature
+
+Retrieve a random line from ~/.zsigs (except those beginning with '#') 
+and use it as the zephyr signature.
+
+=cut
+
+sub random_zephyr_signature 
+{ 
+    my $zsigfile = "$ENV{'HOME'}/.zsigs"; 
+    open FILE, $zsigfile or die "No zsigfile $zsigfile"; 
+    while (<FILE>) { 
+        push @lines, $_ unless /^#/ || /^\s*$/; 
+    } 
+    close FILE; 
+    my $zsig = $lines[int(rand(scalar @lines))]; 
+    chomp $zsig; 
+    return $zsig; 
+}
+
 # Stub for owl::startup / BarnOwl::startup, so it isn't bound to the
 # startup command. This may be redefined in a user's configfile.
 sub startup
diff --git a/variable.c b/variable.c
index 1175ede..037bb02 100644
--- a/variable.c
+++ b/variable.c
@@ -212,7 +212,8 @@ static owl_variable variables_to_init[] = {
 		 "zsig perl function",
 		 "Called every time you start a zephyrgram without an\n"
 		 "explicit zsig.  The default setting implements the policy\n"
-		 "described in the documentation for the 'zsig' variable.\n"),
+		 "described in the documentation for the 'zsig' variable.\n"
+		 "See also BarnOwl::random_zephyr_signature().\n"),
 
   OWLVAR_STRING( "zsig" /* %OwlVarStub */, "",
 	         "zephyr signature",
-- 
1.7.1


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