]> granicus.if.org Git - fortune-mod/blob - fortune-mod/fortune/gen-fortune-docbook-page.pl
gh actions #3: win32 fix pacman
[fortune-mod] / fortune-mod / fortune / gen-fortune-docbook-page.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use autodie;
6 use utf8;
7
8 use File::Basename qw / dirname /;
9 use File::Path qw / mkpath /;
10 use Getopt::Long qw/ GetOptions /;
11
12 my $output_fn;
13 my $cookiedir;
14 my $ocookiedir;
15 my $no_offensive = 0;
16 GetOptions(
17     '--cookiedir=s'        => \$cookiedir,
18     '--ocookiedir=s'       => \$ocookiedir,
19     '--without-offensive!' => \$no_offensive,
20     '--output=s'           => \$output_fn,
21 ) or die "Wrong options - $!";
22
23 if ( !defined($output_fn) )
24 {
25     die "Please specify --output";
26 }
27
28 if ( !defined($cookiedir) )
29 {
30     die "Please specify cookiedir";
31 }
32
33 my $OFF = ( !$no_offensive );
34
35 if ( $OFF and !defined($ocookiedir) )
36 {
37     die "Please specify ocookiedir";
38 }
39
40 my $dirname = dirname($output_fn);
41 if ( $dirname and ( !-e $dirname ) )
42 {
43     mkpath($dirname);
44 }
45
46 # The :raw is to prevent CRs on Win32/etc.
47 open my $out, '>:raw:encoding(utf-8)', $output_fn;
48
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 $ -->
54
55 <!-- Copyright (c) 1985, 1991, 1993
56 The Regents of the University of California.  All rights reserved. -->
57
58 <!-- This code is derived from software contributed to Berkeley by
59 Ken Arnold. -->
60
61 <!-- Redistribution and use in source and binary forms, with or without
62 modification, are permitted provided that the following conditions
63 are met:
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. -->
76
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
87 SUCH DAMAGE. -->
88
89 <!-- @(#)fortune.6      8.3 (Berkeley) 4/19/94 -->
90
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. -->
94
95 <!-- Changes Copyright (c) 1997 Dennis L. Clark.  All rights reserved. -->
96
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. -->
100
101 <refentryinfo><date>19 April 94 [May. 97]</date></refentryinfo>
102 <refmeta>
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>
108 </refmeta>
109 <refnamediv>
110 <refname>fortune</refname>
111 <refpurpose>print a random, hopefully interesting, adage</refpurpose>
112 </refnamediv>
113 <!-- body begins here -->
114 <refsynopsisdiv xml:id='synopsis'>
115 <cmdsynopsis>
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>
120 </cmdsynopsis>
121 </refsynopsisdiv>
122
123
124 <refsect1 xml:id='description'><title>DESCRIPTION</title>
125 <para>When
126 <emphasis role='strong' remap='B'>fortune</emphasis>
127 is run with no arguments it prints out a random epigram. Epigrams are
128 END_OF_STRING
129
130 $out->print(
131     $OFF
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."
135 );
136
137 $out->print(<<'END_OF_STRING');
138 </para>
139
140 <refsect2 xml:id='options'><title>Options</title>
141 <para>The options are as follows:</para>
142 <variablelist remap='TP'>
143   <varlistentry>
144   <term><emphasis role='strong' remap='B'>-a</emphasis></term>
145   <listitem>
146
147 END_OF_STRING
148
149 $out->print(
150     $OFF
151     ? <<'EOF'
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>
155 EOF
156     : <<'EOF'
157 <para>Choose from all lists of maxims.</para>
158 EOF
159 );
160
161 $out->print(<<'END_OF_STRING');
162   </listitem>
163   </varlistentry>
164   <varlistentry>
165   <term><emphasis role='strong' remap='B'>-c</emphasis></term>
166   <listitem>
167 <para>Show the cookie file from which the fortune came.</para>
168   </listitem>
169   </varlistentry>
170   <varlistentry>
171   <term><emphasis role='strong' remap='B'>-e</emphasis></term>
172   <listitem>
173 <para>Consider all fortune files to be of equal size (see discussion below
174 on multiple files).</para>
175   </listitem>
176   </varlistentry>
177   <varlistentry>
178   <term><emphasis role='strong' remap='B'>-f</emphasis></term>
179   <listitem>
180 <para>Print out the list of files which would be searched, but don't
181 print a fortune.</para>
182   </listitem>
183   </varlistentry>
184   <varlistentry>
185   <term><emphasis role='strong' remap='B'>-l</emphasis></term>
186   <listitem>
187 <para>Long dictums only.  See
188 <emphasis role='strong' remap='B'>-n</emphasis>
189 on how “long” is defined in this sense.</para>
190   </listitem>
191   </varlistentry>
192   <varlistentry>
193   <term><emphasis role='strong' remap='B'>-m </emphasis><emphasis remap='I'>pattern</emphasis></term>
194   <listitem>
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>
201
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' -->
216   </listitem>
217   </varlistentry>
218   <varlistentry>
219   <term><emphasis role='strong' remap='B'>-n </emphasis><emphasis remap='I'>length</emphasis></term>
220   <listitem>
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>
226
227
228 END_OF_STRING
229
230 if ($OFF)
231 {
232     $out->print(<<'END_OF_STRING');
233
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>
237
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>
246
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' -->
256
257 END_OF_STRING
258 }
259
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>
265   </listitem>
266   </varlistentry>
267   <varlistentry>
268   <term><emphasis role='strong' remap='B'>-i</emphasis></term>
269   <listitem>
270 <para>Ignore case for
271 <option>-m</option>
272 patterns.</para>
273   </listitem>
274   </varlistentry>
275   <varlistentry>
276   <term><emphasis role='strong' remap='B'>-w</emphasis></term>
277   <listitem>
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>
282   </listitem>
283   </varlistentry>
284 </variablelist>
285
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>
301
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'>
306
307 <para><emphasis role='strong' remap='B'>fortune</emphasis>
308 <emphasis remap='I'>funny not-funny</emphasis>
309
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'>
315
316 <para><emphasis role='strong' remap='B'>fortune</emphasis>
317 90% <emphasis remap='I'>funny</emphasis> 10% <emphasis remap='I'>not-funny</emphasis>
318
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>
323
324 <para>The
325 <emphasis role='strong' remap='B'>-e</emphasis>
326 option says to consider all files equal; thus</para>
327   <blockquote remap='RS'>
328
329 <para><emphasis role='strong' remap='B'>fortune -e</emphasis>
330 <emphasis remap='I'>funny not-funny</emphasis>
331
332   </para></blockquote> <!-- remap='RE' -->
333 <para>is equivalent to</para>
334   <blockquote remap='RS'>
335
336 <para><emphasis role='strong' remap='B'>fortune</emphasis>
337 50% <emphasis remap='I'>funny</emphasis> 50% <emphasis remap='I'>not-funny</emphasis>
338
339   </para></blockquote> <!-- remap='RE' -->
340 END_OF_STRING
341
342 if ($OFF)
343 {
344     $out->print(<<'END_OF_STRING');
345
346
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>
359
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'>
366
367 <para><emphasis role='strong' remap='B'>fortune</emphasis>
368 90%
369 <emphasis remap='I'>definitions definitions-o</emphasis>
370   </para></blockquote> <!-- remap='RE' -->
371
372 END_OF_STRING
373 }
374
375 $out->print(<<"END_OF_STRING");
376
377 </refsect2>
378 </refsect1>
379
380 <refsect1 xml:id='files'><title>FILES</title>
381 <para>Note: these are the defaults as defined at compile time.</para>
382
383 <!-- PD 0 -->
384
385 <para><emphasis remap='I'>${cookiedir}</emphasis>
386 Directory for innoffensive fortunes.</para>
387
388 END_OF_STRING
389
390 if ($OFF)
391 {
392     $out->print(<<"EOF");
393
394 <para><emphasis remap='I'>${ocookiedir}</emphasis>
395 Directory for offensive fortunes.</para>
396 EOF
397 }
398
399 $out->print(<<'END_OF_STRING');
400 <!-- PD -->
401
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
406 since
407 <emphasis role='strong' remap='B'>fortune</emphasis>
408 no longer finds the pointers file, it ignores the text file.</para>
409 </refsect1>
410
411 <refsect1 xml:id='bugs'><title>BUGS</title>
412 END_OF_STRING
413
414 if ($OFF)
415 {
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
423 use the
424 <emphasis role='strong' remap='B'>-a</emphasis>
425 option.</para>
426
427 END_OF_STRING
428 }
429
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>
436
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
439 END_OF_STRING
440
441 $out->print(
442     $OFF
443     ? <<'EOF'
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
450 made.
451 EOF
452     : <<'EOF'
453 content (religion, politics).
454 EOF
455 );
456
457 $out->print(<<'END_OF_STRING');
458
459 </para>
460
461 </refsect1>
462
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>
466
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
478 text file).</para>
479
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>
486
487 <para>At a guess, a great many people have worked on this program, many without
488 leaving attributions.</para>
489 </refsect1>
490
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>
494 </refsect1>
495 </refentry>
496
497 END_OF_STRING
498
499 close($out);