6 static char buf
[BUFSIZE
];
9 static char name
[NAMELEN
];
17 {"static", TOK_STATIC
},
18 {"return", TOK_RETURN
},
19 {"unsigned", TOK_UNSIGNED
},
20 {"signed", TOK_SIGNED
},
25 {"struct", TOK_STRUCT
},
32 {"switch", TOK_SWITCH
},
34 {"sizeof", TOK_SIZEOF
},
37 static char *tok3
[] = {
38 "<<", ">>", "++", "--", "<<=", ">>=", "...", "+=", "-=", "*=", "/=",
39 "%=", "|=", "&=", "^=", "&&", "||", "==", "!=", "<=", ">="
42 static int get_tok3(int num
)
45 for (i
= 0; i
< ARRAY_SIZE(tok3
); i
++)
46 if (num
== TOK3(tok3
[i
]))
51 static int id_char(int c
)
53 return isalnum(c
) || c
== '_';
64 while (cur
< len
&& isspace(buf
[cur
]))
68 if (isdigit(buf
[cur
])) {
70 while (cur
< len
&& isdigit(buf
[cur
]))
75 if (id_char(buf
[cur
])) {
78 while (cur
< len
&& id_char(buf
[cur
]))
81 for (i
= 0; i
< ARRAY_SIZE(kwds
); i
++)
82 if (!strcmp(kwds
[i
].name
, name
))
86 if ((num
= get_tok3(TOK3(buf
+ cur
)))) {
90 if ((num
= get_tok3(TOK2(buf
+ cur
)))) {
94 if (strchr(";,{}()[]<>*&!=+-/%?:|^~", buf
[cur
]))
106 void tok_init(int fd
)
109 while ((n
= read(fd
, buf
+ len
, sizeof(buf
) - len
)) > 0)