#include <stdio.h>
|
#include <stdio.h>
|
#include <stddef.h>
|
#include <stddef.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <string.h>
|
#include "cpp.h"
|
#include "cpp.h"
|
|
|
extern int getopt(int, char *const *, const char *);
|
extern int getopt(int, char *const *, const char *);
|
extern char *optarg, rcsid[];
|
extern char *optarg, rcsid[];
|
extern int optind;
|
extern int optind;
|
int verbose;
|
int verbose;
|
int Mflag; /* only print active include files */
|
int Mflag; /* only print active include files */
|
char *objname; /* "src.$O: " */
|
char *objname; /* "src.$O: " */
|
int Cplusplus = 1;
|
int Cplusplus = 1;
|
|
|
void
|
void
|
setup(int argc, char **argv)
|
setup(int argc, char **argv)
|
{
|
{
|
int c, i;
|
int c, i;
|
FILE *fd;
|
FILE *fd;
|
char *fp, *dp;
|
char *fp, *dp;
|
Tokenrow tr;
|
Tokenrow tr;
|
extern void setup_kwtab(void);
|
extern void setup_kwtab(void);
|
|
|
setup_kwtab();
|
setup_kwtab();
|
while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
|
while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
|
switch (c) {
|
switch (c) {
|
case 'N':
|
case 'N':
|
for (i=0; i<NINCLUDE; i++)
|
for (i=0; i<NINCLUDE; i++)
|
if (includelist[i].always==1)
|
if (includelist[i].always==1)
|
includelist[i].deleted = 1;
|
includelist[i].deleted = 1;
|
break;
|
break;
|
case 'I':
|
case 'I':
|
for (i=NINCLUDE-2; i>=0; i--) {
|
for (i=NINCLUDE-2; i>=0; i--) {
|
if (includelist[i].file==NULL) {
|
if (includelist[i].file==NULL) {
|
includelist[i].always = 1;
|
includelist[i].always = 1;
|
includelist[i].file = optarg;
|
includelist[i].file = optarg;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
if (i<0)
|
if (i<0)
|
error(FATAL, "Too many -I directives");
|
error(FATAL, "Too many -I directives");
|
break;
|
break;
|
case 'D':
|
case 'D':
|
case 'U':
|
case 'U':
|
setsource("<cmdarg>", NULL, optarg);
|
setsource("<cmdarg>", NULL, optarg);
|
maketokenrow(3, &tr);
|
maketokenrow(3, &tr);
|
gettokens(&tr, 1);
|
gettokens(&tr, 1);
|
doadefine(&tr, c);
|
doadefine(&tr, c);
|
unsetsource();
|
unsetsource();
|
break;
|
break;
|
case 'M':
|
case 'M':
|
Mflag++;
|
Mflag++;
|
break;
|
break;
|
case 'v':
|
case 'v':
|
fprintf(stderr, "%s %s\n", argv[0], rcsid);
|
fprintf(stderr, "%s %s\n", argv[0], rcsid);
|
break;
|
break;
|
case 'V':
|
case 'V':
|
verbose++;
|
verbose++;
|
break;
|
break;
|
case '+':
|
case '+':
|
Cplusplus++;
|
Cplusplus++;
|
break;
|
break;
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
dp = ".";
|
dp = ".";
|
fp = "<stdin>";
|
fp = "<stdin>";
|
fd = stdin;
|
fd = stdin;
|
if (optind<argc) {
|
if (optind<argc) {
|
if ((fp = strrchr(argv[optind], '/')) != NULL) {
|
if ((fp = strrchr(argv[optind], '/')) != NULL) {
|
int len = fp - argv[optind];
|
int len = fp - argv[optind];
|
dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
|
dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
|
dp[len] = '\0';
|
dp[len] = '\0';
|
}
|
}
|
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
if ((fd = fopen(fp, "r")) == NULL)
|
if ((fd = fopen(fp, "r")) == NULL)
|
error(FATAL, "Can't open input file %s", fp);
|
error(FATAL, "Can't open input file %s", fp);
|
}
|
}
|
if (optind+1<argc) {
|
if (optind+1<argc) {
|
FILE *fdo = freopen(argv[optind+1], "w", stdout);
|
FILE *fdo = freopen(argv[optind+1], "w", stdout);
|
if (fdo == NULL)
|
if (fdo == NULL)
|
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
}
|
}
|
if(Mflag)
|
if(Mflag)
|
setobjname(fp);
|
setobjname(fp);
|
includelist[NINCLUDE-1].always = 0;
|
includelist[NINCLUDE-1].always = 0;
|
includelist[NINCLUDE-1].file = dp;
|
includelist[NINCLUDE-1].file = dp;
|
setsource(fp, fd, NULL);
|
setsource(fp, fd, NULL);
|
}
|
}
|
|
|