8 static char buf
[BUFSIZE
];
11 static char name
[NAMELEN
];
20 {"static", TOK_STATIC
},
21 {"extern", TOK_EXTERN
},
22 {"return", TOK_RETURN
},
23 {"unsigned", TOK_UNSIGNED
},
24 {"signed", TOK_SIGNED
},
29 {"struct", TOK_STRUCT
},
32 {"typedef", TOK_TYPEDEF
},
38 {"switch", TOK_SWITCH
},
40 {"sizeof", TOK_SIZEOF
},
42 {"continue", TOK_CONTINUE
},
43 {"default", TOK_DEFAULT
},
47 static char *tok3
[] = {
48 "<<=", ">>=", "...", "<<", ">>", "++", "--", "+=", "-=", "*=", "/=",
49 "%=", "|=", "&=", "^=", "&&", "||", "==", "!=", "<=", ">=", "->", "/*"
52 static int get_tok3(int num
)
55 for (i
= 0; i
< ARRAY_SIZE(tok3
); i
++)
56 if (num
== TOK3(tok3
[i
]))
61 static char *esc_code
= "abefnrtv";
62 static char *esc
= "\a\b\e\f\n\r\t\v";
63 static char *digs
= "0123456789abcdef";
65 static int esc_char(int *c
, char *s
)
71 if (strchr(esc_code
, s
[1])) {
72 *c
= esc
[strchr(esc_code
, s
[1]) - esc_code
];
75 if (isdigit(s
[1]) || s
[1] == 'x') {
84 while ((d
= strchr(digs
, s
[i
]))) {
105 static void readnum(void)
108 num_bt
= 4 | BT_SIGNED
;
109 if (buf
[cur
] == '0' && buf
[cur
+ 1] == 'x') {
110 num_bt
&= ~BT_SIGNED
;
114 if (strchr(digs
, tolower(buf
[cur
]))) {
117 if (base
== 10 && buf
[cur
] == '0')
119 while (cur
< len
&& (c
= strchr(digs
, tolower(buf
[cur
])))) {
126 int c
= tolower(buf
[cur
]);
127 if (c
!= 'u' && c
!= 'l')
130 num_bt
&= ~BT_SIGNED
;
132 num_bt
= (num_bt
& BT_SIGNED
) | LONGSZ
;
137 if (buf
[cur
] == '\'') {
139 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
146 static char str
[BUFSIZE
];
149 int tok_str(char *buf
)
152 memcpy(buf
, str
, str_len
);
156 static int readstr(char *out
)
162 while (r
< e
&& *r
!= '"') {
165 r
+= esc_char(&c
, r
);
176 static int id_char(int c
)
178 return isalnum(c
) || c
== '_';
181 static int skipws(void)
186 while (!(r
= cpp_read(buf
+ cur
)))
192 while (cur
< len
&& isspace(buf
[cur
]))
196 if (TOK2(buf
+ cur
) != TOK2("/*"))
198 while (++cur
< len
) {
199 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
219 if (buf
[cur
] == '"') {
221 while (buf
[cur
] == '"') {
222 str_len
+= readstr(str
+ str_len
);
229 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
233 if (id_char(buf
[cur
])) {
236 while (cur
< len
&& id_char(buf
[cur
]))
239 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
240 if (!strcmp(kwds
[i
].name
, name
))
244 if (cur
+ 3 <= len
&& (num
= get_tok3(TOK3(buf
+ cur
)))) {
248 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
252 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
271 return next
== -1 ? cur
: pre
;
274 void tok_jump(long addr
)