xref: /original-bsd/usr.bin/xstr/xstr.1 (revision edc2ab72)
1.\" Copyright (c) 1980, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)xstr.1	8.1 (Berkeley) 06/09/93
7.\"
8.Dd
9.Dt XSTR 1
10.Os BSD 3
11.Sh NAME
12.Nm xstr
13.Nd "extract strings from C programs to implement shared strings"
14.Sh SYNOPSIS
15.Nm xstr
16.Op Fl c
17.Op Fl
18.Op Ar file
19.Sh DESCRIPTION
20.Nm Xstr
21maintains a file
22.Pa strings
23into which strings in component parts of a large program are hashed.
24These strings are replaced with references to this common area.
25This serves to implement shared constant strings, most useful if they
26are also read-only.
27.Pp
28Available options:
29.Bl -tag -width Ds
30.It Fl
31.Nm Xstr
32reads from the standard input.
33.It Fl c
34.Nm Xstr
35will extract the strings from the C source
36.Ar file
37or the standard input
38.Pq Fl ,
39replacing
40string references by expressions of the form (&xstr[number])
41for some number.
42An appropriate declaration of
43.Nm xstr
44is prepended to the file.
45The resulting C text is placed in the file
46.Pa x.c ,
47to then be compiled.
48The strings from this file are placed in the
49.Pa strings
50data base if they are not there already.
51Repeated strings and strings which are suffices of existing strings
52do not cause changes to the data base.
53.El
54.Pp
55After all components of a large program have been compiled a file
56.Pa xs.c
57declaring the common
58.Nm xstr
59space can be created by a command of the form
60.Bd -literal -offset indent
61xstr
62.Ed
63.Pp
64The file
65.Pa xs.c
66should then be compiled and loaded with the rest
67of the program.
68If possible, the array can be made read-only (shared) saving
69space and swap overhead.
70.Pp
71.Nm Xstr
72can also be used on a single file.
73A command
74.Bd -literal -offset indent
75xstr name
76.Ed
77.Pp
78creates files
79.Pa x.c
80and
81.Pa xs.c
82as before, without using or affecting any
83.Pa strings
84file in the same directory.
85.Pp
86It may be useful to run
87.Nm xstr
88after the C preprocessor if any macro definitions yield strings
89or if there is conditional code which contains strings
90which may not, in fact, be needed.
91An appropriate command sequence for running
92.Nm xstr
93after the C preprocessor is:
94.Pp
95.Bd -literal -offset indent -compact
96cc \-E name.c | xstr \-c \-
97cc \-c x.c
98mv x.o name.o
99.Ed
100.Pp
101.Nm Xstr
102does not touch the file
103.Pa strings
104unless new items are added, thus
105.Xr make 1
106can avoid remaking
107.Pa xs.o
108unless truly necessary.
109.Sh FILES
110.Bl -tag -width /tmp/xsxx* -compact
111.It Pa strings
112Data base of strings
113.It Pa x.c
114Massaged C source
115.It Pa xs.c
116C source for definition of array `xstr'
117.It Pa /tmp/xs*
118Temp file when `xstr name' doesn't touch
119.Pa strings
120.El
121.Sh SEE ALSO
122.Xr mkstr 1
123.Sh BUGS
124If a string is a suffix of another string in the data base,
125but the shorter string is seen first by
126.Nm xstr
127both strings will be placed in the data base, when just
128placing the longer one there will do.
129.Sh HISTORY
130The
131.Nm
132command appeared in
133.Bx 3.0 .
134