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