Mercurial > syslog2iptables
comparison src/tokenizer.cpp @ 48:ba0259c9e411 stable-1-0-11
Fixes to compile on Fedora 9 and for const correctness
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 29 May 2008 11:38:42 -0700 |
parents | d9ae11033b4b |
children | 60f59936fabb |
comparison
equal
deleted
inserted
replaced
47:a4861687fbd1 | 48:ba0259c9e411 |
---|---|
4 the GPL version 3 or any later version at your choice available at | 4 the GPL version 3 or any later version at your choice available at |
5 http://www.gnu.org/licenses/gpl-3.0.txt | 5 http://www.gnu.org/licenses/gpl-3.0.txt |
6 | 6 |
7 */ | 7 */ |
8 | 8 |
9 // This version of the tokenizer does not force the config to lower | |
10 // case, to avoid lowercasing the iptables commands, which need some | |
11 // uppercase arguments. It also considers / to be a separate token | |
12 // since that is needed for the cidr style ignore statement. | |
13 | |
9 #include "includes.h" | 14 #include "includes.h" |
10 | 15 |
11 const int maxlen = 1000; // used for snprintf buffers | 16 const int maxlen = 1000; // used for snprintf buffers |
12 | 17 |
13 enum state {s_init, | 18 enum state {s_init, |
14 s_token, | 19 s_token, |
15 s_string, | 20 s_string, |
16 s_ignore, // whitespace | 21 s_ignore, // whitespace |
17 s_eol, // ignore to eol | 22 s_eol, // ignore to eol |
18 end_state, | 23 end_state, |
19 | 24 |
20 s_term, // token terminator | 25 s_term, // token terminator |
21 s_single, | 26 s_single, |
22 s_string1, // first " of string | 27 s_string1, // first " of string |
23 s_string2, // last " of string | 28 s_string2, // last " of string |
24 s_slash // possible start of ignore to eol | 29 s_slash // possible start of ignore to eol |
25 }; | 30 }; |
26 | 31 |
27 typedef state PARSE[end_state]; | 32 typedef state PARSE[end_state]; |
28 | 33 |
29 static PARSE parse_table[256] = { | 34 static PARSE parse_table[256] = { |
30 // s_init s_token s_string s_ignore s_eol | 35 // s_init s_token s_string s_ignore s_eol |
31 { s_single, s_term, s_string, s_single, s_eol, }, // 0x00 | 36 { s_single, s_term, s_string, s_single, s_eol, }, // 0x00 |
32 { s_single, s_term, s_string, s_single, s_eol, }, // 0x01 | 37 { s_single, s_term, s_string, s_single, s_eol, }, // 0x01 |
33 { s_single, s_term, s_string, s_single, s_eol, }, // 0x02 | 38 { s_single, s_term, s_string, s_single, s_eol, }, // 0x02 |
34 { s_single, s_term, s_string, s_single, s_eol, }, // 0x03 | 39 { s_single, s_term, s_string, s_single, s_eol, }, // 0x03 |
35 { s_single, s_term, s_string, s_single, s_eol, }, // 0x04 | 40 { s_single, s_term, s_string, s_single, s_eol, }, // 0x04 |
36 { s_single, s_term, s_string, s_single, s_eol, }, // 0x05 | 41 { s_single, s_term, s_string, s_single, s_eol, }, // 0x05 |
37 { s_single, s_term, s_string, s_single, s_eol, }, // 0x06 | 42 { s_single, s_term, s_string, s_single, s_eol, }, // 0x06 |
38 { s_single, s_term, s_string, s_single, s_eol, }, // 0x07 | 43 { s_single, s_term, s_string, s_single, s_eol, }, // 0x07 |
39 { s_single, s_term, s_string, s_single, s_eol, }, // 0x08 | 44 { s_single, s_term, s_string, s_single, s_eol, }, // 0x08 |
40 { s_ignore, s_term, s_string, s_ignore, s_eol, }, // 0x09 <tab> | 45 { s_ignore, s_term, s_string, s_ignore, s_eol, }, // 0x09 <tab> |
41 { s_ignore, s_term, s_string2, s_ignore, s_ignore, }, // 0x0a <lf> | 46 { s_ignore, s_term, s_string2, s_ignore, s_ignore, }, // 0x0a <lf> |
42 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0b | 47 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0b |
43 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0c | 48 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0c |
44 { s_ignore, s_term, s_string2, s_ignore, s_eol, }, // 0x0d <cr> | 49 { s_ignore, s_term, s_string2, s_ignore, s_eol, }, // 0x0d <cr> |
45 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0e | 50 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0e |
46 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0f | 51 { s_single, s_term, s_string, s_single, s_eol, }, // 0x0f |
47 { s_single, s_term, s_string, s_single, s_eol, }, // 0x10 | 52 { s_single, s_term, s_string, s_single, s_eol, }, // 0x10 |
48 { s_single, s_term, s_string, s_single, s_eol, }, // 0x11 xon char | 53 { s_single, s_term, s_string, s_single, s_eol, }, // 0x11 xon char |
49 { s_single, s_term, s_string, s_single, s_eol, }, // 0x12 | 54 { s_single, s_term, s_string, s_single, s_eol, }, // 0x12 |
50 { s_single, s_term, s_string, s_single, s_eol, }, // 0x13 xoff char | 55 { s_single, s_term, s_string, s_single, s_eol, }, // 0x13 xoff char |
51 { s_single, s_term, s_string, s_single, s_eol, }, // 0x14 | 56 { s_single, s_term, s_string, s_single, s_eol, }, // 0x14 |
52 { s_single, s_term, s_string, s_single, s_eol, }, // 0x15 | 57 { s_single, s_term, s_string, s_single, s_eol, }, // 0x15 |
53 { s_single, s_term, s_string, s_single, s_eol, }, // 0x16 | 58 { s_single, s_term, s_string, s_single, s_eol, }, // 0x16 |
54 { s_single, s_term, s_string, s_single, s_eol, }, // 0x17 | 59 { s_single, s_term, s_string, s_single, s_eol, }, // 0x17 |
55 { s_single, s_term, s_string, s_single, s_eol, }, // 0x18 | 60 { s_single, s_term, s_string, s_single, s_eol, }, // 0x18 |
56 { s_single, s_term, s_string, s_single, s_eol, }, // 0x19 | 61 { s_single, s_term, s_string, s_single, s_eol, }, // 0x19 |
57 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1a | 62 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1a |
58 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1b | 63 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1b |
59 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1c | 64 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1c |
60 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1d | 65 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1d |
61 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1e | 66 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1e |
62 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1f | 67 { s_single, s_term, s_string, s_single, s_eol, }, // 0x1f |
63 { s_ignore, s_term, s_string, s_ignore, s_eol, }, // 0x20 space | 68 { s_ignore, s_term, s_string, s_ignore, s_eol, }, // 0x20 space |
64 { s_single, s_term, s_string, s_single, s_eol, }, // 0x21 ! | 69 { s_single, s_term, s_string, s_single, s_eol, }, // 0x21 ! |
65 { s_string1, s_term, s_string2, s_string1, s_eol, }, // 0x22 " | 70 { s_string1, s_term, s_string2, s_string1, s_eol, }, // 0x22 " |
66 { s_eol, s_term, s_string, s_eol, s_eol, }, // 0x23 # | 71 { s_eol, s_term, s_string, s_eol, s_eol, }, // 0x23 # |
67 { s_single, s_term, s_string, s_single, s_eol, }, // 0x24 $ | 72 { s_single, s_term, s_string, s_single, s_eol, }, // 0x24 $ |
68 { s_single, s_term, s_string, s_single, s_eol, }, // 0x25 % | 73 { s_single, s_term, s_string, s_single, s_eol, }, // 0x25 % |
69 { s_single, s_term, s_string, s_single, s_eol, }, // 0x26 & | 74 { s_single, s_term, s_string, s_single, s_eol, }, // 0x26 & |
70 { s_single, s_term, s_string, s_single, s_eol, }, // 0x27 ' | 75 { s_single, s_term, s_string, s_single, s_eol, }, // 0x27 ' |
71 { s_single, s_term, s_string, s_single, s_eol, }, // 0x28 ( | 76 { s_single, s_term, s_string, s_single, s_eol, }, // 0x28 ( |
72 { s_single, s_term, s_string, s_single, s_eol, }, // 0x29 ) | 77 { s_single, s_term, s_string, s_single, s_eol, }, // 0x29 ) |
73 { s_single, s_term, s_string, s_single, s_eol, }, // 0x2A * | 78 { s_single, s_term, s_string, s_single, s_eol, }, // 0x2A * |
74 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2B + | 79 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2B + |
75 { s_single, s_term, s_string, s_single, s_eol, }, // 0x2C , | 80 { s_single, s_term, s_string, s_single, s_eol, }, // 0x2C , |
76 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2D - | 81 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2D - |
77 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2E . | 82 { s_single, s_token, s_string, s_single, s_eol, }, // 0x2E . |
78 { s_slash, s_term, s_string, s_slash, s_eol, }, // 0x2F / | 83 { s_slash, s_term, s_string, s_slash, s_eol, }, // 0x2F / |
79 { s_token, s_token, s_string, s_token, s_eol, }, // 0x30 0 | 84 { s_token, s_token, s_string, s_token, s_eol, }, // 0x30 0 |
80 { s_token, s_token, s_string, s_token, s_eol, }, // 0x31 1 | 85 { s_token, s_token, s_string, s_token, s_eol, }, // 0x31 1 |
81 { s_token, s_token, s_string, s_token, s_eol, }, // 0x32 2 | 86 { s_token, s_token, s_string, s_token, s_eol, }, // 0x32 2 |
82 { s_token, s_token, s_string, s_token, s_eol, }, // 0x33 3 | 87 { s_token, s_token, s_string, s_token, s_eol, }, // 0x33 3 |
83 { s_token, s_token, s_string, s_token, s_eol, }, // 0x34 4 | 88 { s_token, s_token, s_string, s_token, s_eol, }, // 0x34 4 |
84 { s_token, s_token, s_string, s_token, s_eol, }, // 0x35 5 | 89 { s_token, s_token, s_string, s_token, s_eol, }, // 0x35 5 |
85 { s_token, s_token, s_string, s_token, s_eol, }, // 0x36 6 | 90 { s_token, s_token, s_string, s_token, s_eol, }, // 0x36 6 |
86 { s_token, s_token, s_string, s_token, s_eol, }, // 0x37 7 | 91 { s_token, s_token, s_string, s_token, s_eol, }, // 0x37 7 |
87 { s_token, s_token, s_string, s_token, s_eol, }, // 0x38 8 | 92 { s_token, s_token, s_string, s_token, s_eol, }, // 0x38 8 |
88 { s_token, s_token, s_string, s_token, s_eol, }, // 0x39 9 | 93 { s_token, s_token, s_string, s_token, s_eol, }, // 0x39 9 |
89 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3A : | 94 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3A : |
90 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3B ; | 95 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3B ; |
91 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3C < | 96 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3C < |
92 { s_single, s_token, s_string, s_single, s_eol, }, // 0x3D = | 97 { s_single, s_token, s_string, s_single, s_eol, }, // 0x3D = |
93 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3E > | 98 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3E > |
94 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3F ? | 99 { s_single, s_term, s_string, s_single, s_eol, }, // 0x3F ? |
95 { s_single, s_token, s_string, s_single, s_eol, }, // 0x40 @ | 100 { s_single, s_token, s_string, s_single, s_eol, }, // 0x40 @ |
96 { s_token, s_token, s_string, s_token, s_eol, }, // 0x41 A | 101 { s_token, s_token, s_string, s_token, s_eol, }, // 0x41 A |
97 { s_token, s_token, s_string, s_token, s_eol, }, // 0x42 B | 102 { s_token, s_token, s_string, s_token, s_eol, }, // 0x42 B |
98 { s_token, s_token, s_string, s_token, s_eol, }, // 0x43 C | 103 { s_token, s_token, s_string, s_token, s_eol, }, // 0x43 C |
99 { s_token, s_token, s_string, s_token, s_eol, }, // 0x44 D | 104 { s_token, s_token, s_string, s_token, s_eol, }, // 0x44 D |
100 { s_token, s_token, s_string, s_token, s_eol, }, // 0x45 E | 105 { s_token, s_token, s_string, s_token, s_eol, }, // 0x45 E |
101 { s_token, s_token, s_string, s_token, s_eol, }, // 0x46 F | 106 { s_token, s_token, s_string, s_token, s_eol, }, // 0x46 F |
102 { s_token, s_token, s_string, s_token, s_eol, }, // 0x47 G | 107 { s_token, s_token, s_string, s_token, s_eol, }, // 0x47 G |
103 { s_token, s_token, s_string, s_token, s_eol, }, // 0x48 H | 108 { s_token, s_token, s_string, s_token, s_eol, }, // 0x48 H |
104 { s_token, s_token, s_string, s_token, s_eol, }, // 0x49 I | 109 { s_token, s_token, s_string, s_token, s_eol, }, // 0x49 I |
105 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4A J | 110 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4A J |
106 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4B K | 111 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4B K |
107 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4C L | 112 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4C L |
108 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4D M | 113 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4D M |
109 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4E N | 114 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4E N |
110 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4F O | 115 { s_token, s_token, s_string, s_token, s_eol, }, // 0x4F O |
111 { s_token, s_token, s_string, s_token, s_eol, }, // 0x50 P | 116 { s_token, s_token, s_string, s_token, s_eol, }, // 0x50 P |
112 { s_token, s_token, s_string, s_token, s_eol, }, // 0x51 Q | 117 { s_token, s_token, s_string, s_token, s_eol, }, // 0x51 Q |
113 { s_token, s_token, s_string, s_token, s_eol, }, // 0x52 R | 118 { s_token, s_token, s_string, s_token, s_eol, }, // 0x52 R |
114 { s_token, s_token, s_string, s_token, s_eol, }, // 0x53 S | 119 { s_token, s_token, s_string, s_token, s_eol, }, // 0x53 S |
115 { s_token, s_token, s_string, s_token, s_eol, }, // 0x54 T | 120 { s_token, s_token, s_string, s_token, s_eol, }, // 0x54 T |
116 { s_token, s_token, s_string, s_token, s_eol, }, // 0x55 U | 121 { s_token, s_token, s_string, s_token, s_eol, }, // 0x55 U |
117 { s_token, s_token, s_string, s_token, s_eol, }, // 0x56 V | 122 { s_token, s_token, s_string, s_token, s_eol, }, // 0x56 V |
118 { s_token, s_token, s_string, s_token, s_eol, }, // 0x57 W | 123 { s_token, s_token, s_string, s_token, s_eol, }, // 0x57 W |
119 { s_token, s_token, s_string, s_token, s_eol, }, // 0x58 X | 124 { s_token, s_token, s_string, s_token, s_eol, }, // 0x58 X |
120 { s_token, s_token, s_string, s_token, s_eol, }, // 0x59 Y | 125 { s_token, s_token, s_string, s_token, s_eol, }, // 0x59 Y |
121 { s_token, s_token, s_string, s_token, s_eol, }, // 0x5A Z | 126 { s_token, s_token, s_string, s_token, s_eol, }, // 0x5A Z |
122 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5B [ | 127 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5B [ |
123 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5C backslash | 128 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5C backslash |
124 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5D ] | 129 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5D ] |
125 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5E ^ | 130 { s_single, s_term, s_string, s_single, s_eol, }, // 0x5E ^ |
126 { s_single, s_token, s_string, s_single, s_eol, }, // 0x5F _ | 131 { s_single, s_token, s_string, s_single, s_eol, }, // 0x5F _ |
127 { s_single, s_term, s_string, s_single, s_eol, }, // 0x60 ` | 132 { s_single, s_term, s_string, s_single, s_eol, }, // 0x60 ` |
128 { s_token, s_token, s_string, s_token, s_eol, }, // 0x61 a | 133 { s_token, s_token, s_string, s_token, s_eol, }, // 0x61 a |
129 { s_token, s_token, s_string, s_token, s_eol, }, // 0x62 b | 134 { s_token, s_token, s_string, s_token, s_eol, }, // 0x62 b |
130 { s_token, s_token, s_string, s_token, s_eol, }, // 0x63 c | 135 { s_token, s_token, s_string, s_token, s_eol, }, // 0x63 c |
131 { s_token, s_token, s_string, s_token, s_eol, }, // 0x64 d | 136 { s_token, s_token, s_string, s_token, s_eol, }, // 0x64 d |
132 { s_token, s_token, s_string, s_token, s_eol, }, // 0x65 e | 137 { s_token, s_token, s_string, s_token, s_eol, }, // 0x65 e |
133 { s_token, s_token, s_string, s_token, s_eol, }, // 0x66 f | 138 { s_token, s_token, s_string, s_token, s_eol, }, // 0x66 f |
134 { s_token, s_token, s_string, s_token, s_eol, }, // 0x67 g | 139 { s_token, s_token, s_string, s_token, s_eol, }, // 0x67 g |
135 { s_token, s_token, s_string, s_token, s_eol, }, // 0x68 h | 140 { s_token, s_token, s_string, s_token, s_eol, }, // 0x68 h |
136 { s_token, s_token, s_string, s_token, s_eol, }, // 0x69 i | 141 { s_token, s_token, s_string, s_token, s_eol, }, // 0x69 i |
137 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6A j | 142 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6A j |
138 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6B k | 143 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6B k |
139 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6C l | 144 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6C l |
140 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6D m | 145 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6D m |
141 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6E n | 146 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6E n |
142 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6F o | 147 { s_token, s_token, s_string, s_token, s_eol, }, // 0x6F o |
143 { s_token, s_token, s_string, s_token, s_eol, }, // 0x70 p | 148 { s_token, s_token, s_string, s_token, s_eol, }, // 0x70 p |
144 { s_token, s_token, s_string, s_token, s_eol, }, // 0x71 q | 149 { s_token, s_token, s_string, s_token, s_eol, }, // 0x71 q |
145 { s_token, s_token, s_string, s_token, s_eol, }, // 0x72 r | 150 { s_token, s_token, s_string, s_token, s_eol, }, // 0x72 r |
146 { s_token, s_token, s_string, s_token, s_eol, }, // 0x73 s | 151 { s_token, s_token, s_string, s_token, s_eol, }, // 0x73 s |
147 { s_token, s_token, s_string, s_token, s_eol, }, // 0x74 t | 152 { s_token, s_token, s_string, s_token, s_eol, }, // 0x74 t |
148 { s_token, s_token, s_string, s_token, s_eol, }, // 0x75 u | 153 { s_token, s_token, s_string, s_token, s_eol, }, // 0x75 u |
149 { s_token, s_token, s_string, s_token, s_eol, }, // 0x76 v | 154 { s_token, s_token, s_string, s_token, s_eol, }, // 0x76 v |
150 { s_token, s_token, s_string, s_token, s_eol, }, // 0x77 w | 155 { s_token, s_token, s_string, s_token, s_eol, }, // 0x77 w |
151 { s_token, s_token, s_string, s_token, s_eol, }, // 0x78 x | 156 { s_token, s_token, s_string, s_token, s_eol, }, // 0x78 x |
152 { s_token, s_token, s_string, s_token, s_eol, }, // 0x79 y | 157 { s_token, s_token, s_string, s_token, s_eol, }, // 0x79 y |
153 { s_token, s_token, s_string, s_token, s_eol, }, // 0x7A z | 158 { s_token, s_token, s_string, s_token, s_eol, }, // 0x7A z |
154 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7B { | 159 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7B { |
155 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7C | | 160 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7C | |
156 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7D } | 161 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7D } |
157 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7E ~ | 162 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7E ~ |
158 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7f | 163 { s_single, s_term, s_string, s_single, s_eol, }, // 0x7f |
159 { s_single, s_term, s_string, s_single, s_eol, }, // 0x80 | 164 { s_single, s_term, s_string, s_single, s_eol, }, // 0x80 |
160 { s_single, s_term, s_string, s_single, s_eol, }, // 0x81 | 165 { s_single, s_term, s_string, s_single, s_eol, }, // 0x81 |
161 { s_single, s_term, s_string, s_single, s_eol, }, // 0x82 | 166 { s_single, s_term, s_string, s_single, s_eol, }, // 0x82 |
162 { s_single, s_term, s_string, s_single, s_eol, }, // 0x83 | 167 { s_single, s_term, s_string, s_single, s_eol, }, // 0x83 |
163 { s_single, s_term, s_string, s_single, s_eol, }, // 0x84 | 168 { s_single, s_term, s_string, s_single, s_eol, }, // 0x84 |
164 { s_single, s_term, s_string, s_single, s_eol, }, // 0x85 | 169 { s_single, s_term, s_string, s_single, s_eol, }, // 0x85 |
165 { s_single, s_term, s_string, s_single, s_eol, }, // 0x86 | 170 { s_single, s_term, s_string, s_single, s_eol, }, // 0x86 |
166 { s_single, s_term, s_string, s_single, s_eol, }, // 0x87 | 171 { s_single, s_term, s_string, s_single, s_eol, }, // 0x87 |
167 { s_single, s_term, s_string, s_single, s_eol, }, // 0x88 | 172 { s_single, s_term, s_string, s_single, s_eol, }, // 0x88 |
168 { s_single, s_term, s_string, s_single, s_eol, }, // 0x89 | 173 { s_single, s_term, s_string, s_single, s_eol, }, // 0x89 |
169 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8a | 174 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8a |
170 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8b | 175 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8b |
171 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8c | 176 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8c |
172 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8d | 177 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8d |
173 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8e | 178 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8e |
174 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8f | 179 { s_single, s_term, s_string, s_single, s_eol, }, // 0x8f |
175 { s_single, s_term, s_string, s_single, s_eol, }, // 0x90 | 180 { s_single, s_term, s_string, s_single, s_eol, }, // 0x90 |
176 { s_single, s_term, s_string, s_single, s_eol, }, // 0x91 | 181 { s_single, s_term, s_string, s_single, s_eol, }, // 0x91 |
177 { s_single, s_term, s_string, s_single, s_eol, }, // 0x92 | 182 { s_single, s_term, s_string, s_single, s_eol, }, // 0x92 |
178 { s_single, s_term, s_string, s_single, s_eol, }, // 0x93 | 183 { s_single, s_term, s_string, s_single, s_eol, }, // 0x93 |
179 { s_single, s_term, s_string, s_single, s_eol, }, // 0x94 | 184 { s_single, s_term, s_string, s_single, s_eol, }, // 0x94 |
180 { s_single, s_term, s_string, s_single, s_eol, }, // 0x95 | 185 { s_single, s_term, s_string, s_single, s_eol, }, // 0x95 |
181 { s_single, s_term, s_string, s_single, s_eol, }, // 0x96 | 186 { s_single, s_term, s_string, s_single, s_eol, }, // 0x96 |
182 { s_single, s_term, s_string, s_single, s_eol, }, // 0x97 | 187 { s_single, s_term, s_string, s_single, s_eol, }, // 0x97 |
183 { s_single, s_term, s_string, s_single, s_eol, }, // 0x98 | 188 { s_single, s_term, s_string, s_single, s_eol, }, // 0x98 |
184 { s_single, s_term, s_string, s_single, s_eol, }, // 0x99 | 189 { s_single, s_term, s_string, s_single, s_eol, }, // 0x99 |
185 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9a | 190 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9a |
186 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9b | 191 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9b |
187 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9c | 192 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9c |
188 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9d | 193 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9d |
189 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9e | 194 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9e |
190 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9f | 195 { s_single, s_term, s_string, s_single, s_eol, }, // 0x9f |
191 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa0 | 196 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa0 |
192 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa1 | 197 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa1 |
193 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa2 | 198 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa2 |
194 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa3 | 199 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa3 |
195 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa4 | 200 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa4 |
196 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa5 | 201 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa5 |
197 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa6 | 202 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa6 |
198 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa7 | 203 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa7 |
199 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa8 | 204 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa8 |
200 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa9 | 205 { s_single, s_term, s_string, s_single, s_eol, }, // 0xa9 |
201 { s_single, s_term, s_string, s_single, s_eol, }, // 0xaa | 206 { s_single, s_term, s_string, s_single, s_eol, }, // 0xaa |
202 { s_single, s_term, s_string, s_single, s_eol, }, // 0xab | 207 { s_single, s_term, s_string, s_single, s_eol, }, // 0xab |
203 { s_single, s_term, s_string, s_single, s_eol, }, // 0xac | 208 { s_single, s_term, s_string, s_single, s_eol, }, // 0xac |
204 { s_single, s_term, s_string, s_single, s_eol, }, // 0xad | 209 { s_single, s_term, s_string, s_single, s_eol, }, // 0xad |
205 { s_single, s_term, s_string, s_single, s_eol, }, // 0xae | 210 { s_single, s_term, s_string, s_single, s_eol, }, // 0xae |
206 { s_single, s_term, s_string, s_single, s_eol, }, // 0xaf | 211 { s_single, s_term, s_string, s_single, s_eol, }, // 0xaf |
207 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb0 | 212 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb0 |
208 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb1 | 213 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb1 |
209 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb2 | 214 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb2 |
210 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb3 | 215 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb3 |
211 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb4 | 216 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb4 |
212 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb5 | 217 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb5 |
213 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb6 | 218 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb6 |
214 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb7 | 219 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb7 |
215 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb8 | 220 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb8 |
216 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb9 | 221 { s_single, s_term, s_string, s_single, s_eol, }, // 0xb9 |
217 { s_single, s_term, s_string, s_single, s_eol, }, // 0xba | 222 { s_single, s_term, s_string, s_single, s_eol, }, // 0xba |
218 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbb | 223 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbb |
219 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbc | 224 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbc |
220 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbd | 225 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbd |
221 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbe | 226 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbe |
222 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbf | 227 { s_single, s_term, s_string, s_single, s_eol, }, // 0xbf |
223 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc0 | 228 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc0 |
224 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc1 | 229 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc1 |
225 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc2 | 230 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc2 |
226 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc3 | 231 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc3 |
227 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc4 | 232 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc4 |
228 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc5 | 233 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc5 |
229 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc6 | 234 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc6 |
230 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc7 | 235 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc7 |
231 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc8 | 236 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc8 |
232 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc9 | 237 { s_single, s_term, s_string, s_single, s_eol, }, // 0xc9 |
233 { s_single, s_term, s_string, s_single, s_eol, }, // 0xca | 238 { s_single, s_term, s_string, s_single, s_eol, }, // 0xca |
234 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcb | 239 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcb |
235 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcc | 240 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcc |
236 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcd | 241 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcd |
237 { s_single, s_term, s_string, s_single, s_eol, }, // 0xce | 242 { s_single, s_term, s_string, s_single, s_eol, }, // 0xce |
238 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcf | 243 { s_single, s_term, s_string, s_single, s_eol, }, // 0xcf |
239 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd0 | 244 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd0 |
240 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd1 | 245 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd1 |
241 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd2 | 246 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd2 |
242 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd3 | 247 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd3 |
243 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd4 | 248 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd4 |
244 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd5 | 249 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd5 |
245 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd6 | 250 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd6 |
246 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd7 | 251 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd7 |
247 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd8 | 252 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd8 |
248 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd9 | 253 { s_single, s_term, s_string, s_single, s_eol, }, // 0xd9 |
249 { s_single, s_term, s_string, s_single, s_eol, }, // 0xda | 254 { s_single, s_term, s_string, s_single, s_eol, }, // 0xda |
250 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdb | 255 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdb |
251 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdc | 256 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdc |
252 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdd | 257 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdd |
253 { s_single, s_term, s_string, s_single, s_eol, }, // 0xde | 258 { s_single, s_term, s_string, s_single, s_eol, }, // 0xde |
254 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdf | 259 { s_single, s_term, s_string, s_single, s_eol, }, // 0xdf |
255 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe0 | 260 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe0 |
256 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe1 | 261 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe1 |
257 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe2 | 262 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe2 |
258 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe3 | 263 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe3 |
259 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe4 | 264 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe4 |
260 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe5 | 265 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe5 |
261 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe6 | 266 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe6 |
262 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe7 | 267 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe7 |
263 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe8 | 268 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe8 |
264 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe9 | 269 { s_single, s_term, s_string, s_single, s_eol, }, // 0xe9 |
265 { s_single, s_term, s_string, s_single, s_eol, }, // 0xea | 270 { s_single, s_term, s_string, s_single, s_eol, }, // 0xea |
266 { s_single, s_term, s_string, s_single, s_eol, }, // 0xeb | 271 { s_single, s_term, s_string, s_single, s_eol, }, // 0xeb |
267 { s_single, s_term, s_string, s_single, s_eol, }, // 0xec | 272 { s_single, s_term, s_string, s_single, s_eol, }, // 0xec |
268 { s_single, s_term, s_string, s_single, s_eol, }, // 0xed | 273 { s_single, s_term, s_string, s_single, s_eol, }, // 0xed |
269 { s_single, s_term, s_string, s_single, s_eol, }, // 0xee | 274 { s_single, s_term, s_string, s_single, s_eol, }, // 0xee |
270 { s_single, s_term, s_string, s_single, s_eol, }, // 0xef | 275 { s_single, s_term, s_string, s_single, s_eol, }, // 0xef |
271 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf0 | 276 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf0 |
272 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf1 | 277 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf1 |
273 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf2 | 278 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf2 |
274 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf3 | 279 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf3 |
275 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf4 | 280 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf4 |
276 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf5 | 281 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf5 |
277 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf6 | 282 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf6 |
278 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf7 | 283 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf7 |
279 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf8 | 284 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf8 |
280 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf9 | 285 { s_single, s_term, s_string, s_single, s_eol, }, // 0xf9 |
281 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfa | 286 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfa |
282 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfb | 287 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfb |
283 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfc | 288 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfc |
284 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfd | 289 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfd |
285 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfe | 290 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfe |
286 { s_single, s_term, s_string, s_single, s_eol, }, // 0xff | 291 { s_single, s_term, s_string, s_single, s_eol, }, // 0xff |
287 }; | 292 }; |
288 | 293 |
289 | 294 |
290 TOKEN::TOKEN(char *fn, string_set *includes) { | 295 TOKEN::TOKEN(const char *fn, string_set *includes) { |
291 pushed = false; | 296 pushed = false; |
292 include_files = includes; | 297 include_files = includes; |
293 include(fn); | 298 include(fn); |
294 } | 299 } |
295 | 300 |
296 | 301 |
297 TOKEN::~TOKEN() { | 302 TOKEN::~TOKEN() { |
298 while (!streams.empty()) pop(); | 303 while (!streams.empty()) pop(); |
299 } | 304 } |
300 | 305 |
301 | 306 |
302 void TOKEN::pop() { | 307 void TOKEN::pop() { |
303 ifstream *is = streams.front(); | 308 ifstream *is = streams.front(); |
304 char *fn = filenames.front(); | 309 const char *fn = filenames.front(); |
305 streams.pop_front(); | 310 streams.pop_front(); |
306 filenamess.erase(fn); | 311 filenamess.erase(fn); |
307 if (filenames.size() > 1) filenames.pop_front(); | 312 if (filenames.size() > 1) filenames.pop_front(); |
308 if (linenumbers.size() > 1) linenumbers.pop_front(); | 313 if (linenumbers.size() > 1) linenumbers.pop_front(); |
309 is->close(); | 314 is->close(); |
310 delete is; | 315 delete is; |
311 } | 316 } |
312 | 317 |
313 | 318 |
314 void TOKEN::push_char(u_char c) { | 319 void TOKEN::push_char(u_char c) { |
315 pushed = true; | 320 pushed = true; |
316 pushed_char = c; | 321 pushed_char = c; |
317 } | 322 } |
318 | 323 |
319 | 324 |
320 bool TOKEN::next_char(u_char &uc) { | 325 bool TOKEN::next_char(u_char &uc) { |
321 if (pushed) { | 326 if (pushed) { |
322 //uc = (u_char)tolower((char)pushed_char); | 327 uc = pushed_char; |
323 uc = pushed_char; | 328 pushed = false; |
324 pushed = false; | 329 return true; |
325 return true; | 330 } |
326 } | 331 while (!streams.empty() && streams.front()->eof()) { |
327 while (!streams.empty() && streams.front()->eof()) { | 332 pop(); |
328 pop(); | 333 } |
329 } | 334 if (streams.empty()) return false; |
330 if (streams.empty()) return false; | 335 ifstream *is = streams.front(); |
331 ifstream *is = streams.front(); | 336 uc = (u_char)is->get(); |
332 uc = (u_char)is->get(); | 337 if (is->eof()) return next_char(uc); |
333 if (is->eof()) return next_char(uc); | 338 if (uc == (u_char)'\n') { |
334 if (uc == (u_char)'\n') { | 339 int &line = linenumbers.front(); |
335 int &line = linenumbers.front(); | 340 line++; |
336 line++; | 341 } |
337 } | 342 return true; |
338 //uc = (u_char)tolower((char)uc); | 343 } |
339 return true; | 344 |
340 } | 345 |
341 | 346 bool TOKEN::include(const char *fn) { |
342 | 347 string_set::iterator i = filenamess.find(fn); |
343 bool TOKEN::include(char *fn) { | 348 if (i != filenamess.end()) { |
344 string_set::iterator i = filenamess.find(fn); | 349 token_error("redundant or recursive include file detected"); |
345 if (i != filenamess.end()) { | 350 return false; |
346 token_error("redundant or recursive include file detected"); | 351 } |
347 return false; | 352 ifstream *is = new ifstream; |
348 } | 353 is->open(fn); |
349 ifstream *is = new ifstream; | 354 if (is->fail()) { |
350 is->open(fn); | 355 char buf[maxlen]; |
351 if (is->fail()) { | 356 snprintf(buf, sizeof(buf), "include file %s not found", fn); |
352 char buf[maxlen]; | 357 token_error(buf); |
353 snprintf(buf, sizeof(buf), "include file %s not found", fn); | 358 return false; |
354 token_error(buf); | 359 } |
355 return false; | 360 string_set &inc = *include_files; |
356 } | 361 inc.insert(fn); |
357 string_set &inc = *include_files; | 362 streams.push_front(is); |
358 inc.insert(fn); | 363 filenames.push_front(fn); |
359 streams.push_front(is); | 364 filenamess.insert(fn); |
360 filenames.push_front(fn); | 365 linenumbers.push_front(1); |
361 filenamess.insert(fn); | 366 return true; |
362 linenumbers.push_front(1); | 367 } |
363 return true; | 368 |
364 } | 369 |
365 | 370 const char *TOKEN::next() { |
366 | 371 if (!pending_tokens.empty()) { |
367 char *TOKEN::next() { | 372 const char *t = pending_tokens.front(); |
368 if (!pending_tokens.empty()) { | 373 pending_tokens.pop_front(); |
369 char *t = pending_tokens.front(); | 374 return t; |
370 pending_tokens.pop_front(); | 375 } |
371 return t; | 376 if (streams.empty()) return NULL; |
372 } | 377 const int PENDING_LIMIT = 1000; |
373 if (streams.empty()) return NULL; | 378 u_char buffer[PENDING_LIMIT]; |
374 const int PENDING_LIMIT = 1000; | 379 int count = 0; |
375 static u_char buffer[PENDING_LIMIT]; | 380 state st = s_init; |
376 int count = 0; | 381 while (true) { |
377 state st = s_init; | 382 if (count == (PENDING_LIMIT-1)) { |
378 while (true) { | 383 token_error("token too long"); |
379 if (count == (PENDING_LIMIT-1)) { | 384 break; |
380 token_error("token too long"); | 385 } |
381 break; | 386 if (st >= end_state) { |
382 } | 387 token_error("finite state machine error"); |
383 if (st >= end_state) { | 388 break; |
384 token_error("finite state machine error"); | 389 } |
385 break; | 390 u_char c; |
386 } | 391 if (!next_char(c)) break; |
387 u_char c; | 392 st = parse_table[c][st]; |
388 if (!next_char(c)) break; | 393 switch (st) { |
389 st = parse_table[c][st]; | 394 case s_string: |
390 switch (st) { | 395 case s_token: { |
391 case s_string: | 396 buffer[count++] = c; |
392 case s_token: { | 397 } break; |
393 buffer[count++] = c; | 398 |
394 } break; | 399 case s_term: { |
395 | 400 push_char(c); |
396 case s_term: { | 401 st = s_init; |
397 push_char(c); | 402 } break; |
398 st = s_init; | 403 |
399 } break; | 404 case s_string1: { |
400 | 405 st = s_string; |
401 case s_string1: { | 406 } break; |
402 st = s_string; | 407 |
403 } break; | 408 case s_string2: { |
404 | 409 st = s_init; |
405 case s_string2: { | 410 } break; |
406 st = s_init; | 411 |
407 } break; | 412 case s_single: { |
408 | 413 buffer[count++] = c; |
409 case s_single: { | 414 st = s_init; |
410 buffer[count++] = c; | 415 } break; |
411 st = s_init; | 416 |
412 } break; | 417 case s_ignore: |
413 | 418 case s_eol: { |
414 case s_ignore: | 419 } break; |
415 case s_eol: { | 420 |
416 } break; | 421 |
417 | 422 case s_slash: { |
418 | 423 buffer[count++] = c; |
419 case s_slash: { | 424 if (next_char(c)) { |
420 buffer[count++] = c; | 425 if (c == (u_char)'/') { |
421 if (next_char(c)) { | 426 // start of ignore to eol on // |
422 if (c == (u_char)'/') { | 427 count--; |
423 // start of ignore to eol on // | 428 st = s_eol; |
424 count--; | 429 } |
425 st = s_eol; | 430 else { |
426 } | 431 // not a // token, just return this single / |
427 else { | 432 push_char(c); |
428 // not a // token, just return this single / | 433 st = s_init; |
429 push_char(c); | 434 } |
430 st = s_init; | 435 } |
431 } | 436 else { |
432 } | 437 // cannot get another char |
433 else { | 438 st = s_init; |
434 // cannot get another char | 439 } |
435 st = s_init; | 440 } break; |
436 } | 441 |
437 } break; | 442 default: { |
438 | 443 token_error(); |
439 default: { | 444 token_error("unknown state %d %s", st, " "); |
440 token_error(); | 445 } break; |
441 token_error("unknown state %d %s \n", st, " "); | 446 } |
442 } break; | 447 if (st == s_init) break; |
443 } | 448 } |
444 if (st == s_init) break; | 449 |
445 } | 450 buffer[count] = '\0'; |
446 | 451 if (count == 0) return NULL; |
447 buffer[count] = '\0'; | 452 const char *t = register_string((char*)buffer); |
448 if (count == 0) return NULL; | 453 if (t == token_include) { |
449 char *t = register_string((char*)buffer); | 454 const char *f = next(); // should be file name |
450 if (t == token_include) { | 455 const char *s = next(); // should be semicolon |
451 char *f = next(); // should be file name | 456 if (s == token_semi) { |
452 char *s = next(); // should be semicolon | 457 include(f); |
453 if (s == token_semi) { | 458 return next(); |
454 include(f); | 459 } |
455 return next(); | 460 else { |
456 } | 461 push(s); |
457 else { | 462 push(f); |
458 push(s); | 463 return t; |
459 push(f); | 464 } |
460 return t; | 465 } |
461 } | 466 return t; |
462 } | |
463 return t; | |
464 } | 467 } |
465 | 468 |
466 | 469 |
467 int TOKEN::nextint() { | 470 int TOKEN::nextint() { |
468 char *t = next(); | 471 const char *t = next(); |
469 char *e; | 472 char *e; |
470 long i = strtol(t, &e, 10); | 473 long i = strtol(t, &e, 10); |
471 if (*e != '\0') { | 474 if (*e != '\0') { |
472 token_error("integer", t); | 475 token_error("integer", t); |
473 return 0; | 476 return 0; |
474 } | 477 } |
475 return (int)i; | 478 return (int)i; |
476 } | 479 } |
477 | 480 |
478 | 481 |
479 void TOKEN::skipeol() { | 482 void TOKEN::skipeol() { |
480 while (true) { | 483 while (true) { |
481 u_char c; | 484 u_char c; |
482 if (!next_char(c)) break; | 485 if (!next_char(c)) break; |
483 if (c == (u_char)'\n') break; | 486 if (c == (u_char)'\n') break; |
484 } | 487 } |
485 } | 488 } |
486 | 489 |
487 | 490 |
488 void TOKEN::token_error(const char *err) { | 491 void TOKEN::token_error(const char *err) { |
489 token_error(); | 492 token_error(); |
490 char buf[maxlen]; | 493 char buf[maxlen]; |
491 snprintf(buf, sizeof(buf), "%s \n", err); | 494 snprintf(buf, sizeof(buf), "%s \n", err); |
492 my_syslog(buf); | 495 my_syslog(buf); |
493 } | 496 } |
494 | 497 |
495 | 498 |
496 void TOKEN::token_error(const char *fmt, int d, const char *s) { | 499 void TOKEN::token_error(const char *fmt, int d, const char *s) { |
497 char buf[maxlen]; | 500 char buf[maxlen]; |
498 snprintf(buf, sizeof(buf), fmt, d, s); | 501 snprintf(buf, sizeof(buf), fmt, d, s); |
499 my_syslog(buf); | 502 my_syslog(buf); |
500 } | 503 } |
501 | 504 |
502 | 505 |
503 void TOKEN::token_error(const char *fmt, const char *t, const char *h) { | 506 void TOKEN::token_error(const char *fmt, const char *t, const char *h) { |
504 if (!h) h = "null"; | 507 if (!h) h = "null"; |
505 char buf[maxlen]; | 508 char buf[maxlen]; |
506 snprintf(buf, sizeof(buf), fmt, t, h); | 509 snprintf(buf, sizeof(buf), fmt, t, h); |
507 my_syslog(buf); | 510 my_syslog(buf); |
508 } | 511 } |
509 | 512 |
510 | 513 |
511 void TOKEN::token_error(const char *want, const char *have) { | 514 void TOKEN::token_error(const char *want, const char *have) { |
512 token_error(); | 515 token_error(); |
513 token_error("expecting %s, found %s", want, have); | 516 token_error("expecting %s, found %s", want, have); |
514 } | 517 } |
515 | 518 |
516 | 519 |
517 void TOKEN::token_error() { | 520 void TOKEN::token_error() { |
518 token_error("syntax error at line %d in file %s -- ", cur_line(), cur_fn()); | 521 token_error("syntax error at line %d in file %s -- ", cur_line(), cur_fn()); |
519 line_list::iterator j = linenumbers.begin(); | 522 line_list::iterator j = linenumbers.begin(); |
520 string_list::iterator i = filenames.begin(); | 523 string_list::const_iterator i = filenames.begin(); |
521 for (; i!=filenames.end(); i++,j++) { | 524 for (; i!=filenames.end(); i++,j++) { |
522 if (i != filenames.begin()) { | 525 if (i != filenames.begin()) { |
523 char *fn = (*i); | 526 const char *fn = (*i); |
524 int li = (*j); | 527 int li = (*j); |
525 token_error(" included from line %d in file %s -- ", li, fn); | 528 token_error(" included from line %d in file %s -- ", li, fn); |
526 } | 529 } |
527 } | 530 } |
528 } | 531 } |
529 | 532 |