cpp (1-3), file as cpp1.arc
Martin Minow
minow at decvax.UUCP
Sun Sep 2 11:49:27 AEST 1984
-h- readme.txt Sat Sep 1 21:43:35 1984 readme.txt
Decus CPP is a public-domain implementation of the C preprocessor.
It runs on VMS native (Vax C), VMS compatibilty mode (Decus C),
RSX-11M, RSTS/E, P/OS, and RT11, as well as on several varieties
of Unix, including Ultrix-32. These notes describe how to extract
the cpp source files, configure cpp for your needs, and mention
a few design decisions that may be of interest to maintainers.
Installation
Because the primary development of cpp was not on Unix, it
is distributed using the Decus C archive program (quite similar
to the archiver published in Kernighan and Plauger's Software
Tools). To extract the files from the net.sources distribution,
save this message as cpp1.arc (and the other two distribution
files as cpp2.arc and cpp3.arc). Then, using your favorite editor,
locate the archx.c program, just following the line beginning with
"-h- archx.c" -- the format of the tape is just:
... stuff
-h- archx.c
... archx.c program
-h- archc.c
... archc.c program
Compile archx.c -- it shouldn't require any special editing.
Then run it as follows:
archx cpp1.arc
archx cpp2.arc
archx cpp3.arc
You do not need to remove mail headers from the saved messages.
You should then read through cppdef.h to make sure the HOST and TARGET
(and other implementation-specific) definitions are set correctly for
your machine, editing cppdef.h or makefile.txt as needed.
You may then copy makefile.txt to Makefile, On Unix, cpp should be
compiled by make without further difficulty. On other operating systems,
you should compile the three source modules, linking them together.
Note that, on Decus C based systems, you must extend the default
stack allocation. The Decus C build utility will create the
appropriate command file.
Support Notes
The distribution kit was designed to keep all submissions just
under 50,000 bytes:
cpp1.arc:
readme.txt This file
cpp.mem Documentation page (see below)
archx.c Archive extraction program
archc.c Archive construction program
cpp.rno Source for cpp.mem (see below)
makefile.txt Unix makefile -- copy to Makefile
cpp2.arc:
cpp.h Main header file (structure def's and globals)
cppdef.h Configuration file (host and target definitions)
cpp1.c Mainline code, most #control processing
cpp3.arc:
cpp2.c #define, macro expansion, and #if <expr> processors
cpp3.c Support code (symbol table and I/O routines)
While cpp intentionally does not rely on the presence of a full-scale
macro preprocessor, it does require the simple parameter substitution
preprocessor capabilities of Unix V6 and Decus C. If your C
language lacks full preprocessing, you should make sure "nomacargs"
is #define'd in cpp.h. (This is done automatically by the Decus C
compiler.)
The documentation (manual page) for cpp is included as cpp.mem
and cpp.rno. These are in Dec Runoff format, built by a Decus C
utility (getrno) from original source which is embedded in cpp1.c.
To my knowledge, there is no equivalent program that creates
the nroff source appropriate for Unix.
I would be happy to receive fixes to any problems you encounter.
As I do not maintain distribution kit base-levels, bare-bones
diff listings without sufficient context are not very useful.
It is unlikely that I can find time to help you with other
difficulties.
Acknowledgements
I received a great deal of help from many people in debugging cpp.
Alan Feuer and Sam Kendall used "state of the art" run-time code
checkers to locate several errors. Ed Keiser found problems when
cpp was used on machines with different int and pointer sizes.
Dave Conroy helped with the initial debugging.
Martin Minow
decvax!minow
-h- cpp.mem Sat Sep 1 21:43:35 1984 cpp.mem
1.0 C Pre-Processor
*******
* cpp *
*******
NAME: cpp -- C Pre-Processor
SYNOPSIS:
cpp [-options] [infile [outfile]]
DESCRIPTION:
CPP reads a C source file, expands macros and include
files, and writes an input file for the C compiler. If
no file arguments are given, cpp reads from stdin and
writes to stdout. If one file argument is given, it
will define the input file, while two file arguments
define both input and output files.
The following options are supported. Options may be
given in either case.
-Idirectory Add this directory to the list of
directories searched for #include "..."
and #include <...> commands. Note that
there is no space between the "-I" and
the directory string. More than one -I
command is permitted. On non-Unix
systems "directory" is forced to
upper-case.
-Dname=value Define the name as if the programmer
wrote
#define name value
at the start of the first file. If
"=value" is not given, a value of "1"
will be used.
On non-unix systems, all alphabetic text
will be forced to upper-case.
-Uname Undefine the name as if
#undef name
Page 2
cpp C Pre-Processor
were given. On non-Unix systems, "name"
will be forced to upper-case.
The following variables are pre-defined:
Target computer (as appropriate):
pdp11, vax, M68000 m68000 m68k
Target operating system (as appropriate):
rsx, rt11, vms, unix
Target compiler (as appropriate):
decus, vax11c
The implementor may add definitions to this list. The
default definitions match the definition of the host
computer, operating system, and C compiler.
The following are always available unless undefined:
__FILE__ The input (or #include) file being
compiled (as a quoted string).
__LINE__ The line number being compiled.
__DATE__ The date and time of compilation as a
Unix ctime quoted string (the trailing
newline is removed). Thus,
printf("Bug at line %s,", __LINE__);
printf(" source file %s", __FILE__);
printf(" compiled on %s", __DATE__);
-Xnumber Enable debugging code. If no value is
given, a value of 1 will be used. (For
maintenence of CPP only.)
DRAFT ANSI STANDARD CONSIDERATIONS:
Comments are removed from the input text. The comment
is replaced by a single space character. This differs
from usage on some existing preprocessors (but it
follows the Draft Ansi C Standard).
Note that arguments may be concatenated as follows:
#define I(x)x
#define CAT(x,y)I(x)y
int value = CAT(1,2);
Page 3
cpp C Pre-Processor
If the above macros are defined and invoked without
extraneous spaces, they will be transportable to other
implementations. Unfortunately, this will not properly
expand
int CAT(foo,__LINE__);
int CAT(foo,__LINE__);
as __LINE__ is copied into the input stream, yielding
"foo__LINE__" in both cases, rather than the expected
"foo123", "foo124", which would result if __LINE__ were
expanded and the result copied into the input stream.
Macro formal parameters are not recognized within quoted
strings and character constants in macro definitions.
CPP implements most of the ANSI draft standard. You
should be aware of the following differences:
o In the draft standard, the \n (backslash-newline)
character is "invisible" to all processing. In this
implementation, it is invisible to strings, but acts
a "whitespace" (token-delimiter) outside of strings.
This considerably simplifies error message handling.
o The following new features of C are processed by
cpp:
#elif expression (#else #if)
'\xNNN' (Hexadecimal constants)
'\a' (Ascii BELL [silly])
'\v' (Ascii VT)
#if defined NAME (1 if defined, 0 if not)
#if defined (NAME) (1 if defined, 0 if not)
unary + (gag me with a spoon)
o The draft standard has extended C, adding a string
concatenation operator, where
"foo" "bar"
is regarded as the single string "foobar". (This
does not affect CPP's processing.)
ERROR MESSAGES:
Many. CPP prints warning messages if you try to use
multiple-byte character constants (non-transportable) or
if you #undef a symbol that was not defined.
BUGS:
Cpp prints spurious error or warning messages in #if
sequences such as the following:
Page 4
cpp C Pre-Processor
#define foo 0
#if (foo != 0) ? (100 / foo) : 0
#undef foo
#if ((defined(foo)) ? foo : 0) == 1
Cpp should supress the error message if the expression's
value is already known.
AUTHOR:
Martin Minow
-h- archx.c Sat Sep 1 21:43:35 1984 archx.c
/*
* A R C H X
*
* Archive extraction
*
*/
/*)BUILD $(TKBOPTIONS) = {
TASK = ...ARX
}
*/
#ifdef DOCUMENTATION
title archx text file archiver extraction
index text file archiver extraction
synopsis
arch archive_files
description
Archx manages archives (libraries) of source files, allowing
a large number of small files to be stored without using
excessive system resources. Archx extracts all files from
an archive.
If no archive_name file is given, the standard input is read.
Archive header records are echoed to the standard output.
archive file format
Archive files are standard text files. Each archive element is
preceeded by a line of the format:
.s.nf
-h- file.name date true_name
.s.f
Note that there is no line or byte count. To prevent problems,
a '-' at the beginning of a record within a user file or embedded
archive will be "quoted" by doubling it. The date and true filename
fields are ignored. On some operating systems, file.name is
forced to lowercase.
If the first non-blank line of an input file does not
begin with "-h", the text will be appended to "archx.tmp"
This is needed if archives are distributed by mail
and arrive with initial routing and subject information.
diagnostics
Diagnostic messages should be self-explanatory
author
Martin Minow
bugs
#endif
#include <stdio.h>
#include <ctype.h>
#define EOS 0
#define FALSE 0
#define TRUE 1
#ifdef vms
#include <ssdef.h>
extern int errno;
#define IO_ERROR errno
#define IO_NORMAL SS$_NORMAL
#endif
#ifndef IO_NORMAL
#define IO_NORMAL 0
#endif
#ifndef IO_ERROR
#define IO_ERROR 1
#endif
/*
* The following status codes are returned by gethdr()
*/
#define DONE 0
#define GOTCHA 1
#define NOGOOD 2
char text[513]; /* Working text line */
char name[81]; /* Current archive member name */
char filename[81]; /* Working file name */
char arfilename[81]; /* Archive file name */
char fullname[81]; /* Output for argetname() */
int verbose = TRUE; /* TRUE for verbosity */
int first_archive; /* For mail header skipping */
main(argc, argv)
int argc; /* Arg count */
char *argv[]; /* Arg vector */
{
register int i; /* Random counter */
int status; /* Exit status */
#ifdef vms
argc = getredirection(argc, argv);
#endif
status = IO_NORMAL;
if (argc == 1)
process();
else {
for (i = 1; i < argc; i++) {
if (freopen(argv[i], "r", stdin) != NULL)
process();
else {
perror(argv[i]);
status = IO_ERROR;
}
}
}
exit(status);
}
process()
/*
* Process archive open on stdin
*/
{
register char *fn; /* File name pointer */
register FILE *outfd;
register int i;
text[0] = EOS;
while ((i = gethdr()) != DONE) {
switch (i) {
case GOTCHA:
if ((outfd = fopen(name, "w")) == NULL) {
perror(name);
fprintf(stderr, "Can't create \"%s\"\n", name);
arskip();
continue;
}
break;
case NOGOOD:
fprintf(stderr, "Missing -h-, writing to archx.tmp\n");
fprintf(stderr, "Current text line: %s", text);
strcpy(name, "archx.tmp");
if ((outfd = fopen(name, "a")) == NULL) {
perror(name);
fprintf(stderr, "Cannot append to %s\n", name);
arskip();
continue;
}
break;
}
arexport(outfd);
fclose(outfd);
}
}
int
gethdr()
/*
* If text is null, read a record, returning to signal input state:
* DONE Eof read
* NOGOOD -h- wasn't first non-blank line. Line is in text[]
* GOTCHA -h- found, parsed into name.
*/
{
register char *tp;
register char *np;
again: if (text[0] == EOS
&& fgets(text, sizeof text, stdin) == NULL)
return (DONE);
if (text[0] == '\n' && text[1] == EOS) {
text[0] = EOS;
goto again;
}
if (text[0] != '-'
|| text[1] != 'h'
|| text[2] != '-')
return (NOGOOD);
for (tp = &text[3]; isspace(*tp); tp++)
;
for (np = name; !isspace(*tp); *np++ = *tp++)
;
*np = EOS;
return (GOTCHA);
}
arskip()
/*
* Skip to next header
*/
{
while (fgets(text, sizeof text, stdin) != NULL) {
if (text[0] == '-' && text[1] != '-')
return;
}
text[0] = EOS; /* EOF signal */
}
arexport(outfd)
register FILE *outfd;
/*
* Read secret archive format, writing archived data to outfd.
* Clean out extraneous <cr>,<lf>'s
*/
{
register char *tp;
unsigned int nrecords;
printf("Creating \"%s\", ", name);
nrecords = 0;
while (fgets(text, sizeof text, stdin) != NULL) {
tp = &text[strlen(text)];
if (tp > &text[1] && *--tp == '\n' && *--tp == '\r') {
*tp++ = '\n';
*tp = EOS;
}
if (text[0] == '-') {
if (text[1] != '-')
goto gotcha;
fputs(text+1, outfd);
}
else {
fputs(text, outfd);
}
nrecords++;
}
text[0] = EOS;
gotcha: printf("%u records\n", nrecords);
if (ferror(stdin) || ferror(outfd))
printf("Creation of \"%s\" completed with error\n", name);
}
/*
* getredirection() is intended to aid in porting C programs
* to VMS (Vax-11 C) which does not support '>' and '<'
* I/O redirection. With suitable modification, it may
* useful for other portability problems as well.
*/
#ifdef vms
static int
getredirection(argc, argv)
int argc;
char **argv;
/*
* Process vms redirection arg's. Exit if any error is seen.
* If getredirection() processes an argument, it is erased
* from the vector. getredirection() returns a new argc value.
*
* Warning: do not try to simplify the code for vms. The code
* presupposes that getredirection() is called before any data is
* read from stdin or written to stdout.
*
* Normal usage is as follows:
*
* main(argc, argv)
* int argc;
* char *argv[];
* {
* argc = getredirection(argc, argv);
* }
*/
{
register char *ap; /* Argument pointer */
int i; /* argv[] index */
int j; /* Output index */
int file; /* File_descriptor */
extern int errno; /* Last vms i/o error */
for (j = i = 1; i < argc; i++) { /* Do all arguments */
switch (*(ap = argv[i])) {
case '<': /* <file */
if (freopen(++ap, "r", stdin) == NULL) {
perror(ap); /* Can't find file */
exit(errno); /* Is a fatal error */
}
case '>': /* >file or >>file */
if (*++ap == '>') { /* >>file */
/*
* If the file exists, and is writable by us,
* call freopen to append to the file (using the
* file's current attributes). Otherwise, create
* a new file with "vanilla" attributes as if
* the argument was given as ">filename".
* access(name, 2) is TRUE if we can write on
* the specified file.
*/
if (access(++ap, 2) == 0) {
if (freopen(ap, "a", stdout) != NULL)
break; /* Exit case statement */
perror(ap); /* Error, can't append */
exit(errno); /* After access test */
} /* If file accessable */
}
/*
* On vms, we want to create the file using "standard"
* record attributes. create(...) creates the file
* using the caller's default protection mask and
* "variable length, implied carriage return"
* attributes. dup2() associates the file with stdout.
*/
if ((file = creat(ap, 0, "rat=cr", "rfm=var")) == -1
|| dup2(file, fileno(stdout)) == -1) {
perror(ap); /* Can't create file */
exit(errno); /* is a fatal error */
} /* If '>' creation */
break; /* Exit case test */
default:
argv[j++] = ap; /* Not a redirector */
break; /* Exit case test */
}
} /* For all arguments */
return (j);
}
#endif
-h- archc.c Sat Sep 1 21:43:35 1984 archc.c
/*
* A R C H I V E
*
* Create an archive
*
*/
/*)BUILD $(TKBOPTIONS) = {
TASK = ...ARC
}
*/
#ifdef DOCUMENTATION
title archc text file archive creation
index text file archive creation
synopsis
archc file[s] >archive
description
Archc manages archives (libraries) of source files, allowing
a large number of small files to be stored without using
excessive system resources. It copies the set of named
files to standard output in archive format.
The archx program will recreate the files from an archive.
Note: there are no checks against the same file appearing
twice in an archive.
archive file format
Archive files are standard text files. Each archive element is
preceeded by a line of the format:
.s.nf
-h- file.name date true_path_name
.s.f
Note that there is no line or byte count. To prevent problems,
a '-' at the beginning of a record within a user file or embedded
archive will be "quoted" by doubling it. The date and true filename
fields are ignored. On Dec operating systems, file.name is
forced to lowercase.
diagnostics
Diagnostic messages should be self-explanatory
author
Martin Minow
#endif
#include <stdio.h>
#include <ctype.h>
#define EOS 0
#define FALSE 0
#define TRUE 1
char text[513]; /* Working text */
char name[81]; /* Current archive member name */
char pathname[81]; /* Output for argetname() */
char *timetext; /* Time of day text */
int verbose = TRUE; /* TRUE for verbosity */
FILE *infd; /* Input file */
main(argc, argv)
int argc; /* Arg count */
char *argv[]; /* Arg vector */
{
register int i; /* Random counter */
register char *fn; /* File name pointer */
register char *argp; /* Arg pointer */
int nfiles;
extern char *ctime();
extern long time();
long timval;
time(&timval);
timetext = ctime(&timval);
timetext[24] = EOS;
argc = getredirection(argc, argv);
if (argc <= 1)
fprintf(stderr, "No files to archive?\n");
#ifdef unix
for (i = 1; i < argc; i++) {
if ((infd = fopen(argv[i], "r")) == NULL)
perror(argv[i]);
else {
strcpy(pathname, argv[i]);
import();
fclose(infd);
}
}
#else
for (i = 1; i < argc; i++) {
if ((infd = fwild(argv[i], "r")) == NULL)
perror(argv[i]);
else {
for (nfiles = 0; fnext(infd) != NULL; nfiles++) {
fgetname(infd, pathname);
import();
}
fclose(infd);
if (nfiles == 0)
fprintf(stderr, "No files match \"%s\"\n", argv[i]);
}
}
#endif
}
import()
/*
* Add the file open on infd (with file name in pathname) to
* the archive.
*/
{
unsigned int nrecords;
fixname();
nrecords = 0;
printf("-h- %s\t%s\t%s\n", name, timetext, pathname);
while (fgets(text, sizeof text, infd) != NULL) {
if (text[0] == '-')
putchar('-'); /* Quote */
fputs(text, stdout);
nrecords++;
}
if (ferror(infd)) {
perror(name);
fprintf(stderr, "Error when importing a file\n");
}
if (verbose) {
fprintf(stderr, "%u records read from %s\n",
nrecords, pathname);
}
}
fixname()
/*
* Get file name (in pathname), stripping off device:[directory]
* and ;version. The archive name ("file.ext") is written to name[].
* On a dec operating system, name is forced to lowercase.
*/
{
register char *tp;
register char *ip;
char bracket;
extern char *strrchr();
#ifdef unix
/*
* name is after all directory information
*/
if ((tp = strrchr(pathname, '/')) != NULL)
tp++;
else
tp = pathname;
strcpy(name, tp);
#else
strcpy(name, pathname);
if ((tp = strrchr(name, ';')) != NULL)
*tp = EOS;
while ((tp = strchr(name, ':')) != NULL)
strcpy(name, tp + 1);
switch (name[0]) {
case '[': bracket = ']';
break;
case '<': bracket = '>';
break;
case '(': bracket = ')';
break;
default: bracket = EOS;
break;
}
if (bracket != EOS) {
if ((tp = strchr(name, bracket)) == NULL) {
fprintf(stderr, "? Illegal file name \"%s\"\n",
pathname);
}
else {
strcpy(name, tp + 1);
}
}
for (tp = name; *tp != EOS; tp++) {
if (isupper(*tp))
*tp = tolower(*tp);
}
#endif
}
#ifdef unix
char *
strrchr(stng, chr)
register char *stng;
register char chr;
/*
* Return rightmost instance of chr in stng.
* This has the wrong name on some Unix systems.
*/
{
register char *result;
result = NULL;
do {
if (*stng == chr)
result = stng;
} while (*stng++ != EOS);
return (result);
}
#endif
/*
* getredirection() is intended to aid in porting C programs
* to VMS (Vax-11 C) which does not support '>' and '<'
* I/O redirection. With suitable modification, it may
* useful for other portability problems as well.
*/
static int
getredirection(argc, argv)
int argc;
char **argv;
/*
* Process vms redirection arg's. Exit if any error is seen.
* If getredirection() processes an argument, it is erased
* from the vector. getredirection() returns a new argc value.
*
* Warning: do not try to simplify the code for vms. The code
* presupposes that getredirection() is called before any data is
* read from stdin or written to stdout.
*
* Normal usage is as follows:
*
* main(argc, argv)
* int argc;
* char *argv[];
* {
* argc = getredirection(argc, argv);
* }
*/
{
#ifdef vms
register char *ap; /* Argument pointer */
int i; /* argv[] index */
int j; /* Output index */
int file; /* File_descriptor */
extern int errno; /* Last vms i/o error */
for (j = i = 1; i < argc; i++) { /* Do all arguments */
switch (*(ap = argv[i])) {
case '<': /* <file */
if (freopen(++ap, "r", stdin) == NULL) {
perror(ap); /* Can't find file */
exit(errno); /* Is a fatal error */
}
case '>': /* >file or >>file */
if (*++ap == '>') { /* >>file */
/*
* If the file exists, and is writable by us,
* call freopen to append to the file (using the
* file's current attributes). Otherwise, create
* a new file with "vanilla" attributes as if
* the argument was given as ">filename".
* access(name, 2) is TRUE if we can write on
* the specified file.
*/
if (access(++ap, 2) == 0) {
if (freopen(ap, "a", stdout) != NULL)
break; /* Exit case statement */
perror(ap); /* Error, can't append */
exit(errno); /* After access test */
} /* If file accessable */
}
/*
* On vms, we want to create the file using "standard"
* record attributes. create(...) creates the file
* using the caller's default protection mask and
* "variable length, implied carriage return"
* attributes. dup2() associates the file with stdout.
*/
if ((file = creat(ap, 0, "rat=cr", "rfm=var")) == -1
|| dup2(file, fileno(stdout)) == -1) {
perror(ap); /* Can't create file */
exit(errno); /* is a fatal error */
} /* If '>' creation */
break; /* Exit case test */
default:
argv[j++] = ap; /* Not a redirector */
break; /* Exit case test */
}
} /* For all arguments */
return (j);
#else
/*
* Note: argv[] is referenced to fool the Decus C
* syntax analyser, supressing an unneeded warning
* message.
*/
return (argv[0], argc); /* Just return as seen */
#endif
}
-h- cpp.rno Sat Sep 1 21:43:35 1984 cpp.rno
.lm 8.rm 72.nhy
.no autosubtitle .style headers 3,0,0
.pg.uc.ps 58,80.lm 8.rm 72
.hd
.hd mixed
.head mixed
.st ########cpp#####C Pre-Processor
.pg
.hl 1 ^&C Pre-Processor\&
.s 2
.c ;*******
.c ;* cpp *
.c ;*******
.s 2
.lm +8
.s.i -8;NAME: cpp -- C Pre-Processor
.s.f
.i -8;SYNOPSIS:
.s.nf
cpp [-options] [infile [outfile]]
.s.f
.i -8;DESCRIPTION:
.s
CPP reads a C source file, expands macros and include
files, and writes an input file for the C compiler.
If no file arguments are given, cpp reads from stdin
and writes to stdout. If one file argument is given,
it will define the input file, while two file arguments
define both input and output files.
.s
The following options are supported. Options may
be given in either case.
.lm +16
.p -16
--Idirectory Add this directory to the list of
directories searched for _#include "..." and _#include <...>
commands. Note that there is no space between the
"-I" and the directory string. More than one -I command
is permitted. On non-Unix systems "directory" is forced
to upper-case.
.p -16
--Dname=value Define the name as if the programmer wrote
.s
.nf
_#define name value
.fill
.s
at the start of the first file. If "=value" is not
given, a value of "1" will be used.
.s
On non-unix systems, all alphabetic text will be forced
to upper-case.
.s
.p -16
--Uname Undefine the name as if
.s
.nf
_#undef name
.fill
.s
were given. On non-Unix systems, "name" will be forced to
upper-case.
.s.lm -16
The following variables are pre-defined:
.s
Target computer (as appropriate):
.s
.nf
pdp11, vax, M68000 m68000 m68k
.fill
.s
Target operating system (as appropriate):
.s
.nf
rsx, rt11, vms, unix
.fill
.s
Target compiler (as appropriate):
.s
.nf
decus, vax11c
.fill
.s
The implementor may add definitions to this list.
The default definitions match the definition of the
host computer, operating system, and C compiler.
.s
The following are always available unless undefined:
.lm +16
.p -12
____FILE____ The input (or _#include) file being compiled
(as a quoted string).
.p -12
____LINE____ The line number being compiled.
.p -12
____DATE____ The date and time of compilation as
a Unix ctime quoted string (the trailing newline is removed).
Thus,
.s
.nf
printf("Bug at line _%s,", ____LINE____);
printf(" source file _%s", ____FILE____);
printf(" compiled on _%s", ____DATE____);
.fill
.p -16
--Xnumber Enable debugging code. If no value is
given, a value of 1 will be used. (For maintenence of
CPP only.)
.s.lm -16
.s
.i -8;DRAFT ANSI STANDARD CONSIDERATIONS:
.s
Comments are removed from the input text. The comment
is replaced by a single space character. This differs
from usage on some existing preprocessors (but it follows
the Draft Ansi C Standard).
.s
Note that arguments may be concatenated as follows:
.s.nf
.nf
_#define I(x)x
_#define CAT(x,y)I(x)y
int value = CAT(1,2);
.fill
.s.f
If the above macros are defined and invoked without extraneous
spaces, they will be transportable to other implementations.
Unfortunately, this will not properly expand
.s.nf
.nf
int CAT(foo,____LINE____);
int CAT(foo,____LINE____);
.fill
.s.f
as ____LINE____ is copied into the input stream, yielding
"foo____LINE____" in both cases, rather than the expected
"foo123", "foo124", which would result if ____LINE____
were expanded and the result copied into the input stream.
.s
Macro formal parameters are not recognized within
quoted strings and character constants in macro definitions.
.s
CPP implements most of the ANSI draft standard.
You should be aware of the following differences:
.lm +4
.s.i-4;o###In the draft standard, the _\n (backslash-newline)
character is "invisible" to all processing. In this implementation,
it is invisible to strings, but acts a "whitespace" (token-delimiter)
outside of strings. This considerably simplifies error
message handling.
.s.i-4;o###The following new features of C are processed by cpp:
.s
.br;####_#elif expression####(_#else _#if)
.br;####'_\xNNN'#############(Hexadecimal constants)
.br;####'_\a'################(Ascii BELL [silly])
.br;####'_\v'################(Ascii VT)
.br;####_#if defined NAME####(1 if defined, 0 if not)
.br;####_#if defined (NAME)##(1 if defined, 0 if not)
.br;####_unary +#############(gag me with a spoon)
.s.i-4;o###The draft standard has extended C, adding a string
concatenation operator, where
.s
.nf
"foo" "bar"
.fill
.s
is regarded as the single string "foobar". (This does not
affect CPP's processing.)
.s.lm -4
.i -8;ERROR MESSAGES:
.s
Many. CPP prints warning messages if you try to use
multiple-byte character constants (non-transportable)
or if you _#undef a symbol that was not defined.
.s
.i -8;BUGS:
.s
Cpp prints spurious error or warning messages in _#if
sequences such as the following:
.s
.br;####_#define foo 0
.br;####_#if (foo != 0) _? (100 / foo) _: 0
.br;####_#undef foo
.br;####_#if ((defined(foo)) _? foo _: 0) == 1
.s
Cpp should supress the error message if the expression's
value is already known.
.s
.i -8;AUTHOR:
.s
Martin Minow
.s
.lm 8.rm 72.nhy
-h- makefile.txt Sat Sep 1 21:43:35 1984 makefile.txt
# Unix makefile for cpp
CFLAGS = -O
#
# The following is needed for 4.2 bsd (and maybe some other Unices)
#
CFLAGS = -O -Dstrchr=index -Dstrrchr=rindex
LINT = lint
#
# ** compile cpp
#
SRCS = cpp1.c cpp2.c cpp3.c
OBJECTS.cpp = cpp1.o cpp2.o cpp3.o
cpp: $(OBJECTS.cpp)
$(CC) $(CFLAGS) $(OBJECTS.cpp) -o cpp
#
# ** Test cpp by preprocessing itself, compiling the result,
# ** repeating the process and diff'ing the result. Note: this
# ** is not a good test of cpp, but a simple verification.
# ** The diff's should not report any changes.
#
test:
cpp cpp1.c >old.tmp1.c
cpp cpp2.c >old.tmp2.c
cpp cpp3.c >old.tmp3.c
$(CC) $(CFLAGS) old.tmp[123].c
a.out cpp1.c >new.tmp1.c
a.out cpp2.c >new.tmp2.c
a.out cpp3.c >new.tmp3.c
diff old.tmp1.c new.tmp1.c
diff old.tmp2.c new.tmp2.c
diff old.tmp3.c new.tmp3.c
rm a.out old.tmp[123].* new.tmp[123].*
#
# ** Lint the code
#
lint: $(SRCS)
$(LINT) $(SRCS)
#
# ** Rebuild the archive files needed to distribute cpp
# ** Uses the Decus C archive utility.
#
archc: archc.c
$(CC) $(CFLAGS) archc.c -o archc
archx: archx.c
$(CC) $(CFLAGS) archx.c -o archx
archive: archc
archc readme.txt cpp.mem archx.c archc.c cpp.rno makefile.txt >cpp1.arc
archc cpp*.h cpp1.c >cpp2.arc
archc cpp2.c cpp3.c >cpp3.arc
cpp1.c : cpp.h cppdef.h
cpp2.c : cpp.h cppdef.h
cpp3.c : cpp.h cppdef.h
More information about the Comp.sources.unix
mailing list