annotate src/tokenizer.cpp @ 42:d9ae11033b4b stable-1-9

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