OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [cpp/] [unix.c.ORIG] - Blame information for rev 97

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include 
2
#include 
3
#include 
4
#include 
5
#include "cpp.h"
6
 
7
extern  int getopt(int, char *const *, const char *);
8
extern  char    *optarg, rcsid[];
9
extern  int     optind;
10
int     verbose;
11
int     Mflag;  /* only print active include files */
12
char    *objname; /* "src.$O: " */
13
int     Cplusplus = 1;
14
 
15
void
16
setup(int argc, char **argv)
17
{
18
        int c, i;
19
        FILE *fd;
20
        char *fp, *dp;
21
        Tokenrow tr;
22
        extern void setup_kwtab(void);
23
 
24
        setup_kwtab();
25
        while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
26
                switch (c) {
27
                case 'N':
28
                        for (i=0; i
29
                                if (includelist[i].always==1)
30
                                        includelist[i].deleted = 1;
31
                        break;
32
                case 'I':
33
                        for (i=NINCLUDE-2; i>=0; i--) {
34
                                if (includelist[i].file==NULL) {
35
                                        includelist[i].always = 1;
36
                                        includelist[i].file = optarg;
37
                                        break;
38
                                }
39
                        }
40
                        if (i<0)
41
                                error(FATAL, "Too many -I directives");
42
                        break;
43
                case 'D':
44
                case 'U':
45
                        setsource("", NULL, optarg);
46
                        maketokenrow(3, &tr);
47
                        gettokens(&tr, 1);
48
                        doadefine(&tr, c);
49
                        unsetsource();
50
                        break;
51
                case 'M':
52
                        Mflag++;
53
                        break;
54
                case 'v':
55
                        fprintf(stderr, "%s %s\n", argv[0], rcsid);
56
                        break;
57
                case 'V':
58
                        verbose++;
59
                        break;
60
                case '+':
61
                        Cplusplus++;
62
                        break;
63
                default:
64
                        break;
65
                }
66
        dp = ".";
67
        fp = "";
68
        fd = stdin;
69
        if (optind
70
                if ((fp = strrchr(argv[optind], '/')) != NULL) {
71
                        int len = fp - argv[optind];
72
                        dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
73
                        dp[len] = '\0';
74
                }
75
                fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
76
                if ((fd = fopen(fp, "r")) == NULL)
77
                        error(FATAL, "Can't open input file %s", fp);
78
        }
79
        if (optind+1
80
                FILE *fdo = freopen(argv[optind+1], "w", stdout);
81
                if (fdo == NULL)
82
                        error(FATAL, "Can't open output file %s", argv[optind+1]);
83
        }
84
        if(Mflag)
85
                setobjname(fp);
86
        includelist[NINCLUDE-1].always = 0;
87
        includelist[NINCLUDE-1].file = dp;
88
        setsource(fp, fd, NULL);
89
}
90
 
91
 
92
 
93
/* memmove is defined here because some vendors don't provide it at
94
   all and others do a terrible job (like calling malloc) */
95
void *
96
memmove(void *dp, const void *sp, size_t n)
97
{
98
        unsigned char *cdp, *csp;
99
 
100
        if (n<=0)
101
                return 0;
102
        cdp = dp;
103
        csp = (unsigned char *)sp;
104
        if (cdp < csp) {
105
                do {
106
                        *cdp++ = *csp++;
107
                } while (--n);
108
        } else {
109
                cdp += n;
110
                csp += n;
111
                do {
112
                        *--cdp = *--csp;
113
                } while (--n);
114
        }
115
        return 0;
116
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.