annotate src/tokenizer.cpp @ 16:ae2767aabdbc

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