libxml-ruby 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +23 -23
  2. data/README +144 -144
  3. data/ext/libxml/extconf.rb +26 -27
  4. data/ext/libxml/libxml.c +7 -37
  5. data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
  6. data/ext/libxml/ruby_xml_attr.c +405 -387
  7. data/ext/libxml/ruby_xml_attr.h +19 -18
  8. data/ext/libxml/ruby_xml_document.c +1111 -1115
  9. data/ext/libxml/ruby_xml_document.h +27 -24
  10. data/ext/libxml/ruby_xml_dtd.c +168 -168
  11. data/ext/libxml/ruby_xml_html_parser.c +449 -450
  12. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  13. data/ext/libxml/ruby_xml_input_cbg.c +158 -158
  14. data/ext/libxml/ruby_xml_node.c +2410 -2395
  15. data/ext/libxml/ruby_xml_node.h +1 -1
  16. data/ext/libxml/ruby_xml_node_set.c +170 -170
  17. data/ext/libxml/ruby_xml_node_set.h +1 -1
  18. data/ext/libxml/ruby_xml_ns.c +153 -153
  19. data/ext/libxml/ruby_xml_ns.h +1 -1
  20. data/ext/libxml/ruby_xml_parser.c +1425 -1422
  21. data/ext/libxml/ruby_xml_parser.h +1 -1
  22. data/ext/libxml/ruby_xml_parser_context.c +750 -716
  23. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  24. data/ext/libxml/ruby_xml_reader.c +900 -896
  25. data/ext/libxml/ruby_xml_sax_parser.c +485 -485
  26. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_schema.c +146 -142
  28. data/ext/libxml/ruby_xml_state.c +5 -6
  29. data/ext/libxml/ruby_xml_state.h +1 -0
  30. data/ext/libxml/ruby_xml_tree.c +43 -43
  31. data/ext/libxml/ruby_xml_tree.h +1 -1
  32. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  33. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  34. data/ext/libxml/ruby_xml_xpath.c +243 -252
  35. data/ext/libxml/ruby_xml_xpath.h +1 -1
  36. data/ext/libxml/ruby_xml_xpath_context.c +118 -118
  37. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  38. data/ext/libxml/ruby_xml_xpath_object.c +43 -29
  39. data/ext/libxml/ruby_xml_xpath_object.h +0 -1
  40. data/ext/libxml/ruby_xml_xpointer.c +100 -100
  41. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  42. data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
  43. data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
  44. data/ext/libxml/sax_parser_callbacks.inc +213 -213
  45. data/ext/libxml/version.h +9 -9
  46. data/lib/libxml.rb +24 -3
  47. data/mingw/libiconv-2.dll +0 -0
  48. data/mingw/libxml2-2.dll +0 -0
  49. data/mingw/libxml_ruby.so +0 -0
  50. data/mingw/mingw.rake +36 -0
  51. data/test/dtd-test.rb +24 -24
  52. data/test/etc_doc_to_s.rb +1 -3
  53. data/test/ets_copy_bug.rb +21 -21
  54. data/test/ets_copy_bug2.rb +32 -32
  55. data/test/ets_copy_bug3.rb +38 -0
  56. data/test/ets_doc_file.rb +1 -0
  57. data/test/{model/default_validation_bug.rb → gc.log} +0 -0
  58. data/test/merge_bug.rb +55 -55
  59. data/test/schema-test.rb +74 -74
  60. data/test/tc_well_formed.rb +11 -0
  61. data/test/tc_xml_document.rb +52 -52
  62. data/test/tc_xml_document_write.rb +24 -24
  63. data/test/tc_xml_document_write2.rb +54 -54
  64. data/test/tc_xml_document_write3.rb +96 -96
  65. data/test/tc_xml_html_parser.rb +63 -63
  66. data/test/tc_xml_node.rb +59 -59
  67. data/test/tc_xml_node2.rb +25 -25
  68. data/test/tc_xml_node3.rb +27 -27
  69. data/test/tc_xml_node4.rb +86 -86
  70. data/test/tc_xml_node5.rb +52 -52
  71. data/test/tc_xml_node6.rb +27 -27
  72. data/test/tc_xml_node7.rb +35 -35
  73. data/test/tc_xml_node8.rb +32 -32
  74. data/test/tc_xml_node9.rb +32 -32
  75. data/test/tc_xml_node_set.rb +24 -24
  76. data/test/tc_xml_node_set2.rb +37 -37
  77. data/test/tc_xml_node_xlink.rb +28 -28
  78. data/test/tc_xml_parser.rb +190 -178
  79. data/test/tc_xml_parser2.rb +16 -17
  80. data/test/tc_xml_parser3.rb +23 -23
  81. data/test/tc_xml_parser4.rb +33 -33
  82. data/test/tc_xml_parser5.rb +27 -27
  83. data/test/tc_xml_parser6.rb +23 -23
  84. data/test/tc_xml_parser7.rb +28 -28
  85. data/test/tc_xml_parser8.rb +32 -32
  86. data/test/tc_xml_parser9.rb +11 -0
  87. data/test/tc_xml_parser_context.rb +88 -88
  88. data/test/tc_xml_reader.rb +112 -109
  89. data/test/tc_xml_sax_parser.rb +104 -94
  90. data/test/tc_xml_sax_parser2.rb +51 -0
  91. data/test/tc_xml_xinclude.rb +30 -30
  92. data/test/tc_xml_xpath.rb +38 -38
  93. data/test/tc_xml_xpath2.rb +14 -0
  94. data/test/tc_xml_xpointer.rb +78 -78
  95. data/vc/libxml.sln +20 -0
  96. data/vc/libxml.vcproj +389 -0
  97. data/work/Rakefile +247 -0
  98. data/work/task/make +26 -0
  99. data/work/task/memory +37 -0
  100. data/work/task/rdoc +39 -0
  101. data/work/task/setup +1616 -0
  102. data/work/task/test +29 -0
  103. data/work/test/ets_runner.rb +33 -0
  104. data/work/test/libxml_test.rb +3 -0
  105. data/work/test/runner.rb +0 -0
  106. data/work/test/runner_ets.rb +33 -0
  107. data/work/vc/debug/libxml.exp +0 -0
  108. data/work/vc/debug/libxml.ilk +0 -0
  109. data/work/vc/debug/libxml.lib +0 -0
  110. data/work/vc/debug/libxml.pdb +0 -0
  111. data/work/vc/debug/libxml.so +0 -0
  112. metadata +158 -189
  113. data/MANIFEST +0 -138
  114. data/NOTES +0 -9
  115. data/Rakefile +0 -38
  116. data/TODO +0 -75
  117. data/VERSION +0 -1
  118. data/log/Changelog-0.txt +0 -426
  119. data/log/Changelog.txt +0 -435
  120. data/meta/project.yaml +0 -27
  121. data/meta/unixname +0 -1
  122. data/setup.rb +0 -1472
  123. data/site/css/normal.css +0 -182
  124. data/site/img/raze-tiny.png +0 -0
  125. data/site/img/red-cube.jpg +0 -0
  126. data/site/img/xml-ruby.png +0 -0
  127. data/site/index.xml +0 -43
  128. data/site/install.xml +0 -77
  129. data/site/layout.rhtml +0 -38
  130. data/site/layout.xsl +0 -67
  131. data/site/license.xml +0 -32
  132. data/site/log/changelog.xml +0 -1324
  133. data/site/log/changelog.xsl +0 -42
  134. data/test/model/merge_bug_data.xml +0 -58
  135. data/test/model/rubynet.xml +0 -78
  136. data/test/model/rubynet_project +0 -13
  137. data/test/model/saxtest.xml +0 -5
  138. data/test/model/simple.xml +0 -7
  139. data/test/model/xinclude.xml +0 -5
