annotate src/tokenizer.cpp @ 17:8ebecad6530f stable-1-6

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