home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
243_01
/
cpp3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-14
|
22KB
|
666 lines
/*
** name: cpp3.c
*/
/*
* C P P 3 . C
*
* File open and command line options
*
* Edit history
* 13-Nov-84 MM Split from cpp1.c
* 29-Apr-85 MM Make -N work again.
* 03-Oct-85 CG Change default loc. of <files> for P/OS.
* 08-Nov-85 ado Prevent wierd -D arguments
* 24-Jun-88 BM taught cpp about multiple include directoried in
* INCLUDE environment variable (Blake McBride)
* 15-Dec-88 RA Duplicated logic above for the included directories
* in the DPATH environment variable for OS/2 E 1.1
* (Roberto Artigas Jr) since the headers from the
* data base manager and communications manager are
* picked up from their own specific directories.
*/
#include "cppdef.h"
#include "cpp.h"
FILE_LOCAL void unpredefine();
#if DEBUG && (HOST == SYS_VMS || HOST == SYS_UNIX)
#include <signal.h>
extern int abort(); /* For debugging */
#endif
int
openfile(filename)
char *filename;
/*
* Open a file, add it to the linked list of open files.
* This is called only from openfile() above.
*/
{
register FILE *fp;
if ((fp = fopen(filename, "r")) == NULL) {
#if DEBUG
perror(filename);
#endif
return (FALSE);
}
#if DEBUG
if (debug)
fprintf(stderr, "Reading from \"%s\"\n", filename);
#endif
addfile(fp, filename);
return (TRUE);
}
void
addfile(fp, filename)
FILE *fp; /* Open file pointer */
char *filename; /* Name of the file */
/*
* Initialize tables for this open file. This is called from openfile()
* above (for #include files), and from the entry to cpp to open the main
* input file. It calls a common routine, getfile() to build the FILEINFO
* structure which is used to read characters. (getfile() is also called
* to setup a macro replacement.)
*/
{
register FILEINFO *file;
extern FILEINFO *getfile();
file = getfile(NBUFF, filename);
file->fp = fp; /* Better remember FILE * */
file->buffer[0] = EOS; /* Initialize for first read */
line = 1; /* Working on line 1 now */
wrongline = TRUE; /* Force out initial #line */
}
void
setincdirs()
/*
* Append system-specific directories to the include directory list.
* Called only when cpp is started.
*/
{
#ifdef CPP_INCLUDE
*incend++ = CPP_INCLUDE;
#define IS_INCLUDE 1
#else
#define IS_INCLUDE 0
#endif
#if HOST == SYS_UNIX
*incend++ = "/usr/include";
#define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE)
#endif
#if HOST == SYS_VMS
extern char *getenv();
if (getenv("C$LIBRARY") != NULL)
*incend++ = "C$LIBRARY:";
*incend++ = "SYS$LIBRARY:";
#define MAXINCLUDE (NINCLUDE - 2 - IS_INCLUDE)
#endif
#if HOST == SYS_RSX
extern int $$rsts; /* TRUE on RSTS/E */
extern int $$pos; /* TRUE on PRO-350 P/OS */
extern int $$vms; /* TRUE on VMS compat. */
if ($$pos) { /* P/OS? */
*incend++ = "LB:[ZZDECUSC]"; /* C #includes */
*incend++ = "LB:[1,5]"; /* RSX library */
}
else if ($$rsts) { /* RSTS/E? */
*incend++ = "SY:@"; /* User-defined account */
*incend++ = "C:"; /* Decus-C library */
*incend++ = "LB:[1,1]"; /* RSX library */
}
else if ($$vms) { /* VMS compatibility? */
*incend++ = "C:";
}
else { /* Plain old RSX/IAS */
*incend++ = "LB:[1,1]";
}
#define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE)
#endif
#if HOST == SYS_RT11
extern int $$rsts; /* RSTS/E emulation? */
if ($$rsts)
*incend++ = "SY:@"; /* User-defined account */
*incend++ = "C:"; /* Decus-C library disk */
*incend++ = "SY:"; /* System (boot) disk */
#define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE)
#endif
#if HOST == SYS_MSDOS
{
char incdir[ 100 ];
char *getenv(), *strsave();
char *foo;
foo = getenv( "INCLUDE" );
if ( foo == NULL )
*incend++ = "\\include\\";
else {
while (*foo) {
char *p = incdir;
while (*foo && *foo != ';' && *foo != ' ' && p-incdir < 98)
*p++ = *foo++;
if (p != incdir) {
if (*(p-1) != '\\' && *(p-1) != '/')
*p++ = '\\';
*p = '\0';
*incend++ = strsave(incdir);
}
while (*foo && (*foo == ';' || *foo == ' '))
++foo;
}
} /* End if */
foo = getenv( "DPATH" );
if ( foo != NULL ) {
while (*foo) {
char *p = incdir;
while (*foo && *foo != ';' && *foo != ' ' && p-incdir < 98)
*p++ = *foo++;
if (p != incdir) {
if (*(p-1) != '\\' && *(p-1) != '/')
*p++ = '\\';
*p = '\0';
*incend++ = strsave(incdir);
}
while (*foo && (*foo == ';' || *foo == ' '))
++foo;
}
} /* End if */
} /* End hack */
#define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE)
#endif
}
int
dooptions(argc, argv)
int argc;
char *argv[];
/*
* dooptions is called to process command line arguments (-Detc).
* It is called only at cpp startup.
*/
{
register char *ap;
register DEFBUF *dp;
register int c;
int i, j;
char *arg;
SIZES *sizp; /* For -S */
int size; /* For -S */
int isdatum; /* FALSE for -S* */
int endtest; /* For -S */
char *cp; /* For -D arg test */
for (i = j = 1; i < argc; i++) {
arg = ap = argv[i];
if (*ap++ != '-' || *ap == EOS)
argv[j++] = argv[i];
else {
c = *ap++; /* Option byte */
if (islower(c)) /* Normalize case */
c = toupper(c);
switch (c) { /* Command character */
case 'C': /* Keep comments */
cflag = TRUE;
keepcomments = TRUE;
break;
case 'D': /* Define symbol */
/*
* Check for incorrect argument -- don't allow
* -Dfoo(bar)=something
*/
if (type[*ap] != LET)
cfatal("Argument needed for -D in \"%s\"", arg);
for (cp = ap; *cp != EOS && *cp != '='; cp++) {
if (type[*cp] != LET && type[*cp] != DIG)
cfatal("Incorrect argument for -D in \"%s\"", arg);
}
#if HOST != SYS_UNIX && HOST != SYS_MSDOS
zap_uc(ap); /* Force define to U.C. */
#endif
#if OK_TRIGRAPH
if (tflag)
trigraph(ap);
#endif
/*
* If the option is just "-Dfoo", make it -Dfoo=1
*/
while (*ap != EOS && *ap != '=')
ap++;