* Elimar Riesebieter <riesebie@lxtec.de> [2007-07-07 18:36]: > On Sat, 07 Jul 2007 the mental interface of > Felix C. Stegerman told: > > > * "Felix C. Stegerman" <flx@obfusk.net> [2007-07-06 17:41]: > [...] > > And I've even added something: > > > > $ boxquote -c 'fortune -s perl' > > ,----[ fortune -s perl | ] > > | It's easy to solve the halting problem with a shotgun. :-) > > | -- Larry Wall in <199801151836.KAA14656@wall.org> > > `---- > > And what is the output of > > $ cat boxqoute | boxqoute > > ? $ boxquote -c 'wc -l $(which boxquote)' ,----[ wc -l $(which boxquote) | ] | 290 /usr/local/bin/boxquote `---- Since it's 290 lines, I've chosen not to paste, but instead to attach it. - Felix -- Felix C. Stegerman <flx@obfusk.net> http://obfusk.net ~ "Any sufficiently advanced bug is indistinguishable from a feature." ~ -- R. Kulawiec ~ vim: set ft=mail tw=70 sw=2 sts=2 et:
#!/usr/bin/perl # ******************************************************************** # # boxquote - quote text with a semi-box [based on boxquote.el] # # ******************************************************************** # # Felix C. Stegerman <flx@obfusk.net> # 2007-07-06 [22:47] # # ******************************************************************** # # Copyright (C) 2007 Felix C. Stegerman # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA # # ******************************************************************** our $VERSION = '2007-07-06 [22:47]'; # ******************************************************************** use strict; use warnings; # ******************************************************************** use Getopt::Long; use Pod::Usage; # ******************************************************************** my $prog = 'boxquote'; my %opts = ( 'bottom-corner' => '`', 'command' => [], 'hide-title' => 0, 'label' => '(standard input)', 'side' => '| ', 'title-format' => '[ %s ]', 'top-and-tail' => '----', 'top-corner' => ',', ); # ******************************************************************** Getopt::Long::Configure ('auto_version'); GetOptions ( \%opts, 'help|h|?', 'man', 'bottom-corner|bc=s', 'command|c=s', 'hide-title|ht!', 'label|l=s', 'side|s=s', 'title-format|tf=s', 'top-and-tail|tt=s', 'top-corner|tc=s', ) or pod2usage (2); $opts{'help'} and pod2usage (1); $opts{'man'} and pod2usage ('-verbose' => 2); # ******************************************************************** sub print_top ($) # top text { my $file = shift; # file name my $label = $file eq '-' ? $opts{'label'} : $file; print $opts{'top-corner'}; print $opts{'top-and-tail'}; printf $opts{'title-format'}, $label unless $opts{'hide-title'}; print "\n"; } sub print_side () # side text { print $opts{'side'}; } sub print_bottom () # bottom text { print $opts{'bottom-corner'}; print $opts{'top-and-tail'}; print "\n"; } sub process ($$) # process file[handle] { my $HANDLE = shift; my $title = shift; print_top ($title); while (<$HANDLE>) { print_side; print $_; } print_bottom; } # ******************************************************************** my @commands = @{$opts{'command'}}; my @files = @ARGV ? @ARGV : @commands ? ( ) : ('-') ; my $FILE = undef; # ******************************************************************** foreach my $cmd (@commands) { open ($FILE, '-|', $cmd) or die "Could not open pipe from `$cmd': $!"; process ($FILE, "$cmd |"); close $FILE; } # ******************************************************************** foreach my $file (@files) { $file eq '-' ? open ($FILE, '-') : open ($FILE, '<', $file) or die "Could not open `$file': $!"; process ($FILE, $file); close $FILE; } # ******************************************************************** # vim: set ft=perl tw=70 sw=2 sts=2 et: __END__ =begin comment boxquote.pod Felix C. Stegerman <flx@obfusk.net> 2007-07-07 [15:18] =end comment =head1 NAME boxquote - quote text with a semi-box =head1 SYNOPSIS B<boxquote> [I<options>] [I<file(s)>] =head1 DESCRIPTION The B<boxquote> C<perl(1)> script does more or less what B<boxquote.el> [on which it is based] does [for C<emacs(1)>]. From the description of boxquote.el: "boxquote provides a set of functions for using a text quoting style that partially boxes in the left hand side of an area of text; such a marking style might be used to show externally included text or example code." ,---- | The default style looks like this. `---- Thus, B<boxquote> prints each I<file> (or standard input if the file name F<-> is given) using said quoting style. When no files and no commands (see B<--command>) are specified, standard input is used. =head1 OPTIONS =over 4 =item B<--help>, B<-h>, B<-?> Display a brief help message and exit. =item B<--man> Display the B<boxquote> man page and exit. =item B<--bottom-corner>, B<-bc> I<string> Use I<string> for the bottom corner of the box; the default is "`". =item B<--command>, B<-c> I<command> Open and read from a pipe to I<command> instead of reading from a file. This option may be supplied multiple times to specify several commands. Note: commands will be processed before files. =item B<--hide-title>, B<-ht> Don't title the box with the file (or command) name. =item B<--label>, B<-l> I<label> Use I<label> as the title for standard input (F<->); the default is "(standard input)". =item B<--side>, B<-s> I<string> Use I<string> for the side of the box; the default is "| ". =item B<--title-format>, B<-tf> I<string> Use I<string> as the format string to use when creating a box title; the default is "[ %s ]". =item B<--top-and-tail>, B<-tt> I<string> Use I<string> at the top and tail of the box; the default is "----". =item B<--top-corner>, B<-tc> I<string> Use I<string> for the top corner of the box; the default is ",". =item B<--version>, B<-v> Output version information and exit. =back =head1 EXAMPLES $ echo 'the quick brown fox jumps over the lazy dog' | boxquote ,----[ (standard input) ] | the quick brown fox jumps over the lazy dog `---- $ boxquote -c 'echo Hello, World' --hide-title ,---- | Hello, World `---- $ boxquote -c 'fortune -s perl' ,----[ fortune -s perl | ] | At many levels, Perl is a "diagonal" language. | -- Larry Wall in <199709021854.LAA12794@wall.org> `---- =head1 AUTHOR Felix C. Stegerman <flx@obfusk.net> =head1 BUGS If you find bugs in B<boxquote>, please report these to the author by e-mail. =head1 SEE ALSO B<boxquote.el>, C<perl(1)>, L<perlgpl> =head1 COPYRIGHT Copyright (C) 2007 Felix C. Stegerman This program and its documentation are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. See the LICENSE file for more information. =for comment vim: set ft=perl tw=70 sw=2 sts=2 et: =cut
Attachment:
signature.asc
Description: Digital signature