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,216 @@
1
+ #
2
+ # YAML::BaseNode class
3
+ #
4
+ require 'yaml/ypath'
5
+
6
+ module YAML
7
+
8
+ #
9
+ # YAML Generic Model container
10
+ #
11
+ module BaseNode
12
+
13
+ #
14
+ # Search for YPath entry and return
15
+ # qualified nodes.
16
+ #
17
+ def select( ypath_str )
18
+ matches = match_path( ypath_str )
19
+
20
+ #
21
+ # Create a new generic view of the elements selected
22
+ #
23
+ if matches
24
+ result = []
25
+ matches.each { |m|
26
+ result.push m.last
27
+ }
28
+ YAML.transfer( 'seq', result )
29
+ end
30
+ end
31
+
32
+ #
33
+ # Search for YPath entry and return
34
+ # transformed nodes.
35
+ #
36
+ def select!( ypath_str )
37
+ matches = match_path( ypath_str )
38
+
39
+ #
40
+ # Create a new generic view of the elements selected
41
+ #
42
+ if matches
43
+ result = []
44
+ matches.each { |m|
45
+ result.push m.last.transform
46
+ }
47
+ result
48
+ end
49
+ end
50
+
51
+ #
52
+ # Search for YPath entry and return a list of
53
+ # qualified paths.
54
+ #
55
+ def search( ypath_str )
56
+ matches = match_path( ypath_str )
57
+
58
+ if matches
59
+ matches.collect { |m|
60
+ path = []
61
+ m.each_index { |i|
62
+ path.push m[i] if ( i % 2 ).zero?
63
+ }
64
+ "/" + path.compact.join( "/" )
65
+ }
66
+ end
67
+ end
68
+
69
+ def at( seg )
70
+ if Hash === @value and @value.has_key?( seg )
71
+ @value[seg][1]
72
+ elsif Array === @value and seg =~ /\A\d+\Z/ and @value[seg.to_i]
73
+ @value[seg.to_i]
74
+ end
75
+ end
76
+
77
+ #
78
+ # YPath search returning a complete depth array
79
+ #
80
+ def match_path( ypath_str )
81
+ depth = 0
82
+ matches = []
83
+ YPath.each_path( ypath_str ) do |ypath|
84
+ seg = match_segment( ypath, 0 )
85
+ matches += seg if seg
86
+ end
87
+ matches.uniq
88
+ end
89
+
90
+ #
91
+ # Search a node for a single YPath segment
92
+ #
93
+ def match_segment( ypath, depth )
94
+ deep_nodes = []
95
+ seg = ypath.segments[ depth ]
96
+ if seg == "/"
97
+ unless String === @value
98
+ idx = -1
99
+ @value.collect { |v|
100
+ idx += 1
101
+ if Hash === @value
102
+ match_init = [v[0], v[1][1]]
103
+ match_deep = v[1][1].match_segment( ypath, depth )
104
+ else
105
+ match_init = [idx, v]
106
+ match_deep = v.match_segment( ypath, depth )
107
+ end
108
+ if match_deep
109
+ match_deep.each { |m|
110
+ deep_nodes.push( match_init + m )
111
+ }
112
+ end
113
+ }
114
+ end
115
+ depth += 1
116
+ seg = ypath.segments[ depth ]
117
+ end
118
+ match_nodes =
119
+ case seg
120
+ when "."
121
+ [[nil, self]]
122
+ when ".."
123
+ [["..", nil]]
124
+ when "*"
125
+ if @value.is_a? Enumerable
126
+ idx = -1
127
+ @value.collect { |h|
128
+ idx += 1
129
+ if Hash === @value
130
+ [h[0], h[1][1]]
131
+ else
132
+ [idx, h]
133
+ end
134
+ }
135
+ end
136
+ else
137
+ if seg =~ /^"(.*)"$/
138
+ seg = $1
139
+ elsif seg =~ /^'(.*)'$/
140
+ seg = $1
141
+ end
142
+ if ( v = at( seg ) )
143
+ [[ seg, v ]]
144
+ end
145
+ end
146
+ return deep_nodes unless match_nodes
147
+ pred = ypath.predicates[ depth ]
148
+ if pred
149
+ case pred
150
+ when /^\.=/
151
+ pred = $'
152
+ match_nodes.reject! { |n|
153
+ n.last.value != pred
154
+ }
155
+ else
156
+ match_nodes.reject! { |n|
157
+ n.last.at( pred ).nil?
158
+ }
159
+ end
160
+ end
161
+ return match_nodes + deep_nodes unless ypath.segments.length > depth + 1
162
+
163
+ #puts "DEPTH: #{depth + 1}"
164
+ deep_nodes = []
165
+ match_nodes.each { |n|
166
+ if n[1].is_a? BaseNode
167
+ match_deep = n[1].match_segment( ypath, depth + 1 )
168
+ if match_deep
169
+ match_deep.each { |m|
170
+ deep_nodes.push( n + m )
171
+ }
172
+ end
173
+ else
174
+ deep_nodes = []
175
+ end
176
+ }
177
+ deep_nodes = nil if deep_nodes.length == 0
178
+ deep_nodes
179
+ end
180
+
181
+ #
182
+ # We want the node to act like as Hash
183
+ # if it is.
184
+ #
185
+ def []( *k )
186
+ if Hash === @value
187
+ v = @value.[]( *k )
188
+ v[1] if v
189
+ elsif Array === @value
190
+ @value.[]( *k )
191
+ end
192
+ end
193
+
194
+ def children
195
+ if Hash === @value
196
+ @value.values.collect { |c| c[1] }
197
+ elsif Array === @value
198
+ @value
199
+ end
200
+ end
201
+
202
+ def children_with_index
203
+ if Hash === @value
204
+ @value.keys.collect { |i| [self[i], i] }
205
+ elsif Array === @value
206
+ i = -1; @value.collect { |v| i += 1; [v, i] }
207
+ end
208
+ end
209
+
210
+ def emit
211
+ transform.to_yaml
212
+ end
213
+ end
214
+
215
+ end
216
+
@@ -0,0 +1,26 @@
1
+ #
2
+ # Ruby 1.6 -> 1.8 compatibility
3
+ # (an isolated incident)
4
+ #
5
+ class Object; alias_method :object_id, :id; end unless Object.respond_to? :object_id
6
+
7
+ class Object; def instance_variable_set(k, v); self.instance_eval "#{k} = v"; end; end \
8
+ unless Object.respond_to? :instance_variable_set
9
+
10
+ class Object; def instance_variable_get(k); self.instance_eval "#{k}"; end; end \
11
+ unless Object.respond_to? :instance_variable_get
12
+
13
+ unless Object.respond_to? :allocate
14
+ class Object
15
+ def allocate
16
+ name = self.class.name
17
+ if Marshal::const_defined? :MAJOR_VERSION
18
+ ostr = sprintf( "%c%co:%c%s\000", Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION,
19
+ name.length + 5, name )
20
+ else
21
+ ostr = sprintf( "\004\006o:%c%s\000", name.length + 5, name )
22
+ end
23
+ ::Marshal.load( ostr )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Constants used throughout the library
3
+ #
4
+ module YAML
5
+
6
+ #
7
+ # Constants
8
+ #
9
+ VERSION = '0.60'
10
+ SUPPORTED_YAML_VERSIONS = ['1.0']
11
+
12
+ #
13
+ # Parser tokens
14
+ #
15
+ WORD_CHAR = 'A-Za-z0-9'
16
+ PRINTABLE_CHAR = '-_A-Za-z0-9!?/()$\'". '
17
+ NOT_PLAIN_CHAR = '\x7f\x0-\x1f\x80-\x9f'
18
+ ESCAPE_CHAR = '[\\x00-\\x09\\x0b-\\x1f]'
19
+ INDICATOR_CHAR = '*&!|\\\\^@%{}[]='
20
+ SPACE_INDICATORS = '-#:,?'
21
+ RESTRICTED_INDICATORS = '#:,}]'
22
+ DNS_COMP_RE = "\\w(?:[-\\w]*\\w)?"
23
+ DNS_NAME_RE = "(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
24
+ ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a
25
+ \x08 \t \n \v \f \r \x0e \x0f
26
+ \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17
27
+ \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f
28
+ }
29
+ UNESCAPES = {
30
+ 'a' => "\x07", 'b' => "\x08", 't' => "\x09",
31
+ 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
32
+ 'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
33
+ }
34
+
35
+ #
36
+ # Default settings
37
+ #
38
+ DEFAULTS = {
39
+ :Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0',
40
+ :SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false,
41
+ :WidthType => 'absolute', :BestWidth => 80,
42
+ :UseBlock => false, :UseFold => false, :Encoding => :None
43
+ }
44
+
45
+ end
@@ -0,0 +1,111 @@
1
+ require 'yaml'
2
+ require 'dbm'
3
+ #
4
+ # YAML + DBM = YDBM
5
+ # - Same interface as DBM class
6
+ #
7
+ module YAML
8
+
9
+ class DBM < ::DBM
10
+ VERSION = "0.1"
11
+ def []( key )
12
+ fetch( key )
13
+ end
14
+ def []=( key, val )
15
+ store( key, val )
16
+ end
17
+ def fetch( keystr, ifnone = nil )
18
+ begin
19
+ val = super( keystr )
20
+ return YAML::load( val ) if String === val
21
+ rescue IndexError
22
+ end
23
+ if block_given?
24
+ yield keystr
25
+ else
26
+ ifnone
27
+ end
28
+ end
29
+ def index( keystr )
30
+ super( keystr.to_yaml )
31
+ end
32
+ def values_at( *keys )
33
+ keys.collect { |k| fetch( k ) }
34
+ end
35
+ def delete( key )
36
+ v = super( key )
37
+ if String === v
38
+ v = YAML::load( v )
39
+ end
40
+ v
41
+ end
42
+ def delete_if
43
+ del_keys = keys.dup
44
+ del_keys.delete_if { |k| yield( k, fetch( k ) ) == false }
45
+ del_keys.each { |k| delete( k ) }
46
+ self
47
+ end
48
+ def reject
49
+ hsh = self.to_hash
50
+ hsh.reject { |k,v| yield k, v }
51
+ end
52
+ def each_pair
53
+ keys.each { |k| yield k, fetch( k ) }
54
+ self
55
+ end
56
+ def each_value
57
+ super { |v| yield YAML::load( v ) }
58
+ self
59
+ end
60
+ def values
61
+ super.collect { |v| YAML::load( v ) }
62
+ end
63
+ def has_value?( val )
64
+ each_value { |v| return true if v == val }
65
+ return false
66
+ end
67
+ def invert
68
+ h = {}
69
+ keys.each { |k| h[ self.fetch( k ) ] = k }
70
+ h
71
+ end
72
+ def replace( hsh )
73
+ clear
74
+ update( hsh )
75
+ end
76
+ def shift
77
+ a = super
78
+ a[1] = YAML::load( a[1] ) if a
79
+ a
80
+ end
81
+ def select( *keys )
82
+ if block_given?
83
+ self.keys.collect { |k| v = self[k]; [k, v] if yield k, v }.compact
84
+ else
85
+ values_at( *keys )
86
+ end
87
+ end
88
+ def store( key, val )
89
+ super( key, val.to_yaml )
90
+ val
91
+ end
92
+ def update( hsh )
93
+ hsh.keys.each do |k|
94
+ self.store( k, hsh.fetch( k ) )
95
+ end
96
+ self
97
+ end
98
+ def to_a
99
+ a = []
100
+ keys.each { |k| a.push [ k, self.fetch( k ) ] }
101
+ a
102
+ end
103
+ def to_hash
104
+ h = {}
105
+ keys.each { |k| h[ k ] = self.fetch( k ) }
106
+ h
107
+ end
108
+ alias :each :each_pair
109
+ end
110
+
111
+ end
@@ -0,0 +1,107 @@
1
+ #
2
+ # Output classes and methods
3
+ #
4
+
5
+ require 'yaml/baseemitter'
6
+ require 'yaml/encoding'
7
+
8
+ module YAML
9
+
10
+ #
11
+ # Emit a set of values
12
+ #
13
+
14
+ class Emitter
15
+
16
+ include BaseEmitter
17
+
18
+ attr_accessor :options
19
+
20
+ def initialize( opts )
21
+ opts = {} if opts.class != Hash
22
+ @options = YAML::DEFAULTS.dup.update( opts )
23
+ @headless = 0
24
+ @seq_map = false
25
+ @anchors = {}
26
+ @anchor_extras = {}
27
+ @active_anchors = []
28
+ @level = -1
29
+ self.clear
30
+ end
31
+
32
+ def clear
33
+ @buffer = []
34
+ end
35
+
36
+ def level
37
+ @level
38
+ end
39
+
40
+ #
41
+ # Version string
42
+ #
43
+ def version_s
44
+ " %YAML:#{@options[:Version]}" if @options[:UseVersion]
45
+ end
46
+
47
+ #
48
+ # Header
49
+ #
50
+ def header
51
+ if @headless.nonzero?
52
+ ""
53
+ else
54
+ "---#{version_s} "
55
+ end
56
+ end
57
+
58
+ #
59
+ # Concatenate to the buffer
60
+ #
61
+ def <<( str )
62
+ #p [ self.id, @level, str ]
63
+ @buffer.last << str
64
+ end
65
+
66
+ #
67
+ # Monitor objects and allow references
68
+ #
69
+ def start_object( oid )
70
+ @level += 1
71
+ @buffer.push( "" )
72
+ #p [ self.id, @level, :OPEN ]
73
+ idx = nil
74
+ if oid
75
+ if @anchors.has_key?( oid )
76
+ idx = @active_anchors.index( oid )
77
+ unless idx
78
+ idx = @active_anchors.length
79
+ af_str = "&#{@options[:AnchorFormat]} " % [ idx + 1 ]
80
+ af_str += @anchor_extras[ @anchors[ oid ] ].to_s
81
+ @buffer[ @anchors[ oid ] ][0,0] = af_str
82
+ @headless = 0 if @anchors[ oid ].zero?
83
+ end
84
+ idx += 1
85
+ @active_anchors.push( oid )
86
+ else
87
+ @anchors[ oid ] = @buffer.length - 1
88
+ end
89
+ end
90
+ return idx
91
+ end
92
+
93
+ #
94
+ # Output method
95
+ #
96
+ def end_object
97
+ @level -= 1
98
+ @buffer.push( "" )
99
+ #p [ self.id, @level, :END ]
100
+ if @level < 0
101
+ header + @buffer.to_s[@headless..-1].to_s
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+