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