1#!/usr/bin/perl -w
2package main;
3use strict;
4use vars '$VERSION';
5use Text::FIGlet 2.01;
6$VERSION = 2.19.2;
7
8my %opts;
9$opts{-C} = [];
10$opts{$_} = undef for
11  qw(A D E L R U X c d e f h help -help l r x);
12$opts{$_} = "0 but true" for
13  qw(I m w);
14for (my $i=0; $i <= scalar @ARGV; $i++) {
15  last unless defined($ARGV[$i]);
16  shift && last if $ARGV[$i] eq '--';
17  if( $ARGV[$i]  =~ /^-N$/ ) {
18    shift; $i--;
19    $opts{-C} = [];
20  }
21  if( $ARGV[$i]  =~ /^-C=?(.*)/ ) {
22    shift; $i--;
23    $opts{-C} = [ @{$opts{-C}},
24		  defined($1) && $1 ne '' ?
25		  $1 : defined($opts{-C}) ? do{$i--; shift} : undef
26		];
27    next;
28  }
29  foreach my $key ( sort { length($b)-length($a) } keys %opts) {
30    if( $ARGV[$i] =~ /^-$key=?(.*)/ ){
31      shift; $i--;
32      $opts{$key} = defined($1) && $1 ne '' ?
33	$1 : defined($opts{$key}) ? do{$i--; shift} : 1;
34      last;
35    }
36  }
37}
38defined($_) && $_ eq '0 but true' && ($_ = undef) for values %opts;
39if( $opts{help}||$opts{h}||$opts{-help} ){
40    eval "use Pod::Text;";
41    die("Unable to print man page: $@\n") if $@;
42    pod2text(__FILE__);
43    exit 0;
44}
45
46$opts{I} ||= 0;
47if( $opts{I} == 1 ){
48  my @F = unpack("c*", $VERSION);
49  die(10_000 * $F[0] + 100 * $F[1] +$F[2], "\n");
50}
51
52my $font = Text::FIGlet->new(-D=>$opts{D}&&!$opts{E},
53			  -d=>$opts{d},
54			  -m=>$opts{m}||-2,
55			  -f=>$opts{f});
56@_ = map { -C=> $_ } @{$opts{-C}} if scalar @{$opts{-C}};
57my $ctrl = Text::FIGlet->new( @_,
58			     -d=>$opts{d}) if @_;
59
60if( $opts{I} == 2 ){
61    die("$font->{-d}\n");
62}
63if( $opts{I} == 3 ){
64    die("$font->{-f}\n");
65}
66
67my %figify = (
68	      -U=>$opts{U},
69	      -X=>($opts{L}&&'L')||($opts{R}&&'R'),
70	      -m=>$opts{m},
71	      -w=>$opts{w},
72	      -x=>($opts{l}&&'l')||($opts{c}&&'c')||($opts{r}&&'r') );
73croak("figlet.pl: cannot use both -A and -e") if $opts{A} && $opts{e};
74if( $opts{e} ){
75    $opts{A} = 1;
76    @ARGV = eval "@ARGV";
77    croak($@) if $@;
78}
79if( $opts{A} ){
80    $_ = join(' ', map($_ = $_ eq '' ? $/ : $_, @ARGV));
81    #XXXtraneous space...
82    print scalar $font->figify(-A=>($ctrl ? $ctrl->tr() : $_), %figify);
83    exit 0;
84}
85else{
86    Text::FIGlet::croak("Usage: figlet.pl -help\n") if @ARGV;
87    print scalar $font->figify(-A=>($ctrl ? $ctrl->tr() : $_), %figify)
88      while <STDIN>;
89}
90__END__
91=pod
92
93=head1 NAME
94
95figlet.pl - display large characters made up of ordinary screen characters
96
97=head1 SYNOPSIS
98
99B<figlet.pl>
100[ B<-A> ]
101[ B<-C> ]
102[ B<-D> ]
103[ B<-E> ]
104[ B<-L> ]
105[ B<-N> ]
106[ B<-R> ]
107[ B<-U> ]
108[ B<-X> ]
109[ B<-c> ]
110[ B<-d=>F<fontdirectory> ]
111[ B<-e> C<EXPR>]
112[ B<-f=>F<fontfile> ]
113[ B<-help> ]
114[ B<-l> ]
115[ B<-r> ]
116[ B<-w=>I<outputwidth> ]
117[ B<-x> ]
118
119=head1 DESCRIPTION
120
121B<figlet.pl> prints its input using large characters made up of
122ordinary screen characters. B<figlet.pl> output is generally
123reminiscent of the sort of I<signatures> many people like
124to put at the end of e-mail and UseNet messages. It is
125also reminiscent of the output of some banner programs,
126although it is oriented normally, not sideways.
127
128B<figlet.pl> can print in a variety of fonts, both left-to-right
129and right-to-left, with adjacent characters kerned and
130I<smushed> together in various ways. B<figlet.pl> fonts are
131stored in separate files, which can be identified by the
132suffix I<.flf>. Most B<figlet.pl> font files will be stored in
133FIGlet's default font directory.
134
135B<figlet.pl> can also use control files, which tell it to
136map certain input characters to certain other characters,
137similar to the Unix tr command. Control files can be
138identified by the suffix F<.flc>. Most FIGlet control
139files will be stored in FIGlet's default font directory.
140
141=head1 OPTIONS
142
143=over
144
145=item B<-A>
146
147All Words. Once the - arguments are read, all words remaining on the command
148line are used instead of standard input to print letters. Allows shell scripts
149to generate large letters without having to dummy up standard input files.
150
151An empty character, obtained by two sequential and empty quotes, results in a
152line break.
153
154To include text begining with - that might otherwise appear to be an invalid
155argument, use the argument --
156
157=item B<-C>=F<controlfile>
158B<-N>
159
160These options deal with FIGlet F<controlfiles>. A F<controlfile> is a file
161containing a list of commands that FIGlet executes each time it reads a
162character. These commands can map certain input characters to other characters,
163similar to the Unix tr command or the FIGlet B<-D> option. FIGlet maintains
164a list of F<controlfiles>, which is empty when FIGlet starts up. B<-C> adds
165the given F<controlfile> to the list. B<-N> clears the F<controlfile> list,
166cancelling the effect of any previous B<-C>. FIGlet executes the commands in
167all F<controlfiles> in the list. See the file F<figfont.txt>, provided with
168FIGlet, for details on how to write a F<controlfile>.
169
170=item B<-D>
171B<-E>
172
173B<-E> is the default, and a no-op.
174
175B<-D> switches  to  the German (ISO 646-DE) character set.
176Turns `[', `\' and `]' into umlauted A, O and U,  respectively.
177`{',  `|' and `}' turn into the respective lower case versions of these.
178`~' turns into  s-z.
179
180These options are deprecated, which means they may soon
181be removed. The modern way to achieve this effect is with
182control files, see B<-C>.
183
184=item B<-I>I<infocode>
185
186These options print various information about FIGlet, then exit.
187
188=over
189
190=item 1 Version (integer).
191
192This will print the version of your copy of FIGlet as a decimal integer.
193The main version number is multiplied by 10000, the sub-version number is
194multiplied by 100, and the sub-sub-version number is multiplied by 1.
195These are added together, and the result is printed out. For example,
196FIGlet 2.1.2 will print ``20102''. If there is ever a version 2.1.3,
197it will print ``20103''.  Similarly, version 3.7.2 would print ``30702''.
198These numbers are guaranteed to be ascending, with later versions having
199higher numbers.
200
201=item 2 Default font directory.
202
203This will print the default font directory. It is affected by the B<-d> option.
204
205=item 3 Font.
206
207This will print the name of the font FIGlet would use. It is affected by the
208B<-f> option. This is not a filename; the I<.flf> suffix is not printed.
209
210=back
211
212=item B<-L>
213B<-R>
214B<-X>
215
216These options control whether FIGlet prints left-to-right or right-to-left.
217B<-L> selects left-to-right printing. B<-R> selects right-to-left printing.
218B<-X> (default) makes FIGlet use whichever is specified in the font file.
219
220=item B<-U>
221
222Process input as Unicode, if you use a control file with the C<u>
223directive unicode processing is automagically enabled for any text
224processed with that control.
225
226=item B<-c>
227B<-l>
228B<-r>
229B<-x>
230
231These options handle the justification of FIGlet output. B<-c> centers the
232output horizontally. B<-l> makes the output flush-left. B<-r> makes it
233flush-right. B<-x> (default) sets the justification according to whether
234left-to-right or right-to-left text is selected. Left-to-right text will be
235flush-left, while right-to-left text will be flush-right. (Left-to-rigt
236versus right-to-left text is controlled by B<-L>, B<-R> and B<-X>.)
237
238=item B<-d>=F<fontdirectory>
239
240Change the default font directory. FIGlet looks for fonts first in the default
241directory and then in the current directory. If the B<-d> option is not
242specified, FIGlet uses the directory that was specified when it was compiled.
243To find out which directory this is, use the B<-I2> option.
244
245=item B<-e> C<EXPR>
246
247Evaluates the remaining arguments as perl and processes the results.
248This can be especially useful for retrieving Unicode characters.
249
250=item B<-f>=F<fontfile>
251
252Select the font. The I<.flf> suffix may be left off of fontfile, in which case
253FIGlet automatically appends it. FIGlet looks for the file first in the default
254font directory and then in the current directory, or, if fontfile was given as
255a full pathname, in the given directory. If the B<-f> option is not specified,
256FIGlet uses the font that was specified when it was compiled. To find out which
257font this is, use the B<-I3> option.
258
259=item B<-m=>I<smushmode>
260
261Specifies how B<Text::FIGlet::Font> should ``smush'' and kern consecutive
262characters together. On the command line, B<-m0> can be useful, as it tells
263FIGlet to kern characters without smushing them together. Otherwise, this
264option is rarely needed, as a B<Text::FIGlet::Font> font file specifies the
265best smushmode to use with the font. B<-m> is, therefore, most useful to font
266designers testing the various smushmodes with their font. I<smushmode> can be
267-2 through 63.
268
269=over
270
271=item S<-2>
272
273Get mode from font file (default).
274
275Every FIGlet font file specifies the best smushmode to use with the font.
276This will be one of the smushmodes (-1 through 63) described in the following
277paragraphs.
278
279=item S<-1>
280
281No smushing or kerning.
282
283Characters are simply concatenated together.
284
285=item S<-0>
286
287Fixed width.
288
289This will pad each character in the font such that they are all a consistent
290width. The padding is done such that the character is centered in it's "cell",
291and any odd padding is the trailing edge.
292
293=item S<0>
294
295Kern only.
296
297Characters are pushed together until they touch.
298
299=back
300
301=item B<-w>=I<outputwidth>
302
303These options control the outputwidth, or the
304screen width FIGlet assumes when formatting its
305output. FIGlet uses the outputwidth to determine
306when to break lines and how to center the output.
307Normally, FIGlet assumes 80 columns so that people
308with wide terminals won't annoy the people they e-mail
309FIGlet output to. B<-w> sets the outputwidth
310to the given integer. An outputwidth of 1 is a
311special value that tells FIGlet to print each non-
312space character, in its entirety, on a separate line,
313no matter how wide it is. Another special outputwidth
314is -1, it means to not warp.
315
316=back
317
318=head1 EXAMPLES
319
320C<figlet.pl -A Hello "" World>
321
322=head1 ENVIRONMENT
323
324B<figlet.pl> will make use of these environment variables if present
325
326=over
327
328=item FIGFONT
329
330The default font to load.
331If undefined the default is F<standard.flf>
332It should reside in the directory specified by FIGLIB.
333
334=item FIGLIB
335
336The default location of fonts.
337If undefined the default is F</usr/local/share/figlet>
338
339=back
340
341=head1 FILES
342
343FIGlet font files are available at
344
345  ftp://ftp.figlet.org/pub/figlet/
346
347=head1 BUGS
348
349Under pre 5.8 perl B<-e> may munge the first character if it is Unicode,
350this is a bug in perl itself. The output is usually:
351
352=over
353
354=item 197  LATIN CAPITAL LETTER A WITH RING ABOVE
355
356=item 187  RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
357
358=back
359
360    o   \\
361   /_\   >>
362  /   \ //
363
364If this occurs, prepend the sequence with a null.
365
366=head1 SEE ALSO
367
368L<Text::FIGlet>, L<figlet(6)>, L<banner(6)>, L<http://www.figlet.org|>
369
370=head1 AUTHOR
371
372Jerrad Pierce <jpierce@cpan.org>|<webmaster@pthbb.org>
373
374=cut
375