Move everything from /var/adm to /var/log
[unleashed.git] / share / man / man1 / xstr.1
blobc81584bc94b850b23ce046ec7d4ff84c05619d42
1 '\" te
2 .\" Copyright (c) 1992, Sun Microsystems, Inc.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH XSTR 1 "Sep 14, 1992"
7 .SH NAME
8 xstr \- extract strings from C programs to implement shared strings
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBxstr\fR \fB-c\fR \fIfilename\fR [\fB-v\fR] [\fB-l\fR \fIarray\fR]
13 .fi
15 .LP
16 .nf
17 \fBxstr\fR [\fB-l\fR \fIarray\fR]
18 .fi
20 .LP
21 .nf
22 \fBxstr\fR \fIfilename\fR [\fB-v\fR] [\fB-l\fR \fIarray\fR]
23 .fi
25 .SH DESCRIPTION
26 .sp
27 .LP
28 \fBxstr\fR maintains a file called \fBstrings\fR into which strings in
29 component parts of a large program are hashed. These strings are replaced with
30 references to this common area. This serves to implement shared constant
31 strings, which are most useful if they are also read-only.
32 .sp
33 .LP
34 The command:
35 .sp
36 .in +2
37 .nf
38 \fBexample% xstr \(mic \fR\fIfilename\fR
39 .fi
40 .in -2
41 .sp
43 .sp
44 .LP
45 extracts the strings from the C source in name, replacing string references by
46 expressions of the form \fB&xstr[\fR\fInumber\fR\fB]\fR for some number. An
47 appropriate declaration of \fBxstr\fR is prepended to the file.  The resulting
48 C text is placed in the file \fBx.c\fR, to then be compiled.  The strings from
49 this file are placed in the \fBstrings\fR data base if they are not there
50 already. Repeated strings and strings which are suffixes of existing strings do
51 not cause changes to the data base.
52 .sp
53 .LP
54 After all components of a large program have been compiled, a file declaring
55 the common \fBxstr\fR space called \fBxs.c\fR can be created by a command of
56 the form:
57 .sp
58 .in +2
59 .nf
60 \fBexample%\fR \fBxstr\fR
61 .fi
62 .in -2
63 .sp
65 .sp
66 .LP
67 This \fBxs.c\fR file should then be compiled and loaded with the rest of the
68 program.  If possible, the array can be made read-only (shared) saving space
69 and swap overhead.
70 .sp
71 .LP
72 \fBxstr\fR can also be used on a single file.  A command:
73 .sp
74 .LP
75 \fBexample% xstr \fR\fIfilename\fR
76 .sp
77 .LP
78 creates files \fBx.c\fR and \fBxs.c\fR as before, without using or affecting
79 any \fBstrings\fR file in the same directory.
80 .sp
81 .LP
82 It may be useful to run \fBxstr\fR after the C preprocessor if any macro
83 definitions yield strings or if there is conditional code which contains
84 strings which may not, in fact, be needed. \fBxstr\fR reads from the standard
85 input when the argument `\fB\(mi\fR\&' is given. An appropriate command
86 sequence for running \fBxstr\fR after the C preprocessor is:
87 .sp
88 .in +2
89 .nf
90 \fBexample% cc \(miE name.c | xstr \(mic \(mi
91 example% cc \(mic x.c
92 example% mv x.o name.o\fR
93 .fi
94 .in -2
95 .sp
97 .sp
98 .LP
99 \fBxstr\fR does not touch the file \fBstrings\fR unless new items are added;
100 thus \fBmake\fR(1S) can avoid remaking \fBxs.o\fR unless truly necessary.
101 .SH OPTIONS
103 .ne 2
105 \fB\fB\(mic \fR\fIfilename\fR\fR
107 .RS 18n
108 Take C source text from \fIfilename\fR.
112 .ne 2
114 \fB\fB-v\fR\fR
116 .RS 18n
117 Verbose: display a progress report indicating where new or duplicate strings
118 were found.
122 .ne 2
124 \fB\fB\(mil \fR\fIarray\fR\fR
126 .RS 18n
127 Specify the named  \fIarray\fR in program references to abstracted strings.
128 The default array name is \fBxstr\fR.
131 .SH FILES
133 .ne 2
135 \fB\fBstrings\fR\fR
137 .RS 12n
138 data base of strings
142 .ne 2
144 \fB\fBx.c\fR\fR
146 .RS 12n
147 massaged C source
151 .ne 2
153 \fB\fBxs.c\fR\fR
155 .RS 12n
156 C source for definition of array "xstr*(rq
160 .ne 2
162 \fB\fB/tmp/xs*\fR\fR
164 .RS 12n
165 temp file when \fBxstr \fR\fIfilename\fR doesn't touch \fBstrings\fR
168 .SH SEE ALSO
171 \fBmake\fR(1S), \fBattributes\fR(5)
172 .SH BUGS
175 If a string is a suffix of another string in the data base, but the shorter
176 string is seen first by \fBxstr\fR both strings will be placed in the data
177 base, when just placing the longer one there would do.
178 .SH NOTES
181 Be aware that \fBxstr\fR indiscriminately replaces all strings with expressions
182 of the form \fB&xstr[\fR\fInumber\fR\fB]\fR regardless of the way the original
183 C code might have used the string.  For example, you will encounter a problem
184 with  code that uses \fBsizeof()\fR to determine the length of a literal string
185 because \fBxstr\fR will replace the literal string with a pointer that most
186 likely will have a different size than the string's. To circumvent this
187 problem:
188 .RS +4
190 .ie t \(bu
191 .el o
192 use \fBstrlen()\fR instead of  \fBsizeof()\fR; note that  \fBsizeof()\fR
193 returns the size of the array (including the null byte at the end), whereas
194 \fBstrlen()\fR doesn't count the null byte. The equivalent of
195 \fBsizeof("\fR\fIxxx\fR\fB")\fR really is \fB(strlen("\fR\fIxxx\fR\fB"))+1\fR.
197 .RS +4
199 .ie t \(bu
200 .el o
201 use \fB#define\fR for operands of \fBsizeof()\fR and use the \fBdefine\fR'd
202 version. \fBxstr\fR ignores \fB#define\fR statements.  Make sure you run
203 \fBxstr\fR on \fIfilename\fR before you run it on the preprocessor.
207 You will also encounter a problem when declaring an initialized character array
208 of the form
210 .in +2
212 \fBchar x[] = "\fR\fIxxx\fR\fB";\fR
214 .in -2
219 \fBxstr\fR will replace  \fIxxx\fR with an expression of the form
220 \fB&xstr[\fR\fInumber\fR\fB]\fR which will not compile.  To circumvent this
221 problem, use \fBstatic char *x = "xxx"\fR instead of \fBstatic char x[] =
222 "xxx"\fR.