Yet Another Fortune Program 0.6 02 Jul 2000 Donald King ============================================ This software is Copyright (C) 2000 by Donald L. King. However, it may be distributed and modified freely, provided that my name remains attached to any programs or products derived from it. The following files are included with the program: README This file Makefile Simple makefile to install YAFP autostr Automates running strfile fortune Displays random fortunes strfile Generates indexes for fortune databases unstr Re-generates fortune databases in different orders YAFP is a Perl-coded replacement for the fortune(6) command from the BSD Games collection. It supports most of the options from the original fortune; see the to-do list below for details. I wrote this program after I noticed a few glaring bugs in the original -- specifically, using -m to search offensive fortunes doesn't work unless you ROT13 your search regex. There are also a number of bugs in the standard strfile(8): -o doesn't sort, it just sets STR_ORDERED; -r doesn't randomize, it just sets STR_RANDOM; the str_shortlen field is always (unsigned long)-1L; and others. Plus, unstr(8) doesn't even exist on my system, so I had to write my own. Please note that this release uses a strfile index format which is completely incompatible with BSD fortune. This is because the original format simply wasn't thought through properly. If the index is in any order other than that of the source data, it becomes impossible to calculate the length of any arbitrary entry without actually opening the data file, seeking, and reading until a delimiter is encountered. Since fortune needs to know lengths to implement the -s and -l options, standard BSD fortune breaks on a correct but sorted index file. A redesign of the index format resulted in a bulkier but more robust structure. Installation ------------ root@host:~# tar xzf yafp-0.1.tar.gz root@host:~# cd yafp-0.1 root@host:~/yafp-0.1# make install The install code will install the programs in the standard locations under ${PREFIX} ("/usr/local" is the default). Fortunes go under the $(PREFIX)/share/fortune directory, where a sample "get more fortunes" fortune is installed. You can get real fortunes from metalab.unc.edu. File Formats ------------ The fortune files are in approximately the same format as BSD; however, the YAFP format is more rigidly defined. First, a delimiter is a '%' (or other character, see strfile(1)) on a line by itself with no whitespace, and a fortune is one or more non-delimiter lines followed by a delimiter. Thus, a fortune file consists of fortune[0], delimiter, ..., fortune[n], delimiter. A fortune file MUST NOT begin with a delimiter, MUST NOT contain two consecutive delimiters, and MUST end with a delimiter. This is much stricter than the standard fortune(6) seems to accept, but IMO it makes more sense. [Note: actually, there *was* a valid reason for rejecting such files in both BSD fortune and YAFP 0.5, since fortune depended on reading bytes until the next delimiter was encountered. With the index redesign, these requirements are relaxed, although they still produce warnings. In the near future, these warnings will go away.] The index files generated by strfile(1) are in a new, from-scratch format which is more robust than the BSD format. All numbers are in big-endian (network) order. The file begins with a header of the following form: #define MAGIC 0xE072976B /* Random magic number */ #define VERSION 0x0002 /* Format revision */ #define STR_RANDOM 0x0001 /* Entries are in random order */ #define STR_ORDERED 0x0002 /* Entries are in sorted order */ #define STR_ROTATED 0x0004 /* Text is ROT13-coded */ struct strfile_header { uint32 str_magic; /* Always MAGIC */ uint32 str_version; /* Always VERSION */ uint32 str_count; /* Number of offsets in this file */ uint32 str_longlen; /* Length of longest entry */ uint32 str_shortlen; /* Length of shortest entry */ uint32 str_flags; /* Bitvector of STR_* */ }; Immediately following the header come entries, each consisting of a 32-bit offset and a 32-bit length. Bugs, Caveats, and To-Do's -------------------------- * Specifying a percentage weight, as in "fortune 90% funny 10% not-funny", does not work yet. * The index files created by strfile and used by fortune and unstr are NOT compatible with either YAFP 0.5 or BSD fortune.