7 extern void cpp_init(int fd
);
8 extern int cpp_read(char *s
);
10 static char buf
[BUFSIZE
];
13 static char name
[NAMELEN
];
22 {"static", TOK_STATIC
},
23 {"extern", TOK_EXTERN
},
24 {"return", TOK_RETURN
},
25 {"unsigned", TOK_UNSIGNED
},
26 {"signed", TOK_SIGNED
},
31 {"struct", TOK_STRUCT
},
34 {"typedef", TOK_TYPEDEF
},
40 {"switch", TOK_SWITCH
},
42 {"sizeof", TOK_SIZEOF
},
44 {"continue", TOK_CONTINUE
},
45 {"default", TOK_DEFAULT
},
49 static char *tok3
[] = {
50 "<<", ">>", "++", "--", "<<=", ">>=", "...", "+=", "-=", "*=", "/=",
51 "%=", "|=", "&=", "^=", "&&", "||", "==", "!=", "<=", ">=", "->", "/*"
54 static int get_tok3(int num
)
57 for (i
= 0; i
< ARRAY_SIZE(tok3
); i
++)
58 if (num
== TOK3(tok3
[i
]))
63 static char *esc_code
= "abefnrtv";
64 static char *esc
= "\a\b\e\f\n\r\t\v";
65 static char *digs
= "0123456789abcdef";
67 static int esc_char(int *c
, char *s
)
73 if (strchr(esc_code
, s
[1])) {
74 *c
= esc
[strchr(esc_code
, s
[1]) - esc_code
];
77 if (isdigit(s
[1]) || s
[1] == 'x') {
86 while ((d
= strchr(digs
, s
[i
]))) {
105 static void readnum(void)
108 if (buf
[cur
] == '0' && buf
[cur
+ 1] == 'x') {
112 if (strchr(digs
, buf
[cur
])) {
115 if (base
== 10 && buf
[cur
] == '0')
117 while (cur
< len
&& (c
= strchr(digs
, buf
[cur
]))) {
123 while (cur
< len
&& tolower(buf
[cur
]) == 'u' ||
124 tolower(buf
[cur
]) == 'l')
128 if (buf
[cur
] == '\'') {
130 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
137 static char str
[BUFSIZE
];
140 int tok_str(char *buf
)
143 memcpy(buf
, str
, str_len
);
147 static int readstr(char *out
)
153 while (r
< e
&& *r
!= '"') {
156 r
+= esc_char(&c
, r
);
167 static int id_char(int c
)
169 return isalnum(c
) || c
== '_';
172 static int skipws(void)
177 while (!(r
= cpp_read(buf
+ cur
)))
183 while (cur
< len
&& isspace(buf
[cur
]))
187 if (TOK2(buf
+ cur
) != TOK2("/*"))
189 while (++cur
< len
) {
190 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
210 if (buf
[cur
] == '"') {
212 while (buf
[cur
] == '"') {
213 str_len
+= readstr(str
+ str_len
);
220 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
224 if (id_char(buf
[cur
])) {
227 while (cur
< len
&& id_char(buf
[cur
]))
230 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
231 if (!strcmp(kwds
[i
].name
, name
))
235 if ((num
= get_tok3(TOK3(buf
+ cur
)))) {
239 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
243 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
255 void tok_init(int fd
)
268 return next
== -1 ? cur
: pre
;
271 void tok_jump(long addr
)