xref: /freebsd/usr.bin/xstr/xstr.1 (revision 61e21613)
1.\" Copyright (c) 1980, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd December 30, 1993
29.Dt XSTR 1
30.Os
31.Sh NAME
32.Nm xstr
33.Nd "extract strings from C programs to implement shared strings"
34.Sh SYNOPSIS
35.Nm
36.Op Fl cv
37.Op Fl
38.Op Ar
39.Sh DESCRIPTION
40The
41.Nm
42utility maintains a file
43.Pa strings
44into which strings in component parts of a large program are hashed.
45These strings are replaced with references to this common area.
46This serves to implement shared constant strings, most useful if they
47are also read-only.
48.Pp
49The following options are available:
50.Bl -tag -width indent
51.It Fl
52Read from the standard input.
53.It Fl c
54Extract the strings from the C source
55.Ar file
56or the standard input
57.Pq Fl ,
58replacing
59string references by expressions of the form
60.Li (&xstr[number])
61for some
62.Ar number .
63An appropriate declaration of
64.Va xstr
65is prepended to the file.
66The resulting C text is placed in the file
67.Pa x.c ,
68to then be compiled.
69The strings from this file are placed in the
70.Pa strings
71data base if they are not there already.
72Repeated strings and strings which are suffixes of existing strings
73do not cause changes to the data base.
74.It Fl v
75Verbose mode.
76.El
77.Pp
78After all components of a large program have been compiled a file
79.Pa xs.c
80declaring the common
81.Va xstr
82space can be created by a command of the form
83.Pp
84.Dl xstr
85.Pp
86The file
87.Pa xs.c
88should then be compiled and loaded with the rest
89of the program.
90If possible, the array can be made read-only (shared) saving
91space and swap overhead.
92.Pp
93The
94.Nm
95utility can also be used on a single file.
96A command
97.Bd -literal -offset indent
98xstr name
99.Ed
100.Pp
101creates files
102.Pa x.c
103and
104.Pa xs.c
105as before, without using or affecting any
106.Pa strings
107file in the same directory.
108.Pp
109It may be useful to run
110.Nm
111after the C preprocessor if any macro definitions yield strings
112or if there is conditional code which contains strings
113which may not, in fact, be needed.
114An appropriate command sequence for running
115.Nm
116after the C preprocessor is:
117.Pp
118.Bd -literal -offset indent -compact
119cc -E name.c | xstr -c -
120cc -c x.c
121mv x.o name.o
122.Ed
123.Pp
124The
125.Nm
126utility does not touch the file
127.Pa strings
128unless new items are added, thus
129.Xr make 1
130can avoid remaking
131.Pa xs.o
132unless truly necessary.
133.Sh FILES
134.Bl -tag -width ".Pa /tmp/xs*" -compact
135.It Pa strings
136data base of strings
137.It Pa x.c
138massaged C source
139.It Pa xs.c
140C source for definition of array
141.Va xstr
142.It Pa /tmp/xs*
143temporary file when
144.Dq Li "xstr name"
145does not touch
146.Pa strings
147.El
148.Sh SEE ALSO
149.Xr mkstr 1
150.Sh HISTORY
151The
152.Nm
153command appeared in
154.Bx 3.0 .
155.Sh BUGS
156If a string is a suffix of another string in the data base,
157but the shorter string is seen first by
158.Nm
159both strings will be placed in the data base, when just
160placing the longer one there will do.
161