57e4efe9 |
1 | static int my_isblank(char c) |
2 | { |
3 | return c == '\t' || c == ' ' || c == '\r' || c == '\n'; |
4 | } |
5 | |
6 | static int my_issep(char c) |
7 | { |
8 | return c == '(' || c == ')' || c == '[' || c == ']' |
06c5d854 |
9 | || c == '<' || c == '>' || c == ',' || c == ';' |
91977a1c |
10 | || c == '+' || c == '-' || c == '*' || c == '/'; |
57e4efe9 |
11 | } |
12 | |
13 | static char *sskip(char *s) |
14 | { |
15 | while (my_isblank(*s)) |
16 | s++; |
17 | |
18 | return s; |
19 | } |
20 | |
21 | static char *next_word(char *w, size_t wsize, char *s) |
22 | { |
23 | size_t i; |
24 | |
25 | s = sskip(s); |
26 | |
27 | for (i = 0; i < wsize - 1; i++) { |
91977a1c |
28 | if (s[i] == 0 || my_isblank(s[i])) |
57e4efe9 |
29 | break; |
30 | w[i] = s[i]; |
31 | } |
32 | w[i] = 0; |
33 | |
91977a1c |
34 | if (s[i] != 0 && !my_isblank(s[i])) |
57e4efe9 |
35 | printf("warning: '%s' truncated\n", w); |
36 | |
37 | return s + i; |
38 | } |
39 | |
40 | static inline char *next_idt(char *w, size_t wsize, char *s) |
41 | { |
42 | size_t i; |
43 | |
44 | s = sskip(s); |
45 | |
46 | for (i = 0; i < wsize - 1; i++) { |
91977a1c |
47 | if (s[i] == 0 || my_isblank(s[i]) || my_issep(s[i])) |
57e4efe9 |
48 | break; |
49 | w[i] = s[i]; |
50 | } |
51 | w[i] = 0; |
52 | |
91977a1c |
53 | if (s[i] != 0 && !my_isblank(s[i]) && !my_issep(s[i])) |
57e4efe9 |
54 | printf("warning: '%s' truncated\n", w); |
55 | |
56 | return s + i; |
57 | } |