Dec 132017
 
String constant folding (C).
File XSTR.ZIP from The Programmer’s Corner in
Category C Source Code
String constant folding (C).
File Name File Size Zip Size Zip Type
DUMPSTR.C 155 127 deflated
MAKEFILE 1481 477 deflated
TEST.C 472 242 deflated
TEST2.C 239 126 deflated
XSTR.C 9819 3251 deflated
XSTR.DOC 6999 2156 deflated
XSTR.EXE 9040 5195 deflated

Download File XSTR.ZIP Here

Contents of the XSTR.DOC file




































































XSTR (1) xstr.exer XSTR (1)


XSTR
XSTR

xstr.exe - string constant folding utility

SYNOPSIS
SYNOPSIS

xstr
xstr [-c -v -f FILE -dsymbol] file1 . . . filen

v
-v causes the program to print out information at runtime
pertaining to its operation.

-f FILE causes the program to read the list of files to
FILE
process from FILE. This file consists of one or more lines,
each containing one or more file names seperated by single
blanks or tabs. Additional files may also be specified on
the command line.

c
-c causes the program to filter input through the c
pre-processor. This defaults to Gimpel Software's PC-Lint
with the -P option. If you want to use something else for a
preprocessor, set the environment variable CPP to the name
of the program to use.

file1 filen
file1 . . . filen are the files to be processed.

DESCRIPTION
DESCRIPTION

In a large application written in C, there is usually a
large number of string constants, occuring in several
xstr
different source modules. xstr is a utility that goes
through several source files, and produces a table that
contains all of the string literals used in those files.
This literal table is written out to a source file called
xstr cx
xstr.cx. It then makes a copy of each source file
cx
(distinguished from the original by the extension .cx ) that
changes all references to literal strings to references to
cx
the literal table. The resulting .cx files can then be
compiled and linked together.

Each time a string literal is encountered in a source file,
it is compared to the literals alread in the table. If the
literal is already in the table, or if it is a suffix of a
string already in the table, then it isn't added to the
cx
table. When the .cx file is written out, all string literal
references will be replaced by references to the string
literal table, contained in xstr.cx.

constant folding
This process is called constant folding, as constants that
re-occur are 'folded' into a single constant. In a large
program with many string constants, this can result in
considerable space savings.

CAVEATS
CAVEATS

xstr
xstr will produce uncompilable code for initialized string
arrays. For example,

char string[] = "string";


-1-


XSTR (1) xstr.exer XSTR (1)


becomes

extern char xstr[];
char string[] = (xstr+100);

which is bad syntax.

If your program modifies string constants, the modification
will affect all references to those string constants.

EXAMPLES
EXAMPLES

The source files below are included in the distribution
package (xstr.arc)

rem run xstr over the various source files
xstr test.c test2.c
rem compile the resulting .cx files
cc test.cx
cc test2.cx
rem compile the string literal table file
cc xstr.cx
rem link them together
ln test.o test2.o xstr.o -lc


FILES
FILES

xstr xstr cx
xstr creates a file xstr.cx that must be compiled and linked
with all other modules that comprise a program.

dumpstr c
dumpstr.c is a small program that, when linked to xstr.cx,
dump out the contents of the string table in a more or less
readable format.

RETURN VALUE
RETURN VALUE

Returns -1 to DOS for any fatal error.

SEE ALSO
SEE ALSO

Xenix programmer's reference manuals.

WARNINGS
WARNINGS

No warranty is given or implied. The program works as
documented, as best I can test it.

BUGS
BUGS

xstr
xstr will handle C line continuations - a line ending in a
backslash is concantenated with the next line. The maximum
line length is 1024 characters, and if that limit is
exceeded, the program dies very ungracefully.

If you use PC-LINT as a preprocessor, It ignores line
continuations, and throws away leading blanks in source
lines. This has bad consequences if you continue a line


-2-


XSTR (1) xstr.exer XSTR (1)


with a backslash, and start the continuing line with a
space.

NOTES
NOTES


PC-Lint by Gimpel Software is a fine product, that does its
job better even than Unix lint. I am in no way connected to
xstr xstr
Gimpel Software. xstr is a recoding of the Xenix xstr
utility. Questions or comments should be directed to

Kent Williams
722 Rundell St.
Iowa City, IA 52240
(319) 338-6053
UUCP: ... decvax!cwruecmp!ncoast!kent












































-3-



 December 13, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)