7 extern int cpp_read(char *s
);
9 static char buf
[BUFSIZE
];
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
< ARRAY_SIZE(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
= strchr(digs
, s
[i
]))) {
104 static void readnum(void)
107 if (buf
[cur
] == '0' && buf
[cur
+ 1] == 'x') {
111 if (strchr(digs
, buf
[cur
])) {
114 if (base
== 10 && buf
[cur
] == '0')
116 while (cur
< len
&& (c
= strchr(digs
, tolower(buf
[cur
])))) {
122 while (cur
< len
&& tolower(buf
[cur
]) == 'u' ||
123 tolower(buf
[cur
]) == 'l')
127 if (buf
[cur
] == '\'') {
129 cur
+= 2 + esc_char(&ret
, buf
+ cur
+ 1);
136 static char str
[BUFSIZE
];
139 int tok_str(char *buf
)
142 memcpy(buf
, str
, str_len
);
146 static int readstr(char *out
)
152 while (r
< e
&& *r
!= '"') {
155 r
+= esc_char(&c
, r
);
166 static int id_char(int c
)
168 return isalnum(c
) || c
== '_';
171 static int skipws(void)
176 while (!(r
= cpp_read(buf
+ cur
)))
182 while (cur
< len
&& isspace(buf
[cur
]))
186 if (TOK2(buf
+ cur
) != TOK2("/*"))
188 while (++cur
< len
) {
189 if (buf
[cur
] == '*' && buf
[cur
+ 1] == '/') {
209 if (buf
[cur
] == '"') {
211 while (buf
[cur
] == '"') {
212 str_len
+= readstr(str
+ str_len
);
219 if (isdigit(buf
[cur
]) || buf
[cur
] == '\'') {
223 if (id_char(buf
[cur
])) {
226 while (cur
< len
&& id_char(buf
[cur
]))
229 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
230 if (!strcmp(kwds
[i
].name
, name
))
234 if ((num
= get_tok3(TOK3(buf
+ cur
)))) {
238 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
242 if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf
[cur
]))
261 return next
== -1 ? cur
: pre
;
264 void tok_jump(long addr
)