@@ -1,716 +1,750 @@
1
- /* $Id: ruby_xml_parser_context.c 225 2007-12-07 04:58:09Z transami $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "libxml.h"
6
- #include "ruby_xml_parser_context.h"
7
-
8
- /* TODO:
9
- *
10
- * *) xmlParserInput class/structure
11
- * *) errNo and mappings
12
- * *) validity context
13
- * *) record_info or stats class/structure
14
- * *) xmlParserNodeInfoSeq
15
- * *) xmlParserInputState
16
- */
17
- VALUE cXMLParserContext;
18
-
19
- /*
20
- * call-seq:
21
- * context.data_directory => "dir"
22
- *
23
- * Obtain the data directory associated with this context.
24
- */
25
- VALUE
26
- ruby_xml_parser_context_data_directory_get(VALUE self) {
27
- ruby_xml_parser_context *rxpc;
28
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
29
-
30
- if (rxpc->ctxt->directory == NULL)
31
- return(Qnil);
32
- else
33
- return(rb_str_new2(rxpc->ctxt->directory));
34
- }
35
-
36
-
37
- /*
38
- * call-seq:
39
- * context.depth => num
40
- *
41
- * Obtain the depth of this context.
42
- */
43
- VALUE
44
- ruby_xml_parser_context_depth_get(VALUE self) {
45
- ruby_xml_parser_context *rxpc;
46
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
47
-
48
- return(INT2NUM(rxpc->ctxt->depth));
49
- }
50
-
51
-
52
- /*
53
- * call-seq:
54
- * context.disable_sax? => (true|false)
55
- *
56
- * Determine whether SAX-based processing is disabled
57
- * in this context.
58
- */
59
- VALUE
60
- ruby_xml_parser_context_disable_sax_q(VALUE self) {
61
- ruby_xml_parser_context *rxpc;
62
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
63
-
64
- if (rxpc->ctxt->disableSAX)
65
- return(Qtrue);
66
- else
67
- return(Qfalse);
68
- }
69
-
70
-
71
- /*
72
- * call-seq:
73
- * context.doc => document
74
- *
75
- * Obtain the +XML::Document+ associated with this context.
76
- */
77
- VALUE
78
- ruby_xml_parser_context_doc_get(VALUE self) {
79
- ruby_xml_parser_context *rxpc;
80
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
81
-
82
- if (rxpc->ctxt->myDoc == NULL)
83
- return(Qnil);
84
-
85
- return(ruby_xml_document_wrap(cXMLDocument, rxpc->ctxt->myDoc));
86
- }
87
-
88
-
89
- /*
90
- * call-seq:
91
- * context.docbook? => (true|false)
92
- *
93
- * Determine whether this is a docbook context.
94
- */
95
- VALUE
96
- ruby_xml_parser_context_docbook_q(VALUE self) {
97
- ruby_xml_parser_context *rxpc;
98
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
99
-
100
- if (rxpc->ctxt->html == 2) // TODO check this
101
- return(Qtrue);
102
- else
103
- return(Qfalse);
104
- }
105
-
106
-
107
- /*
108
- * call-seq:
109
- * context.encoding => "encoding"
110
- *
111
- * Obtain the character encoding identifier used in
112
- * this context.
113
- */
114
- VALUE
115
- ruby_xml_parser_context_encoding_get(VALUE self) {
116
- ruby_xml_parser_context *rxpc;
117
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
118
-
119
- if (rxpc->ctxt->encoding == NULL)
120
- return(Qnil);
121
- else
122
- return(rb_str_new2((const char*)rxpc->ctxt->encoding));
123
- }
124
-
125
-
126
- /*
127
- * call-seq:
128
- * context.errno => num
129
- *
130
- * Obtain the last-error number in this context.
131
- */
132
- VALUE
133
- ruby_xml_parser_context_errno_get(VALUE self) {
134
- ruby_xml_parser_context *rxpc;
135
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
136
-
137
- return(INT2NUM(rxpc->ctxt->errNo));
138
- }
139
-
140
-
141
- void
142
- ruby_xml_parser_context_free(ruby_xml_parser_context *rxpc) {
143
- if (rxpc->ctxt != NULL) {
144
- xmlFreeParserCtxt(rxpc->ctxt);
145
- rxpc->ctxt = NULL;
146
- }
147
-
148
- free(rxpc);
149
- }
150
-
151
- void
152
- ruby_xml_parser_context_mark(void *v) {
153
- if ( v == NULL ) return;
154
- ruby_xml_state_marker();
155
- }
156
-
157
- /*
158
- * call-seq:
159
- * context.html? => (true|false)
160
- *
161
- * Determine whether this is an html context.
162
- */
163
- VALUE
164
- ruby_xml_parser_context_html_q(VALUE self) {
165
- ruby_xml_parser_context *rxpc;
166
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
167
-
168
- if (rxpc->ctxt->html == 1)
169
- return(Qtrue);
170
- else
171
- return(Qfalse);
172
- }
173
-
174
-
175
- /*
176
- * call-seq:
177
- * context.max_num_streams => num
178
- *
179
- * Obtain the limit on the number of IO streams opened in
180
- * this context.
181
- */
182
- VALUE
183
- ruby_xml_parser_context_io_max_num_streams_get(VALUE self) {
184
- // TODO alias to max_streams and dep this?
185
- ruby_xml_parser_context *rxpc;
186
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
187
-
188
- return(INT2NUM(rxpc->ctxt->inputMax));
189
- }
190
-
191
-
192
- /*
193
- * call-seq:
194
- * context.num_streams => "dir"
195
- *
196
- * Obtain the actual number of IO streams in this
197
- * context.
198
- */
199
- VALUE
200
- ruby_xml_parser_context_io_num_streams_get(VALUE self) {
201
- ruby_xml_parser_context *rxpc;
202
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
203
-
204
- return(INT2NUM(rxpc->ctxt->inputNr));
205
- }
206
-
207
-
208
- /*
209
- * call-seq:
210
- * context.keep_blanks? => (true|false)
211
- *
212
- * Determine whether parsers in this context retain
213
- * whitespace.
214
- */
215
- VALUE
216
- ruby_xml_parser_context_keep_blanks_q(VALUE self) {
217
- ruby_xml_parser_context *rxpc;
218
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
219
-
220
- if (rxpc->ctxt->keepBlanks)
221
- return(Qtrue);
222
- else
223
- return(Qfalse);
224
- }
225
-
226
-
227
- /*
228
- * call-seq:
229
- * context.name_depth => num
230
- *
231
- * Obtain the name depth for this context.
232
- */
233
- VALUE
234
- ruby_xml_parser_context_name_depth_get(VALUE self) {
235
- ruby_xml_parser_context *rxpc;
236
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
237
-
238
- return(INT2NUM(rxpc->ctxt->nameNr));
239
- }
240
-
241
-
242
- /*
243
- * call-seq:
244
- * context.name_depth_max => num
245
- *
246
- * Obtain the maximum name depth for this context.
247
- */
248
- VALUE
249
- ruby_xml_parser_context_name_depth_max_get(VALUE self) {
250
- ruby_xml_parser_context *rxpc;
251
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
252
-
253
- return(INT2NUM(rxpc->ctxt->nameMax));
254
- }
255
-
256
-
257
- /*
258
- * call-seq:
259
- * context.name_node => "name"
260
- *
261
- * Obtain the name node for this context.
262
- */
263
- VALUE
264
- ruby_xml_parser_context_name_node_get(VALUE self) {
265
- ruby_xml_parser_context *rxpc;
266
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
267
-
268
- if (rxpc->ctxt->name == NULL)
269
- return(Qnil);
270
- else
271
- return(rb_str_new2((const char*)rxpc->ctxt->name));
272
- }
273
-
274
-
275
- /*
276
- * call-seq:
277
- * context.name_tab => ["name", ..., "name"]
278
- *
279
- * Obtain the name table for this context.
280
- */
281
- VALUE
282
- ruby_xml_parser_context_name_tab_get(VALUE self) {
283
- int i;
284
- ruby_xml_parser_context *rxpc;
285
- VALUE tab_ary;
286
-
287
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
288
-
289
- if (rxpc->ctxt->nameTab == NULL)
290
- return(Qnil);
291
-
292
- tab_ary = rb_ary_new();
293
-
294
- for (i = (rxpc->ctxt->nameNr - 1); i >= 0; i--) {
295
- if (rxpc->ctxt->nameTab[i] == NULL)
296
- continue;
297
- else
298
- rb_ary_push(tab_ary, rb_str_new2((const char*)rxpc->ctxt->nameTab[i]));
299
- }
300
-
301
- return(tab_ary);
302
- }
303
-
304
-
305
- /*
306
- * call-seq:
307
- * context.node_depth => num
308
- *
309
- * Obtain the node depth for this context.
310
- */
311
- VALUE
312
- ruby_xml_parser_context_node_depth_get(VALUE self) {
313
- ruby_xml_parser_context *rxpc;
314
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
315
-
316
- return(INT2NUM(rxpc->ctxt->nodeNr));
317
- }
318
-
319
-
320
- /*
321
- * call-seq:
322
- * context.node => node
323
- *
324
- * Obtain the root node of this context.
325
- */
326
- VALUE
327
- ruby_xml_parser_context_node_get(VALUE self) {
328
- ruby_xml_parser_context *rxpc;
329
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
330
-
331
- if (rxpc->ctxt->node == NULL)
332
- return(Qnil);
333
- else
334
- return(ruby_xml_node2_wrap(cXMLNode,
335
- rxpc->ctxt->node));
336
- }
337
-
338
-
339
- /*
340
- * call-seq:
341
- * context.node_depth_max => num
342
- *
343
- * Obtain the maximum node depth for this context.
344
- */
345
- VALUE
346
- ruby_xml_parser_context_node_depth_max_get(VALUE self) {
347
- ruby_xml_parser_context *rxpc;
348
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
349
-
350
- return(INT2NUM(rxpc->ctxt->nodeMax));
351
- }
352
-
353
-
354
- /*
355
- * call-seq:
356
- * context.num_chars => num
357
- *
358
- * Obtain the number of characters in this context.
359
- */
360
- VALUE
361
- ruby_xml_parser_context_num_chars_get(VALUE self) {
362
- ruby_xml_parser_context *rxpc;
363
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
364
-
365
- return(LONG2NUM(rxpc->ctxt->nbChars));
366
- }
367
-
368
-
369
- VALUE
370
- ruby_xml_parser_context_new(VALUE class, xmlParserCtxtPtr ctxt) {
371
- ruby_xml_parser_context *rxpc;
372
-
373
- rxpc = ALLOC(ruby_xml_parser_context);
374
-
375
- rxpc->ctxt = ctxt;
376
- return Data_Wrap_Struct(class,
377
- ruby_xml_parser_context_mark,
378
- ruby_xml_parser_context_free,
379
- rxpc);
380
- }
381
-
382
-
383
- VALUE
384
- ruby_xml_parser_context_new2(VALUE class) {
385
- return(ruby_xml_parser_context_new(class, NULL));
386
- }
387
-
388
-
389
- VALUE
390
- ruby_xml_parser_context_new3() {
391
- return(ruby_xml_parser_context_new2(cXMLParserContext));
392
- }
393
-
394
-
395
- /*
396
- * call-seq:
397
- * context.replace_entities? => (true|false)
398
- *
399
- * Determine whether external entity replacement is enabled in this
400
- * context.
401
- */
402
- VALUE
403
- ruby_xml_parser_context_replace_entities_q(VALUE self) {
404
- ruby_xml_parser_context *rxpc;
405
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
406
-
407
- if (rxpc->ctxt->replaceEntities)
408
- return(Qtrue);
409
- else
410
- return(Qfalse);
411
- }
412
-
413
-
414
- /*
415
- * call-seq:
416
- * context.replace_entities = true|false
417
- *
418
- * Control whether external entity replacement is enabled in this
419
- * context.
420
- */
421
- VALUE
422
- ruby_xml_parser_context_replace_entities_set(VALUE self, VALUE bool) {
423
- ruby_xml_parser_context *rxpc;
424
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
425
-
426
- if (TYPE(bool) == T_FALSE) {
427
- rxpc->ctxt->replaceEntities = 0;
428
- return(Qfalse);
429
- } else {
430
- rxpc->ctxt->replaceEntities = 1;
431
- return(Qfalse);
432
- }
433
- }
434
-
435
-
436
- /*
437
- * call-seq:
438
- * context.space_depth => num
439
- *
440
- * Obtain the space depth for this context.
441
- */
442
- VALUE
443
- ruby_xml_parser_context_space_depth_get(VALUE self) {
444
- ruby_xml_parser_context *rxpc;
445
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
446
-
447
- return(INT2NUM(rxpc->ctxt->spaceNr));
448
- }
449
-
450
-
451
- /*
452
- * call-seq:
453
- * context.space_depth => num
454
- *
455
- * Obtain the maximum space depth for this context.
456
- */
457
- VALUE
458
- ruby_xml_parser_context_space_depth_max_get(VALUE self) {
459
- ruby_xml_parser_context *rxpc;
460
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
461
-
462
- return(INT2NUM(rxpc->ctxt->spaceMax));
463
- }
464
-
465
-
466
- /*
467
- * call-seq:
468
- * context.subset_external? => (true|false)
469
- *
470
- * Determine whether this context is a subset of an
471
- * external context.
472
- */
473
- VALUE
474
- ruby_xml_parser_context_subset_external_q(VALUE self) {
475
- ruby_xml_parser_context *rxpc;
476
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
477
-
478
- if (rxpc->ctxt->inSubset == 2)
479
- return(Qtrue);
480
- else
481
- return(Qfalse);
482
- }
483
-
484
-
485
- /*
486
- * call-seq:
487
- * context.subset_internal? => (true|false)
488
- *
489
- * Determine whether this context is a subset of an
490
- * internal context.
491
- */
492
- VALUE
493
- ruby_xml_parser_context_subset_internal_q(VALUE self) {
494
- ruby_xml_parser_context *rxpc;
495
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
496
-
497
- if (rxpc->ctxt->inSubset == 1)
498
- return(Qtrue);
499
- else
500
- return(Qfalse);
501
- }
502
-
503
-
504
- /*
505
- * call-seq:
506
- * context.subset_name => "name"
507
- *
508
- * Obtain this context's subset name (valid only if
509
- * either of subset_external? or subset_internal?
510
- * is true).
511
- */
512
- VALUE
513
- ruby_xml_parser_context_subset_name_get(VALUE self) {
514
- ruby_xml_parser_context *rxpc;
515
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
516
-
517
- if (rxpc->ctxt->intSubName == NULL)
518
- return(Qnil);
519
- else
520
- return(rb_str_new2((const char*)rxpc->ctxt->intSubName));
521
- }
522
-
523
-
524
- /*
525
- * call-seq:
526
- * context.subset_external_uri => "uri"
527
- *
528
- * Obtain this context's external subset URI. (valid only if
529
- * either of subset_external? or subset_internal?
530
- * is true).
531
- */
532
- VALUE
533
- ruby_xml_parser_context_subset_external_uri_get(VALUE self) {
534
- ruby_xml_parser_context *rxpc;
535
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
536
-
537
- if (rxpc->ctxt->extSubURI == NULL)
538
- return(Qnil);
539
- else
540
- return(rb_str_new2((const char*)rxpc->ctxt->extSubURI));
541
- }
542
-
543
-
544
- /*
545
- * call-seq:
546
- * context.subset_external_system_id => "system_id"
547
- *
548
- * Obtain this context's external subset system identifier.
549
- * (valid only if either of subset_external? or subset_internal?
550
- * is true).
551
- */
552
- VALUE
553
- ruby_xml_parser_context_subset_external_system_id_get(VALUE self) {
554
- ruby_xml_parser_context *rxpc;
555
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
556
-
557
- if (rxpc->ctxt->extSubSystem == NULL)
558
- return(Qnil);
559
- else
560
- return(rb_str_new2((const char*)rxpc->ctxt->extSubSystem));
561
- }
562
-
563
-
564
- /*
565
- * call-seq:
566
- * context.standalone? => (true|false)
567
- *
568
- * Determine whether this is a standalone context.
569
- */
570
- VALUE
571
- ruby_xml_parser_context_standalone_q(VALUE self) {
572
- ruby_xml_parser_context *rxpc;
573
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
574
-
575
- if (rxpc->ctxt->standalone)
576
- return(Qtrue);
577
- else
578
- return(Qfalse);
579
- }
580
-
581
-
582
- /*
583
- * call-seq:
584
- * context.stats? => (true|false)
585
- *
586
- * Determine whether this context maintains statistics.
587
- */
588
- VALUE
589
- ruby_xml_parser_context_stats_q(VALUE self) {
590
- ruby_xml_parser_context *rxpc;
591
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
592
-
593
- if (rxpc->ctxt->record_info)
594
- return(Qtrue);
595
- else
596
- return(Qfalse);
597
- }
598
-
599
-
600
- /*
601
- * call-seq:
602
- * context.valid? => (true|false)
603
- *
604
- * Determine whether this context is valid.
605
- */
606
- VALUE
607
- ruby_xml_parser_context_valid_q(VALUE self) {
608
- ruby_xml_parser_context *rxpc;
609
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
610
-
611
- if (rxpc->ctxt->valid)
612
- return(Qtrue);
613
- else
614
- return(Qfalse);
615
- }
616
-
617
-
618
- /*
619
- * call-seq:
620
- * context.validate? => (true|false)
621
- *
622
- * Determine whether validation is enabled in this context.
623
- */
624
- VALUE
625
- ruby_xml_parser_context_validate_q(VALUE self) {
626
- ruby_xml_parser_context *rxpc;
627
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
628
-
629
- if (rxpc->ctxt->validate)
630
- return(Qtrue);
631
- else
632
- return(Qfalse);
633
- }
634
-
635
-
636
- /*
637
- * call-seq:
638
- * context.version => "version"
639
- *
640
- * Obtain this context's version identifier.
641
- */
642
- VALUE
643
- ruby_xml_parser_context_version_get(VALUE self) {
644
- ruby_xml_parser_context *rxpc;
645
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
646
-
647
- if (rxpc->ctxt->version == NULL)
648
- return(Qnil);
649
- else
650
- return(rb_str_new2((const char*)rxpc->ctxt->version));
651
- }
652
-
653
-
654
- /*
655
- * call-seq:
656
- * context.well_formed? => (true|false)
657
- *
658
- * Determine whether this context contains well-formed XML.
659
- */
660
- VALUE
661
- ruby_xml_parser_context_well_formed_q(VALUE self) {
662
- ruby_xml_parser_context *rxpc;
663
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
664
-
665
- if (rxpc->ctxt->wellFormed)
666
- return(Qtrue);
667
- else
668
- return(Qfalse);
669
- }
670
-
671
-
672
- // Rdoc needs to know
673
- #ifdef RDOC_NEVER_DEFINED
674
- mXML = rb_define_module("XML");
675
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
676
- #endif
677
-
678
- void
679
- ruby_init_xml_parser_context(void) {
680
- cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
681
-
682
- rb_define_method(cXMLParserContext, "data_directory", ruby_xml_parser_context_data_directory_get, 0);
683
- rb_define_method(cXMLParserContext, "depth", ruby_xml_parser_context_depth_get, 0);
684
- rb_define_method(cXMLParserContext, "disable_sax?", ruby_xml_parser_context_disable_sax_q, 0);
685
- rb_define_method(cXMLParserContext, "doc", ruby_xml_parser_context_doc_get, 0);
686
- rb_define_method(cXMLParserContext, "docbook?", ruby_xml_parser_context_docbook_q, 0);
687
- rb_define_method(cXMLParserContext, "encoding", ruby_xml_parser_context_encoding_get, 0);
688
- rb_define_method(cXMLParserContext, "errno", ruby_xml_parser_context_errno_get, 0);
689
- rb_define_method(cXMLParserContext, "html?", ruby_xml_parser_context_html_q, 0);
690
- rb_define_method(cXMLParserContext, "io_max_num_streams", ruby_xml_parser_context_io_max_num_streams_get, 0);
691
- rb_define_method(cXMLParserContext, "io_num_streams", ruby_xml_parser_context_io_num_streams_get, 0);
692
- rb_define_method(cXMLParserContext, "keep_blanks?", ruby_xml_parser_context_keep_blanks_q, 0);
693
- rb_define_method(cXMLParserContext, "name_node", ruby_xml_parser_context_name_node_get, 0);
694
- rb_define_method(cXMLParserContext, "name_depth", ruby_xml_parser_context_name_depth_get, 0);
695
- rb_define_method(cXMLParserContext, "name_depth_max", ruby_xml_parser_context_name_depth_max_get, 0);
696
- rb_define_method(cXMLParserContext, "name_tab", ruby_xml_parser_context_name_tab_get, 0);
697
- rb_define_method(cXMLParserContext, "node", ruby_xml_parser_context_node_get, 0);
698
- rb_define_method(cXMLParserContext, "node_depth", ruby_xml_parser_context_node_depth_get, 0);
699
- rb_define_method(cXMLParserContext, "node_depth_max", ruby_xml_parser_context_node_depth_max_get, 0);
700
- rb_define_method(cXMLParserContext, "num_chars", ruby_xml_parser_context_num_chars_get, 0);
701
- rb_define_method(cXMLParserContext, "replace_entities?", ruby_xml_parser_context_replace_entities_q, 0);
702
- rb_define_method(cXMLParserContext, "replace_entities=", ruby_xml_parser_context_replace_entities_set, 1);
703
- rb_define_method(cXMLParserContext, "space_depth", ruby_xml_parser_context_space_depth_get, 0);
704
- rb_define_method(cXMLParserContext, "space_depth_max", ruby_xml_parser_context_space_depth_max_get, 0);
705
- rb_define_method(cXMLParserContext, "subset_external?", ruby_xml_parser_context_subset_external_q, 0);
706
- rb_define_method(cXMLParserContext, "subset_external_system_id", ruby_xml_parser_context_subset_external_system_id_get, 0);
707
- rb_define_method(cXMLParserContext, "subset_external_uri", ruby_xml_parser_context_subset_name_get, 0);
708
- rb_define_method(cXMLParserContext, "subset_internal?", ruby_xml_parser_context_subset_internal_q, 0);
709
- rb_define_method(cXMLParserContext, "subset_internal_name", ruby_xml_parser_context_subset_name_get, 0);
710
- rb_define_method(cXMLParserContext, "stats?", ruby_xml_parser_context_stats_q, 0);
711
- rb_define_method(cXMLParserContext, "standalone?", ruby_xml_parser_context_standalone_q, 0);
712
- rb_define_method(cXMLParserContext, "valid", ruby_xml_parser_context_valid_q, 0);
713
- rb_define_method(cXMLParserContext, "validate?", ruby_xml_parser_context_validate_q, 0);
714
- rb_define_method(cXMLParserContext, "version", ruby_xml_parser_context_version_get, 0);
715
- rb_define_method(cXMLParserContext, "well_formed?", ruby_xml_parser_context_well_formed_q, 0);
716
- }
1
+ /* $Id: ruby_xml_parser_context.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_parser_context.h"
7
+
8
+ /* TODO:
9
+ *
10
+ * *) xmlParserInput class/structure
11
+ * *) errNo and mappings
12
+ * *) validity context
13
+ * *) record_info or stats class/structure
14
+ * *) xmlParserNodeInfoSeq
15
+ * *) xmlParserInputState
16
+ */
17
+ VALUE cXMLParserContext;
18
+
19
+ /*
20
+ * call-seq:
21
+ * context.data_directory => "dir"
22
+ *
23
+ * Obtain the data directory associated with this context.
24
+ */
25
+ VALUE
26
+ ruby_xml_parser_context_data_directory_get(VALUE self) {
27
+ ruby_xml_parser_context *rxpc;
28
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
29
+
30
+ if (rxpc->ctxt->directory == NULL)
31
+ return(Qnil);
32
+ else
33
+ return(rb_str_new2(rxpc->ctxt->directory));
34
+ }
35
+
36
+
37
+ /*
38
+ * call-seq:
39
+ * context.depth => num
40
+ *
41
+ * Obtain the depth of this context.
42
+ */
43
+ VALUE
44
+ ruby_xml_parser_context_depth_get(VALUE self) {
45
+ ruby_xml_parser_context *rxpc;
46
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
47
+
48
+ return(INT2NUM(rxpc->ctxt->depth));
49
+ }
50
+
51
+
52
+ /*
53
+ * call-seq:
54
+ * context.disable_sax? => (true|false)
55
+ *
56
+ * Determine whether SAX-based processing is disabled
57
+ * in this context.
58
+ */
59
+ VALUE
60
+ ruby_xml_parser_context_disable_sax_q(VALUE self) {
61
+ ruby_xml_parser_context *rxpc;
62
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
63
+
64
+ if (rxpc->ctxt->disableSAX)
65
+ return(Qtrue);
66
+ else
67
+ return(Qfalse);
68
+ }
69
+
70
+
71
+ /*
72
+ * call-seq:
73
+ * context.doc => document
74
+ *
75
+ * Obtain the +XML::Document+ associated with this context.
76
+ */
77
+ VALUE
78
+ ruby_xml_parser_context_doc_get(VALUE self) {
79
+ ruby_xml_parser_context *rxpc;
80
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
81
+
82
+ if (rxpc->ctxt->myDoc == NULL)
83
+ return(Qnil);
84
+
85
+ return(ruby_xml_document_wrap(rxpc->ctxt->myDoc));
86
+ }
87
+
88
+
89
+ /*
90
+ * call-seq:
91
+ * context.docbook? => (true|false)
92
+ *
93
+ * Determine whether this is a docbook context.
94
+ */
95
+ VALUE
96
+ ruby_xml_parser_context_docbook_q(VALUE self) {
97
+ ruby_xml_parser_context *rxpc;
98
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
99
+
100
+ if (rxpc->ctxt->html == 2) // TODO check this
101
+ return(Qtrue);
102
+ else
103
+ return(Qfalse);
104
+ }
105
+
106
+
107
+ /*
108
+ * call-seq:
109
+ * context.encoding => "encoding"
110
+ *
111
+ * Obtain the character encoding identifier used in
112
+ * this context.
113
+ */
114
+ VALUE
115
+ ruby_xml_parser_context_encoding_get(VALUE self) {
116
+ ruby_xml_parser_context *rxpc;
117
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
118
+
119
+ if (rxpc->ctxt->encoding == NULL)
120
+ return(Qnil);
121
+ else
122
+ return(rb_str_new2((const char*)rxpc->ctxt->encoding));
123
+ }
124
+
125
+
126
+ /*
127
+ * call-seq:
128
+ * context.errno => num
129
+ *
130
+ * Obtain the last-error number in this context.
131
+ */
132
+ VALUE
133
+ ruby_xml_parser_context_errno_get(VALUE self) {
134
+ ruby_xml_parser_context *rxpc;
135
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
136
+
137
+ return(INT2NUM(rxpc->ctxt->errNo));
138
+ }
139
+
140
+
141
+ void
142
+ ruby_xml_parser_context_free(ruby_xml_parser_context *rxpc) {
143
+ if (rxpc->ctxt != NULL) {
144
+ xmlFreeParserCtxt(rxpc->ctxt);
145
+ rxpc->ctxt = NULL;
146
+ }
147
+
148
+ ruby_xfree(rxpc);
149
+ }
150
+
151
+ void
152
+ ruby_xml_parser_context_mark(void *v) {
153
+ if ( v == NULL ) return;
154
+ ruby_xml_state_marker();
155
+ }
156
+
157
+ /*
158
+ * call-seq:
159
+ * context.html? => (true|false)
160
+ *
161
+ * Determine whether this is an html context.
162
+ */
163
+ VALUE
164
+ ruby_xml_parser_context_html_q(VALUE self) {
165
+ ruby_xml_parser_context *rxpc;
166
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
167
+
168
+ if (rxpc->ctxt->html == 1)
169
+ return(Qtrue);
170
+ else
171
+ return(Qfalse);
172
+ }
173
+
174
+
175
+ /*
176
+ * call-seq:
177
+ * context.max_num_streams => num
178
+ *
179
+ * Obtain the limit on the number of IO streams opened in
180
+ * this context.
181
+ */
182
+ VALUE
183
+ ruby_xml_parser_context_io_max_num_streams_get(VALUE self) {
184
+ // TODO alias to max_streams and dep this?
185
+ ruby_xml_parser_context *rxpc;
186
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
187
+
188
+ return(INT2NUM(rxpc->ctxt->inputMax));
189
+ }
190
+
191
+
192
+ /*
193
+ * call-seq:
194
+ * context.num_streams => "dir"
195
+ *
196
+ * Obtain the actual number of IO streams in this
197
+ * context.
198
+ */
199
+ VALUE
200
+ ruby_xml_parser_context_io_num_streams_get(VALUE self) {
201
+ ruby_xml_parser_context *rxpc;
202
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
203
+
204
+ return(INT2NUM(rxpc->ctxt->inputNr));
205
+ }
206
+
207
+
208
+ /*
209
+ * call-seq:
210
+ * context.keep_blanks? => (true|false)
211
+ *
212
+ * Determine whether parsers in this context retain
213
+ * whitespace.
214
+ */
215
+ VALUE
216
+ ruby_xml_parser_context_keep_blanks_q(VALUE self) {
217
+ ruby_xml_parser_context *rxpc;
218
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
219
+
220
+ if (rxpc->ctxt->keepBlanks)
221
+ return(Qtrue);
222
+ else
223
+ return(Qfalse);
224
+ }
225
+
226
+
227
+ /*
228
+ * call-seq:
229
+ * context.name_depth => num
230
+ *
231
+ * Obtain the name depth for this context.
232
+ */
233
+ VALUE
234
+ ruby_xml_parser_context_name_depth_get(VALUE self) {
235
+ ruby_xml_parser_context *rxpc;
236
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
237
+
238
+ return(INT2NUM(rxpc->ctxt->nameNr));
239
+ }
240
+
241
+
242
+ /*
243
+ * call-seq:
244
+ * context.name_depth_max => num
245
+ *
246
+ * Obtain the maximum name depth for this context.
247
+ */
248
+ VALUE
249
+ ruby_xml_parser_context_name_depth_max_get(VALUE self) {
250
+ ruby_xml_parser_context *rxpc;
251
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
252
+
253
+ return(INT2NUM(rxpc->ctxt->nameMax));
254
+ }
255
+
256
+
257
+ /*
258
+ * call-seq:
259
+ * context.name_node => "name"
260
+ *
261
+ * Obtain the name node for this context.
262
+ */
263
+ VALUE
264
+ ruby_xml_parser_context_name_node_get(VALUE self) {
265
+ ruby_xml_parser_context *rxpc;
266
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
267
+
268
+ if (rxpc->ctxt->name == NULL)
269
+ return(Qnil);
270
+ else
271
+ return(rb_str_new2((const char*)rxpc->ctxt->name));
272
+ }
273
+
274
+
275
+ /*
276
+ * call-seq:
277
+ * context.name_tab => ["name", ..., "name"]
278
+ *
279
+ * Obtain the name table for this context.
280
+ */
281
+ VALUE
282
+ ruby_xml_parser_context_name_tab_get(VALUE self) {
283
+ int i;
284
+ ruby_xml_parser_context *rxpc;
285
+ VALUE tab_ary;
286
+
287
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
288
+
289
+ if (rxpc->ctxt->nameTab == NULL)
290
+ return(Qnil);
291
+
292
+ tab_ary = rb_ary_new();
293
+
294
+ for (i = (rxpc->ctxt->nameNr - 1); i >= 0; i--) {
295
+ if (rxpc->ctxt->nameTab[i] == NULL)
296
+ continue;
297
+ else
298
+ rb_ary_push(tab_ary, rb_str_new2((const char*)rxpc->ctxt->nameTab[i]));
299
+ }
300
+
301
+ return(tab_ary);
302
+ }
303
+
304
+
305
+ /*
306
+ * call-seq:
307
+ * context.node_depth => num
308
+ *
309
+ * Obtain the node depth for this context.
310
+ */
311
+ VALUE
312
+ ruby_xml_parser_context_node_depth_get(VALUE self) {
313
+ ruby_xml_parser_context *rxpc;
314
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
315
+
316
+ return(INT2NUM(rxpc->ctxt->nodeNr));
317
+ }
318
+
319
+
320
+ /*
321
+ * call-seq:
322
+ * context.node => node
323
+ *
324
+ * Obtain the root node of this context.
325
+ */
326
+ VALUE
327
+ ruby_xml_parser_context_node_get(VALUE self) {
328
+ ruby_xml_parser_context *rxpc;
329
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
330
+
331
+ if (rxpc->ctxt->node == NULL)
332
+ return(Qnil);
333
+ else
334
+ return(ruby_xml_node2_wrap(cXMLNode,
335
+ rxpc->ctxt->node));
336
+ }
337
+
338
+
339
+ /*
340
+ * call-seq:
341
+ * context.node_depth_max => num
342
+ *
343
+ * Obtain the maximum node depth for this context.
344
+ */
345
+ VALUE
346
+ ruby_xml_parser_context_node_depth_max_get(VALUE self) {
347
+ ruby_xml_parser_context *rxpc;
348
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
349
+
350
+ return(INT2NUM(rxpc->ctxt->nodeMax));
351
+ }
352
+
353
+
354
+ /*
355
+ * call-seq:
356
+ * context.num_chars => num
357
+ *
358
+ * Obtain the number of characters in this context.
359
+ */
360
+ VALUE
361
+ ruby_xml_parser_context_num_chars_get(VALUE self) {
362
+ ruby_xml_parser_context *rxpc;
363
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
364
+
365
+ return(LONG2NUM(rxpc->ctxt->nbChars));
366
+ }
367
+
368
+
369
+ VALUE
370
+ ruby_xml_parser_context_new(VALUE class, xmlParserCtxtPtr ctxt) {
371
+ ruby_xml_parser_context *rxpc;
372
+
373
+ rxpc = ALLOC(ruby_xml_parser_context);
374
+
375
+ rxpc->ctxt = ctxt;
376
+ return Data_Wrap_Struct(class,
377
+ ruby_xml_parser_context_mark,
378
+ ruby_xml_parser_context_free,
379
+ rxpc);
380
+ }
381
+
382
+
383
+ VALUE
384
+ ruby_xml_parser_context_new2(VALUE class) {
385
+ return(ruby_xml_parser_context_new(class, NULL));
386
+ }
387
+
388
+
389
+ VALUE
390
+ ruby_xml_parser_context_new3() {
391
+ return(ruby_xml_parser_context_new2(cXMLParserContext));
392
+ }
393
+
394
+
395
+ VALUE
396
+ ruby_xml_parser_context_options_set(VALUE self, VALUE options) {
397
+ ruby_xml_parser_context *rxpc;
398
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
399
+
400
+ if (xmlCtxtUseOptions(rxpc->ctxt, NUM2INT(options)))
401
+ return Qfalse;
402
+ else
403
+ return Qtrue;
404
+ }
405
+
406
+ VALUE
407
+ ruby_xml_parser_context_options_get(VALUE self) {
408
+ ruby_xml_parser_context *rxpc;
409
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
410
+ return INT2NUM(rxpc->ctxt->options);
411
+ }
412
+
413
+ /*
414
+ * call-seq:
415
+ * context.replace_entities? => (true|false)
416
+ *
417
+ * Determine whether external entity replacement is enabled in this
418
+ * context.
419
+ */
420
+ VALUE
421
+ ruby_xml_parser_context_replace_entities_q(VALUE self) {
422
+ ruby_xml_parser_context *rxpc;
423
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
424
+
425
+ if (rxpc->ctxt->replaceEntities)
426
+ return(Qtrue);
427
+ else
428
+ return(Qfalse);
429
+ }
430
+
431
+
432
+ /*
433
+ * call-seq:
434
+ * context.replace_entities = true|false
435
+ *
436
+ * Control whether external entity replacement is enabled in this
437
+ * context.
438
+ */
439
+ VALUE
440
+ ruby_xml_parser_context_replace_entities_set(VALUE self, VALUE bool) {
441
+ ruby_xml_parser_context *rxpc;
442
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
443
+
444
+ if (TYPE(bool) == T_FALSE) {
445
+ rxpc->ctxt->replaceEntities = 0;
446
+ return(Qfalse);
447
+ } else {
448
+ rxpc->ctxt->replaceEntities = 1;
449
+ return(Qfalse);
450
+ }
451
+ }
452
+
453
+
454
+ /*
455
+ * call-seq:
456
+ * context.reset
457
+ *
458
+ * Resets the parser context.
459
+ */
460
+ VALUE
461
+ ruby_xml_parser_context_reset(VALUE self) {
462
+ ruby_xml_parser_context *rxpc;
463
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
464
+ xmlCtxtReset(rxpc->ctxt);
465
+ }
466
+
467
+ /*
468
+ * call-seq:
469
+ * context.space_depth => num
470
+ *
471
+ * Obtain the space depth for this context.
472
+ */
473
+ VALUE
474
+ ruby_xml_parser_context_space_depth_get(VALUE self) {
475
+ ruby_xml_parser_context *rxpc;
476
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
477
+
478
+ return(INT2NUM(rxpc->ctxt->spaceNr));
479
+ }
480
+
481
+
482
+ /*
483
+ * call-seq:
484
+ * context.space_depth => num
485
+ *
486
+ * Obtain the maximum space depth for this context.
487
+ */
488
+ VALUE
489
+ ruby_xml_parser_context_space_depth_max_get(VALUE self) {
490
+ ruby_xml_parser_context *rxpc;
491
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
492
+
493
+ return(INT2NUM(rxpc->ctxt->spaceMax));
494
+ }
495
+
496
+
497
+ /*
498
+ * call-seq:
499
+ * context.subset_external? => (true|false)
500
+ *
501
+ * Determine whether this context is a subset of an
502
+ * external context.
503
+ */
504
+ VALUE
505
+ ruby_xml_parser_context_subset_external_q(VALUE self) {
506
+ ruby_xml_parser_context *rxpc;
507
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
508
+
509
+ if (rxpc->ctxt->inSubset == 2)
510
+ return(Qtrue);
511
+ else
512
+ return(Qfalse);
513
+ }
514
+
515
+
516
+ /*
517
+ * call-seq:
518
+ * context.subset_internal? => (true|false)
519
+ *
520
+ * Determine whether this context is a subset of an
521
+ * internal context.
522
+ */
523
+ VALUE
524
+ ruby_xml_parser_context_subset_internal_q(VALUE self) {
525
+ ruby_xml_parser_context *rxpc;
526
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
527
+
528
+ if (rxpc->ctxt->inSubset == 1)
529
+ return(Qtrue);
530
+ else
531
+ return(Qfalse);
532
+ }
533
+
534
+
535
+ /*
536
+ * call-seq:
537
+ * context.subset_name => "name"
538
+ *
539
+ * Obtain this context's subset name (valid only if
540
+ * either of subset_external? or subset_internal?
541
+ * is true).
542
+ */
543
+ VALUE
544
+ ruby_xml_parser_context_subset_name_get(VALUE self) {
545
+ ruby_xml_parser_context *rxpc;
546
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
547
+
548
+ if (rxpc->ctxt->intSubName == NULL)
549
+ return(Qnil);
550
+ else
551
+ return(rb_str_new2((const char*)rxpc->ctxt->intSubName));
552
+ }
553
+
554
+
555
+ /*
556
+ * call-seq:
557
+ * context.subset_external_uri => "uri"
558
+ *
559
+ * Obtain this context's external subset URI. (valid only if
560
+ * either of subset_external? or subset_internal?
561
+ * is true).
562
+ */
563
+ VALUE
564
+ ruby_xml_parser_context_subset_external_uri_get(VALUE self) {
565
+ ruby_xml_parser_context *rxpc;
566
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
567
+
568
+ if (rxpc->ctxt->extSubURI == NULL)
569
+ return(Qnil);
570
+ else
571
+ return(rb_str_new2((const char*)rxpc->ctxt->extSubURI));
572
+ }
573
+
574
+
575
+ /*
576
+ * call-seq:
577
+ * context.subset_external_system_id => "system_id"
578
+ *
579
+ * Obtain this context's external subset system identifier.
580
+ * (valid only if either of subset_external? or subset_internal?
581
+ * is true).
582
+ */
583
+ VALUE
584
+ ruby_xml_parser_context_subset_external_system_id_get(VALUE self) {
585
+ ruby_xml_parser_context *rxpc;
586
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
587
+
588
+ if (rxpc->ctxt->extSubSystem == NULL)
589
+ return(Qnil);
590
+ else
591
+ return(rb_str_new2((const char*)rxpc->ctxt->extSubSystem));
592
+ }
593
+
594
+
595
+ /*
596
+ * call-seq:
597
+ * context.standalone? => (true|false)
598
+ *
599
+ * Determine whether this is a standalone context.
600
+ */
601
+ VALUE
602
+ ruby_xml_parser_context_standalone_q(VALUE self) {
603
+ ruby_xml_parser_context *rxpc;
604
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
605
+
606
+ if (rxpc->ctxt->standalone)
607
+ return(Qtrue);
608
+ else
609
+ return(Qfalse);
610
+ }
611
+
612
+
613
+ /*
614
+ * call-seq:
615
+ * context.stats? => (true|false)
616
+ *
617
+ * Determine whether this context maintains statistics.
618
+ */
619
+ VALUE
620
+ ruby_xml_parser_context_stats_q(VALUE self) {
621
+ ruby_xml_parser_context *rxpc;
622
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
623
+
624
+ if (rxpc->ctxt->record_info)
625
+ return(Qtrue);
626
+ else
627
+ return(Qfalse);
628
+ }
629
+
630
+
631
+ /*
632
+ * call-seq:
633
+ * context.valid? => (true|false)
634
+ *
635
+ * Determine whether this context is valid.
636
+ */
637
+ VALUE
638
+ ruby_xml_parser_context_valid_q(VALUE self) {
639
+ ruby_xml_parser_context *rxpc;
640
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
641
+
642
+ if (rxpc->ctxt->valid)
643
+ return(Qtrue);
644
+ else
645
+ return(Qfalse);
646
+ }
647
+
648
+
649
+ /*
650
+ * call-seq:
651
+ * context.validate? => (true|false)
652
+ *
653
+ * Determine whether validation is enabled in this context.
654
+ */
655
+ VALUE
656
+ ruby_xml_parser_context_validate_q(VALUE self) {
657
+ ruby_xml_parser_context *rxpc;
658
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
659
+
660
+ if (rxpc->ctxt->validate)
661
+ return(Qtrue);
662
+ else
663
+ return(Qfalse);
664
+ }
665
+
666
+
667
+ /*
668
+ * call-seq:
669
+ * context.version => "version"
670
+ *
671
+ * Obtain this context's version identifier.
672
+ */
673
+ VALUE
674
+ ruby_xml_parser_context_version_get(VALUE self) {
675
+ ruby_xml_parser_context *rxpc;
676
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
677
+
678
+ if (rxpc->ctxt->version == NULL)
679
+ return(Qnil);
680
+ else
681
+ return(rb_str_new2((const char*)rxpc->ctxt->version));
682
+ }
683
+
684
+
685
+ /*
686
+ * call-seq:
687
+ * context.well_formed? => (true|false)
688
+ *
689
+ * Determine whether this context contains well-formed XML.
690
+ */
691
+ VALUE
692
+ ruby_xml_parser_context_well_formed_q(VALUE self) {
693
+ ruby_xml_parser_context *rxpc;
694
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
695
+
696
+ if (rxpc->ctxt->wellFormed)
697
+ return(Qtrue);
698
+ else
699
+ return(Qfalse);
700
+ }
701
+
702
+
703
+ // Rdoc needs to know
704
+ #ifdef RDOC_NEVER_DEFINED
705
+ mXML = rb_define_module("XML");
706
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
707
+ #endif
708
+
709
+ void
710
+ ruby_init_xml_parser_context(void) {
711
+ cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
712
+
713
+ rb_define_method(cXMLParserContext, "data_directory", ruby_xml_parser_context_data_directory_get, 0);
714
+ rb_define_method(cXMLParserContext, "depth", ruby_xml_parser_context_depth_get, 0);
715
+ rb_define_method(cXMLParserContext, "disable_sax?", ruby_xml_parser_context_disable_sax_q, 0);
716
+ rb_define_method(cXMLParserContext, "doc", ruby_xml_parser_context_doc_get, 0);
717
+ rb_define_method(cXMLParserContext, "docbook?", ruby_xml_parser_context_docbook_q, 0);
718
+ rb_define_method(cXMLParserContext, "encoding", ruby_xml_parser_context_encoding_get, 0);
719
+ rb_define_method(cXMLParserContext, "errno", ruby_xml_parser_context_errno_get, 0);
720
+ rb_define_method(cXMLParserContext, "html?", ruby_xml_parser_context_html_q, 0);
721
+ rb_define_method(cXMLParserContext, "io_max_num_streams", ruby_xml_parser_context_io_max_num_streams_get, 0);
722
+ rb_define_method(cXMLParserContext, "io_num_streams", ruby_xml_parser_context_io_num_streams_get, 0);
723
+ rb_define_method(cXMLParserContext, "keep_blanks?", ruby_xml_parser_context_keep_blanks_q, 0);
724
+ rb_define_method(cXMLParserContext, "name_node", ruby_xml_parser_context_name_node_get, 0);
725
+ rb_define_method(cXMLParserContext, "name_depth", ruby_xml_parser_context_name_depth_get, 0);
726
+ rb_define_method(cXMLParserContext, "name_depth_max", ruby_xml_parser_context_name_depth_max_get, 0);
727
+ rb_define_method(cXMLParserContext, "name_tab", ruby_xml_parser_context_name_tab_get, 0);
728
+ rb_define_method(cXMLParserContext, "node", ruby_xml_parser_context_node_get, 0);
729
+ rb_define_method(cXMLParserContext, "node_depth", ruby_xml_parser_context_node_depth_get, 0);
730
+ rb_define_method(cXMLParserContext, "node_depth_max", ruby_xml_parser_context_node_depth_max_get, 0);
731
+ rb_define_method(cXMLParserContext, "num_chars", ruby_xml_parser_context_num_chars_get, 0);
732
+ rb_define_method(cXMLParserContext, "options", ruby_xml_parser_context_options_get, 0);
733
+ rb_define_method(cXMLParserContext, "options=", ruby_xml_parser_context_options_set, 1);
734
+ rb_define_method(cXMLParserContext, "replace_entities?", ruby_xml_parser_context_replace_entities_q, 0);
735
+ rb_define_method(cXMLParserContext, "replace_entities=", ruby_xml_parser_context_replace_entities_set, 1);
736
+ rb_define_method(cXMLParserContext, "reset", ruby_xml_parser_context_reset, 0);
737
+ rb_define_method(cXMLParserContext, "space_depth", ruby_xml_parser_context_space_depth_get, 0);
738
+ rb_define_method(cXMLParserContext, "space_depth_max", ruby_xml_parser_context_space_depth_max_get, 0);
739
+ rb_define_method(cXMLParserContext, "subset_external?", ruby_xml_parser_context_subset_external_q, 0);
740
+ rb_define_method(cXMLParserContext, "subset_external_system_id", ruby_xml_parser_context_subset_external_system_id_get, 0);
741
+ rb_define_method(cXMLParserContext, "subset_external_uri", ruby_xml_parser_context_subset_name_get, 0);
742
+ rb_define_method(cXMLParserContext, "subset_internal?", ruby_xml_parser_context_subset_internal_q, 0);
743
+ rb_define_method(cXMLParserContext, "subset_internal_name", ruby_xml_parser_context_subset_name_get, 0);
744
+ rb_define_method(cXMLParserContext, "stats?", ruby_xml_parser_context_stats_q, 0);
745
+ rb_define_method(cXMLParserContext, "standalone?", ruby_xml_parser_context_standalone_q, 0);
746
+ rb_define_method(cXMLParserContext, "valid", ruby_xml_parser_context_valid_q, 0);
747
+ rb_define_method(cXMLParserContext, "validate?", ruby_xml_parser_context_validate_q, 0);
748
+ rb_define_method(cXMLParserContext, "version", ruby_xml_parser_context_version_get, 0);
749
+ rb_define_method(cXMLParserContext, "well_formed?", ruby_xml_parser_context_well_formed_q, 0);
750
+ }