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