9 static char buf
[BUFLEN
];
12 static char name
[NAMELEN
];
21 {"static", TOK_STATIC
},
22 {"extern", TOK_EXTERN
},
23 {"return", TOK_RETURN
},
24 {"unsigned", TOK_UNSIGNED
},
25 {"signed", TOK_SIGNED
},
30 {"struct", TOK_STRUCT
},
33 {"typedef", TOK_TYPEDEF
},
39 {"switch", TOK_SWITCH
},
41 {"sizeof", TOK_SIZEOF
},
43 {"continue", TOK_CONTINUE
},
44 {"default", TOK_DEFAULT
},
48 static char *tok3
[] = {
49 "<<=", ">>=", "...", "<<", ">>", "++", "--", "+=", "-=", "*=", "/=",
50 "%=", "|=", "&=", "^=", "&&", "||", "==", "!=", "<=", ">=", "->"
53 static int get_tok3(int num
)
56 for (i
= 0; i
< LEN(tok3
); i
++)
57 if (num
== TOK3(tok3
[i
]))
62 static char *esc_code
= "abefnrtv";
63 static char *esc
= "\a\b\e\f\n\r\t\v";
64 static char *digs
= "0123456789abcdef";
66 static int esc_char(int *c
, char *s
)
72 if (strchr(esc_code
, s
[1])) {
73 *c
= esc
[strchr(esc_code
, s
[1]) - esc_code
];
76 if (isdigit(s
[1]) || s
[1] == 'x') {
85 while ((d
= memchr(digs
, s
[i
], base
))) {
106 static void readnum(void)
109 num_bt
= 4 | BT_SIGNED
;
110 if (buf
[cur
] == '0' && buf
[cur
+ 1] == 'x') {
111 num_bt
&= ~BT_SIGNED
;
115 if (strchr(digs
, tolower(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
) | LONGSZ
;
138 if (buf
[cur
] == '\'') {
140 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
147 static char str
[STRLEN
];
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 (buf
[cur
] == '\\' && buf
[cur
+ 1] == '\n') {
201 if (buf
[cur
] == '/' && buf
[cur
+ 1] == '/') {
202 while (cur
< len
&& buf
[cur
] != '\n')
206 if (buf
[cur
] == '/' && buf
[cur
+ 1] == '*') {
207 while (++cur
< len
) {
208 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
231 if (buf
[cur
] == '"') {
233 while (buf
[cur
] == '"') {
234 str_len
+= readstr(str
+ str_len
);
241 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
245 if (id_char(buf
[cur
])) {
248 while (cur
< len
&& id_char(buf
[cur
]))
251 for (i
= 0; i
< LEN(kwds
); i
++)
252 if (!strcmp(kwds
[i
].name
, name
))
256 if (cur
+ 3 <= len
&& (num
= get_tok3(TOK3(buf
+ cur
)))) {
260 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
264 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
283 return next
== -1 ? cur
: pre
;
286 void tok_jump(long addr
)