#!/usr/bin/perl ################### # # signature engine # # version: 0.0.2 # # A template-based signature randomizer. Issue command "perldoc sigenv" # on the command line to get full documentation for the program. # # Copyright (c) 1999 Matti Airas. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # 07.03.2000 v.0.0.2.1 Martti Rahkila: date additions ###################################################################### # the code begins here. use strict; use Getopt::Long; # dirty hack to get a clear error message if any of the non-standard # modules do not exist BEGIN { eval { require LWP::UserAgent; import LWP::UserAgent; require HTTP::Request::Common; import HTTP::Request::Common; require HTML::Entities; import HTML::Entities; #+mr require HTTP::Date; import HTTP::Date; }; die < "$ENV{HOME}/.sig/template"; # function declarations sub usage; ###################################################################### # parse command line arguments my ($single_line_quotes,$translate,$template_file); Getopt::Long::Configure(qw/bundling/); GetOptions( "s" => \$single_line_quotes, "x" => \$translate, "t=s" => \$template_file) or usage; $template_file ||= DEF_TEMPLATE; ###################################################################### # get the template my $tmpl; open TMPL,$template_file or die "Could not open $template_file, died"; { local $/ = undef; $tmpl = ; } close TMPL; # strip trailing whitespaces $tmpl =~ s/^(.*?)\s*$/$1/s; ###################################################################### # get the quote my ($quote,$quote_orig,$quote_xlated); my (@quote,@quote_orig,@quote_xlated);; srand; { (local $/ = '%%\n') unless $single_line_quotes; rand($.) < 1 && ($quote = $_) while <>; } # strip leading and trailing whitespaces $quote =~ s/^\s*(.*?)\s*$/$1/s; $quote_orig = $quote; @quote_orig = split /\n/,$quote_orig; ###################################################################### # optionally translate the quote if ($translate) { my $xlate_url = "http://www.kielikone.fi/kielikone/demot/transmart2.shtml"; # get the translation of the text my $ua = new LWP::UserAgent; my $resp = $ua->request(GET $xlate_url."?src=".$quote); # extract the desired text from the results ($quote) = $resp->{_content } =~ m{ TranSmartin\ tuottama\ käännös: .*?
\s* (.*?) \s*
}six; $quote =~ s{.*?}{}sig; $quote =~ s{<.*?>}{}sig; decode_entities($quote); $quote_xlated = $quote; @quote_xlated = split /\n/,$quote_xlated; } @quote = split /\n/,$quote; ###################################################################### #+mr get date and time in the ISO 8601 format my $date_iso8601 = HTTP::Date::time2iso; # change it to Finnish style my $date = $date_iso8601; $date =~ s/(\d+)-(\d+)-(\d+)\s(\d+:\d+:\d+)/$3\.$2\.$1\ $4/; #-mr both of these can be used in the template! ###################################################################### # output the results # get the format my $form=< [ B<-s> ] [ B<-x> ] [ B<-t> I ] I ... =head1 DESCRIPTION B is another signature randomizer with arbitrary output formatting capabilities. =head1 OPTIONS =over 8 =item -s Treat the quote-file as a collection of single-line quotes. The default is to have a fortune-like formatting (multi-line quotes separated by "%%" on an empty line. =item -x Translate the quote to another language. Currently the translation used is hard-coded in the source and translates from Finnish to English but this may change in the future. Note that actually the quote is just mangled through a web page, and the functionality could be used for other purposes than translation also. =item -t Template file. See below for discussion of the format of the template file. If the parameter is not given, default value of ~/.sig/template is used instead. =item quote-file Quote files are the files containing all those snappy texts you want to share with the rest of the world. The files can either be formatted as a collection of single-line quotes (each line is a quote of its own) or as a fortune-like text file with double percentage signs on an empty line separating the quotes (see L<-s>). =head1 TEMPLATE FILE FORMAT The template file is actually a Perl format (see L). The following examples should cover the most common signature use. =item Contact info on top, quote follows as-is John Doe - www.john.doe @* $quote The string C<"@*"> is a place-holder for the whole quote text. =item Contact info on top with date and time in ISO 8601 format, quote follows as-is John Doe - www.john.doe - @* $date_iso8601 @* $quote The first C<"@*"> is replaced with date and time, the second with the whole quote. =item Contact info on top, wrapped quote follows John Doe - john.doe@foo.bar - www.john.doe "@" ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ $quote The quote text begins at the first caret and fills the space allotted by the lesser-than signs. The double tilde indicates that the line formatting will be repeated as long as there is input. The at-sign in the e-mail address requires a dirty hack. =item Contact info on the left, wrapped text on the right John Doe ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $quote john.doe@foo.bar ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "@", $quote www.john.doe ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $quote ~~ ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $quote The quote text fills the space allotted for them, even on multiple rows. If the double tilde is removed, a four-line limit is imposed. Still better, if it is replaced with a single tilde, the last line will be removed if empty. =item Contact info on the left, wrapped text on the right, Finnish style date on the bottom John Doe ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $quote john.doe@foo.bar ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "@", $quote www.john.doe/@jdoe ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "~", $quote ~ ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $quote -------------------------------------------------------- ^<<<<<<<<<<<<<<<<<<< $date The quote text fills the space allotted for them, even on multiple rows, the last line will be removed if empty. On the bottom there is a line of dashes and below that, date and time in the customary Finnish format. The tilde (~) in the url is a kludge. =item Four-line limit, unfilled paragraphs John Doe @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $quote[0] john.doe@foo.bar @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< "@", $quote[1] www.john.doe @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $quote[2] ~ @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $quote[3] You can pick a specific line of the quote by using an array subscript. =item Perl statements in the signature John Doe @>>>>>>>>@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $ENV{USER}, "@", $ENV{HOSTNAME} Written: @||||||||||||||||||||||||||||||||||||||||||||| scalar localtime Uptime: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< `uptime` @* $quote You can easily access any perl code through the template. The quote is not even required, if you get away with other information! =item Two simultaneous languages ^<<<<<<<<<<<<<<<<<<<<<<<<< ^>>>>>>>>>>>>>>>>>>>>>>>>> ~~ $quote_orig, $quote_xlated Both fields are filled and wrapped automatically. =head1 EXAMPLES See L