1xstr(1)                          User Commands                         xstr(1)
2
3
4

NAME

6       xstr - extract strings from C programs to implement shared strings
7

SYNOPSIS

9       xstr -c filename [-v] [-l array]
10
11
12       xstr [-l array]
13
14
15       xstr filename [-v] [-l array]
16
17

DESCRIPTION

19       xstr  maintains  a  file called strings into which strings in component
20       parts of a large program are hashed. These strings  are  replaced  with
21       references  to  this  common area. This serves to implement shared con‐
22       stant strings, which are most useful if they are also read-only.
23
24
25       The command:
26
27         example% xstr −c filename
28
29
30
31
32       extracts the strings from the C source in name, replacing string refer‐
33       ences  by  expressions  of  the  form &xstr[number] for some number. An
34       appropriate declaration of xstr is prepended to the file.  The  result‐
35       ing C text is placed in the file x.c, to then be compiled.  The strings
36       from this file are placed in the strings data  base  if  they  are  not
37       there  already.  Repeated  strings  and  strings  which are suffixes of
38       existing strings do not cause changes to the data base.
39
40
41       After all components of a large program  have  been  compiled,  a  file
42       declaring the common xstr space called xs.c can be created by a command
43       of the form:
44
45         example% xstr
46
47
48
49
50       This xs.c file should then be compiled and loaded with the rest of  the
51       program.   If possible, the array can be made read-only (shared) saving
52       space and swap overhead.
53
54
55       xstr can also be used on a single file.  A command:
56
57
58       example% xstr filename
59
60
61       creates files x.c and xs.c as before, without using  or  affecting  any
62       strings file in the same directory.
63
64
65       It may be useful to run xstr after the C preprocessor if any macro def‐
66       initions yield strings or if there is conditional code  which  contains
67       strings which may not, in fact, be needed. xstr reads from the standard
68       input when the argument `' is given. An appropriate  command  sequence
69       for running xstr after the C preprocessor is:
70
71         example% cc −E name.c | xstr −c −
72         example% cc −c x.c
73         example% mv x.o name.o
74
75
76
77
78       xstr  does  not touch the file strings unless new items are added; thus
79       make(1S) can avoid remaking xs.o unless truly necessary.
80

OPTIONS

82       −c filename       Take C source text from filename.
83
84
85       -v                Verbose: display a progress report  indicating  where
86                         new or duplicate strings were found.
87
88
89       −l array          Specify  the  named   array  in program references to
90                         abstracted strings.  The default array name is xstr.
91
92

FILES

94       strings     data base of strings
95
96
97       x.c         massaged C source
98
99
100       xs.c        C source for definition of array "xstr*(rq
101
102
103       /tmp/xs*    temp file when xstr filename doesn't touch strings
104
105

ATTRIBUTES

107       See attributes(5) for descriptions of the following attributes:
108
109
110
111
112       ┌─────────────────────────────┬─────────────────────────────┐
113       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
114       ├─────────────────────────────┼─────────────────────────────┤
115       │Availability                 │SUNWcsu                      │
116       └─────────────────────────────┴─────────────────────────────┘
117

SEE ALSO

119       make(1S), attributes(5)
120

BUGS

122       If a string is a suffix of another string in the  data  base,  but  the
123       shorter string is seen first by xstr both strings will be placed in the
124       data base, when just placing the longer one there would do.
125

NOTES

127       Be aware that xstr indiscriminately replaces all strings  with  expres‐
128       sions  of  the  form &xstr[number] regardless of the way the original C
129       code might have used the string.  For example,  you  will  encounter  a
130       problem with  code that uses sizeof() to determine the length of a lit‐
131       eral string because xstr will replace the literal string with a pointer
132       that  most likely will have a different size than the string's. To cir‐
133       cumvent this problem:
134
135           o      use strlen()  instead  of   sizeof();  note  that   sizeof()
136                  returns  the  size  of the array (including the null byte at
137                  the end), whereas strlen() doesn't count the null byte.  The
138                  equivalent of sizeof("xxx") really is (strlen("xxx"))+1.
139
140           o      use  #define  for  operands of sizeof() and use the define'd
141                  version. xstr ignores #define statements.  Make sure you run
142                  xstr on filename before you run it on the preprocessor.
143
144
145       You will also encounter a problem when declaring an initialized charac‐
146       ter array of the form
147
148         char x[] = "xxx";
149
150
151
152
153       xstr will replace  xxx with an expression  of  the  form  &xstr[number]
154       which will not compile.  To circumvent this problem, use static char *x
155       = "xxx" instead of static char x[] = "xxx".
156
157
158
159SunOS 5.11                        14 Sep 1992                          xstr(1)
Impressum