xref: /freebsd/usr.bin/fortune/strfile/strfile.8 (revision 1da7f3f6f72b2245e458fc7195733268ae4a1136)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" Ken Arnold.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd February 17, 2005
33.Dt STRFILE 8
34.Os
35.Sh NAME
36.Nm strfile ,
37.Nm unstr
38.Nd "create a random access file for storing strings"
39.Sh SYNOPSIS
40.Nm
41.Op Fl Ciorsx
42.Op Fl c Ar char
43.Ar source_file
44.Op Ar output_file
45.Nm unstr
46.Ar source_file
47.Sh DESCRIPTION
48The
49.Nm
50utility
51reads a file containing groups of lines separated by a line containing
52a single percent
53.Ql %
54sign and creates a data file which contains
55a header structure and a table of file offsets for each group of lines.
56This allows random access of the strings.
57.Pp
58The output file, if not specified on the command line, is named
59.Ar source_file Ns Pa .dat .
60.Pp
61The options are as follows:
62.Bl -tag -width ".Fl c Ar char"
63.It Fl C
64Flag the file as containing comments.
65This option cases the
66.Dv STR_COMMENTS
67bit in the header
68.Va str_flags
69field to be set.
70Comments are designated by two delimiter characters at the
71beginning of the line, though
72.Nm
73does not give any special
74treatment to comment lines.
75.It Fl c Ar char
76Change the delimiting character from the percent sign to
77.Ar char .
78.It Fl i
79Ignore case when ordering the strings.
80.It Fl o
81Order the strings in alphabetical order.
82The offset table will be sorted in the alphabetical order of the
83groups of lines referenced.
84Any initial non-alphanumeric characters are ignored.
85This option causes the
86.Dv STR_ORDERED
87bit in the header
88.Va str_flags
89field to be set.
90.It Fl r
91Randomize access to the strings.
92Entries in the offset table will be randomly ordered.
93This option causes the
94.Dv STR_RANDOM
95bit in the header
96.Va str_flags
97field to be set.
98.It Fl s
99Run silently; do not give a summary message when finished.
100.It Fl x
101Note that each alphabetic character in the groups of lines is rotated
10213 positions in a simple caesar cypher.
103This option causes the
104.Dv STR_ROTATED
105bit in the header
106.Va str_flags
107field to be set.
108.El
109.Pp
110The format of the header is:
111.Bd -literal
112#define	VERSION	1
113uint32_t	str_version;	/* version number */
114uint32_t	str_numstr;	/* # of strings in the file */
115uint32_t	str_longlen;	/* length of longest string */
116uint32_t	str_shortlen;	/* length of shortest string */
117#define	STR_RANDOM	0x1	/* randomized pointers */
118#define	STR_ORDERED	0x2	/* ordered pointers */
119#define	STR_ROTATED	0x4	/* rot-13'd text */
120#define	STR_COMMENTS	0x8	/* embedded comments */
121uint32_t	str_flags;	/* bit field for flags */
122char		str_delim;	/* delimiting character */
123.Ed
124.Pp
125All fields are written in network byte order.
126.Pp
127The purpose of
128.Nm unstr
129is to undo the work of
130.Nm .
131It prints out the strings contained in the file
132.Ar source_file
133in the order that they are listed in
134the header file
135.Ar source_file Ns Pa .dat
136to standard output.
137It is possible to create sorted versions of input files by using
138.Fl o
139when
140.Nm
141is run and then using
142.Nm unstr
143to dump them out in the table order.
144.Sh FILES
145.Bl -tag -width ".Pa strfile.dat" -compact
146.It Pa strfile.dat
147default output file.
148.El
149.Sh SEE ALSO
150.Xr byteorder 3 ,
151.Xr fortune 6
152.Sh HISTORY
153The
154.Nm
155utility first appeared in
156.Bx 4.4 .
157