ox 2.14.13 → 2.14.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/ext/ox/attr.h +33 -39
- data/ext/ox/base64.c +48 -42
- data/ext/ox/base64.h +4 -4
- data/ext/ox/buf.h +80 -86
- data/ext/ox/builder.c +378 -423
- data/ext/ox/cache.c +2 -2
- data/ext/ox/cache8.c +37 -40
- data/ext/ox/cache8.h +7 -7
- data/ext/ox/dump.c +838 -867
- data/ext/ox/err.c +16 -13
- data/ext/ox/err.h +11 -12
- data/ext/ox/extconf.rb +5 -5
- data/ext/ox/gen_load.c +135 -137
- data/ext/ox/hash_load.c +130 -148
- data/ext/ox/helper.h +32 -39
- data/ext/ox/intern.c +1 -2
- data/ext/ox/obj_load.c +590 -644
- data/ext/ox/ox.c +2 -2
- data/ext/ox/ox.h +5 -5
- data/ext/ox/parse.c +836 -874
- data/ext/ox/sax.c +38 -23
- data/ext/ox/sax.h +2 -2
- data/ext/ox/sax_as.c +78 -94
- data/ext/ox/sax_buf.c +85 -94
- data/ext/ox/sax_buf.h +101 -120
- data/ext/ox/sax_hint.c +175 -184
- data/ext/ox/sax_hint.h +19 -19
- data/ext/ox/sax_stack.h +59 -45
- data/ext/ox/slotcache.c +2 -2
- data/ext/ox/slotcache.h +4 -4
- data/ext/ox/special.c +320 -327
- data/ext/ox/special.h +2 -2
- data/ext/ox/type.h +19 -19
- data/lib/ox/bag.rb +13 -9
- data/lib/ox/cdata.rb +0 -2
- data/lib/ox/comment.rb +0 -2
- data/lib/ox/doctype.rb +0 -2
- data/lib/ox/document.rb +3 -5
- data/lib/ox/element.rb +41 -26
- data/lib/ox/error.rb +0 -3
- data/lib/ox/hasattrs.rb +7 -8
- data/lib/ox/instruct.rb +4 -6
- data/lib/ox/node.rb +3 -4
- data/lib/ox/raw.rb +0 -2
- data/lib/ox/sax.rb +20 -36
- data/lib/ox/version.rb +1 -2
- data/lib/ox/xmlrpc_adapter.rb +4 -6
- data/lib/ox.rb +15 -16
- metadata +6 -5
data/ext/ox/obj_load.c
CHANGED
@@ -3,112 +3,107 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#include <stdlib.h>
|
7
6
|
#include <errno.h>
|
7
|
+
#include <stdarg.h>
|
8
8
|
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
9
10
|
#include <string.h>
|
10
|
-
#include <stdarg.h>
|
11
11
|
#include <time.h>
|
12
12
|
|
13
|
-
#include "ruby.h"
|
14
|
-
#include "ruby/encoding.h"
|
15
|
-
|
16
13
|
#include "base64.h"
|
17
|
-
#include "ox.h"
|
18
14
|
#include "intern.h"
|
15
|
+
#include "ox.h"
|
16
|
+
#include "ruby.h"
|
17
|
+
#include "ruby/encoding.h"
|
19
18
|
|
20
|
-
static void
|
21
|
-
static void
|
22
|
-
static void
|
23
|
-
static void
|
24
|
-
|
25
|
-
static VALUE
|
26
|
-
static VALUE
|
27
|
-
static VALUE
|
28
|
-
static VALUE
|
29
|
-
|
30
|
-
static ID
|
31
|
-
static VALUE
|
32
|
-
static VALUE
|
33
|
-
static VALUE
|
34
|
-
static unsigned long
|
35
|
-
static CircArray
|
36
|
-
static void
|
37
|
-
static void
|
38
|
-
static VALUE
|
39
|
-
|
40
|
-
static void
|
41
|
-
static void
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
0,
|
47
|
-
0,
|
48
|
-
0, // add_cdata,
|
19
|
+
static void instruct(PInfo pi, const char *target, Attr attrs, const char *content);
|
20
|
+
static void add_text(PInfo pi, char *text, int closed);
|
21
|
+
static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren);
|
22
|
+
static void end_element(PInfo pi, const char *ename);
|
23
|
+
|
24
|
+
static VALUE parse_time(const char *text, VALUE clas);
|
25
|
+
static VALUE parse_xsd_time(const char *text, VALUE clas);
|
26
|
+
static VALUE parse_double_time(const char *text, VALUE clas);
|
27
|
+
static VALUE parse_regexp(const char *text);
|
28
|
+
|
29
|
+
static ID get_var_sym_from_attrs(Attr a, void *encoding);
|
30
|
+
static VALUE get_obj_from_attrs(Attr a, PInfo pi, VALUE base_class);
|
31
|
+
static VALUE get_class_from_attrs(Attr a, PInfo pi, VALUE base_class);
|
32
|
+
static VALUE classname2class(const char *name, PInfo pi, VALUE base_class);
|
33
|
+
static unsigned long get_id_from_attrs(PInfo pi, Attr a);
|
34
|
+
static CircArray circ_array_new(void);
|
35
|
+
static void circ_array_free(CircArray ca);
|
36
|
+
static void circ_array_set(CircArray ca, VALUE obj, unsigned long id);
|
37
|
+
static VALUE circ_array_get(CircArray ca, unsigned long id);
|
38
|
+
|
39
|
+
static void debug_stack(PInfo pi, const char *comment);
|
40
|
+
static void fill_indent(PInfo pi, char *buf, size_t size);
|
41
|
+
|
42
|
+
struct _parseCallbacks _ox_obj_callbacks = {
|
43
|
+
instruct, // instruct,
|
44
|
+
0, // add_doctype,
|
45
|
+
0, // add_comment,
|
46
|
+
0, // add_cdata,
|
49
47
|
add_text,
|
50
48
|
add_element,
|
51
49
|
end_element,
|
52
50
|
NULL,
|
53
51
|
};
|
54
52
|
|
55
|
-
ParseCallbacks
|
53
|
+
ParseCallbacks ox_obj_callbacks = &_ox_obj_callbacks;
|
56
54
|
|
57
|
-
extern ParseCallbacks
|
55
|
+
extern ParseCallbacks ox_gen_callbacks;
|
58
56
|
|
59
|
-
inline static VALUE
|
60
|
-
|
61
|
-
|
62
|
-
ID ci = rb_intern(class_name);
|
57
|
+
inline static VALUE resolve_classname(VALUE mod, const char *class_name, Effort effort, VALUE base_class) {
|
58
|
+
VALUE clas;
|
59
|
+
ID ci = rb_intern(class_name);
|
63
60
|
|
64
61
|
switch (effort) {
|
65
62
|
case TolerantEffort:
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
if (rb_const_defined_at(mod, ci)) {
|
64
|
+
clas = rb_const_get_at(mod, ci);
|
65
|
+
} else {
|
66
|
+
clas = Qundef;
|
67
|
+
}
|
68
|
+
break;
|
72
69
|
case AutoEffort:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
if (rb_const_defined_at(mod, ci)) {
|
71
|
+
clas = rb_const_get_at(mod, ci);
|
72
|
+
} else {
|
73
|
+
clas = rb_define_class_under(mod, class_name, base_class);
|
74
|
+
}
|
75
|
+
break;
|
79
76
|
case StrictEffort:
|
80
77
|
default:
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
// raise an error if name is not defined
|
79
|
+
clas = rb_const_get_at(mod, ci);
|
80
|
+
break;
|
84
81
|
}
|
85
82
|
return clas;
|
86
83
|
}
|
87
84
|
|
88
|
-
inline static VALUE
|
89
|
-
|
90
|
-
VALUE clas = classname2class(name, pi, base_class);
|
85
|
+
inline static VALUE classname2obj(const char *name, PInfo pi, VALUE base_class) {
|
86
|
+
VALUE clas = classname2class(name, pi, base_class);
|
91
87
|
|
92
88
|
if (Qundef == clas) {
|
93
|
-
|
89
|
+
return Qnil;
|
94
90
|
} else {
|
95
|
-
|
91
|
+
return rb_obj_alloc(clas);
|
96
92
|
}
|
97
93
|
}
|
98
94
|
|
99
|
-
inline static VALUE
|
100
|
-
|
101
|
-
|
102
|
-
const char *s = name;
|
95
|
+
inline static VALUE structname2obj(const char *name) {
|
96
|
+
VALUE ost;
|
97
|
+
const char *s = name;
|
103
98
|
|
104
99
|
for (; 1; s++) {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
100
|
+
if ('\0' == *s) {
|
101
|
+
s = name;
|
102
|
+
break;
|
103
|
+
} else if (':' == *s) {
|
104
|
+
s += 2;
|
105
|
+
break;
|
106
|
+
}
|
112
107
|
}
|
113
108
|
ost = rb_const_get(ox_struct_class, rb_intern(s));
|
114
109
|
#if HAVE_RB_STRUCT_ALLOC_NOINIT
|
@@ -118,403 +113,364 @@ structname2obj(const char *name) {
|
|
118
113
|
#endif
|
119
114
|
}
|
120
115
|
|
121
|
-
inline static VALUE
|
122
|
-
|
123
|
-
unsigned long n = 0;
|
116
|
+
inline static VALUE parse_ulong(const char *s, PInfo pi) {
|
117
|
+
unsigned long n = 0;
|
124
118
|
|
125
119
|
for (; '\0' != *s; s++) {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
120
|
+
if ('0' <= *s && *s <= '9') {
|
121
|
+
n = n * 10 + (*s - '0');
|
122
|
+
} else {
|
123
|
+
set_error(&pi->err, "Invalid number for a julian day", pi->str, pi->s);
|
124
|
+
return Qundef;
|
125
|
+
}
|
132
126
|
}
|
133
127
|
return ULONG2NUM(n);
|
134
128
|
}
|
135
129
|
|
136
130
|
// 2010-07-09T10:47:45.895826162+09:00
|
137
|
-
inline static VALUE
|
138
|
-
|
139
|
-
VALUE t;
|
131
|
+
inline static VALUE parse_time(const char *text, VALUE clas) {
|
132
|
+
VALUE t;
|
140
133
|
|
141
|
-
if (Qnil == (t = parse_double_time(text, clas)) &&
|
142
|
-
|
143
|
-
VALUE args[1];
|
134
|
+
if (Qnil == (t = parse_double_time(text, clas)) && Qnil == (t = parse_xsd_time(text, clas))) {
|
135
|
+
VALUE args[1];
|
144
136
|
|
145
|
-
|
146
|
-
|
137
|
+
*args = rb_str_new2(text);
|
138
|
+
t = rb_funcall2(ox_time_class, ox_parse_id, 1, args);
|
147
139
|
}
|
148
140
|
return t;
|
149
141
|
}
|
150
142
|
|
151
|
-
static VALUE
|
152
|
-
|
153
|
-
VALUE
|
154
|
-
VALUE clas;
|
143
|
+
static VALUE classname2class(const char *name, PInfo pi, VALUE base_class) {
|
144
|
+
VALUE *slot;
|
145
|
+
VALUE clas;
|
155
146
|
|
156
147
|
if (Qundef == (clas = slot_cache_get(ox_class_cache, name, &slot, 0))) {
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
148
|
+
char class_name[1024];
|
149
|
+
char *s;
|
150
|
+
const char *n = name;
|
151
|
+
|
152
|
+
clas = rb_cObject;
|
153
|
+
for (s = class_name; '\0' != *n; n++) {
|
154
|
+
if (':' == *n) {
|
155
|
+
*s = '\0';
|
156
|
+
n++;
|
157
|
+
if (':' != *n) {
|
158
|
+
set_error(&pi->err, "Invalid classname, expected another ':'", pi->str, pi->s);
|
159
|
+
return Qundef;
|
160
|
+
}
|
161
|
+
if (Qundef == (clas = resolve_classname(clas, class_name, pi->options->effort, base_class))) {
|
162
|
+
return Qundef;
|
163
|
+
}
|
164
|
+
s = class_name;
|
165
|
+
} else {
|
166
|
+
*s++ = *n;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
*s = '\0';
|
170
|
+
if (Qundef != (clas = resolve_classname(clas, class_name, pi->options->effort, base_class))) {
|
171
|
+
*slot = clas;
|
172
|
+
rb_gc_register_address(slot);
|
173
|
+
}
|
183
174
|
}
|
184
175
|
return clas;
|
185
176
|
}
|
186
177
|
|
187
|
-
static ID
|
188
|
-
get_var_sym_from_attrs(Attr a, void *encoding) {
|
178
|
+
static ID get_var_sym_from_attrs(Attr a, void *encoding) {
|
189
179
|
for (; 0 != a->name; a++) {
|
190
|
-
|
191
|
-
|
180
|
+
if ('a' == *a->name && '\0' == *(a->name + 1)) {
|
181
|
+
const char *val = a->value;
|
192
182
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
183
|
+
if ('0' <= *val && *val <= '9') {
|
184
|
+
return INT2NUM(atoi(val));
|
185
|
+
}
|
186
|
+
return ox_id_intern(val, strlen(val));
|
187
|
+
}
|
198
188
|
}
|
199
189
|
return 0;
|
200
190
|
}
|
201
191
|
|
202
|
-
static VALUE
|
203
|
-
get_obj_from_attrs(Attr a, PInfo pi, VALUE base_class) {
|
192
|
+
static VALUE get_obj_from_attrs(Attr a, PInfo pi, VALUE base_class) {
|
204
193
|
for (; 0 != a->name; a++) {
|
205
|
-
|
206
|
-
|
207
|
-
|
194
|
+
if ('c' == *a->name && '\0' == *(a->name + 1)) {
|
195
|
+
return classname2obj(a->value, pi, base_class);
|
196
|
+
}
|
208
197
|
}
|
209
198
|
return Qundef;
|
210
199
|
}
|
211
200
|
|
212
|
-
static VALUE
|
213
|
-
get_struct_from_attrs(Attr a) {
|
201
|
+
static VALUE get_struct_from_attrs(Attr a) {
|
214
202
|
for (; 0 != a->name; a++) {
|
215
|
-
|
216
|
-
|
217
|
-
|
203
|
+
if ('c' == *a->name && '\0' == *(a->name + 1)) {
|
204
|
+
return structname2obj(a->value);
|
205
|
+
}
|
218
206
|
}
|
219
207
|
return Qundef;
|
220
208
|
}
|
221
209
|
|
222
|
-
static VALUE
|
223
|
-
get_class_from_attrs(Attr a, PInfo pi, VALUE base_class) {
|
210
|
+
static VALUE get_class_from_attrs(Attr a, PInfo pi, VALUE base_class) {
|
224
211
|
for (; 0 != a->name; a++) {
|
225
|
-
|
226
|
-
|
227
|
-
|
212
|
+
if ('c' == *a->name && '\0' == *(a->name + 1)) {
|
213
|
+
return classname2class(a->value, pi, base_class);
|
214
|
+
}
|
228
215
|
}
|
229
216
|
return Qundef;
|
230
217
|
}
|
231
218
|
|
232
|
-
static unsigned long
|
233
|
-
get_id_from_attrs(PInfo pi, Attr a) {
|
219
|
+
static unsigned long get_id_from_attrs(PInfo pi, Attr a) {
|
234
220
|
for (; 0 != a->name; a++) {
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
221
|
+
if ('i' == *a->name && '\0' == *(a->name + 1)) {
|
222
|
+
unsigned long id = 0;
|
223
|
+
const char *text = a->value;
|
224
|
+
char c;
|
225
|
+
|
226
|
+
for (; '\0' != *text; text++) {
|
227
|
+
c = *text;
|
228
|
+
if ('0' <= c && c <= '9') {
|
229
|
+
id = id * 10 + (c - '0');
|
230
|
+
} else {
|
231
|
+
set_error(&pi->err, "bad number format", pi->str, pi->s);
|
232
|
+
return 0;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
return id;
|
236
|
+
}
|
251
237
|
}
|
252
238
|
return 0;
|
253
239
|
}
|
254
240
|
|
255
|
-
static CircArray
|
256
|
-
|
257
|
-
CircArray ca;
|
241
|
+
static CircArray circ_array_new() {
|
242
|
+
CircArray ca;
|
258
243
|
|
259
|
-
ca
|
244
|
+
ca = ALLOC(struct _circArray);
|
260
245
|
ca->objs = ca->obj_array;
|
261
246
|
ca->size = sizeof(ca->obj_array) / sizeof(VALUE);
|
262
|
-
ca->cnt
|
247
|
+
ca->cnt = 0;
|
263
248
|
|
264
249
|
return ca;
|
265
250
|
}
|
266
251
|
|
267
|
-
static void
|
268
|
-
circ_array_free(CircArray ca) {
|
252
|
+
static void circ_array_free(CircArray ca) {
|
269
253
|
if (ca->objs != ca->obj_array) {
|
270
|
-
|
254
|
+
xfree(ca->objs);
|
271
255
|
}
|
272
256
|
xfree(ca);
|
273
257
|
}
|
274
258
|
|
275
|
-
static void
|
276
|
-
circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
259
|
+
static void circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
277
260
|
if (0 < id) {
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
261
|
+
unsigned long i;
|
262
|
+
|
263
|
+
if (ca->size < id) {
|
264
|
+
unsigned long cnt = id + 512;
|
265
|
+
|
266
|
+
if (ca->objs == ca->obj_array) {
|
267
|
+
ca->objs = ALLOC_N(VALUE, cnt);
|
268
|
+
memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
|
269
|
+
} else {
|
270
|
+
REALLOC_N(ca->objs, VALUE, cnt);
|
271
|
+
}
|
272
|
+
ca->size = cnt;
|
273
|
+
}
|
274
|
+
id--;
|
275
|
+
for (i = ca->cnt; i < id; i++) {
|
276
|
+
ca->objs[i] = Qundef;
|
277
|
+
}
|
278
|
+
ca->objs[id] = obj;
|
279
|
+
if (ca->cnt <= id) {
|
280
|
+
ca->cnt = id + 1;
|
281
|
+
}
|
299
282
|
}
|
300
283
|
}
|
301
284
|
|
302
|
-
static VALUE
|
303
|
-
|
304
|
-
VALUE obj = Qundef;
|
285
|
+
static VALUE circ_array_get(CircArray ca, unsigned long id) {
|
286
|
+
VALUE obj = Qundef;
|
305
287
|
|
306
288
|
if (id <= ca->cnt) {
|
307
|
-
|
289
|
+
obj = ca->objs[id - 1];
|
308
290
|
}
|
309
291
|
return obj;
|
310
292
|
}
|
311
293
|
|
312
|
-
static VALUE
|
313
|
-
|
314
|
-
|
315
|
-
int options = 0;
|
294
|
+
static VALUE parse_regexp(const char *text) {
|
295
|
+
const char *te;
|
296
|
+
int options = 0;
|
316
297
|
|
317
298
|
te = text + strlen(text) - 1;
|
318
299
|
#ifdef ONIG_OPTION_IGNORECASE
|
319
300
|
for (; text < te && '/' != *te; te--) {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
301
|
+
switch (*te) {
|
302
|
+
case 'i': options |= ONIG_OPTION_IGNORECASE; break;
|
303
|
+
case 'm': options |= ONIG_OPTION_MULTILINE; break;
|
304
|
+
case 'x': options |= ONIG_OPTION_EXTEND; break;
|
305
|
+
default: break;
|
306
|
+
}
|
326
307
|
}
|
327
308
|
#endif
|
328
309
|
return rb_reg_new(text + 1, te - text - 1, options);
|
329
310
|
}
|
330
311
|
|
331
|
-
static void
|
332
|
-
instruct(PInfo pi, const char *target, Attr attrs, const char *content) {
|
312
|
+
static void instruct(PInfo pi, const char *target, Attr attrs, const char *content) {
|
333
313
|
if (0 == strcmp("xml", target)) {
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
314
|
+
for (; 0 != attrs->name; attrs++) {
|
315
|
+
if (0 == strcmp("encoding", attrs->name)) {
|
316
|
+
pi->options->rb_enc = rb_enc_find(attrs->value);
|
317
|
+
}
|
318
|
+
}
|
339
319
|
}
|
340
320
|
}
|
341
321
|
|
342
|
-
static void
|
343
|
-
|
344
|
-
Helper h = helper_stack_peek(&pi->helpers);
|
322
|
+
static void add_text(PInfo pi, char *text, int closed) {
|
323
|
+
Helper h = helper_stack_peek(&pi->helpers);
|
345
324
|
|
346
325
|
if (!closed) {
|
347
|
-
|
348
|
-
|
326
|
+
set_error(&pi->err, "Text not closed", pi->str, pi->s);
|
327
|
+
return;
|
349
328
|
}
|
350
329
|
if (0 == h) {
|
351
|
-
|
352
|
-
|
330
|
+
set_error(&pi->err, "Unexpected text", pi->str, pi->s);
|
331
|
+
return;
|
353
332
|
}
|
354
333
|
if (DEBUG <= pi->options->trace) {
|
355
|
-
|
334
|
+
char indent[128];
|
356
335
|
|
357
|
-
|
358
|
-
|
336
|
+
fill_indent(pi, indent, sizeof(indent));
|
337
|
+
printf("%s '%s' to type %c\n", indent, text, h->type);
|
359
338
|
}
|
360
339
|
switch (h->type) {
|
361
340
|
case NoCode:
|
362
341
|
case StringCode:
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
case FixnumCode:
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
case
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
break;
|
431
|
-
}
|
432
|
-
case Symbol64Code:
|
433
|
-
{
|
434
|
-
unsigned long str_size = b64_orig_size(text);
|
435
|
-
char *str = ALLOCA_N(char, str_size + 1);
|
436
|
-
|
437
|
-
from_base64(text, (uchar*)str);
|
438
|
-
h->obj = ox_sym_intern(str, strlen(str), NULL);
|
439
|
-
break;
|
342
|
+
h->obj = rb_str_new2(text);
|
343
|
+
if (0 != pi->options->rb_enc) {
|
344
|
+
rb_enc_associate(h->obj, pi->options->rb_enc);
|
345
|
+
}
|
346
|
+
if (0 != pi->circ_array) {
|
347
|
+
circ_array_set(pi->circ_array, h->obj, (unsigned long)pi->id);
|
348
|
+
}
|
349
|
+
break;
|
350
|
+
case FixnumCode: {
|
351
|
+
long n = 0;
|
352
|
+
char c;
|
353
|
+
int neg = 0;
|
354
|
+
|
355
|
+
if ('-' == *text) {
|
356
|
+
neg = 1;
|
357
|
+
text++;
|
358
|
+
}
|
359
|
+
for (; '\0' != *text; text++) {
|
360
|
+
c = *text;
|
361
|
+
if ('0' <= c && c <= '9') {
|
362
|
+
n = n * 10 + (c - '0');
|
363
|
+
} else {
|
364
|
+
set_error(&pi->err, "bad number format", pi->str, pi->s);
|
365
|
+
return;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
if (neg) {
|
369
|
+
n = -n;
|
370
|
+
}
|
371
|
+
h->obj = LONG2NUM(n);
|
372
|
+
break;
|
373
|
+
}
|
374
|
+
case FloatCode: h->obj = rb_float_new(strtod(text, 0)); break;
|
375
|
+
case SymbolCode: h->obj = ox_sym_intern(text, strlen(text), NULL); break;
|
376
|
+
case DateCode: {
|
377
|
+
VALUE args[1];
|
378
|
+
|
379
|
+
if (Qundef == (*args = parse_ulong(text, pi))) {
|
380
|
+
return;
|
381
|
+
}
|
382
|
+
h->obj = rb_funcall2(ox_date_class, ox_jd_id, 1, args);
|
383
|
+
break;
|
384
|
+
}
|
385
|
+
case TimeCode: h->obj = parse_time(text, ox_time_class); break;
|
386
|
+
case String64Code: {
|
387
|
+
unsigned long str_size = b64_orig_size(text);
|
388
|
+
VALUE v;
|
389
|
+
char *str = ALLOCA_N(char, str_size + 1);
|
390
|
+
|
391
|
+
from_base64(text, (uchar *)str);
|
392
|
+
v = rb_str_new(str, str_size);
|
393
|
+
if (0 != pi->options->rb_enc) {
|
394
|
+
rb_enc_associate(v, pi->options->rb_enc);
|
395
|
+
}
|
396
|
+
if (0 != pi->circ_array) {
|
397
|
+
circ_array_set(pi->circ_array, v, (unsigned long)h->obj);
|
398
|
+
}
|
399
|
+
h->obj = v;
|
400
|
+
break;
|
401
|
+
}
|
402
|
+
case Symbol64Code: {
|
403
|
+
unsigned long str_size = b64_orig_size(text);
|
404
|
+
char *str = ALLOCA_N(char, str_size + 1);
|
405
|
+
|
406
|
+
from_base64(text, (uchar *)str);
|
407
|
+
h->obj = ox_sym_intern(str, strlen(str), NULL);
|
408
|
+
break;
|
440
409
|
}
|
441
410
|
case RegexpCode:
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
case BignumCode:
|
453
|
-
|
454
|
-
|
455
|
-
case BigDecimalCode:
|
456
|
-
h->obj = rb_funcall(rb_cObject, ox_bigdecimal_id, 1, rb_str_new2(text));
|
457
|
-
break;
|
458
|
-
default:
|
459
|
-
h->obj = Qnil;
|
460
|
-
break;
|
411
|
+
if ('/' == *text) {
|
412
|
+
h->obj = parse_regexp(text);
|
413
|
+
} else {
|
414
|
+
unsigned long str_size = b64_orig_size(text);
|
415
|
+
char *str = ALLOCA_N(char, str_size + 1);
|
416
|
+
|
417
|
+
from_base64(text, (uchar *)str);
|
418
|
+
h->obj = parse_regexp(str);
|
419
|
+
}
|
420
|
+
break;
|
421
|
+
case BignumCode: h->obj = rb_cstr_to_inum(text, 10, 1); break;
|
422
|
+
case BigDecimalCode: h->obj = rb_funcall(rb_cObject, ox_bigdecimal_id, 1, rb_str_new2(text)); break;
|
423
|
+
default: h->obj = Qnil; break;
|
461
424
|
}
|
462
425
|
}
|
463
426
|
|
464
|
-
static void
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
unsigned long id;
|
427
|
+
static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
428
|
+
Attr a;
|
429
|
+
Helper h;
|
430
|
+
unsigned long id;
|
469
431
|
|
470
432
|
if (TRACE <= pi->options->trace) {
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
}
|
490
|
-
if (helper_stack_empty(&pi->helpers)) {
|
491
|
-
|
492
|
-
|
493
|
-
|
433
|
+
char buf[1024];
|
434
|
+
char indent[128];
|
435
|
+
char *s = buf;
|
436
|
+
char *end = buf + sizeof(buf) - 2;
|
437
|
+
|
438
|
+
s += snprintf(s, end - s, " <%s%s", (hasChildren) ? "" : "/", ename);
|
439
|
+
for (a = attrs; 0 != a->name; a++) {
|
440
|
+
s += snprintf(s, end - s, " %s=%s", a->name, a->value);
|
441
|
+
}
|
442
|
+
*s++ = '>';
|
443
|
+
*s++ = '\0';
|
444
|
+
if (DEBUG <= pi->options->trace) {
|
445
|
+
printf("===== add element stack(%d) =====\n", helper_stack_depth(&pi->helpers));
|
446
|
+
debug_stack(pi, buf);
|
447
|
+
} else {
|
448
|
+
fill_indent(pi, indent, sizeof(indent));
|
449
|
+
printf("%s%s\n", indent, buf);
|
450
|
+
}
|
451
|
+
}
|
452
|
+
if (helper_stack_empty(&pi->helpers)) { // top level object
|
453
|
+
if (0 != (id = get_id_from_attrs(pi, attrs))) {
|
454
|
+
pi->circ_array = circ_array_new();
|
455
|
+
}
|
494
456
|
}
|
495
457
|
if ('\0' != ename[1]) {
|
496
|
-
|
497
|
-
|
458
|
+
set_error(&pi->err, "Invalid element name", pi->str, pi->s);
|
459
|
+
return;
|
498
460
|
}
|
499
|
-
h = helper_stack_push(&pi->helpers, get_var_sym_from_attrs(attrs, (void*)pi->options->rb_enc), Qundef, *ename);
|
461
|
+
h = helper_stack_push(&pi->helpers, get_var_sym_from_attrs(attrs, (void *)pi->options->rb_enc), Qundef, *ename);
|
500
462
|
switch (h->type) {
|
501
|
-
case NilClassCode:
|
502
|
-
|
503
|
-
|
504
|
-
case TrueClassCode:
|
505
|
-
h->obj = Qtrue;
|
506
|
-
break;
|
507
|
-
case FalseClassCode:
|
508
|
-
h->obj = Qfalse;
|
509
|
-
break;
|
463
|
+
case NilClassCode: h->obj = Qnil; break;
|
464
|
+
case TrueClassCode: h->obj = Qtrue; break;
|
465
|
+
case FalseClassCode: h->obj = Qfalse; break;
|
510
466
|
case StringCode:
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
467
|
+
// h->obj will be replaced by add_text if it is called
|
468
|
+
h->obj = ox_empty_string;
|
469
|
+
if (0 != pi->circ_array) {
|
470
|
+
pi->id = get_id_from_attrs(pi, attrs);
|
471
|
+
circ_array_set(pi->circ_array, h->obj, pi->id);
|
472
|
+
}
|
473
|
+
break;
|
518
474
|
case FixnumCode:
|
519
475
|
case FloatCode:
|
520
476
|
case SymbolCode:
|
@@ -525,251 +481,243 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
525
481
|
case ComplexCode:
|
526
482
|
case DateCode:
|
527
483
|
case TimeCode:
|
528
|
-
case RationalCode:
|
529
|
-
|
530
|
-
|
531
|
-
|
484
|
+
case RationalCode: // sub elements read next
|
485
|
+
// value will be read in the following add_text
|
486
|
+
h->obj = Qundef;
|
487
|
+
break;
|
532
488
|
case String64Code:
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
489
|
+
h->obj = Qundef;
|
490
|
+
if (0 != pi->circ_array) {
|
491
|
+
pi->id = get_id_from_attrs(pi, attrs);
|
492
|
+
}
|
493
|
+
break;
|
538
494
|
case ArrayCode:
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
495
|
+
h->obj = rb_ary_new();
|
496
|
+
if (0 != pi->circ_array) {
|
497
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
498
|
+
}
|
499
|
+
break;
|
544
500
|
case HashCode:
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
case RangeCode:
|
551
|
-
h->obj = rb_ary_new_from_args(3, Qnil, Qnil, Qfalse);
|
552
|
-
break;
|
501
|
+
h->obj = rb_hash_new();
|
502
|
+
if (0 != pi->circ_array) {
|
503
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
504
|
+
}
|
505
|
+
break;
|
506
|
+
case RangeCode: h->obj = rb_ary_new_from_args(3, Qnil, Qnil, Qfalse); break;
|
553
507
|
case RawCode:
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
508
|
+
if (hasChildren) {
|
509
|
+
h->obj = ox_parse(pi->s, pi->end - pi->s, ox_gen_callbacks, &pi->s, pi->options, &pi->err);
|
510
|
+
if (0 != pi->circ_array) {
|
511
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
512
|
+
}
|
513
|
+
} else {
|
514
|
+
h->obj = Qnil;
|
515
|
+
}
|
516
|
+
break;
|
563
517
|
case ExceptionCode:
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
518
|
+
if (Qundef == (h->obj = get_obj_from_attrs(attrs, pi, rb_eException))) {
|
519
|
+
return;
|
520
|
+
}
|
521
|
+
if (0 != pi->circ_array && Qnil != h->obj) {
|
522
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
523
|
+
}
|
524
|
+
break;
|
571
525
|
case ObjectCode:
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
526
|
+
if (Qundef == (h->obj = get_obj_from_attrs(attrs, pi, ox_bag_clas))) {
|
527
|
+
return;
|
528
|
+
}
|
529
|
+
if (0 != pi->circ_array && Qnil != h->obj) {
|
530
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
531
|
+
}
|
532
|
+
break;
|
579
533
|
case StructCode:
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
534
|
+
h->obj = get_struct_from_attrs(attrs);
|
535
|
+
if (0 != pi->circ_array) {
|
536
|
+
circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
|
537
|
+
}
|
538
|
+
break;
|
585
539
|
case ClassCode:
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
540
|
+
if (Qundef == (h->obj = get_class_from_attrs(attrs, pi, ox_bag_clas))) {
|
541
|
+
return;
|
542
|
+
}
|
543
|
+
break;
|
590
544
|
case RefCode:
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
545
|
+
h->obj = Qundef;
|
546
|
+
if (0 != pi->circ_array) {
|
547
|
+
h->obj = circ_array_get(pi->circ_array, get_id_from_attrs(pi, attrs));
|
548
|
+
}
|
549
|
+
if (Qundef == h->obj) {
|
550
|
+
set_error(&pi->err, "Invalid circular reference", pi->str, pi->s);
|
551
|
+
return;
|
552
|
+
}
|
553
|
+
break;
|
600
554
|
default:
|
601
|
-
|
602
|
-
|
603
|
-
|
555
|
+
set_error(&pi->err, "Invalid element name", pi->str, pi->s);
|
556
|
+
return;
|
557
|
+
break;
|
604
558
|
}
|
605
559
|
if (DEBUG <= pi->options->trace) {
|
606
|
-
|
560
|
+
debug_stack(pi, " -----------");
|
607
561
|
}
|
608
562
|
}
|
609
563
|
|
610
|
-
static void
|
611
|
-
end_element(PInfo pi, const char *ename) {
|
564
|
+
static void end_element(PInfo pi, const char *ename) {
|
612
565
|
if (TRACE <= pi->options->trace) {
|
613
|
-
|
566
|
+
char indent[128];
|
614
567
|
|
615
|
-
|
616
|
-
|
568
|
+
if (DEBUG <= pi->options->trace) {
|
569
|
+
char buf[1024];
|
617
570
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
571
|
+
printf("===== end element stack(%d) =====\n", helper_stack_depth(&pi->helpers));
|
572
|
+
snprintf(buf, sizeof(buf) - 1, "</%s>", ename);
|
573
|
+
debug_stack(pi, buf);
|
574
|
+
} else {
|
575
|
+
fill_indent(pi, indent, sizeof(indent));
|
576
|
+
printf("%s</%s>\n", indent, ename);
|
577
|
+
}
|
625
578
|
}
|
626
579
|
if (!helper_stack_empty(&pi->helpers)) {
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
rb_hash_aset(gh->obj, ph->obj, h->obj);
|
694
|
-
}
|
695
|
-
break;
|
696
|
-
case ComplexCode:
|
580
|
+
Helper h = helper_stack_pop(&pi->helpers);
|
581
|
+
Helper ph = helper_stack_peek(&pi->helpers);
|
582
|
+
|
583
|
+
if (ox_empty_string == h->obj) {
|
584
|
+
// special catch for empty strings
|
585
|
+
h->obj = rb_str_new2("");
|
586
|
+
} else if (Qundef == h->obj) {
|
587
|
+
set_error(&pi->err, "Invalid element for object mode", pi->str, pi->s);
|
588
|
+
return;
|
589
|
+
} else if (RangeCode == h->type) { // Expect an array of 3 elements.
|
590
|
+
const VALUE *ap = RARRAY_PTR(h->obj);
|
591
|
+
|
592
|
+
h->obj = rb_range_new(*ap, *(ap + 1), Qtrue == *(ap + 2));
|
593
|
+
}
|
594
|
+
pi->obj = h->obj;
|
595
|
+
if (0 != ph) {
|
596
|
+
switch (ph->type) {
|
597
|
+
case ArrayCode: rb_ary_push(ph->obj, h->obj); break;
|
598
|
+
case ExceptionCode:
|
599
|
+
case ObjectCode:
|
600
|
+
if (Qnil != ph->obj) {
|
601
|
+
if (0 == h->var || NULL == rb_id2name(h->var)) {
|
602
|
+
set_error(&pi->err, "Invalid element for object mode", pi->str, pi->s);
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
if (RUBY_T_OBJECT != rb_type(ph->obj)) {
|
606
|
+
set_error(&pi->err, "Corrupt object encoding", pi->str, pi->s);
|
607
|
+
return;
|
608
|
+
}
|
609
|
+
rb_ivar_set(ph->obj, h->var, h->obj);
|
610
|
+
}
|
611
|
+
break;
|
612
|
+
case StructCode:
|
613
|
+
if (0 == h->var) {
|
614
|
+
set_error(&pi->err, "Invalid element for object mode", pi->str, pi->s);
|
615
|
+
return;
|
616
|
+
}
|
617
|
+
rb_struct_aset(ph->obj, h->var, h->obj);
|
618
|
+
break;
|
619
|
+
case HashCode:
|
620
|
+
// put back h
|
621
|
+
helper_stack_push(&pi->helpers, h->var, h->obj, KeyCode);
|
622
|
+
break;
|
623
|
+
case RangeCode:
|
624
|
+
if (ox_beg_id == h->var) {
|
625
|
+
rb_ary_store(ph->obj, 0, h->obj);
|
626
|
+
} else if (ox_end_id == h->var) {
|
627
|
+
rb_ary_store(ph->obj, 1, h->obj);
|
628
|
+
} else if (ox_excl_id == h->var) {
|
629
|
+
rb_ary_store(ph->obj, 2, h->obj);
|
630
|
+
} else {
|
631
|
+
set_error(&pi->err, "Invalid range attribute", pi->str, pi->s);
|
632
|
+
return;
|
633
|
+
}
|
634
|
+
break;
|
635
|
+
case KeyCode: {
|
636
|
+
Helper gh;
|
637
|
+
|
638
|
+
helper_stack_pop(&pi->helpers);
|
639
|
+
if (NULL == (gh = helper_stack_peek(&pi->helpers)) || Qundef == ph->obj || Qundef == h->obj) {
|
640
|
+
set_error(&pi->err, "Corrupt parse stack, container is wrong type", pi->str, pi->s);
|
641
|
+
return;
|
642
|
+
}
|
643
|
+
rb_hash_aset(gh->obj, ph->obj, h->obj);
|
644
|
+
} break;
|
645
|
+
case ComplexCode:
|
697
646
|
#ifdef T_COMPLEX
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
647
|
+
if (Qundef == ph->obj) {
|
648
|
+
ph->obj = h->obj;
|
649
|
+
} else {
|
650
|
+
ph->obj = rb_complex_new(ph->obj, h->obj);
|
651
|
+
}
|
703
652
|
#else
|
704
|
-
|
705
|
-
|
653
|
+
set_error(&pi->err, "Complex Objects not implemented in Ruby 1.8.7", pi->str, pi->s);
|
654
|
+
return;
|
706
655
|
#endif
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
656
|
+
break;
|
657
|
+
case RationalCode: {
|
658
|
+
if (Qundef == h->obj || RUBY_T_FIXNUM != rb_type(h->obj)) {
|
659
|
+
set_error(&pi->err, "Invalid object format", pi->str, pi->s);
|
660
|
+
return;
|
661
|
+
}
|
713
662
|
#ifdef T_RATIONAL
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
663
|
+
if (Qundef == ph->obj) {
|
664
|
+
ph->obj = h->obj;
|
665
|
+
} else {
|
666
|
+
if (Qundef == ph->obj || RUBY_T_FIXNUM != rb_type(h->obj)) {
|
667
|
+
set_error(&pi->err, "Corrupt parse stack, container is wrong type", pi->str, pi->s);
|
668
|
+
return;
|
669
|
+
}
|
721
670
|
#ifdef RUBINIUS_RUBY
|
722
|
-
|
671
|
+
ph->obj = rb_Rational(ph->obj, h->obj);
|
723
672
|
#else
|
724
|
-
|
673
|
+
ph->obj = rb_rational_new(ph->obj, h->obj);
|
725
674
|
#endif
|
726
|
-
|
675
|
+
}
|
727
676
|
#else
|
728
|
-
|
729
|
-
|
677
|
+
set_error(&pi->err, "Rational Objects not implemented in Ruby 1.8.7", pi->str, pi->s);
|
678
|
+
return;
|
730
679
|
#endif
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
680
|
+
break;
|
681
|
+
}
|
682
|
+
default:
|
683
|
+
set_error(&pi->err, "Corrupt parse stack, container is wrong type", pi->str, pi->s);
|
684
|
+
return;
|
685
|
+
break;
|
686
|
+
}
|
687
|
+
}
|
739
688
|
}
|
740
689
|
if (0 != pi->circ_array && helper_stack_empty(&pi->helpers)) {
|
741
|
-
|
742
|
-
|
690
|
+
circ_array_free(pi->circ_array);
|
691
|
+
pi->circ_array = 0;
|
743
692
|
}
|
744
693
|
if (DEBUG <= pi->options->trace) {
|
745
|
-
|
694
|
+
debug_stack(pi, " ----------");
|
746
695
|
}
|
747
696
|
}
|
748
697
|
|
749
|
-
static VALUE
|
750
|
-
|
751
|
-
long
|
752
|
-
|
753
|
-
|
754
|
-
char c;
|
698
|
+
static VALUE parse_double_time(const char *text, VALUE clas) {
|
699
|
+
long v = 0;
|
700
|
+
long v2 = 0;
|
701
|
+
const char *dot = 0;
|
702
|
+
char c;
|
755
703
|
|
756
704
|
for (; '.' != *text; text++) {
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
705
|
+
c = *text;
|
706
|
+
if (c < '0' || '9' < c) {
|
707
|
+
return Qnil;
|
708
|
+
}
|
709
|
+
v = 10 * v + (long)(c - '0');
|
762
710
|
}
|
763
711
|
dot = text++;
|
764
712
|
for (; '\0' != *text && text - dot <= 6; text++) {
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
713
|
+
c = *text;
|
714
|
+
if (c < '0' || '9' < c) {
|
715
|
+
return Qnil;
|
716
|
+
}
|
717
|
+
v2 = 10 * v2 + (long)(c - '0');
|
770
718
|
}
|
771
719
|
for (; text - dot <= 9; text++) {
|
772
|
-
|
720
|
+
v2 *= 10;
|
773
721
|
}
|
774
722
|
#if HAVE_RB_TIME_NANO_NEW
|
775
723
|
return rb_time_nano_new(v, v2);
|
@@ -779,54 +727,53 @@ parse_double_time(const char *text, VALUE clas) {
|
|
779
727
|
}
|
780
728
|
|
781
729
|
typedef struct _tp {
|
782
|
-
int
|
783
|
-
char
|
784
|
-
char
|
730
|
+
int cnt;
|
731
|
+
char end;
|
732
|
+
char alt;
|
785
733
|
} *Tp;
|
786
734
|
|
787
|
-
static VALUE
|
788
|
-
|
789
|
-
long
|
790
|
-
long
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
struct tm tm;
|
735
|
+
static VALUE parse_xsd_time(const char *text, VALUE clas) {
|
736
|
+
long cargs[10];
|
737
|
+
long *cp = cargs;
|
738
|
+
long v;
|
739
|
+
int i;
|
740
|
+
char c;
|
741
|
+
struct _tp tpa[10] = {{4, '-', '-'},
|
742
|
+
{2, '-', '-'},
|
743
|
+
{2, 'T', 'T'},
|
744
|
+
{2, ':', ':'},
|
745
|
+
{2, ':', ':'},
|
746
|
+
{2, '.', '.'},
|
747
|
+
{9, '+', '-'},
|
748
|
+
{2, ':', ':'},
|
749
|
+
{2, '\0', '\0'},
|
750
|
+
{0, '\0', '\0'}};
|
751
|
+
Tp tp = tpa;
|
752
|
+
struct tm tm;
|
806
753
|
|
807
754
|
for (; 0 != tp->cnt; tp++) {
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
755
|
+
for (i = tp->cnt, v = 0; 0 < i; text++, i--) {
|
756
|
+
c = *text;
|
757
|
+
if (c < '0' || '9' < c) {
|
758
|
+
if (tp->end == c || tp->alt == c) {
|
759
|
+
break;
|
760
|
+
}
|
761
|
+
return Qnil;
|
762
|
+
}
|
763
|
+
v = 10 * v + (long)(c - '0');
|
764
|
+
}
|
765
|
+
c = *text++;
|
766
|
+
if (tp->end != c && tp->alt != c) {
|
767
|
+
return Qnil;
|
768
|
+
}
|
769
|
+
*cp++ = v;
|
823
770
|
}
|
824
771
|
tm.tm_year = (int)cargs[0] - 1900;
|
825
|
-
tm.tm_mon
|
772
|
+
tm.tm_mon = (int)cargs[1] - 1;
|
826
773
|
tm.tm_mday = (int)cargs[2];
|
827
774
|
tm.tm_hour = (int)cargs[3];
|
828
|
-
tm.tm_min
|
829
|
-
tm.tm_sec
|
775
|
+
tm.tm_min = (int)cargs[4];
|
776
|
+
tm.tm_sec = (int)cargs[5];
|
830
777
|
#if HAVE_RB_TIME_NANO_NEW
|
831
778
|
return rb_time_nano_new(mktime(&tm), cargs[6]);
|
832
779
|
#else
|
@@ -835,51 +782,50 @@ parse_xsd_time(const char *text, VALUE clas) {
|
|
835
782
|
}
|
836
783
|
|
837
784
|
// debug functions
|
838
|
-
static void
|
839
|
-
|
840
|
-
size_t cnt;
|
785
|
+
static void fill_indent(PInfo pi, char *buf, size_t size) {
|
786
|
+
size_t cnt;
|
841
787
|
|
842
788
|
if (0 < (cnt = helper_stack_depth(&pi->helpers))) {
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
789
|
+
cnt *= 2;
|
790
|
+
if (size < cnt + 1) {
|
791
|
+
cnt = size - 1;
|
792
|
+
}
|
793
|
+
memset(buf, ' ', cnt);
|
794
|
+
buf += cnt;
|
849
795
|
}
|
850
796
|
*buf = '\0';
|
851
797
|
}
|
852
798
|
|
853
|
-
static void
|
854
|
-
|
855
|
-
|
856
|
-
Helper h;
|
799
|
+
static void debug_stack(PInfo pi, const char *comment) {
|
800
|
+
char indent[128];
|
801
|
+
Helper h;
|
857
802
|
|
858
803
|
fill_indent(pi, indent, sizeof(indent));
|
859
804
|
printf("%s%s\n", indent, comment);
|
860
805
|
if (!helper_stack_empty(&pi->helpers)) {
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
806
|
+
for (h = pi->helpers.head; h < pi->helpers.tail; h++) {
|
807
|
+
const char *clas = "---";
|
808
|
+
const char *key = "---";
|
809
|
+
|
810
|
+
if (Qundef != h->obj) {
|
811
|
+
VALUE c = rb_obj_class(h->obj);
|
812
|
+
|
813
|
+
clas = rb_class2name(c);
|
814
|
+
}
|
815
|
+
if (0 != h->var) {
|
816
|
+
if (HashCode == h->type) {
|
817
|
+
VALUE v;
|
818
|
+
|
819
|
+
v = rb_funcall2(h->var, rb_intern("to_s"), 0, 0);
|
820
|
+
key = StringValuePtr(v);
|
821
|
+
} else if (ObjectCode == (h - 1)->type || ExceptionCode == (h - 1)->type ||
|
822
|
+
RangeCode == (h - 1)->type || StructCode == (h - 1)->type) {
|
823
|
+
key = rb_id2name(h->var);
|
824
|
+
} else {
|
825
|
+
printf("%s*** corrupt stack ***\n", indent);
|
826
|
+
}
|
827
|
+
}
|
828
|
+
printf("%s [%c] %s : %s\n", indent, h->type, clas, key);
|
829
|
+
}
|
884
830
|
}
|
885
831
|
}
|