1STRFILE(1) UNIX System Manager's Manual STRFILE(1)
2
3
4
6 strfile - create a random access file for storing strings
7 unstr - dump strings in pointer order
8
10 strfile [-iorsx] [-c char] sourcefile [outputfile]
11 unstr [-c char] datafile[.ext] [outputfile]
12
14 strfile reads a file containing groups of lines separated by a line
15 containing a single percent `%' sign (or other specified delimiter
16 character) and creates a data file which contains a header structure
17 and a table of file offsets for each group of lines. This allows random
18 access of the strings.
19
20 The output file, if not specified on the command line, is named source‐
21 file.dat.
22
23 The purpose of unstr is to undo the work of strfile. It prints out the
24 strings contained in the sourcefile, which is datafile.ext without its
25 extension, or datafile if no extension is specified (in this case, the
26 extension .dat is added to the name of the datafile) in the order that
27 they are listed in the header file datafile. If no outputfile is spec‐
28 ified, it prints to standard output; otherwise it prints to the file
29 specified. unstr can also universally change the delimiter character
30 in a strings file. It is possible to create sorted versions of input
31 files by using strfile -o and then using unstr to dump them out in the
32 table order.
33
34 Options
35 The options are as follows:
36
37 -c char
38 Change the delimiting character from the percent sign to char.
39 This option is available for both strfile and unstr.
40
41 -i Ignore case when ordering the strings.
42
43 -o Order the strings in alphabetical order. The offset table will
44 be sorted in the alphabetical order of the groups of lines ref‐
45 erenced. Any initial non-alphanumeric characters are ignored.
46 This option causes the STR_ORDERED bit in the header str_flags
47 field to be set. (It also now really does sort! It didn't used
48 to).
49
50 -r Randomize access to the strings. Entries in the offset table
51 will be randomly ordered. This option causes the STR_RANDOM bit
52 in the header str_flags field to be set. (And really does ran‐
53 domize)
54
55 -s Run silently; don't give a summary message when finished.
56
57 -x Note that each alphabetic character in the groups of lines is
58 rotated 13 positions in a simple caesar cypher. This option
59 causes the STR_ROTATED bit in the header str_flags field to be
60 set. Note that it does not rotate the strings--that operation
61 must be performed separately.
62
63 Header
64 The format of the header is:
65
66 #define VERSION 1
67 unsigned long str_version; /* version number */
68 unsigned long str_numstr; /* # of strings in the file */
69 unsigned long str_longlen; /* length of longest string */
70 unsigned long str_shortlen; /* shortest string length */
71 #define STR_RANDOM 0x1 /* randomized pointers */
72 #define STR_ORDERED 0x2 /* ordered pointers */
73 #define STR_ROTATED 0x4 /* rot-13'd text */
74 unsigned long str_flags; /* bit field for flags */
75 char str_delim; /* delimiting character */
76
77 All fields are written in network byte order.
78
80 Fewer now, one hopes. However, fortunes (text strings) beginning with
81 a blank line appear to be sorted between random letters. This includes
82 ASCII art that contains no letters, and first lines that are solely
83 non-alphanumeric, apparently. I've no idea why this should be.
84
86 What can you do with this besides printing sarcastic and obscene mes‐
87 sages to the screens of lusers at login or logout?
88
89 There are some other possibilities. Source code for a sample program,
90 randstr, is included with this distribution: randstr splits the differ‐
91 ence between unstr and fortune. It reads a single, specified file, and
92 randomly selects a single text string.
93
94 1 Include strfile.h into a news reading/posting program, to gener‐
95 ate random signatures. Tin(1) does something similar, in a much
96 more complex manner.
97
98 2 Include it in a game. While strfile doesn't support 'fields' or
99 'records', there's no reason that the text strings can't be con‐
100 sistent: first line, a die roll; second line, a score; third and
101 subsequent lines, a text message.
102
103 3 Use it to store your address book. Hell, some of the guys I
104 know would be as well off using it to decide who to call on Fri‐
105 day nights (and for some, it wouldn't matter whether there were
106 phone numbers in it or not).
107
108 4 Use it in 'lottery' situations. If you're an ISP, write a
109 script to store login names and GECOS from /etc/passwd in str‐
110 file format, write another to send 'congratulations, you've won'
111 to the lucky login selected. The prize might be a month's free
112 service, or if you're AOL, a month free on a real service
113 provider.
114
116 byteorder(3), fortune(6)
117
119 The strfile utility first appeared in 4.4BSD. This version was heavily
120 modified, much of it in ways peculiar to Linux. Work has since been
121 done to make the code more generic, and has so far been tested to work
122 with SunOS 4.x. More platforms are expected to be supported as work
123 continues.
124
125
126
1274th Berkeley Distribution June 9, 1993 [Apr. '97] STRFILE(1)