8 use File::Basename qw / dirname /;
9 use File::Path qw / mkpath /;
10 use Getopt::Long qw/ GetOptions /;
17 '--cookiedir=s' => \$cookiedir,
18 '--ocookiedir=s' => \$ocookiedir,
19 '--without-offensive!' => \$no_offensive,
20 '--output=s' => \$output_fn,
21 ) or die "Wrong options - $!";
23 if ( !defined($output_fn) )
25 die "Please specify --output";
28 if ( !defined($cookiedir) )
30 die "Please specify cookiedir";
33 my $OFF = ( !$no_offensive );
35 if ( $OFF and !defined($ocookiedir) )
37 die "Please specify ocookiedir";
40 my $dirname = dirname($output_fn);
41 if ( $dirname and ( !-e $dirname ) )
46 # The :raw is to prevent CRs on Win32/etc.
47 open my $out, '>:raw:encoding(utf-8)', $output_fn;
49 $out->print(<<'END_OF_STRING');
50 <?xml version="1.0" encoding="UTF-8"?>
51 <!-- lifted from man+troff by doclifter -->
52 <refentry xmlns='http://docbook.org/ns/docbook' version='5.0' xml:lang='en' xml:id='fortune'>
53 <!-- $NetBSD: fortune.6,v 1.4 1995/03/23 08:28:37 cgd Exp $ -->
55 <!-- Copyright (c) 1985, 1991, 1993
56 The Regents of the University of California. All rights reserved. -->
58 <!-- This code is derived from software contributed to Berkeley by
61 <!-- Redistribution and use in source and binary forms, with or without
62 modification, are permitted provided that the following conditions
64 1. Redistributions of source code must retain the above copyright
65 notice, this list of conditions and the following disclaimer.
66 2. Redistributions in binary form must reproduce the above copyright
67 notice, this list of conditions and the following disclaimer in the
68 documentation and/or other materials provided with the distribution.
69 3. All advertising materials mentioning features or use of this software
70 must display the following acknowledgement:
71 This product includes software developed by the University of
72 California, Berkeley and its contributors.
73 4. Neither the name of the University nor the names of its contributors
74 may be used to endorse or promote products derived from this software
75 without specific prior written permission. -->
77 <!-- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
78 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
79 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
80 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 <!-- @(#)fortune.6 8.3 (Berkeley) 4/19/94 -->
91 <!-- This version of the man page has been modified heavily, like the
92 program it documents. Some of the changes may be exclusive to
93 Linux. Amy A. Lewis, September, 1995. -->
95 <!-- Changes Copyright (c) 1997 Dennis L. Clark. All rights reserved. -->
97 <!-- The changes in this file may be freely redistributed, modified or
98 included in other software, as long as both the above copyright
99 notice and these conditions appear intact. -->
101 <refentryinfo><date>19 April 94 [May. 97]</date></refentryinfo>
103 <refentrytitle>FORTUNE</refentrytitle>
104 <manvolnum>6</manvolnum>
105 <refmiscinfo class='date'>19 April 94 [May. 97]</refmiscinfo>
106 <refmiscinfo class='source'>BSD Experimental</refmiscinfo>
107 <refmiscinfo class='manual'>UNIX Reference Manual</refmiscinfo>
110 <refname>fortune</refname>
111 <refpurpose>print a random, hopefully interesting, adage</refpurpose>
113 <!-- body begins here -->
114 <refsynopsisdiv xml:id='synopsis'>
116 <command>fortune</command> <arg choice='opt'>-acefilosw </arg>
117 <arg choice='opt'><arg choice='plain'>-n </arg><arg choice='plain'><replaceable>length</replaceable></arg></arg>
118 <arg choice='opt'><arg choice='plain'>-m </arg><arg choice='plain'><replaceable>pattern</replaceable></arg></arg>
119 <arg choice='opt'><arg choice='opt'><replaceable>n%</replaceable></arg><arg choice='plain'><replaceable>file/dir/all</replaceable></arg></arg>
124 <refsect1 xml:id='description'><title>DESCRIPTION</title>
126 <emphasis role='strong' remap='B'>fortune</emphasis>
127 is run with no arguments it prints out a random epigram. Epigrams are
132 ? "divided into several categories, where each category is sub-divided
133 into those which are potentially offensive and those which are not."
134 : "divided into several categories."
137 $out->print(<<'END_OF_STRING');
140 <refsect2 xml:id='options'><title>Options</title>
141 <para>The options are as follows:</para>
142 <variablelist remap='TP'>
144 <term><emphasis role='strong' remap='B'>-a</emphasis></term>
152 <para>Choose from all lists of maxims, both offensive and not. (See the
153 <emphasis role='strong' remap='B'>-o</emphasis>
154 option for more information on offensive fortunes.)</para>
157 <para>Choose from all lists of maxims.</para>
161 $out->print(<<'END_OF_STRING');
165 <term><emphasis role='strong' remap='B'>-c</emphasis></term>
167 <para>Show the cookie file from which the fortune came.</para>
171 <term><emphasis role='strong' remap='B'>-e</emphasis></term>
173 <para>Consider all fortune files to be of equal size (see discussion below
174 on multiple files).</para>
178 <term><emphasis role='strong' remap='B'>-f</emphasis></term>
180 <para>Print out the list of files which would be searched, but don't
181 print a fortune.</para>
185 <term><emphasis role='strong' remap='B'>-l</emphasis></term>
187 <para>Long dictums only. See
188 <emphasis role='strong' remap='B'>-n</emphasis>
189 on how “long” is defined in this sense.</para>
193 <term><emphasis role='strong' remap='B'>-m </emphasis><emphasis remap='I'>pattern</emphasis></term>
195 <para>Print out all fortunes which match the basic regular expression
196 <emphasis remap='I'>pattern</emphasis>.
197 The syntax of these expressions depends on how your system defines
198 <citerefentry><refentrytitle>re_comp</refentrytitle><manvolnum>3</manvolnum></citerefentry> or <citerefentry><refentrytitle>regcomp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
199 but it should nevertheless be similar to the syntax used in
200 <citerefentry><refentrytitle>grep</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
202 <blockquote remap='RS'>
203 <para>The fortunes are output to standard output, while the names of the file
204 from which each fortune comes are printed to standard error. Either or
205 both can be redirected; if standard output is redirected to a file, the
206 result is a valid fortunes database file. If standard error is
207 <emphasis remap='I'>also</emphasis>
208 redirected to this file, the result is
209 <emphasis remap='I'>still valid</emphasis>,
210 <emphasis role='strong' remap='B'>but there will be “bogus”</emphasis>
211 <emphasis role='strong' remap='B'>fortunes</emphasis>,
212 i.e. the filenames themselves, in parentheses. This can be useful if you
213 wish to remove the gathered matches from their original files, since each
214 filename-record will precede the records from the file it names.
215 </para></blockquote> <!-- remap='RE' -->
219 <term><emphasis role='strong' remap='B'>-n </emphasis><emphasis remap='I'>length</emphasis></term>
221 <para>Set the longest fortune length (in characters) considered to be
222 “short” (the default is 160). All fortunes longer than this are
223 considered “long”. Be careful! If you set the length too short and
224 ask for short fortunes, or too long and ask for long ones, fortune goes
225 into a never-ending thrash loop.</para>
232 $out->print(<<'END_OF_STRING');
234 <para><emphasis role='strong' remap='B'>-o</emphasis>
235 Choose only from potentially offensive aphorisms. The -o option is
236 ignored if a fortune directory is specified.</para>
238 <para><emphasis role='strong' remap='B'>Please, please, please request a potentially</emphasis>
239 <emphasis role='strong' remap='B'>offensive fortune if and only if</emphasis>
240 <emphasis role='strong' remap='B'>you believe, deep in your heart,</emphasis>
241 <emphasis role='strong' remap='B'>that you are willing to be</emphasis>
242 <emphasis role='strong' remap='B'>offended. (And that you'll just quit</emphasis>
243 <emphasis role='strong' remap='B'>using</emphasis> -o <emphasis role='strong' remap='B'>rather</emphasis>
244 <emphasis role='strong' remap='B'>than give us grief about it,</emphasis>
245 <emphasis role='strong' remap='B'>okay?)</emphasis></para>
247 <blockquote remap='RS'>
248 <para>... let us keep in mind the basic governing philosophy of The
249 Brotherhood, as handsomely summarized in these words: we believe in
250 healthy, hearty laughter -- at the expense of the whole human race, if
251 needs be. Needs be.</para>
252 <blockquote remap='RS'>
253 <para>--H. Allen Smith, "Rude Jokes"
254 </para></blockquote> <!-- remap='RE' -->
255 </blockquote> <!-- remap='RE' -->
260 $out->print(<<'END_OF_STRING');
261 <para><emphasis role='strong' remap='B'>-s</emphasis>
262 Short apothegms only. See
263 <emphasis role='strong' remap='B'>-n</emphasis>
264 on which fortunes are considered “short”.</para>
268 <term><emphasis role='strong' remap='B'>-i</emphasis></term>
270 <para>Ignore case for
276 <term><emphasis role='strong' remap='B'>-w</emphasis></term>
278 <para>Wait before termination for an amount of time calculated from the
279 number of characters in the message. This is useful if it is executed
280 as part of the logout procedure to guarantee that the message can be
281 read before the screen is cleared.</para>
286 <para>The user may specify alternate sayings. You can specify a specific
287 file, a directory which contains one or more files, or the special word
288 <emphasis remap='I'>all</emphasis>
289 which says to use all the standard databases. Any of these may be
290 preceded by a percentage, which is a number
291 <emphasis remap='I'>n</emphasis>
292 between 0 and 100 inclusive, followed by a
293 <emphasis remap='I'>%</emphasis>.
294 If it is, there will be a
295 <emphasis remap='I'>n</emphasis>
296 percent probability that an adage will be picked from that file or
297 directory. If the percentages do not sum to 100, and there are
298 specifications without percentages, the remaining percent will apply
299 to those files and/or directories, in which case the probability of
300 selecting from one of them will be based on their relative sizes.</para>
302 <para>As an example, given two databases
303 <emphasis remap='I'>funny</emphasis> and <emphasis remap='I'>not-funny</emphasis>, with <emphasis remap='I'>funny</emphasis>
304 twice as big (in number of fortunes, not raw file size), saying</para>
305 <blockquote remap='RS'>
307 <para><emphasis role='strong' remap='B'>fortune</emphasis>
308 <emphasis remap='I'>funny not-funny</emphasis>
310 </para></blockquote> <!-- remap='RE' -->
311 <para>will get you fortunes out of
312 <emphasis remap='I'>funny</emphasis>
313 two-thirds of the time. The command</para>
314 <blockquote remap='RS'>
316 <para><emphasis role='strong' remap='B'>fortune</emphasis>
317 90% <emphasis remap='I'>funny</emphasis> 10% <emphasis remap='I'>not-funny</emphasis>
319 </para></blockquote> <!-- remap='RE' -->
320 <para>will pick out 90% of its fortunes from
321 <emphasis remap='I'>funny</emphasis>
322 (the “10% not-funny” is unnecessary, since 10% is all that's left).</para>
325 <emphasis role='strong' remap='B'>-e</emphasis>
326 option says to consider all files equal; thus</para>
327 <blockquote remap='RS'>
329 <para><emphasis role='strong' remap='B'>fortune -e</emphasis>
330 <emphasis remap='I'>funny not-funny</emphasis>
332 </para></blockquote> <!-- remap='RE' -->
333 <para>is equivalent to</para>
334 <blockquote remap='RS'>
336 <para><emphasis role='strong' remap='B'>fortune</emphasis>
337 50% <emphasis remap='I'>funny</emphasis> 50% <emphasis remap='I'>not-funny</emphasis>
339 </para></blockquote> <!-- remap='RE' -->
344 $out->print(<<'END_OF_STRING');
347 <para>This fortune also supports the BSD method of appending “-o” to
348 database names to specify offensive fortunes. However this is
349 <emphasis role='strong' remap='B'>not</emphasis>
350 how fortune stores them: offensive fortunes are stored in a separate
351 directory without the “-o” infix. A plain name (i.e., not a path to a
352 file or directory) that ends in “-o” will be assumed to be an
353 offensive database, and will have its suffix stripped off and be
354 searched in the offensive directory (even if the neither of the
355 <option>-a</option> or <option>-o</option>
356 options were specified). This feature is not only for
357 backwards-compatibility, but also to allow users to distinguish between
358 inoffensive and offensive databases of the same name.</para>
360 <para>For example, assuming there is a database named
361 <emphasis remap='I'>definitions</emphasis>
362 in both the inoffensive and potentially offensive collections, then the
363 following command will select an inoffensive definition 90% of the time,
364 and a potentially offensive definition for the remaining 10%:</para>
365 <blockquote remap='RS'>
367 <para><emphasis role='strong' remap='B'>fortune</emphasis>
369 <emphasis remap='I'>definitions definitions-o</emphasis>
370 </para></blockquote> <!-- remap='RE' -->
375 $out->print(<<"END_OF_STRING");
380 <refsect1 xml:id='files'><title>FILES</title>
381 <para>Note: these are the defaults as defined at compile time.</para>
385 <para><emphasis remap='I'>${cookiedir}</emphasis>
386 Directory for innoffensive fortunes.</para>
392 $out->print(<<"EOF");
394 <para><emphasis remap='I'>${ocookiedir}</emphasis>
395 Directory for offensive fortunes.</para>
399 $out->print(<<'END_OF_STRING');
402 <para>If a particular set of fortunes is particularly unwanted, there is an
403 easy solution: delete the associated
404 <markup>.dat</markup>
405 file. This leaves the data intact, should the file later be wanted, but
407 <emphasis role='strong' remap='B'>fortune</emphasis>
408 no longer finds the pointers file, it ignores the text file.</para>
411 <refsect1 xml:id='bugs'><title>BUGS</title>
416 $out->print(<<'END_OF_STRING');
417 <para>The division of fortunes into offensive and non-offensive by directory,
418 rather than via the `-o' file infix, is not 100% compatible with
419 original BSD fortune. Although the `-o' infix is recognised as referring
420 to an offensive database, the offensive database files still need to be
421 in a separate directory. The workaround, of course, is to move the `-o'
422 files into the offensive directory (with or without renaming), and to
424 <emphasis role='strong' remap='B'>-a</emphasis>
430 $out->print(<<'END_OF_STRING');
431 <para>The supplied fortune databases have been attacked, in order to correct
432 orthographical and grammatical errors, and particularly to reduce
433 redundancy and repetition and redundancy. But especially to avoid
434 repetitiousness. This has not been a complete success. In the process,
435 some fortunes may also have been lost.</para>
437 <para>The fortune databases are now divided into a larger number of smaller
438 files, some organized by format (poetry, definitions), and some by
444 content (religion, politics). There are parallel files in the main
445 directory and in the offensive files directory (e.g., fortunes/definitions and
446 fortunes/off/definitions). Not all the potentially offensive fortunes are in
447 the offensive fortunes files, nor are all the fortunes in the offensive
448 files potentially offensive, probably, though a strong attempt has been
449 made to achieve greater consistency. Also, a better division might be
453 content (religion, politics).
457 $out->print(<<'END_OF_STRING');
463 <refsect1 xml:id='history'><title>HISTORY</title>
464 <para>This version of fortune is based on the NetBSD fortune 1.4, but with a
465 number of bug fixes and enhancements.</para>
467 <para>The original fortune/strfile format used a single file; strfile read the
468 text file and converted it to null-delimited strings, which were stored
469 after the table of pointers in the .dat file. By NetBSD fortune 1.4,
470 this had changed to two separate files: the .dat file was only the header
471 (the table of pointers, plus flags; see
472 <emphasis remap='I'>strfile.h</emphasis>),
473 and the text strings were left in their own file. The potential problem
474 with this is that text file and header file may get out of synch, but the
475 advantage is that the text files can be easily edited without resorting
476 to unstr, and there is a potential savings in disk space (on the
477 assumption that the sysadmin kept both .dat file with strings and the
480 <para>Many of the enhancements made over the NetBSD version assumed a Linux
481 system, and thus caused it to fail under other platforms, including BSD.
482 The source code has since been made more generic, and currently works on
483 SunOS 4.x as well as Linux, with support for more platforms expected in
484 the future. Note that some bugs were inadvertently discovered and fixed
485 during this process.</para>
487 <para>At a guess, a great many people have worked on this program, many without
488 leaving attributions.</para>
491 <refsect1 xml:id='see_also'><title>SEE ALSO</title>
492 <para><citerefentry><refentrytitle>re_comp</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>regcomp</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>strfile</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
493 <citerefentry><refentrytitle>unstr</refentrytitle><manvolnum>1</manvolnum></citerefentry></para>