[2672] in BarnOwl Developers

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

Re: [PATCH] add a random zsig function

daemon@ATHENA.MIT.EDU (Nelson Elhage)
Sat Sep 25 17:58:54 2010

From: Nelson Elhage <nelhage@MIT.EDU>
To: Kevin Riggle <kevinr@free-dissociation.com>, barnowl-dev@mit.edu
Cc: Kevin Riggle <kevinr@free-dissociation.com>
In-Reply-To: <1285043636-3610-1-git-send-email-kevinr@free-dissociation.com>
Date: Sat, 25 Sep 2010 17:58:50 -0400

lgtm, committed.

On Tue, 21 Sep 2010 00:33:56 -0400, Kevin Riggle <kevinr@free-dissociation.com> wrote:
> ---
>  perl/lib/BarnOwl.pm |   19 +++++++++++++++++++
>  variable.c          |    3 ++-
>  2 files changed, 21 insertions(+), 1 deletions(-)
> 
> diff --git a/perl/lib/BarnOwl.pm b/perl/lib/BarnOwl.pm
> index b097cdd..cc25be9 100644
> --- a/perl/lib/BarnOwl.pm
> +++ b/perl/lib/BarnOwl.pm
> @@ -560,6 +560,25 @@ 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 my $file, '<', $zsigfile or die "Error opening file $zsigfile: $!";
> +    my @lines = grep !(/^#/ || /^\s*$/), <$file>;
> +    close $file;
> +    return '' if !@lines;
> +    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