summaryrefslogtreecommitdiff
path: root/static/v10/man8/xstr.8
blob: 681f2e2fdf2113c0a93c72e12b5972f9889a2b62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.TH XSTR 8
.CT 1 prog_c
.SH NAME
xstr \- preprocessor for sharing strings in C programs
.SH SYNOPSIS
.B xstr
[
.B -c
]
[
.B -
]
[
.I file
]
.SH DESCRIPTION
.I Xstr
maintains a file
.F strings
into which strings in component parts of a large program are hashed.
These strings are replaced with references to this common area.
This serves to implement shared constant strings, most useful if they
are also read-only.
.PP
The command
.IP
.L
xstr -c name.c
.PP
will extract the strings from the named C source, replacing
string references by expressions of the form
.BI (&xstr[ number ])
for some
.I number.
An appropriate declaration of
.I xstr
is prepended to the file.
The resulting C text is placed in the file
.BR x.c .
The strings from this file are placed in the
.F strings
data base if they are not there already.
Repeated strings and strings which are suffixes of existing strings
do not cause changes to the data base.
.PP
After all components of a large program have been compiled a file
.B xs.c
declaring the common
.I xstr
space can be created by running
.B xstr
with no arguments.
This
.B xs.c
file should then be compiled and loaded with the rest
of the program.
If possible, the array can be made read-only (shared) saving
space and swap overhead.
.PP
Without option
.BR -c ,
creates files
.I x.c
and
.I xs.c
as before, but does not use or affect any
.F strings
file in the same directory.
.PP
It may be useful to run
.I xstr
after the C preprocessor if any macro definitions yield strings
or if there is conditional code which contains strings
which may not, in fact, be needed.
.I Xstr
reads from its standard input when the argument 
.L -
is given.
An appropriate command sequence for running
.I xstr
after the C preprocessor is:
.IP
.EX
cc -E name.c | xstr -c -
cc -c x.c
mv x.o name.o
.EE
.SH FILES
.TF /tmp/xs*
.TP
.F strings
Data base of strings
.TP
.F x.c
Massaged C source
.TP
.F xs.c
C source for definition of array
.L xstr
.TP
.F /tmp/xs*
Temp file
.SH BUGS
If a string is a suffix of another string in the data base,
but the shorter string is seen first by
.I xstr
both strings will be placed in the data base, when just
placing the longer one there will do.