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') {
112 num_bt
&= ~BT_SIGNED
;
116 if (strchr(digs
, tolower(buf
[cur
]))) {
119 if (base
== 10 && buf
[cur
] == '0')
121 while (cur
< len
&& (c
= strchr(digs
, tolower(buf
[cur
])))) {
128 int c
= tolower(buf
[cur
]);
129 if (c
!= 'u' && c
!= 'l')
132 num_bt
&= ~BT_SIGNED
;
134 num_bt
= (num_bt
& BT_SIGNED
) | LONGSZ
;
139 if (buf
[cur
] == '\'') {
141 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
148 static char str
[BUFSIZE
];
151 int tok_str(char *buf
)
154 memcpy(buf
, str
, str_len
);
158 static int readstr(char *out
)
164 while (r
< e
&& *r
!= '"') {
167 r
+= esc_char(&c
, r
);
178 static int id_char(int c
)
180 return isalnum(c
) || c
== '_';
183 static int skipws(void)
188 while (!(r
= cpp_read(buf
+ cur
)))
194 while (cur
< len
&& isspace(buf
[cur
]))
198 if (TOK2(buf
+ cur
) != TOK2("/*"))
200 while (++cur
< len
) {
201 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
221 if (buf
[cur
] == '"') {
223 while (buf
[cur
] == '"') {
224 str_len
+= readstr(str
+ str_len
);
231 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
235 if (id_char(buf
[cur
])) {
238 while (cur
< len
&& id_char(buf
[cur
]))
241 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
242 if (!strcmp(kwds
[i
].name
, name
))
246 if (cur
+ 3 <= len
&& (num
= get_tok3(TOK3(buf
+ cur
)))) {
250 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
254 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
273 return next
== -1 ? cur
: pre
;
276 void tok_jump(long addr
)