annotate src/tokenizer.cpp @ 37:e4eb969dfc4a

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