home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
243_01
/
cpp1.c
< prev
next >
Wrap
Text File
|
1990-05-14
|
36KB
|
883 lines
/*
** name: cpp1.c
*/
/*
* CPP main program.
*
* Edit history
* 21-May-84 MM "Field test" release
* 23-May-84 MM Some minor hacks.
* 30-May-84 ARF Didn't get enough memory for __DATE__
* Added code to read stdin if no input
* files are provided.
* 29-Jun-84 MM Added ARF's suggestions, Unixifying cpp.
* 11-Jul-84 MM "Official" first release (that's what I thought!)
* 22-Jul-84 MM/ARF/SCK Fixed line number bugs, added cpp recognition
* of #line, fixed problems with #include.
* 23-Jul-84 MM More (minor) include hacking, some documentation.
* Also, redid cpp's #include files
* 25-Jul-84 MM #line filename isn't used for #include searchlist
* #line format is <number> <optional name>
* 25-Jul-84 ARF/MM Various bugs, mostly serious. Removed homemade doprint
* 01-Aug-84 MM Fixed recursion bug, remove extra newlines and
* leading whitespace from cpp output.
* 02-Aug-84 MM Hacked (i.e. optimized) out blank lines and unneeded
* whitespace in general. Cleaned up unget()'s.
* 03-Aug-84 Keie Several bug fixes from Ed Keizer, Vrije Universitet.
* -- corrected arg. count in -D and pre-defined
* macros. Also, allow \n inside macro actual parameter
* lists.
* 06-Aug-84 MM If debugging, dump the preset vector at startup.
* 12-Aug-84 MM/SCK Some small changes from Sam Kendall
* 15-Aug-84 Keie/MM cerror, cwarn, etc. take a single string arg.
* cierror, etc. take a single int. arg.
* changed LINE_PREFIX slightly so it can be
* changed in the makefile.
* 31-Aug-84 MM USENET net.sources release.
* 7-Sep-84 SCH/ado Lint complaints
* 10-Sep-84 Keie Char's can't be signed in some implementations
* 11-Sep-84 ado Added -C flag, pathological line number fix
* 13-Sep-84 ado Added -E flag (does nothing) and "-" file for stdin.
* 14-Sep-84 MM Allow # 123 as a synonym for #line 123
* 19-Sep-84 MM scanid always reads to token, make sure #line is
* written to a new line, even if -C switch given.
* Also, cpp - - reads stdin, writes stdout.
* 03-Oct-84 ado/MM Several changes to line counting and keepcomments
* stuff. Also a rewritten control() hasher -- much
* simpler and no less "perfect". Note also changes
* in cpp3.c to fix numeric scanning.
* 04-Oct-84 MM Added recognition of macro formal parameters if
* they are the only thing in a string, per the
* draft standard.
* 08-Oct-84 MM One more attack on scannumber
* 15-Oct-84 MM/ado Added -N to disable predefined symbols. Fixed
* linecount if COMMENT_INVISIBLE enabled.
* 22-Oct-84 MM Don't evaluate the #if/#ifdef argument if
* compilation is supressed. This prevents
* unnecessary error messages in sequences such as
* #ifdef FOO -- undefined
* #if FOO == 10 -- shouldn't print warning
* 25-Oct-84 MM Fixed bug in false ifdef supression. On vms,
* #include <foo> should open foo.h -- this duplicates
* the behavior of Vax-C
* 31-Oct-84 ado/MM Parametized $ in indentifiers. Added a better
* token concatenator and took out the trial
* concatenation code. Also improved #ifdef code
* and cleaned up the macro recursion tester.
* 2-Nov-84 MM/ado Some bug fixes in token concatenation, also
* a variety of minor (uninteresting) hacks.
* 6-Nov-84 MM Happy Birthday. Broke into 4 files and added
* #if sizeof (basic_types)
* 9-Nov-84 MM Added -S* for pointer type sizes
* 13-Nov-84 MM Split cpp1.c, added vms defaulting
* 23-Nov-84 MM/ado -E supresses error exit, added CPP_INCLUDE,
* fixed strncpy bug.
* 3-Dec-84 ado/MM Added OLD_PREPROCESSOR
* 7-Dec-84 MM Stuff in Nov 12 Draft Standard
* 17-Dec-84 george Fixed problems with recursive macros
* 17-Dec-84 MM Yet another attack on #if's (f/t)level removed.
* 07-Jan-85 ado Init defines before doing command line options
* so -Uunix works.
* 14-Jan-85 MM Fixed bug with logical device translation on VMS.
* 18-Jan-85 MM Rearrainged fgetname() conditionals.
* 27-Mar-85 ado Fix bug in pcc
* 28-Mar-85 MM Another attack on concatenation and some minor
* cleanup and typo corrections.
* 29-Mar-85 ado/MM trigraphs, also fixed bug with / at end of macro.
* 11-Apr-85 ado Buglets (typos and lint picking)
* 29-Apr-85 MM Added concat without reexpansion. Suggestion from ado.
* 07-Jun-85 KR added -P option. don't output #line
*/
/*)BUILD
$(PROGRAM) = cpp
$(FILES) = { cpp1 cpp2 cpp3 cpp4 cpp5 cpp6 }
$(INCLUDE) = { cppdef.h cpp.h }
$(STACK) = 3000
$(TKBOPTIONS) = {
STACK = 2000
}
*/
#ifdef DOCUMENTATION
title cpp C Pre-Processor
index C pre-processor
synopsis
.s.nf
cpp [-options] [infile [outfile]]
.s.f
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 file name "-"
is a synonym for stdin or stdout as appropriate.
The following options are supported. Options may
be given in either case.
.lm +16
.p -16
-C If set, source-file comments are written
to the output file. This allows the output of CPP to be
used as the input to a program, such as lint, that expects
commands embedded in specially-formatted comments.
.p -16
-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.
.p -16
-E Always return "success" to the operating
system, even if errors were detected. Note that some fatal
errors, such as a missing #include file, will terminate
CPP, returning "failure" even if the -E option is given.
.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
-N CPP normally predefines some symbols defining
the target computer and operating system. If -N is specified,
no symbols will be predefined. If -N -N is specified, the
"always present" symbols, __LINE__, __FILE__, and __DATE__
are not defined.
.p -16
-P CPP normally writes lines of the form
#line <number> <file.name> to the output file so the compiler
can print the line number and name of the original source file
f