Fortune data files format

Diomidis Spinellis diomidis at ecrcvax.UUCP
Tue Jun 6 19:32:33 AEST 1989


In article <19854 at adm.BRL.MIL> 91erm at bigbird.cc.williams.edu writes:
>[...]
>Does anyone have a good description of the format used by
>fortune data files ?  I haven't source access, so I can't
>just go look, but I'd like to be able to add/delete my own messages
>which should be doable once I know the file format.

The complete fortune program was mailed in comp.sources.games about two
years ago.  It was an improved version over the one distributed with 4.3
BSD and included more fortunes and documentation for the commands used
to build the fortune database.  For some reason it does not seem to be
included in the freely distributed files of the 4.3 BSD Tahoe release.

The fortune database can exist in two forms:  The strfile(5)* form
consists of a list of fortunes separated by lines starting with %%.
Furthermore different classes of strings are divided by %-.  This is
used to divide the ``scene'' from the obscene fortunes if your system
supports them.

A program called strfile(8)* takes the original file and creates a file
containing a header describing the lengths of the strings, a list of
offsets and some flags, followed by the list of null character
separated strings.  This is the file that appears as fortunes.dat.  A 
program that reverses this transformation, called unstr(8)*, also exists.

(*) Manual pages for strfile(5) strfile(8) and unstr(8) appeared in the
comp.sources.games release of fortune, but I have not seen them on any
other system.

The simplest way I can think of, to add a fortune would be to:
- Get strfile and unstr from your friendly comp.sources.games archive.
- unstr fortunes (this reads fortunes.dat and produces fortunes)
- Edit fortunes.   Put a non-obscene fortune before the %- delimiter,
  an obscene one after it.
- strfile -r fortunes

Alternatively you could try to write your own program to add fortunes
to the file or use an editor that can edit non-text files.  The
functional description of the current fortune header is as follows
(note that this is not the same as the general description of the file
produced by strfile and that I have only verified it on a 4.3 BSD system):

struct fortune_header {
    long file_end;	/* Offset to the end of the file */
    unsigned longest;	/* The length of the longest fortune */
    unsigned shortest;	/* The length of the shortest fortune */
    long scenes_end;	/* Offset to the end of the non-obscene fortunes */ 
    long curr_scene;	/* Offset to the last non-obscene fortune printed */
    long cur_obscene;	/* Offset to the last obscene fortune printed */ 
    int flags;		/* flags & 1 means randomized flags & 2 means sorted */ 
};

Following the header are the fortunes, each terminated with a 0 byte.  In 
the 4.3 BSD implementation first come the non-obscene fortunes, followed 
by the obscene.

-- 
Diomidis Spinellis                   European Computer-Industry Research Centre
Arabellastrasse 17, D-8000 Muenchen 81, West Germany          +49 (89) 92699199
USA: diomidis%ecrcvax.uucp at pyramid.pyramid.com     ...!pyramid!ecrcvax!diomidis
Europe: diomidis at ecrcvax.uucp                        ...!unido!ecrcvax!diomidis



More information about the Comp.unix.questions mailing list