mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,142 @@
1
+ #include "libxml.h"
2
+ #include "ruby_xml_schema.h"
3
+
4
+ VALUE cXMLSchema;
5
+
6
+ static void
7
+ ruby_xml_schema_mark(ruby_xml_schema *rxschema) {
8
+ return;
9
+ }
10
+
11
+ void
12
+ ruby_xml_schema_free(ruby_xml_schema *rxschema) {
13
+ if (rxschema->schema != NULL) {
14
+ xmlSchemaFree(rxschema->schema);
15
+ rxschema->schema = NULL;
16
+ }
17
+
18
+ free(rxschema);
19
+ }
20
+
21
+ /*
22
+ * call-seq:
23
+ * XML::Schema.new(schema_uri) => schema
24
+ *
25
+ * Create a new schema from the specified URI.
26
+ */
27
+ VALUE
28
+ ruby_xml_schema_init_from_uri(int argc, VALUE *argv, VALUE class) {
29
+ VALUE uri;
30
+ xmlSchemaParserCtxtPtr parser;
31
+ xmlSchemaPtr sptr;
32
+
33
+ switch (argc) {
34
+ case 1:
35
+ rb_scan_args(argc, argv, "10", &uri);
36
+
37
+ Check_Type(uri, T_STRING);
38
+
39
+ parser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
40
+ sptr = xmlSchemaParse(parser);
41
+ xmlSchemaFreeParserCtxt(parser);
42
+ break;
43
+ default:
44
+ rb_raise(rb_eArgError, "wrong number of arguments (need 1)");
45
+ }
46
+ return Qnil;
47
+ }
48
+
49
+ /*
50
+ * call-seq:
51
+ * XML::Schema.from_string("schema_data") => "value"
52
+ *
53
+ * Create a new schema using the specified string.
54
+ */
55
+ VALUE
56
+ ruby_xml_schema_init_from_str(int argc, VALUE *argv, VALUE class) {
57
+ VALUE schema_str;
58
+
59
+ xmlSchemaParserCtxtPtr parser;
60
+ //xmlSchemaPtr sptr;
61
+ ruby_xml_schema *rxschema;
62
+
63
+ switch (argc) {
64
+ case 1:
65
+ rb_scan_args(argc, argv, "10", &schema_str);
66
+
67
+ Check_Type(schema_str, T_STRING);
68
+
69
+ parser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(StringValuePtr(schema_str)));
70
+ rxschema = ALLOC(ruby_xml_schema);
71
+ rxschema->schema = xmlSchemaParse(parser);
72
+ xmlSchemaFreeParserCtxt(parser);
73
+
74
+ return( Data_Wrap_Struct(cXMLSchema, ruby_xml_schema_mark, ruby_xml_schema_free, rxschema) );
75
+ default:
76
+ rb_raise(rb_eArgError, "wrong number of arguments (need 1)");
77
+ }
78
+ return Qnil;
79
+ }
80
+
81
+ /* TODO what is this patch doing here?
82
+
83
+ xmlSchemaParserCtxtPtr parser;
84
+ xmlSchemaPtr sptr;
85
+ xmlSchemaValidCtxtPtr vptr;
86
+ + int is_invalid;
87
+
88
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) {
89
+ return;
90
+ @@ -598,26 +598,24 @@
91
+ convert_to_string_ex(&source);
92
+ parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
93
+ sptr = xmlSchemaParse(parser);
94
+ break;
95
+ case SCHEMA_BLOB:
96
+ convert_to_string_ex(&source);
97
+ parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source));
98
+ sptr = xmlSchemaParse(parser);
99
+ break;
100
+ }
101
+
102
+ vptr = xmlSchemaNewValidCtxt(sptr);
103
+ + is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
104
+ xmlSchemaFree(sptr);
105
+ xmlSchemaFreeValidCtxt(vptr);
106
+ xmlSchemaFreeParserCtxt(parser);
107
+
108
+ - if (is_valid) {
109
+ - RETURN_TRUE;
110
+ - } else {
111
+ + if (is_invalid) {
112
+ RETURN_FALSE;
113
+ + } else {
114
+ + RETURN_TRUE;
115
+ }
116
+ }
117
+ }}}
118
+ @@ -695,7 +693,7 @@
119
+ {
120
+ if (!strcmp(method, "xsearch")) {
121
+ simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
122
+ -#ifdef xmlSchemaParserCtxtPtr
123
+ +#ifdef LIBXML_SCHEMAS_ENABLED
124
+ } else if (!strcmp(method, "validate_schema_file")) {
125
+ simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE);
126
+ } else if (!strcmp(method, "validate_schema_buffer")) {
127
+ */
128
+
129
+ void ruby_schema_free(ruby_xml_schema *rxs) {
130
+ }
131
+
132
+ // Rdoc needs to know
133
+ #ifdef RDOC_NEVER_DEFINED
134
+ mXML = rb_define_module("XML");
135
+ #endif
136
+
137
+ void ruby_init_xml_schema(void) {
138
+ cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
139
+ rb_define_singleton_method(cXMLSchema, "new", ruby_xml_schema_init_from_uri, -1);
140
+ rb_define_singleton_method(cXMLSchema, "from_string", ruby_xml_schema_init_from_str, -1);
141
+ }
142
+
@@ -0,0 +1,16 @@
1
+ #ifndef __RUBY_XML_SCHEMA__
2
+ #define __RUBY_XML_SCHEMA__
3
+
4
+ #include <libxml/schemasInternals.h>
5
+ #include <libxml/xmlschemas.h>
6
+
7
+ extern VALUE cXMLSchema;
8
+
9
+ typedef struct rxp_schema {
10
+ xmlSchemaPtr schema; /* Schema interface */
11
+ } ruby_xml_schema;
12
+
13
+ void ruby_init_xml_schema(void);
14
+ void ruby_schema_free(ruby_xml_schema *rxs);
15
+ #endif
16
+
@@ -0,0 +1,43 @@
1
+ /* $Id: ruby_xml_tree.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "libxml.h"
6
+ #include "ruby_xml_tree.h"
7
+
8
+ VALUE cXMLTree;
9
+
10
+ // Rdoc needs to know
11
+ #ifdef RDOC_NEVER_DEFINED
12
+ mXML = rb_define_module("XML");
13
+ #endif
14
+
15
+ void
16
+ ruby_init_xml_tree(void) {
17
+ cXMLTree = rb_define_class_under(mXML, "Tree", rb_cObject);
18
+
19
+ rb_define_const(cXMLTree, "ELEMENT_NODE", INT2FIX(XML_ELEMENT_NODE));
20
+ rb_define_const(cXMLTree, "ATTRIBUTE_NODE", INT2FIX(XML_ATTRIBUTE_NODE));
21
+ rb_define_const(cXMLTree, "TEXT_NODE", INT2FIX(XML_TEXT_NODE));
22
+ rb_define_const(cXMLTree, "CDATA_SECTION_NODE", INT2FIX(XML_CDATA_SECTION_NODE));
23
+ rb_define_const(cXMLTree, "ENTITY_REF_NODE", INT2FIX(XML_ENTITY_REF_NODE));
24
+ rb_define_const(cXMLTree, "ENTITY_NODE", INT2FIX(XML_ENTITY_NODE));
25
+ rb_define_const(cXMLTree, "PI_NODE", INT2FIX(XML_PI_NODE));
26
+ rb_define_const(cXMLTree, "COMMENT_NODE", INT2FIX(XML_COMMENT_NODE));
27
+ rb_define_const(cXMLTree, "DOCUMENT_NODE", INT2FIX(XML_DOCUMENT_NODE));
28
+ rb_define_const(cXMLTree, "DOCUMENT_TYPE_NODE", INT2FIX(XML_DOCUMENT_TYPE_NODE));
29
+ rb_define_const(cXMLTree, "DOCUMENT_FRAG_NODE", INT2FIX(XML_DOCUMENT_FRAG_NODE));
30
+ rb_define_const(cXMLTree, "NOTATION_NODE", INT2FIX(XML_NOTATION_NODE));
31
+ rb_define_const(cXMLTree, "HTML_DOCUMENT_NODE", INT2FIX(XML_HTML_DOCUMENT_NODE));
32
+ rb_define_const(cXMLTree, "DTD_NODE", INT2FIX(XML_DTD_NODE));
33
+ rb_define_const(cXMLTree, "ELEMENT_DECL", INT2FIX(XML_ELEMENT_DECL));
34
+ rb_define_const(cXMLTree, "ATTRIBUTE_DECL", INT2FIX(XML_ATTRIBUTE_DECL));
35
+ rb_define_const(cXMLTree, "ENTITY_DECL", INT2FIX(XML_ENTITY_DECL));
36
+ rb_define_const(cXMLTree, "NAMESPACE_DECL", INT2FIX(XML_NAMESPACE_DECL));
37
+ rb_define_const(cXMLTree, "XINCLUDE_START", INT2FIX(XML_XINCLUDE_START));
38
+ rb_define_const(cXMLTree, "XINCLUDE_END", INT2FIX(XML_XINCLUDE_END));
39
+
40
+ #ifdef LIBXML_DOCB_ENABLED
41
+ rb_define_const(cXMLTree, "DOCB_DOCUMENT_NODE", INT2FIX(XML_DOCB_DOCUMENT_NODE));
42
+ #endif
43
+ }
@@ -0,0 +1,12 @@
1
+ /* $Id: ruby_xml_tree.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_TREE__
6
+ #define __RUBY_XML_TREE__
7
+
8
+ extern VALUE cXMLTree;
9
+
10
+ void ruby_init_xml_tree(void);
11
+
12
+ #endif
@@ -0,0 +1,20 @@
1
+ /* $Id: ruby_xml_xinclude.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "libxml.h"
6
+ #include "ruby_xml_xinclude.h"
7
+
8
+ VALUE cXMLXInclude;
9
+ VALUE eXMLXIncludeError;
10
+
11
+ // Rdoc needs to know
12
+ #ifdef RDOC_NEVER_DEFINED
13
+ mXML = rb_define_module("XML");
14
+ #endif
15
+
16
+ void
17
+ ruby_init_xml_xinclude(void) {
18
+ cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
19
+ eXMLXIncludeError = rb_define_class_under(cXMLXInclude, "Error", rb_eRuntimeError);
20
+ }
@@ -0,0 +1,13 @@
1
+ /* $Id: ruby_xml_xinclude.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XINCLUDE__
6
+ #define __RUBY_XML_XINCLUDE__
7
+
8
+ extern VALUE cXMLXInclude;
9
+ extern VALUE eXMLXIncludeError;
10
+
11
+ void ruby_init_xml_xinclude(void);
12
+
13
+ #endif
@@ -0,0 +1,363 @@
1
+ /* $Id: ruby_xml_xpath.c,v 1.2 2006/04/14 14:45:25 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "libxml.h"
6
+ #include "ruby_xml_xpath.h"
7
+
8
+ /*
9
+ * Document-class: XML::XPath
10
+ *
11
+ * Includes Enumerable.
12
+ */
13
+ VALUE cXMLXPath;
14
+ VALUE eXMLXPathInvalidPath;
15
+
16
+ #ifdef LIBXML_XPATH_ENABLED
17
+
18
+ /*
19
+ * call-seq:
20
+ * xpath.debug => (true|false)
21
+ *
22
+ * Dump libxml debugging information to stdout.
23
+ * Requires Libxml be compiled with debugging enabled.
24
+ */
25
+ VALUE
26
+ ruby_xml_xpath_debug(VALUE self) {
27
+ #ifdef LIBXML_DEBUG_ENABLED
28
+ ruby_xml_xpath *rxxp;
29
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
30
+
31
+ if (rxxp->xpop != NULL) {
32
+ xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
33
+ return(Qtrue);
34
+ } else {
35
+ return(Qfalse);
36
+ }
37
+ #else
38
+ rb_warn("libxml does not have debugging turned on");
39
+ return(Qfalse);
40
+ #endif
41
+ }
42
+
43
+ // TODO Maybe we should support [] or some other kind of access if poss.
44
+
45
+ /*
46
+ * call-seq:
47
+ * xpath.each { |node| ... } => self
48
+ *
49
+ * Call the supplied block for each matching node.
50
+ */
51
+ VALUE
52
+ ruby_xml_xpath_each(VALUE self) {
53
+ ruby_xml_xpath *rxxp;
54
+ VALUE rxnset;
55
+
56
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
57
+
58
+ if (rxxp->xpop == NULL || rxxp->xpop->type != XPATH_NODESET)
59
+ return(Qnil);
60
+
61
+ rxnset = ruby_xml_node_set_new(cXMLNodeSet, rxxp->xd, self,
62
+ rxxp->xpop->nodesetval);
63
+ ruby_xml_node_set_each(rxnset);
64
+ return(rxnset);
65
+ }
66
+
67
+ ///////////////////////////////////////////////////
68
+ // TODO xpath_find is throwing TypeError:
69
+ //
70
+ // TypeError: can't convert nil into String
71
+ //
72
+ // When given a namespace when non exist.
73
+
74
+ /*
75
+ * call-seq:
76
+ * XML::XPath.find(path, namespaces = [any]) => xpath
77
+ *
78
+ * Find nodes matching the specified xpath (and optionally any of the
79
+ * supplied namespaces) and return as an XML::Node::Set.
80
+ *
81
+ * The optional namespaces argument may take one of
82
+ * two forms:
83
+ *
84
+ * * A string in the form of: "prefix:uri", or
85
+ * * An array of:
86
+ * * strings in the form like above
87
+ * * arrays in the form of ['prefix','uri']
88
+ *
89
+ * If not specified, matching nodes from any namespace
90
+ * will be included.
91
+ */
92
+ VALUE
93
+ ruby_xml_xpath_find(int argc, VALUE *argv, VALUE class) {
94
+ #ifdef LIBXML_XPATH_ENABLED
95
+ xmlXPathCompExprPtr comp;
96
+ ruby_xml_node *node;
97
+ ruby_xml_xpath *rxxp;
98
+ ruby_xml_xpath_context *rxxpc;
99
+ ruby_xml_ns *rxns;
100
+ VALUE rnode, rprefix, ruri, xxpc, xpath, xpath_expr;
101
+ char *cp;
102
+ long i;
103
+
104
+ switch(argc) {
105
+ case 3:
106
+ /* array of namespaces we allow.
107
+ *
108
+ * Accept either:
109
+ * A string in the form of: "prefix:uri", or
110
+ * An array of:
111
+ * *) strings in the form like above
112
+ * *) arrays in the form of ['prefix','uri']
113
+ */
114
+
115
+ /* Intentionally fall through, we deal with the last arg below
116
+ * after the XPathContext object has been setup */
117
+ case 2:
118
+ rnode = argv[0];
119
+ xpath_expr = argv[1];
120
+ break;
121
+ default:
122
+ rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
123
+ }
124
+
125
+ Data_Get_Struct(rnode, ruby_xml_node, node);
126
+
127
+ xxpc = ruby_xml_xpath_context_new4(rnode);
128
+ if (NIL_P(xxpc))
129
+ return(Qnil);
130
+ Data_Get_Struct(xxpc, ruby_xml_xpath_context, rxxpc);
131
+
132
+ xpath = ruby_xml_xpath_new(cXMLXPath, rnode, xxpc, NULL);
133
+ Data_Get_Struct(xpath, ruby_xml_xpath, rxxp);
134
+
135
+ rxxpc->ctxt->node = node->node;
136
+ if (node->node->type == XML_DOCUMENT_NODE) {
137
+ rxxpc->ctxt->namespaces = xmlGetNsList(node->node->doc,
138
+ xmlDocGetRootElement(node->node->doc));
139
+ } else {
140
+ rxxpc->ctxt->namespaces = xmlGetNsList(node->node->doc, node->node);
141
+ }
142
+
143
+ rxxpc->ctxt->nsNr = 0;
144
+ if (rxxpc->ctxt->namespaces != NULL) {
145
+ while (rxxpc->ctxt->namespaces[rxxpc->ctxt->nsNr] != NULL)
146
+ rxxpc->ctxt->nsNr++;
147
+ }
148
+
149
+ /* Need to loop through the 2nd argument and iterate through the
150
+ * list of namespaces that we want to allow */
151
+ if (argc == 3) {
152
+ switch (TYPE(argv[2])) {
153
+ case T_STRING:
154
+ cp = strchr(StringValuePtr(argv[2]), (int)':');
155
+ if (cp == NULL) {
156
+ rprefix = argv[2];
157
+ ruri = Qnil;
158
+ } else {
159
+ rprefix = rb_str_new(StringValuePtr(argv[2]), (int)((long)cp - (long)StringValuePtr(argv[2])));
160
+ ruri = rb_str_new2(&cp[1]);
161
+ }
162
+ /* Should test the results of this */
163
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
164
+ break;
165
+ case T_ARRAY:
166
+ for (i = 0; i < RARRAY(argv[2])->len; i++) {
167
+ switch (TYPE(RARRAY(argv[2])->ptr[i])) {
168
+ case T_STRING:
169
+ cp = strchr(StringValuePtr(RARRAY(argv[2])->ptr[i]), (int)':');
170
+ if (cp == NULL) {
171
+ rprefix = RARRAY(argv[2])->ptr[i];
172
+ ruri = Qnil;
173
+ } else {
174
+ rprefix = rb_str_new(StringValuePtr(RARRAY(argv[2])->ptr[i]), (int)((long)cp - (long)StringValuePtr(RARRAY(argv[2])->ptr[i])));
175
+ ruri = rb_str_new2(&cp[1]);
176
+ }
177
+ /* Should test the results of this */
178
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
179
+ break;
180
+ case T_ARRAY:
181
+ if (RARRAY(RARRAY(argv[2])->ptr[i])->len == 2) {
182
+ rprefix = RARRAY(RARRAY(argv[2])->ptr[i])->ptr[0];
183
+ ruri = RARRAY(RARRAY(argv[2])->ptr[i])->ptr[1];
184
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
185
+ } else {
186
+ rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
187
+ }
188
+ break;
189
+ default:
190
+ if (rb_obj_is_kind_of(RARRAY(argv[2])->ptr[i], cXMLNS) == Qtrue) {
191
+ Data_Get_Struct(argv[2], ruby_xml_ns, rxns);
192
+ rprefix = rb_str_new2((const char*)rxns->ns->prefix);
193
+ ruri = rb_str_new2((const char*)rxns->ns->href);
194
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
195
+ } else
196
+ rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
197
+ }
198
+ }
199
+ break;
200
+ default:
201
+ if (rb_obj_is_kind_of(argv[2], cXMLNS) == Qtrue) {
202
+ Data_Get_Struct(argv[2], ruby_xml_ns, rxns);
203
+ rprefix = rb_str_new2((const char*)rxns->ns->prefix);
204
+ ruri = rb_str_new2((const char*)rxns->ns->href);
205
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
206
+ } else
207
+ rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
208
+ }
209
+ }
210
+ comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
211
+
212
+ if (comp == NULL) {
213
+ xmlXPathFreeCompExpr(comp);
214
+ rb_raise(eXMLXPathInvalidPath, "Invalid XPath expression");
215
+ }
216
+ rxxp->xpop = xmlXPathCompiledEval(comp, rxxpc->ctxt);
217
+ xmlXPathFreeCompExpr(comp);
218
+
219
+ if (rxxpc->ctxt->namespaces != NULL)
220
+ xmlFree(rxxpc->ctxt->namespaces);
221
+
222
+ if (rxxp->xpop == NULL)
223
+ rb_raise(eXMLXPathInvalidPath,
224
+ "Invalid XPath expression for this document");
225
+
226
+ if (rxxp->xpop->type != XPATH_NODESET)
227
+ return(Qnil);
228
+
229
+ return(ruby_xml_node_set_new2(node->xd, xpath,
230
+ rxxp->xpop->nodesetval));
231
+ #else
232
+ rb_warn("libxml was compiled without XPath support");
233
+ return(Qfalse);
234
+ #endif
235
+ }
236
+
237
+
238
+ VALUE
239
+ ruby_xml_xpath_find2(int argc, VALUE *argv) {
240
+ return(ruby_xml_xpath_find(argc, argv, cXMLXPath));
241
+ }
242
+
243
+
244
+ void
245
+ ruby_xml_xpath_free(ruby_xml_xpath *rxxp) {
246
+ if (rxxp->xpop != NULL) {
247
+ xmlXPathFreeObject(rxxp->xpop);
248
+ rxxp->xpop = NULL;
249
+ }
250
+
251
+ free(rxxp);
252
+ }
253
+
254
+
255
+ void
256
+ ruby_xml_xpath_mark(ruby_xml_xpath *rxxp) {
257
+ if (rxxp == NULL) return;
258
+ if (!NIL_P(rxxp->ctxt)) rb_gc_mark(rxxp->ctxt);
259
+ if (!NIL_P(rxxp->xd)) rb_gc_mark(rxxp->xd);
260
+ }
261
+
262
+
263
+ VALUE
264
+ ruby_xml_xpath_new(VALUE class, VALUE xd, VALUE ctxt,
265
+ xmlXPathObjectPtr xpop) {
266
+ ruby_xml_xpath *rxxp;
267
+
268
+ rxxp = ALLOC(ruby_xml_xpath);
269
+ rxxp->ctxt = ctxt;
270
+ rxxp->xd = xd;
271
+ rxxp->xpop = xpop;
272
+ return(Data_Wrap_Struct(class, ruby_xml_xpath_mark,
273
+ ruby_xml_xpath_free, rxxp));
274
+ }
275
+
276
+
277
+ /*
278
+ * call-seq:
279
+ * xpath.set => nodeset
280
+ *
281
+ * Obtain an XML::Node::Set with nodes matching this xpath.
282
+ */
283
+ VALUE
284
+ ruby_xml_xpath_set(VALUE self) {
285
+ ruby_xml_xpath *rxxp;
286
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
287
+
288
+ if (rxxp->xpop == NULL || rxxp->xpop->type != XPATH_NODESET)
289
+ return(Qnil);
290
+
291
+ return(ruby_xml_node_set_new(cXMLNodeSet, rxxp->xd, self,
292
+ rxxp->xpop->nodesetval));
293
+ }
294
+
295
+
296
+ /*
297
+ * call-seq:
298
+ * xpath.set_type => num
299
+ *
300
+ * Obtains the type identifier of this xpath
301
+ * set.
302
+ */
303
+ VALUE
304
+ ruby_xml_xpath_set_type(VALUE self) {
305
+ ruby_xml_xpath *rxxp;
306
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
307
+
308
+ return(INT2FIX(rxxp->xpop->type));
309
+ }
310
+
311
+ // TODO maybe 'string' should alias as 'to_s'?
312
+
313
+ /*
314
+ * call-seq:
315
+ * xpath.string => "xpath"
316
+ *
317
+ * Obtain a string representation of this xpath.
318
+ */
319
+ VALUE
320
+ ruby_xml_xpath_string(VALUE self) {
321
+ ruby_xml_xpath *rxxp;
322
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
323
+
324
+ if (rxxp->xpop->stringval == NULL)
325
+ return(Qnil);
326
+ else
327
+ return(rb_str_new2((const char*)rxxp->xpop->stringval));
328
+ }
329
+
330
+ // Rdoc needs to know
331
+ #ifdef RDOC_NEVER_DEFINED
332
+ mXML = rb_define_module("XML");
333
+ #endif
334
+
335
+ void
336
+ ruby_init_xml_xpath(void) {
337
+ cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
338
+ rb_include_module(cXMLNode, rb_const_get(rb_cObject, rb_intern("Enumerable")));
339
+
340
+ eXMLXPathInvalidPath = rb_define_class_under(cXMLXPath,
341
+ "InvalidPath", rb_eException);
342
+
343
+ rb_define_const(cXMLXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
344
+ rb_define_const(cXMLXPath, "NODESET", INT2NUM(XPATH_NODESET));
345
+ rb_define_const(cXMLXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
346
+ rb_define_const(cXMLXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
347
+ rb_define_const(cXMLXPath, "STRING", INT2NUM(XPATH_STRING));
348
+ rb_define_const(cXMLXPath, "POINT", INT2NUM(XPATH_POINT));
349
+ rb_define_const(cXMLXPath, "RANGE", INT2NUM(XPATH_RANGE));
350
+ rb_define_const(cXMLXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
351
+ rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
352
+ rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
353
+
354
+ rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_find, 2);
355
+
356
+ rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
357
+ rb_define_method(cXMLXPath, "each", ruby_xml_xpath_each, 0);
358
+ rb_define_method(cXMLXPath, "set", ruby_xml_xpath_set, 0);
359
+ rb_define_method(cXMLXPath, "set_type", ruby_xml_xpath_set_type, 0);
360
+ rb_define_method(cXMLXPath, "string", ruby_xml_xpath_string, 0);
361
+ }
362
+
363
+ #endif /* ifdef LIBXML_XPATH_ENABLED */