annotate src/tokenizer.cpp @ 4:311e331f1bab

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