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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [input.c] - Blame information for rev 149

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

Line No. Rev Author Line
1 4 hellwig
#include "c.h"
2
 
3
static char rcsid[] = "$Id: input.c,v 1.1 2002/08/28 23:12:44 drh Exp $";
4
 
5
static void pragma(void);
6
static void resynch(void);
7
 
8
static int bsize;
9
static unsigned char buffer[MAXLINE+1 + BUFSIZE+1];
10
unsigned char *cp;      /* current input character */
11
char *file;             /* current input file name */
12
char *firstfile;        /* first input file */
13
unsigned char *limit;   /* points to last character + 1 */
14
char *line;             /* current line */
15
int lineno;             /* line number of current line */
16
 
17
void nextline(void) {
18
        do {
19
                if (cp >= limit) {
20
                        fillbuf();
21
                        if (cp >= limit)
22
                                cp = limit;
23
                        if (cp == limit)
24
                                return;
25
                } else {
26
                        lineno++;
27
                        for (line = (char *)cp; *cp==' ' || *cp=='\t'; cp++)
28
                                ;
29
                        if (*cp == '#') {
30
                                resynch();
31
                                nextline();
32
                        }
33
                }
34
        } while (*cp == '\n' && cp == limit);
35
}
36
void fillbuf(void) {
37
        if (bsize == 0)
38
                return;
39
        if (cp >= limit)
40
                cp = &buffer[MAXLINE+1];
41
        else
42
                {
43
                        int n = limit - cp;
44
                        unsigned char *s = &buffer[MAXLINE+1] - n;
45
                        assert(s >= buffer);
46
                        line = (char *)s - ((char *)cp - line);
47
                        while (cp < limit)
48
                                *s++ = *cp++;
49
                        cp = &buffer[MAXLINE+1] - n;
50
                }
51
        if (feof(stdin))
52
                bsize = 0;
53
        else
54
                bsize = fread(&buffer[MAXLINE+1], 1, BUFSIZE, stdin);
55
        if (bsize < 0) {
56
                error("read error\n");
57
                exit(EXIT_FAILURE);
58
        }
59
        limit = &buffer[MAXLINE+1+bsize];
60
        *limit = '\n';
61
}
62
void input_init(int argc, char *argv[]) {
63
        static int inited;
64
 
65
        if (inited)
66
                return;
67
        inited = 1;
68
        main_init(argc, argv);
69
        limit = cp = &buffer[MAXLINE+1];
70
        bsize = -1;
71
        lineno = 0;
72
        file = NULL;
73
        fillbuf();
74
        if (cp >= limit)
75
                cp = limit;
76
        nextline();
77
}
78
 
79
/* ident - handle #ident "string" */
80
static void ident(void) {
81
        while (*cp != '\n' && *cp != '\0')
82
                cp++;
83
}
84
 
85
/* pragma - handle #pragma ref id... */
86
static void pragma(void) {
87
        if ((t = gettok()) == ID && strcmp(token, "ref") == 0)
88
                for (;;) {
89
                        while (*cp == ' ' || *cp == '\t')
90
                                cp++;
91
                        if (*cp == '\n' || *cp == 0)
92
                                break;
93
                        if ((t = gettok()) == ID && tsym) {
94
                                tsym->ref++;
95
                                use(tsym, src);
96
                        }
97
                }
98
}
99
 
100
/* resynch - set line number/file name in # n [ "file" ], #pragma, etc. */
101
static void resynch(void) {
102
        for (cp++; *cp == ' ' || *cp == '\t'; )
103
                cp++;
104
        if (limit - cp < MAXLINE)
105
                fillbuf();
106
        if (strncmp((char *)cp, "pragma", 6) == 0) {
107
                cp += 6;
108
                pragma();
109
        } else if (strncmp((char *)cp, "ident", 5) == 0) {
110
                cp += 5;
111
                ident();
112
        } else if (*cp >= '0' && *cp <= '9') {
113
        line:   for (lineno = 0; *cp >= '0' && *cp <= '9'; )
114
                        lineno = 10*lineno + *cp++ - '0';
115
                lineno--;
116
                while (*cp == ' ' || *cp == '\t')
117
                        cp++;
118
                if (*cp == '"') {
119
                        file = (char *)++cp;
120
                        while (*cp && *cp != '"' && *cp != '\n')
121
                                cp++;
122
                        file = stringn(file, (char *)cp - file);
123
                        if (*cp == '\n')
124
                                warning("missing \" in preprocessor line\n");
125
                        if (firstfile == 0)
126
                                firstfile = file;
127
                }
128
        } else if (strncmp((char *)cp, "line", 4) == 0) {
129
                for (cp += 4; *cp == ' ' || *cp == '\t'; )
130
                        cp++;
131
                if (*cp >= '0' && *cp <= '9')
132
                        goto line;
133
                if (Aflag >= 2)
134
                        warning("unrecognized control line\n");
135
        } else if (Aflag >= 2 && *cp != '\n')
136
                warning("unrecognized control line\n");
137
        while (*cp)
138
                if (*cp++ == '\n')
139
                        if (cp == limit + 1) {
140
                                nextline();
141
                                if (cp == limit)
142
                                        break;
143
                        } else
144
                                break;
145
}
146
 

powered by: WebSVN 2.1.0

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