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
]))) {
107 static void readnum(void)
110 num_bt
= 4 | BT_SIGNED
;
111 if (buf
[cur
] == '0' && buf
[cur
+ 1] == 'x') {
115 if (strchr(digs
, buf
[cur
])) {
118 if (base
== 10 && buf
[cur
] == '0')
120 while (cur
< len
&& (c
= strchr(digs
, tolower(buf
[cur
])))) {
127 int c
= tolower(buf
[cur
]);
128 if (c
!= 'u' && c
!= 'l')
131 num_bt
&= ~BT_SIGNED
;
133 num_bt
= (num_bt
& BT_SIGNED
) | 8;
138 if (buf
[cur
] == '\'') {
140 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
147 static char str
[BUFSIZE
];
150 int tok_str(char *buf
)
153 memcpy(buf
, str
, str_len
);
157 static int readstr(char *out
)
163 while (r
< e
&& *r
!= '"') {
166 r
+= esc_char(&c
, r
);
177 static int id_char(int c
)
179 return isalnum(c
) || c
== '_';
182 static int skipws(void)
187 while (!(r
= cpp_read(buf
+ cur
)))
193 while (cur
< len
&& isspace(buf
[cur
]))
197 if (TOK2(buf
+ cur
) != TOK2("/*"))
199 while (++cur
< len
) {
200 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
220 if (buf
[cur
] == '"') {
222 while (buf
[cur
] == '"') {
223 str_len
+= readstr(str
+ str_len
);
230 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
234 if (id_char(buf
[cur
])) {
237 while (cur
< len
&& id_char(buf
[cur
]))
240 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
241 if (!strcmp(kwds
[i
].name
, name
))
245 if ((num
= get_tok3(TOK3(buf
+ cur
)))) {
249 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
253 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
272 return next
== -1 ? cur
: pre
;
275 void tok_jump(long addr
)