ox 1.5.8 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ox might be problematic. Click here for more details.
- data/README.md +11 -3
- data/ext/ox/base64.c +16 -16
- data/ext/ox/base64.h +3 -4
- data/ext/ox/cache.c +18 -8
- data/ext/ox/cache8.c +2 -2
- data/ext/ox/cache8_test.c +1 -1
- data/ext/ox/cache_test.c +3 -3
- data/ext/ox/dump.c +38 -33
- data/ext/ox/extconf.rb +4 -2
- data/ext/ox/gen_load.c +8 -8
- data/ext/ox/obj_load.c +17 -17
- data/ext/ox/ox.c +15 -15
- data/ext/ox/ox.h +16 -16
- data/ext/ox/parse.c +31 -31
- data/ext/ox/sax.c +38 -39
- data/lib/ox/version.rb +1 -1
- metadata +2 -2
data/ext/ox/extconf.rb
CHANGED
@@ -16,7 +16,9 @@ dflags = {
|
|
16
16
|
'RUBY_VERSION_MAJOR' => version[0],
|
17
17
|
'RUBY_VERSION_MINOR' => version[1],
|
18
18
|
'RUBY_VERSION_MICRO' => version[2],
|
19
|
-
'HAS_RB_TIME_TIMESPEC' => ('ruby' == type && ('1.9.3' == RUBY_VERSION
|
19
|
+
'HAS_RB_TIME_TIMESPEC' => ('ruby' == type && ('1.9.3' == RUBY_VERSION)) ? 1 : 0,
|
20
|
+
#'HAS_RB_TIME_TIMESPEC' => ('ruby' == type && ('1.9.3' == RUBY_VERSION || '2' <= version[0])) ? 1 : 0,
|
21
|
+
'HAS_TM_GMTOFF' => ('ruby' == type && '2' <= version[0]) ? 0 : 1,
|
20
22
|
'HAS_ENCODING_SUPPORT' => (('ruby' == type || 'rubinius' == type) &&
|
21
23
|
(('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
|
22
24
|
'HAS_NANO_TIME' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
|
@@ -26,7 +28,7 @@ dflags = {
|
|
26
28
|
'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
|
27
29
|
}
|
28
30
|
|
29
|
-
if 'i386-darwin10.0.0'
|
31
|
+
if ['i386-darwin10.0.0', 'x86_64-darwin10.8.0'].include? RUBY_PLATFORM
|
30
32
|
dflags['NEEDS_STPCPY'] = nil
|
31
33
|
|
32
34
|
dflags['HAS_IVAR_HELPERS'] = 0 if ('ruby' == type && '1.9.1' == RUBY_VERSION)
|
data/ext/ox/gen_load.c
CHANGED
@@ -51,7 +51,7 @@ static void end_element(PInfo pi, const char *ename);
|
|
51
51
|
extern ParseCallbacks ox_obj_callbacks;
|
52
52
|
|
53
53
|
struct _ParseCallbacks _ox_gen_callbacks = {
|
54
|
-
instruct,
|
54
|
+
instruct, /* instruct, */
|
55
55
|
add_doctype,
|
56
56
|
add_comment,
|
57
57
|
add_cdata,
|
@@ -107,7 +107,7 @@ create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
|
|
107
107
|
VALUE nodes;
|
108
108
|
VALUE sym;
|
109
109
|
|
110
|
-
if (0 != pi->h) {
|
110
|
+
if (0 != pi->h) { /* top level object */
|
111
111
|
rb_raise(rb_eSyntaxError, "Prolog must be the first element in an XML document.\n");
|
112
112
|
}
|
113
113
|
pi->h = pi->helpers;
|
@@ -162,7 +162,7 @@ instruct(PInfo pi, const char *target, Attr attrs) {
|
|
162
162
|
rb_raise(rb_eSyntaxError, "Only Ox XML Object version 1.0 supported, not %s.\n", attrs->value);
|
163
163
|
}
|
164
164
|
}
|
165
|
-
|
165
|
+
/* ignore other instructions */
|
166
166
|
}
|
167
167
|
} else {
|
168
168
|
if (TRACE <= pi->options->trace) {
|
@@ -215,7 +215,7 @@ add_doctype(PInfo pi, const char *docType) {
|
|
215
215
|
}
|
216
216
|
#endif
|
217
217
|
rb_ivar_set(n, ox_at_value_id, s);
|
218
|
-
if (0 == pi->h) {
|
218
|
+
if (0 == pi->h) { /* top level object */
|
219
219
|
create_doc(pi);
|
220
220
|
}
|
221
221
|
rb_ary_push(pi->h->obj, n);
|
@@ -232,7 +232,7 @@ add_comment(PInfo pi, const char *comment) {
|
|
232
232
|
}
|
233
233
|
#endif
|
234
234
|
rb_ivar_set(n, ox_at_value_id, s);
|
235
|
-
if (0 == pi->h) {
|
235
|
+
if (0 == pi->h) { /* top level object */
|
236
236
|
create_doc(pi);
|
237
237
|
}
|
238
238
|
rb_ary_push(pi->h->obj, n);
|
@@ -249,7 +249,7 @@ add_cdata(PInfo pi, const char *cdata, size_t len) {
|
|
249
249
|
}
|
250
250
|
#endif
|
251
251
|
rb_ivar_set(n, ox_at_value_id, s);
|
252
|
-
if (0 == pi->h) {
|
252
|
+
if (0 == pi->h) { /* top level object */
|
253
253
|
create_doc(pi);
|
254
254
|
}
|
255
255
|
rb_ary_push(pi->h->obj, n);
|
@@ -264,7 +264,7 @@ add_text(PInfo pi, char *text, int closed) {
|
|
264
264
|
rb_enc_associate(s, pi->encoding);
|
265
265
|
}
|
266
266
|
#endif
|
267
|
-
if (0 == pi->h) {
|
267
|
+
if (0 == pi->h) { /* top level object */
|
268
268
|
create_doc(pi);
|
269
269
|
}
|
270
270
|
rb_ary_push(pi->h->obj, s);
|
@@ -323,7 +323,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
323
323
|
}
|
324
324
|
rb_ivar_set(e, ox_attributes_id, ah);
|
325
325
|
}
|
326
|
-
if (0 == pi->h) {
|
326
|
+
if (0 == pi->h) { /* top level object */
|
327
327
|
pi->h = pi->helpers;
|
328
328
|
pi->obj = e;
|
329
329
|
} else {
|
data/ext/ox/obj_load.c
CHANGED
@@ -64,10 +64,10 @@ static void fill_indent(PInfo pi, char *buf, size_t size);
|
|
64
64
|
|
65
65
|
|
66
66
|
struct _ParseCallbacks _ox_obj_callbacks = {
|
67
|
-
instruct,
|
68
|
-
0,
|
69
|
-
0,
|
70
|
-
0,
|
67
|
+
instruct, /* instruct, */
|
68
|
+
0, /* add_doctype, */
|
69
|
+
0, /* add_comment, */
|
70
|
+
0, /* add_cdata, */
|
71
71
|
add_text,
|
72
72
|
add_element,
|
73
73
|
end_element,
|
@@ -146,7 +146,7 @@ resolve_classname(VALUE mod, const char *class_name, Effort effort, VALUE base_c
|
|
146
146
|
break;
|
147
147
|
case StrictEffort:
|
148
148
|
default:
|
149
|
-
|
149
|
+
/* raise an error if name is not defined */
|
150
150
|
clas = rb_const_get_at(mod, ci);
|
151
151
|
break;
|
152
152
|
}
|
@@ -180,7 +180,7 @@ structname2obj(const char *name) {
|
|
180
180
|
}
|
181
181
|
}
|
182
182
|
ost = rb_const_get(ox_struct_class, rb_intern(s));
|
183
|
-
|
183
|
+
/* use encoding as the indicator for Ruby 1.8.7 or 1.9.x */
|
184
184
|
#if HAS_ENCODING_SUPPORT
|
185
185
|
return rb_struct_alloc_noinit(ost);
|
186
186
|
#else
|
@@ -203,7 +203,7 @@ parse_ulong(const char *s, PInfo pi) {
|
|
203
203
|
return ULONG2NUM(n);
|
204
204
|
}
|
205
205
|
|
206
|
-
|
206
|
+
/* 2010-07-09T10:47:45.895826162+09:00 */
|
207
207
|
inline static VALUE
|
208
208
|
parse_time(const char *text, VALUE clas) {
|
209
209
|
VALUE t;
|
@@ -212,7 +212,7 @@ parse_time(const char *text, VALUE clas) {
|
|
212
212
|
Qnil == (t = parse_xsd_time(text, clas))) {
|
213
213
|
VALUE args[1];
|
214
214
|
|
215
|
-
|
215
|
+
/*printf("**** time parse\n"); */
|
216
216
|
*args = rb_str_new2(text);
|
217
217
|
t = rb_funcall2(ox_time_class, ox_parse_id, 1, args);
|
218
218
|
}
|
@@ -486,7 +486,7 @@ add_text(PInfo pi, char *text, int closed) {
|
|
486
486
|
VALUE v;
|
487
487
|
char *str = ALLOCA_N(char, str_size + 1);
|
488
488
|
|
489
|
-
from_base64(text, (
|
489
|
+
from_base64(text, (uchar*)str);
|
490
490
|
v = rb_str_new(str, str_size);
|
491
491
|
#if HAS_ENCODING_SUPPORT
|
492
492
|
if (0 != pi->encoding) {
|
@@ -506,7 +506,7 @@ add_text(PInfo pi, char *text, int closed) {
|
|
506
506
|
unsigned long str_size = b64_orig_size(text);
|
507
507
|
char *str = ALLOCA_N(char, str_size + 1);
|
508
508
|
|
509
|
-
from_base64(text, (
|
509
|
+
from_base64(text, (uchar*)str);
|
510
510
|
if (Qundef == (sym = ox_cache_get(ox_symbol_cache, str, &slot))) {
|
511
511
|
sym = str2sym(str, pi->encoding);
|
512
512
|
*slot = sym;
|
@@ -521,7 +521,7 @@ add_text(PInfo pi, char *text, int closed) {
|
|
521
521
|
unsigned long str_size = b64_orig_size(text);
|
522
522
|
char *str = ALLOCA_N(char, str_size + 1);
|
523
523
|
|
524
|
-
from_base64(text, (
|
524
|
+
from_base64(text, (uchar*)str);
|
525
525
|
pi->h->obj = parse_regexp(str);
|
526
526
|
}
|
527
527
|
break;
|
@@ -559,7 +559,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
559
559
|
printf("%s%s\n", indent, buf);
|
560
560
|
}
|
561
561
|
}
|
562
|
-
if (0 == pi->h) {
|
562
|
+
if (0 == pi->h) { /* top level object */
|
563
563
|
pi->h = pi->helpers;
|
564
564
|
if (0 != (id = get_id_from_attrs(pi, attrs))) {
|
565
565
|
pi->circ_array = circ_array_new();
|
@@ -584,7 +584,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
584
584
|
h->obj = Qfalse;
|
585
585
|
break;
|
586
586
|
case StringCode:
|
587
|
-
|
587
|
+
/* h->obj will be replaced by add_text if it is called */
|
588
588
|
h->obj = ox_empty_string;
|
589
589
|
if (0 != pi->circ_array) {
|
590
590
|
pi->id = get_id_from_attrs(pi, attrs);
|
@@ -600,8 +600,8 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
600
600
|
case ComplexCode:
|
601
601
|
case DateCode:
|
602
602
|
case TimeCode:
|
603
|
-
case RationalCode:
|
604
|
-
|
603
|
+
case RationalCode: /* sub elements read next */
|
604
|
+
/* value will be read in the following add_text */
|
605
605
|
h->obj = Qundef;
|
606
606
|
break;
|
607
607
|
case String64Code:
|
@@ -697,7 +697,7 @@ end_element(PInfo pi, const char *ename) {
|
|
697
697
|
Helper h = pi->h;
|
698
698
|
|
699
699
|
if (ox_empty_string == h->obj) {
|
700
|
-
|
700
|
+
/* special catch for empty strings */
|
701
701
|
h->obj = rb_str_new2("");
|
702
702
|
}
|
703
703
|
pi->obj = h->obj;
|
@@ -872,7 +872,7 @@ parse_xsd_time(const char *text, VALUE clas) {
|
|
872
872
|
#endif
|
873
873
|
}
|
874
874
|
|
875
|
-
|
875
|
+
/* debug functions */
|
876
876
|
static void
|
877
877
|
fill_indent(PInfo pi, char *buf, size_t size) {
|
878
878
|
if (0 != pi->h) {
|
data/ext/ox/ox.c
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
#include "ruby.h"
|
37
37
|
#include "ox.h"
|
38
38
|
|
39
|
-
|
39
|
+
/* maximum to allocate on the stack, arbitrary limit */
|
40
40
|
#define SMALL_XML 65536
|
41
41
|
|
42
42
|
typedef struct _YesNoOpt {
|
@@ -129,17 +129,17 @@ static VALUE with_xml_sym;
|
|
129
129
|
static VALUE xsd_date_sym;
|
130
130
|
|
131
131
|
struct _Options ox_default_options = {
|
132
|
-
{ '\0' },
|
133
|
-
2,
|
134
|
-
0,
|
135
|
-
No,
|
136
|
-
No,
|
137
|
-
No,
|
138
|
-
No,
|
139
|
-
No,
|
140
|
-
NoMode,
|
141
|
-
StrictEffort,
|
142
|
-
Yes
|
132
|
+
{ '\0' }, /* encoding */
|
133
|
+
2, /* indent */
|
134
|
+
0, /* trace */
|
135
|
+
No, /* with_dtd */
|
136
|
+
No, /* with_xml */
|
137
|
+
No, /* with_instruct */
|
138
|
+
No, /* circular */
|
139
|
+
No, /* xsd_date */
|
140
|
+
NoMode, /* mode */
|
141
|
+
StrictEffort, /* effort */
|
142
|
+
Yes /* sym_keys */
|
143
143
|
};
|
144
144
|
|
145
145
|
extern ParseCallbacks ox_obj_callbacks;
|
@@ -306,7 +306,7 @@ to_obj(VALUE self, VALUE ruby_xml) {
|
|
306
306
|
VALUE obj;
|
307
307
|
|
308
308
|
Check_Type(ruby_xml, T_STRING);
|
309
|
-
|
309
|
+
/* the xml string gets modified so make a copy of it */
|
310
310
|
len = RSTRING_LEN(ruby_xml) + 1;
|
311
311
|
if (SMALL_XML < len) {
|
312
312
|
xml = ALLOC_N(char, len);
|
@@ -335,7 +335,7 @@ to_gen(VALUE self, VALUE ruby_xml) {
|
|
335
335
|
VALUE obj;
|
336
336
|
|
337
337
|
Check_Type(ruby_xml, T_STRING);
|
338
|
-
|
338
|
+
/* the xml string gets modified so make a copy of it */
|
339
339
|
len = RSTRING_LEN(ruby_xml) + 1;
|
340
340
|
if (SMALL_XML < len) {
|
341
341
|
xml = ALLOC_N(char, len);
|
@@ -436,7 +436,7 @@ load_str(int argc, VALUE *argv, VALUE self) {
|
|
436
436
|
VALUE obj;
|
437
437
|
|
438
438
|
Check_Type(*argv, T_STRING);
|
439
|
-
|
439
|
+
/* the xml string gets modified so make a copy of it */
|
440
440
|
len = RSTRING_LEN(*argv) + 1;
|
441
441
|
if (SMALL_XML < len) {
|
442
442
|
xml = ALLOC_N(char, len);
|
data/ext/ox/ox.h
CHANGED
@@ -50,7 +50,7 @@ extern "C" {
|
|
50
50
|
enum st_retval {ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK};
|
51
51
|
#else
|
52
52
|
#if HAS_TOP_LEVEL_ST_H
|
53
|
-
|
53
|
+
/* Only on travis, local is where it is for all others. Seems to vary depending on the travis machine picked up. */
|
54
54
|
#include "st.h"
|
55
55
|
#else
|
56
56
|
#include "ruby/st.h"
|
@@ -118,9 +118,9 @@ typedef enum {
|
|
118
118
|
typedef enum {
|
119
119
|
NoCode = 0,
|
120
120
|
ArrayCode = 'a',
|
121
|
-
String64Code = 'b',
|
121
|
+
String64Code = 'b', /* base64 encoded String */
|
122
122
|
ClassCode = 'c',
|
123
|
-
Symbol64Code = 'd',
|
123
|
+
Symbol64Code = 'd', /* base64 encoded Symbol */
|
124
124
|
DateCode = 'D',
|
125
125
|
ExceptionCode = 'e',
|
126
126
|
FloatCode = 'f',
|
@@ -128,7 +128,7 @@ typedef enum {
|
|
128
128
|
HashCode = 'h',
|
129
129
|
FixnumCode = 'i',
|
130
130
|
BignumCode = 'j',
|
131
|
-
KeyCode = 'k',
|
131
|
+
KeyCode = 'k', /* indicates the value is a hash key, kind of a hack */
|
132
132
|
RationalCode = 'l',
|
133
133
|
SymbolCode = 'm',
|
134
134
|
FalseClassCode = 'n',
|
@@ -170,22 +170,22 @@ typedef struct _ParseCallbacks {
|
|
170
170
|
typedef struct _CircArray {
|
171
171
|
VALUE obj_array[1024];
|
172
172
|
VALUE *objs;
|
173
|
-
unsigned long size;
|
173
|
+
unsigned long size; /* allocated size or initial array size */
|
174
174
|
unsigned long cnt;
|
175
175
|
} *CircArray;
|
176
176
|
|
177
177
|
typedef struct _Options {
|
178
|
-
char encoding[64];
|
179
|
-
int indent;
|
180
|
-
int trace;
|
181
|
-
char with_dtd;
|
182
|
-
char with_xml;
|
183
|
-
char with_instruct;
|
184
|
-
char circular;
|
185
|
-
char xsd_date;
|
186
|
-
char mode;
|
187
|
-
char effort;
|
188
|
-
char sym_keys;
|
178
|
+
char encoding[64]; /* encoding, stored in the option to avoid GC invalidation in default values */
|
179
|
+
int indent; /* indention for dump, default 2 */
|
180
|
+
int trace; /* trace level */
|
181
|
+
char with_dtd; /* YesNo */
|
182
|
+
char with_xml; /* YesNo */
|
183
|
+
char with_instruct; /* YesNo */
|
184
|
+
char circular; /* YesNo */
|
185
|
+
char xsd_date; /* YesNo */
|
186
|
+
char mode; /* LoadMode */
|
187
|
+
char effort; /* Effort */
|
188
|
+
char sym_keys; /* symbolize keys */
|
189
189
|
} *Options;
|
190
190
|
|
191
191
|
/* parse information structure */
|
data/ext/ox/parse.c
CHANGED
@@ -41,7 +41,7 @@ static void read_doctype(PInfo pi);
|
|
41
41
|
static void read_comment(PInfo pi);
|
42
42
|
static void read_element(PInfo pi);
|
43
43
|
static void read_text(PInfo pi);
|
44
|
-
|
44
|
+
/*static void read_reduced_text(PInfo pi); */
|
45
45
|
static void read_cdata(PInfo pi);
|
46
46
|
static char* read_name_token(PInfo pi);
|
47
47
|
static char* read_quoted_value(PInfo pi);
|
@@ -116,7 +116,7 @@ ox_parse(char *xml, ParseCallbacks pcb, char **endp, Options options) {
|
|
116
116
|
pi.encoding = 0;
|
117
117
|
pi.options = options;
|
118
118
|
while (1) {
|
119
|
-
next_non_white(&pi);
|
119
|
+
next_non_white(&pi); /* skip white space */
|
120
120
|
if ('\0' == *pi.s) {
|
121
121
|
break;
|
122
122
|
}
|
@@ -124,12 +124,12 @@ ox_parse(char *xml, ParseCallbacks pcb, char **endp, Options options) {
|
|
124
124
|
*endp = pi.s;
|
125
125
|
break;
|
126
126
|
}
|
127
|
-
if ('<' != *pi.s) {
|
127
|
+
if ('<' != *pi.s) { /* all top level entities start with < */
|
128
128
|
raise_error("invalid format, expected <", pi.str, pi.s);
|
129
129
|
}
|
130
|
-
pi.s++;
|
130
|
+
pi.s++; /* past < */
|
131
131
|
switch (*pi.s) {
|
132
|
-
case '?':
|
132
|
+
case '?': /* prolog */
|
133
133
|
pi.s++;
|
134
134
|
read_instruction(&pi);
|
135
135
|
break;
|
@@ -138,11 +138,11 @@ ox_parse(char *xml, ParseCallbacks pcb, char **endp, Options options) {
|
|
138
138
|
if ('\0' == *pi.s) {
|
139
139
|
raise_error("invalid format, DOCTYPE or comment not terminated", pi.str, pi.s);
|
140
140
|
} else if ('-' == *pi.s) {
|
141
|
-
pi.s++;
|
141
|
+
pi.s++; /* skip - */
|
142
142
|
if ('-' != *pi.s) {
|
143
143
|
raise_error("invalid format, bad comment format", pi.str, pi.s);
|
144
144
|
} else {
|
145
|
-
pi.s++;
|
145
|
+
pi.s++; /* skip second - */
|
146
146
|
read_comment(&pi);
|
147
147
|
}
|
148
148
|
} else if (0 == strncmp("DOCTYPE", pi.s, 7)) {
|
@@ -178,7 +178,7 @@ read_instruction(PInfo pi) {
|
|
178
178
|
end = pi->s;
|
179
179
|
next_non_white(pi);
|
180
180
|
c = *pi->s;
|
181
|
-
*end = '\0';
|
181
|
+
*end = '\0'; /* terminate name */
|
182
182
|
if ('?' != c) {
|
183
183
|
while ('?' != *pi->s) {
|
184
184
|
if ('\0' == *pi->s) {
|
@@ -191,8 +191,8 @@ read_instruction(PInfo pi) {
|
|
191
191
|
if ('=' != *pi->s++) {
|
192
192
|
raise_error("invalid format, no attribute value", pi->str, pi->s);
|
193
193
|
}
|
194
|
-
*end = '\0';
|
195
|
-
|
194
|
+
*end = '\0'; /* terminate name */
|
195
|
+
/* read value */
|
196
196
|
next_non_white(pi);
|
197
197
|
a->value = read_quoted_value(pi);
|
198
198
|
a++;
|
@@ -276,7 +276,7 @@ read_comment(PInfo pi) {
|
|
276
276
|
break;
|
277
277
|
}
|
278
278
|
}
|
279
|
-
*end = '\0';
|
279
|
+
*end = '\0'; /* in case the comment was blank */
|
280
280
|
pi->s = end + 3;
|
281
281
|
if (0 != pi->pcb->add_comment) {
|
282
282
|
pi->pcb->add_comment(pi, comment);
|
@@ -308,7 +308,7 @@ read_element(PInfo pi) {
|
|
308
308
|
/* empty element, no attributes and no children */
|
309
309
|
pi->s++;
|
310
310
|
if ('>' != *pi->s) {
|
311
|
-
|
311
|
+
/*printf("*** '%s' ***\n", pi->s); */
|
312
312
|
raise_error("invalid format, element not closed", pi->str, pi->s);
|
313
313
|
}
|
314
314
|
pi->s++; /* past > */
|
@@ -328,7 +328,7 @@ read_element(PInfo pi) {
|
|
328
328
|
case '\0':
|
329
329
|
raise_error("invalid format, document not terminated", pi->str, pi->s);
|
330
330
|
case '/':
|
331
|
-
|
331
|
+
/* Element with just attributes. */
|
332
332
|
pi->s++;
|
333
333
|
if ('>' != *pi->s) {
|
334
334
|
raise_error("invalid format, element not closed", pi->str, pi->s);
|
@@ -340,7 +340,7 @@ read_element(PInfo pi) {
|
|
340
340
|
|
341
341
|
return;
|
342
342
|
case '>':
|
343
|
-
|
343
|
+
/* has either children or a value */
|
344
344
|
pi->s++;
|
345
345
|
hasChildren = 1;
|
346
346
|
done = 1;
|
@@ -348,16 +348,16 @@ read_element(PInfo pi) {
|
|
348
348
|
pi->pcb->add_element(pi, ename, attrs, hasChildren);
|
349
349
|
break;
|
350
350
|
default:
|
351
|
-
|
352
|
-
|
351
|
+
/* Attribute name so it's an element and the attribute will be */
|
352
|
+
/* added to it. */
|
353
353
|
ap->name = read_name_token(pi);
|
354
354
|
end = pi->s;
|
355
355
|
next_non_white(pi);
|
356
356
|
if ('=' != *pi->s++) {
|
357
357
|
raise_error("invalid format, no attribute value", pi->str, pi->s);
|
358
358
|
}
|
359
|
-
*end = '\0';
|
360
|
-
|
359
|
+
*end = '\0'; /* terminate name */
|
360
|
+
/* read value */
|
361
361
|
next_non_white(pi);
|
362
362
|
ap->value = read_quoted_value(pi);
|
363
363
|
if (0 != strchr(ap->value, '&')) {
|
@@ -377,7 +377,7 @@ read_element(PInfo pi) {
|
|
377
377
|
char *start;
|
378
378
|
|
379
379
|
done = 0;
|
380
|
-
|
380
|
+
/* read children */
|
381
381
|
while (!done) {
|
382
382
|
start = pi->s;
|
383
383
|
next_non_white(pi);
|
@@ -418,21 +418,21 @@ read_element(PInfo pi) {
|
|
418
418
|
case '\0':
|
419
419
|
raise_error("invalid format, document not terminated", pi->str, pi->s);
|
420
420
|
default:
|
421
|
-
|
421
|
+
/* a child element */
|
422
422
|
read_element(pi);
|
423
423
|
break;
|
424
424
|
}
|
425
|
-
} else {
|
425
|
+
} else { /* read as TEXT */
|
426
426
|
pi->s = start;
|
427
|
-
|
427
|
+
/*pi->s--; */
|
428
428
|
read_text(pi);
|
429
|
-
|
429
|
+
/*read_reduced_text(pi); */
|
430
430
|
|
431
|
-
|
431
|
+
/* to exit read_text with no errors the next character must be < */
|
432
432
|
if ('/' == *(pi->s + 1) &&
|
433
433
|
0 == strncmp(ename, pi->s + 2, elen) &&
|
434
434
|
'>' == *(pi->s + elen + 2)) {
|
435
|
-
|
435
|
+
/* close tag after text so treat as a value */
|
436
436
|
pi->s += elen + 3;
|
437
437
|
pi->pcb->end_element(pi, ename);
|
438
438
|
return;
|
@@ -579,9 +579,9 @@ read_name_token(PInfo pi) {
|
|
579
579
|
case '\r':
|
580
580
|
return start;
|
581
581
|
case '\0':
|
582
|
-
|
582
|
+
/* documents never terminate after a name token */
|
583
583
|
raise_error("invalid format, document not terminated", pi->str, pi->s);
|
584
|
-
break;
|
584
|
+
break; /* to avoid warnings */
|
585
585
|
default:
|
586
586
|
break;
|
587
587
|
}
|
@@ -634,15 +634,15 @@ read_quoted_value(PInfo pi) {
|
|
634
634
|
if ('"' == *pi->s || ('\'' == *pi->s && StrictEffort != pi->options->effort)) {
|
635
635
|
char term = *pi->s;
|
636
636
|
|
637
|
-
pi->s++;
|
637
|
+
pi->s++; /* skip quote character */
|
638
638
|
value = pi->s;
|
639
639
|
for (; *pi->s != term; pi->s++) {
|
640
640
|
if ('\0' == *pi->s) {
|
641
641
|
raise_error("invalid format, document not terminated", pi->str, pi->s);
|
642
642
|
}
|
643
643
|
}
|
644
|
-
*pi->s = '\0';
|
645
|
-
pi->s++;
|
644
|
+
*pi->s = '\0'; /* terminate value */
|
645
|
+
pi->s++; /* move past quote */
|
646
646
|
} else if (StrictEffort == pi->options->effort) {
|
647
647
|
raise_error("invalid format, expected a quote character", pi->str, pi->s);
|
648
648
|
} else {
|
@@ -651,7 +651,7 @@ read_quoted_value(PInfo pi) {
|
|
651
651
|
if ('\0' == *pi->s) {
|
652
652
|
raise_error("invalid format, document not terminated", pi->str, pi->s);
|
653
653
|
}
|
654
|
-
*pi->s++ = '\0';
|
654
|
+
*pi->s++ = '\0'; /* terminate value */
|
655
655
|
}
|
656
656
|
return value;
|
657
657
|
}
|