2005-08-26 17:39:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "cpp.h"
|
|
|
|
|
2008-04-23 17:39:39 +00:00
|
|
|
extern int lcc_getopt(int, char *const *, const char *);
|
2005-08-26 17:39:27 +00:00
|
|
|
extern char *optarg, rcsid[];
|
|
|
|
extern int optind;
|
|
|
|
int verbose;
|
|
|
|
int Mflag; /* only print active include files */
|
|
|
|
char *objname; /* "src.$O: " */
|
|
|
|
int Cplusplus = 1;
|
|
|
|
|
|
|
|
void
|
|
|
|
setup(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c, fd, i;
|
|
|
|
char *fp, *dp;
|
|
|
|
Tokenrow tr;
|
|
|
|
extern void setup_kwtab(void);
|
2006-03-24 16:28:07 +00:00
|
|
|
uchar *includeDirs[ NINCLUDE ] = { 0 };
|
2006-03-21 21:58:39 +00:00
|
|
|
int numIncludeDirs = 0;
|
2005-08-26 17:39:27 +00:00
|
|
|
|
|
|
|
setup_kwtab();
|
2008-04-23 17:39:39 +00:00
|
|
|
while ((c = lcc_getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
|
2005-08-26 17:39:27 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'N':
|
|
|
|
for (i=0; i<NINCLUDE; i++)
|
|
|
|
if (includelist[i].always==1)
|
|
|
|
includelist[i].deleted = 1;
|
|
|
|
break;
|
|
|
|
case 'I':
|
2006-03-21 21:58:39 +00:00
|
|
|
includeDirs[ numIncludeDirs++ ] = newstring( (uchar *)optarg, strlen( optarg ), 0 );
|
2005-08-26 17:39:27 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'U':
|
|
|
|
setsource("<cmdarg>", -1, optarg);
|
|
|
|
maketokenrow(3, &tr);
|
|
|
|
gettokens(&tr, 1);
|
|
|
|
doadefine(&tr, c);
|
|
|
|
unsetsource();
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
Mflag++;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
fprintf(stderr, "%s %s\n", argv[0], rcsid);
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
Cplusplus++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dp = ".";
|
|
|
|
fp = "<stdin>";
|
|
|
|
fd = 0;
|
|
|
|
if (optind<argc) {
|
2005-11-01 22:09:15 +00:00
|
|
|
dp = basepath( argv[optind] );
|
2005-08-26 17:39:27 +00:00
|
|
|
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
|
|
|
if ((fd = open(fp, 0)) <= 0)
|
|
|
|
error(FATAL, "Can't open input file %s", fp);
|
|
|
|
}
|
|
|
|
if (optind+1<argc) {
|
|
|
|
int fdo = creat(argv[optind+1], 0666);
|
|
|
|
if (fdo<0)
|
|
|
|
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
|
|
|
dup2(fdo, 1);
|
|
|
|
}
|
|
|
|
if(Mflag)
|
|
|
|
setobjname(fp);
|
|
|
|
includelist[NINCLUDE-1].always = 0;
|
|
|
|
includelist[NINCLUDE-1].file = dp;
|
2006-03-21 21:58:39 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numIncludeDirs; i++ )
|
2006-03-24 16:28:07 +00:00
|
|
|
appendDirToIncludeList( (char *)includeDirs[ i ] );
|
2006-03-21 21:58:39 +00:00
|
|
|
|
2005-08-26 17:39:27 +00:00
|
|
|
setsource(fp, fd, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
char *basepath( char *fname )
|
|
|
|
{
|
|
|
|
char *dp = ".";
|
|
|
|
char *p;
|
|
|
|
if ((p = strrchr(fname, '/')) != NULL) {
|
|
|
|
int dlen = p - fname;
|
|
|
|
dp = (char*)newstring((uchar*)fname, dlen+1, 0);
|
|
|
|
dp[dlen] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return dp;
|
|
|
|
}
|
2005-08-26 17:39:27 +00:00
|
|
|
|
|
|
|
/* memmove is defined here because some vendors don't provide it at
|
|
|
|
all and others do a terrible job (like calling malloc) */
|
2005-10-09 13:06:33 +00:00
|
|
|
// -- ouch, that hurts -- ln
|
2006-01-15 15:22:13 +00:00
|
|
|
#ifndef MACOS_X /* always use the system memmove() on Mac OS X. --ryan. */
|
2005-10-09 13:06:33 +00:00
|
|
|
#ifdef memmove
|
|
|
|
#undef memmove
|
|
|
|
#endif
|
2005-08-26 17:39:27 +00:00
|
|
|
void *
|
|
|
|
memmove(void *dp, const void *sp, size_t n)
|
|
|
|
{
|
|
|
|
unsigned char *cdp, *csp;
|
|
|
|
|
|
|
|
if (n<=0)
|
|
|
|
return 0;
|
|
|
|
cdp = dp;
|
|
|
|
csp = (unsigned char *)sp;
|
|
|
|
if (cdp < csp) {
|
|
|
|
do {
|
|
|
|
*cdp++ = *csp++;
|
|
|
|
} while (--n);
|
|
|
|
} else {
|
|
|
|
cdp += n;
|
|
|
|
csp += n;
|
|
|
|
do {
|
|
|
|
*--cdp = *--csp;
|
|
|
|
} while (--n);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-01-15 15:22:13 +00:00
|
|
|
#endif
|