00001 #include <stdio.h>
00002 #include <stddef.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include "cpp.h"
00006
00007 extern int getopt(int, char *const *, const char *);
00008 extern char *optarg, rcsid[];
00009 extern int optind;
00010 int verbose;
00011 int Mflag;
00012 char *objname;
00013 int Cplusplus = 1;
00014
00015 void
00016 setup(int argc, char **argv)
00017 {
00018 int c, fd, i;
00019 char *fp, *dp;
00020 Tokenrow tr;
00021 extern void setup_kwtab(void);
00022
00023 setup_kwtab();
00024 while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
00025 switch (c) {
00026 case 'N':
00027 for (i=0; i<NINCLUDE; i++)
00028 if (includelist[i].always==1)
00029 includelist[i].deleted = 1;
00030 break;
00031 case 'I':
00032 for (i=NINCLUDE-2; i>=0; i--) {
00033 if (includelist[i].file==NULL) {
00034 includelist[i].always = 1;
00035 includelist[i].file = optarg;
00036 break;
00037 }
00038 }
00039 if (i<0)
00040 error(FATAL, "Too many -I directives");
00041 break;
00042 case 'D':
00043 case 'U':
00044 setsource("<cmdarg>", -1, optarg);
00045 maketokenrow(3, &tr);
00046 gettokens(&tr, 1);
00047 doadefine(&tr, c);
00048 unsetsource();
00049 break;
00050 case 'M':
00051 Mflag++;
00052 break;
00053 case 'v':
00054 fprintf(stderr, "%s %s\n", argv[0], rcsid);
00055 break;
00056 case 'V':
00057 verbose++;
00058 break;
00059 case '+':
00060 Cplusplus++;
00061 break;
00062 default:
00063 break;
00064 }
00065 dp = ".";
00066 fp = "<stdin>";
00067 fd = 0;
00068 if (optind<argc) {
00069 if ((fp = strrchr(argv[optind], '/')) != NULL) {
00070 int len = fp - argv[optind];
00071 dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
00072 dp[len] = '\0';
00073 }
00074 fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
00075 if ((fd = open(fp, 0)) <= 0)
00076 error(FATAL, "Can't open input file %s", fp);
00077 }
00078 if (optind+1<argc) {
00079 int fdo = creat(argv[optind+1], 0666);
00080 if (fdo<0)
00081 error(FATAL, "Can't open output file %s", argv[optind+1]);
00082 dup2(fdo, 1);
00083 }
00084 if(Mflag)
00085 setobjname(fp);
00086 includelist[NINCLUDE-1].always = 0;
00087 includelist[NINCLUDE-1].file = dp;
00088 setsource(fp, fd, NULL);
00089 }
00090
00091
00092
00093
00094
00095 void *
00096 memmove(void *dp, const void *sp, size_t n)
00097 {
00098 unsigned char *cdp, *csp;
00099
00100 if (n<=0)
00101 return 0;
00102 cdp = dp;
00103 csp = (unsigned char *)sp;
00104 if (cdp < csp) {
00105 do {
00106 *cdp++ = *csp++;
00107 } while (--n);
00108 } else {
00109 cdp += n;
00110 csp += n;
00111 do {
00112 *--cdp = *--csp;
00113 } while (--n);
00114 }
00115 return 0;
00116 }