rwdlanguage 0.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Readme.txt +475 -0
  2. data/bin/rwdlanguage +19 -0
  3. data/code/01rwdcore/01rwdcore.rb +29 -0
  4. data/code/01rwdcore/02helptexthashbegin.rb +16 -0
  5. data/code/01rwdcore/03helptexthash.rb +21 -0
  6. data/code/01rwdcore/jumplinkcommand.rb +36 -0
  7. data/code/01rwdcore/openhelpwindow.rb +38 -0
  8. data/code/01rwdcore/returntomain.rb +10 -0
  9. data/code/01rwdcore/rundocuments.rb +10 -0
  10. data/code/01rwdcore/runeditconfiguration.rb +10 -0
  11. data/code/01rwdcore/runhelpabout.rb +15 -0
  12. data/code/01rwdcore/runopentinkerdocument.rb +7 -0
  13. data/code/01rwdcore/runtab.rb +15 -0
  14. data/code/01rwdcore/rwdtinkerversion.rb +22 -0
  15. data/code/01rwdcore/rwdwindowreturn.rb +9 -0
  16. data/code/01rwdcore/selectiontab.rb +11 -0
  17. data/code/01rwdcore/setuphelpaboutoptions.rb +15 -0
  18. data/code/01rwdcore/setuptinkerdocuments.rb +7 -0
  19. data/code/01rwdcore/test_cases.rb +158 -0
  20. data/code/01rwdcore/test_harness.rb +20 -0
  21. data/code/01rwdcore/uploadreturns.rb +65 -0
  22. data/code/dd0viewphoto/dd0viewphoto.rb +5 -0
  23. data/code/superant.com.language/0uninstallapplet.rb +22 -0
  24. data/code/superant.com.language/googlelang.rb +25 -0
  25. data/code/superant.com.language/helptexthashload.rb +22 -0
  26. data/code/superant.com.language/loadconfigurationrecord.rb +22 -0
  27. data/code/superant.com.language/loadconfigurationvariables.rb +14 -0
  28. data/code/superant.com.language/openhelpwindow.rb +24 -0
  29. data/code/superant.com.language/rubySteak.rb +40 -0
  30. data/code/superant.com.language/runappletwindow.rb +12 -0
  31. data/code/superant.com.language/runrwdshellwindow.rb +12 -0
  32. data/code/superant.com.language/runrwdwordsbackwindow.rb +10 -0
  33. data/code/superant.com.language/rwdtinkerversion.rb +10 -0
  34. data/code/superant.com.language/saveconfigurationrecord.rb +20 -0
  35. data/code/superant.com.language/test_cases.rb +20 -0
  36. data/code/superant.com.rwdtinkerbackwindow/changelocale.rb +84 -0
  37. data/code/superant.com.rwdtinkerbackwindow/diagnostictab.rb +19 -0
  38. data/code/superant.com.rwdtinkerbackwindow/initiateapplets.rb +169 -0
  39. data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +38 -0
  40. data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +20 -0
  41. data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
  42. data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +55 -0
  43. data/code/superant.com.rwdtinkerbackwindow/listinstalledfiles.rb +14 -0
  44. data/code/superant.com.rwdtinkerbackwindow/listzips.rb +37 -0
  45. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationrecord.rb +24 -0
  46. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationvariables.rb +14 -0
  47. data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
  48. data/code/superant.com.rwdtinkerbackwindow/openappletname.rb +19 -0
  49. data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +40 -0
  50. data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
  51. data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +46 -0
  52. data/code/superant.com.rwdtinkerbackwindow/removeappletvariables.rb +52 -0
  53. data/code/superant.com.rwdtinkerbackwindow/runremoteinstall.rb +11 -0
  54. data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +15 -0
  55. data/code/superant.com.rwdtinkerbackwindow/rwdtinkerwin2version.rb +13 -0
  56. data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +19 -0
  57. data/code/superant.com.rwdtinkerbackwindow/showlocaleoptions.rb +9 -0
  58. data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +23 -0
  59. data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +24 -0
  60. data/code/superant.com.rwdtinkerbackwindow/viewlogfile.rb +16 -0
  61. data/code/superant.com.thesaurus/clearhttpview3.rb +9 -0
  62. data/code/superant.com.thesaurus/listwordlookup.rb +37 -0
  63. data/code/superant.com.thesaurus/runappletwindow.rb +12 -0
  64. data/code/superant.com.words/dictlookup.rb +20 -0
  65. data/code/superant.com.words/runrwdwordsbackwindow.rb +10 -0
  66. data/code/superant.com.words/rwdtinkerversion.rb +10 -0
  67. data/code/zz0applicationend/zz0end.rb +5 -0
  68. data/configuration/rwdtinker.dist +15 -0
  69. data/configuration/rwdwlanguage.dist +21 -0
  70. data/configuration/tinkerwin2variables.dist +23 -0
  71. data/gui/00coreguibegin/applicationguitop.rwd +9 -0
  72. data/gui/frontwindow0/cc0openphoto.rwd +22 -0
  73. data/gui/frontwindowselections/00selectiontabbegin.rwd +11 -0
  74. data/gui/frontwindowselections/jumplinkcommands.rwd +15 -0
  75. data/gui/frontwindowselections/wwselectionend.rwd +3 -0
  76. data/gui/frontwindowtdocuments/00documentbegin.rwd +6 -0
  77. data/gui/frontwindowtdocuments/tinkerdocuments.rwd +14 -0
  78. data/gui/frontwindowtdocuments/zzdocumentend.rwd +8 -0
  79. data/gui/helpaboutbegin/zzzrwdlasttab.rwd +6 -0
  80. data/gui/helpaboutbegin/zzzzhelpscreenstart.rwd +3 -0
  81. data/gui/helpaboutbegin/zzzzzzhelpabouttab.rwd +15 -0
  82. data/gui/helpaboutzend/helpscreenend.rwd +3 -0
  83. data/gui/helpaboutzend/zhelpscreenstart2.rwd +3 -0
  84. data/gui/helpaboutzend/zzzzhelpabout2.rwd +15 -0
  85. data/gui/helpaboutzend/zzzzhelpscreen2end.rwd +3 -0
  86. data/gui/tinkerbackwindows/superant.com.language/1appname.rwd +4 -0
  87. data/gui/tinkerbackwindows/superant.com.language/22google.rwd +38 -0
  88. data/gui/tinkerbackwindows/superant.com.language/44germany.rwd +19 -0
  89. data/gui/tinkerbackwindows/superant.com.language/67viewconfiguration.rwd +27 -0
  90. data/gui/tinkerbackwindows/superant.com.language/77jumplinkcommands.rwd +17 -0
  91. data/gui/tinkerbackwindows/superant.com.language/z9end.rwd +6 -0
  92. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/1appname.rwd +5 -0
  93. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +41 -0
  94. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
  95. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +44 -0
  96. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +30 -0
  97. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/70rwddiagnostics.rwd +29 -0
  98. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/75rwdlogfile.rwd +20 -0
  99. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/80localechanger.rwd +17 -0
  100. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/81jumplinkcommands.rwd +17 -0
  101. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/9backend.rwd +6 -0
  102. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +31 -0
  103. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/9end.rwd +4 -0
  104. data/gui/tinkerbackwindows/superant.com.versionwindow/1appname.rwd +19 -0
  105. data/gui/tinkerbackwindows/superant.com.versionwindow/helpaboutwindow.rwd +17 -0
  106. data/gui/tinkerbackwindows/superant.com.words/1appname.rwd +4 -0
  107. data/gui/tinkerbackwindows/superant.com.words/1dictionary.rwd +19 -0
  108. data/gui/tinkerbackwindows/superant.com.words/4thesaurus.rwd +36 -0
  109. data/gui/tinkerbackwindows/superant.com.words/77jumplinkcommands.rwd +17 -0
  110. data/gui/tinkerbackwindows/superant.com.words/z9end.rwd +6 -0
  111. data/gui/zzcoreguiend/yy9rwdend.rwd +4 -0
  112. data/init.rb +179 -0
  113. data/installed/rwdwlanguage.inf +24 -0
  114. data/installed/temp.rb +1 -0
  115. data/lang/en/rwdcore/en.po +197 -0
  116. data/lang/en/rwdlanguage/en.po +32 -0
  117. data/lang/es/rwdcore/es.po +184 -0
  118. data/lang/es/rwdlanguage/en.po +32 -0
  119. data/lang/fr/rwdcore/fr.po +169 -0
  120. data/lang/fr/rwdlanguage/en.po +32 -0
  121. data/lang/hi/rwdcore/hi.po +173 -0
  122. data/lang/hi/rwdlanguage/en.po +32 -0
  123. data/lang/ja/rwdcore/ja.po +171 -0
  124. data/lang/ja/rwdlanguage/en.po +32 -0
  125. data/lang/nl/rwdcore/nl.po +169 -0
  126. data/lang/nl/rwdlanguage/en.po +32 -0
  127. data/lib/dict.rb +438 -0
  128. data/lib/g_translate.rb +43 -0
  129. data/lib/g_translate/client.rb +84 -0
  130. data/lib/g_translate/translator.rb +57 -0
  131. data/lib/ger-eng.txt +111283 -0
  132. data/lib/oothesaurus.rb +76 -0
  133. data/lib/rconftool.rb +387 -0
  134. data/lib/rwd/browser.rb +123 -0
  135. data/lib/rwd/ftools.rb +174 -0
  136. data/lib/rwd/mime.rb +328 -0
  137. data/lib/rwd/net.rb +877 -0
  138. data/lib/rwd/ruby.rb +889 -0
  139. data/lib/rwd/rwd.rb +1425 -0
  140. data/lib/rwd/sgml.rb +236 -0
  141. data/lib/rwd/thread.rb +63 -0
  142. data/lib/rwd/tree.rb +371 -0
  143. data/lib/rwd/xml.rb +101 -0
  144. data/lib/rwdthemes/default.rwd +317 -0
  145. data/lib/rwdthemes/pda.rwd +72 -0
  146. data/lib/rwdthemes/windowslike.rwd +171 -0
  147. data/lib/rwdtinker/rwdcodedir.rb +56 -0
  148. data/lib/rwdtinker/rwdguidir.rb +57 -0
  149. data/lib/rwdtinker/rwdlangdir.rb +60 -0
  150. data/lib/rwdtinker/rwdtinkertools.rb +25 -0
  151. data/lib/zip/ioextras.rb +155 -0
  152. data/lib/zip/stdrubyext.rb +111 -0
  153. data/lib/zip/tempfile_bugfixed.rb +195 -0
  154. data/lib/zip/zip.rb +1847 -0
  155. data/lib/zip/zipfilesystem.rb +609 -0
  156. data/lib/zip/ziprequire.rb +90 -0
  157. data/rwd_files/HowTo_Language.txt +179 -0
  158. data/rwd_files/HowTo_Tinker.txt +515 -0
  159. data/rwd_files/HowTo_TinkerWin2.txt +202 -0
  160. data/rwd_files/Readme.txt +57 -0
  161. data/rwd_files/RubyWebDialogs.html +6 -0
  162. data/rwd_files/Tinkerhelptexthash.txt +84 -0
  163. data/rwd_files/favicon.ico +0 -0
  164. data/rwd_files/log/rwdtinker.log +726 -0
  165. data/rwd_files/rdoc-style.css +175 -0
  166. data/rwd_files/rwdapplications.html +76 -0
  167. data/rwd_files/rwdlanguagehelpfiles.txt +34 -0
  168. data/rwd_files/tinker.png +0 -0
  169. data/rwdconfig.dist +24 -0
  170. data/rwdlanguage.rb +1 -0
  171. data/tests/RubyGauge.rb +179 -0
  172. data/tests/checkdepends.sh +4 -0
  173. data/tests/cleancnf.sh +6 -0
  174. data/tests/makedist-rwdwlanguage.rb +56 -0
  175. data/tests/makedist.rb +66 -0
  176. data/tests/rdep.rb +354 -0
  177. data/tests/totranslate.lang +93 -0
  178. data/zips/rwdwcalc-0.63.zip +0 -0
  179. data/zips/rwdwfoldeditor-0.08.zip +0 -0
  180. data/zips/rwdwhypernote-0.16.zip +0 -0
  181. data/zips/rwdwlanguage-0.01.zip +0 -0
  182. data/zips/rwdwmovies-0.98.zip +0 -0
  183. data/zips/rwdwruby-1.08.zip +0 -0
  184. data/zips/temp.rb +1 -0
  185. data/zips/tinkerbellw-0.04.zip +0 -0
  186. data/zips/wrubyslippers-1.08.zip +0 -0
  187. metadata +246 -0
data/lib/rwd/ruby.rb ADDED
@@ -0,0 +1,889 @@
1
+ require "cgi"
2
+ require "rbconfig"
3
+ require "thread"
4
+
5
+ Thread.abort_on_exception = true
6
+
7
+ $DEBUG = ($DEBUG or ENV["RUBYDEBUG"] or false)
8
+
9
+ #tekens = '\w\~\@\#\$\%\^\&\*\-\+'
10
+ tekens = '^\s\r\n\`\!\(\)\[\]\{\}\<\>\,\.\/\?\\\|\=\;\:\"'
11
+
12
+ #tekens11 = '\w'
13
+ tekens11 = tekens + "'"
14
+
15
+ tekens21 = tekens + "'"
16
+ tekens22 = tekens
17
+ tekens23 = tekens + "'"
18
+
19
+ tekens31 = '\w\s\r\n'
20
+
21
+ RegExpStringWord = "([#{tekens11}]+)" ; RegExpWord = Regexp.new(RegExpStringWord)
22
+ RegExpStringWord2 = "([#{tekens21}]([#{tekens22}]*[#{tekens23}])?)" ; RegExpWord2 = Regexp.new(RegExpStringWord2)
23
+ RegExpStringText = "([#{tekens31}]+)" ; RegExpText = Regexp.new(RegExpStringText)
24
+ RegExpStringFile = '(\w[\w\.\-]*)' ; RegExpFile = Regexp.new(RegExpStringFile)
25
+ RegExpStringEmail = '([\w\-\.]+@[\w\-\.]+)' ; RegExpEmail = Regexp.new(RegExpStringEmail)
26
+ RegExpStringURL = '(\w+:\/\/[\w\.\-]+(:\d*)?\/[\w\.\-\/\#\?\=\%]*)' ; RegExpURL = Regexp.new(RegExpStringURL)
27
+ RegExpStringPrint = '([\w \t\r\n\`\~\!\@\#\$\%\^\&\*\(\)\-\+\=\[\]\{\}\;\:\'\"\,\.\/\<\>\?\\\|]+)' ; RegExpPrint = Regexp.new(RegExpStringPrint)
28
+ RegExpStringDiff = '(^[\-\+]([^\-\+].*)?)' ; RegExpDiff = Regexp.new(RegExpStringDiff)
29
+ RegExpStringHTHLink = '(`[\w\,]*\ba\b[^`]*`)' ; RegExpHTHLink = Regexp.new(RegExpStringHTHLink)
30
+ RegExpStringHTHSpecial = '(`[^`]*`)' ; RegExpHTHSpecial = Regexp.new(RegExpStringHTHSpecial)
31
+
32
+ module Enumerable
33
+ def deep_dup
34
+ Marshal::load(Marshal::dump(dup))
35
+ end
36
+
37
+ def deep_clone
38
+ Marshal::load(Marshal::dump(clone))
39
+ end
40
+ end
41
+
42
+ class Thread
43
+ def self.background(*args)
44
+ new(*args) do |*args|
45
+ Thread.pass
46
+
47
+ yield(*args)
48
+ end
49
+ end
50
+ end
51
+
52
+ class Object
53
+ alias deep_dup :dup
54
+ alias deep_clone :clone
55
+
56
+ def to_fs
57
+ to_s
58
+ end
59
+
60
+ def ids
61
+ id
62
+ end
63
+ end
64
+
65
+ class Numeric
66
+ def to_fs
67
+ to_f
68
+ end
69
+
70
+ def to_html(eolconversion=true)
71
+ self.to_s.to_html(eolconversion)
72
+ end
73
+ end
74
+
75
+ class Integer
76
+ def oct
77
+ n = self
78
+ res = []
79
+
80
+ while n > 8
81
+ n, x = n.divmod(8)
82
+ res << x
83
+ end
84
+ res << n
85
+
86
+ res.reverse.join("")
87
+ end
88
+ end
89
+
90
+ class String
91
+ def chomp!(dummy=nil)
92
+ self.gsub!(/[\r\n]*\z/, "")
93
+ end
94
+
95
+ def chomp(dummy=nil)
96
+ self.gsub(/[\r\n]*\z/, "")
97
+ end
98
+
99
+ def lf
100
+ self.gsub(/\r*\n/, "\n").gsub(/\n\z/, "") + "\n"
101
+ end
102
+
103
+ def crlf
104
+ self.gsub(/\r*\n/, "\r\n").gsub(/\r\n\z/, "") + "\r\n"
105
+ end
106
+
107
+ def strip
108
+ self.stripbefore.stripafter
109
+ end
110
+
111
+ def stripbefore
112
+ self.gsub(/\A[[:blank:]\r\n]*/, "")
113
+ end
114
+
115
+ def stripafter
116
+ self.gsub(/[[:blank:]\r\n]*\z/, "")
117
+ end
118
+
119
+ def compress
120
+ self.gsub(/[[:blank:]\r\n]+/, " ").strip
121
+ end
122
+
123
+ def compressspaces
124
+ self.gsub(/[[:blank:]]+/, " ")
125
+ end
126
+
127
+ def compressperline
128
+ res = self.split(/\n/)
129
+ res.collect!{|line| line.compress}
130
+ res.delete_if{|line| line.empty?}
131
+ res.join("\n")
132
+ end
133
+
134
+ def numeric?
135
+ d, a, n = [self].to_par
136
+
137
+ not n.empty?
138
+ end
139
+
140
+ def exec(input=nil, output=true)
141
+ res = []
142
+
143
+ IO.popen(self, "w+") do |f|
144
+ f.puts input unless input.nil?
145
+ f.close_write
146
+
147
+ res = f.readlines if output
148
+ end
149
+
150
+ res.join("")
151
+ end
152
+
153
+ def eval
154
+ Kernel::eval(self)
155
+ end
156
+
157
+ def speak
158
+ require "drb"
159
+
160
+ DRb.start_service
161
+ DRbObject.new(nil, "druby://localhost:3100").speak(self)
162
+ end
163
+
164
+ def splitblocks(*delimiters)
165
+ begindelimiters = []
166
+ enddelimiters = []
167
+
168
+ delimiters.each do |k, v|
169
+ begindelimiters << k.downcase
170
+ enddelimiters << v.downcase
171
+ end
172
+
173
+ bd = begindelimiters.collect {|s| Regexp.escape(s)}
174
+ ed = enddelimiters.collect {|s| Regexp.escape(s)}
175
+
176
+ be = bd.join("|")
177
+ ee = ed.join("|")
178
+
179
+ res = []
180
+ type = 0
181
+ tmp = ""
182
+ bs = ""
183
+ es = ""
184
+
185
+ self.split(/(#{ee}|#{be})/i).each do |s|
186
+ if type == 0
187
+ if begindelimiters.include?(s.downcase)
188
+ i = begindelimiters.index(s.downcase)
189
+ type = i+1
190
+ tmp = s
191
+ bs = s.downcase
192
+ es = enddelimiters[i]
193
+ else
194
+ res << [0, s] unless s.empty?
195
+ end
196
+ else
197
+ if s.downcase == es
198
+ res << [type, tmp + s]
199
+ type = 0
200
+ tmp = ""
201
+ bs = ""
202
+ es = ""
203
+ else
204
+ if s.downcase == bs
205
+ res << [0, tmp]
206
+ tmp = s
207
+ else
208
+ tmp = tmp + s
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ res << [0, tmp] unless tmp.empty?
215
+
216
+ return res
217
+ end
218
+
219
+ def splitwords(tokens=[])
220
+ tokens = [tokens] unless tokens.kind_of?(Array)
221
+ res = []
222
+
223
+ self.splitblocks(["'", "'"], ['"', '"']).each do |type, s|
224
+ case type
225
+ when 0
226
+ tokens.each do |token|
227
+ token2 = token
228
+ token2 = Regexp.escape(token2) if token2.kind_of?(String)
229
+ s.gsub!(/#{token2}/, " #{token} ")
230
+ end
231
+ s.split().each do |w|
232
+ res << w
233
+ end
234
+ when 1, 2
235
+ res << s[1..-2]
236
+ end
237
+ end
238
+
239
+ return res
240
+ end
241
+
242
+ def uncomment
243
+ res = []
244
+
245
+ self.splitblocks(["'", "'"], ['"', '"'], ["#", "\n"]).each do |type, s|
246
+ case type
247
+ when 0, 1, 2 then res << s
248
+ when 3 then res << "\n"
249
+ end
250
+ end
251
+
252
+ res.join("")
253
+ end
254
+
255
+ def noquotes
256
+ self.sub(/\A['"]/, "").sub(/['"]\z/, "")
257
+ end
258
+
259
+ def to_html(eolconversion=true)
260
+ s = CGI.escapeHTML(self)
261
+
262
+ s.gsub!(/\"/, "\&#34;")
263
+ s.gsub!(/\'/, "\&#180;")
264
+
265
+ if eolconversion
266
+ s.gsub!(/\n/ , "<br>")
267
+ end
268
+
269
+ s
270
+ end
271
+
272
+ def from_html(eolconversion=true)
273
+ s = self
274
+
275
+ s.gsub!(/&#34;/ , "\"")
276
+ s.gsub!(/&#180;/, "\'")
277
+
278
+ # s = CGI.unescapeHTML(self)
279
+
280
+ if eolconversion
281
+ s.gsub!(/<br>/, "\n")
282
+ end
283
+
284
+ s
285
+ end
286
+
287
+ def to_fs
288
+ if numeric?
289
+ to_f
290
+ else
291
+ to_s
292
+ end
293
+ end
294
+ end
295
+
296
+ class Array
297
+ def chomp!
298
+ self.collect!{|s| s.chomp}
299
+ end
300
+
301
+ def chomp
302
+ self.collect{|s| s.chomp}
303
+ end
304
+
305
+ def compress
306
+ self.collect{|s| s.compress}
307
+ end
308
+
309
+ def uncomment
310
+ self.join("\0").uncomment.split("\0")
311
+ end
312
+
313
+ def strip
314
+ self.collect{|s| s.strip}
315
+ end
316
+
317
+ def sum
318
+ res = 0
319
+ self.each do |n|
320
+ res += n
321
+ end
322
+ res
323
+ end
324
+
325
+ def product
326
+ res = 1
327
+ self.each do |n|
328
+ res *= n
329
+ end
330
+ res
331
+ end
332
+
333
+ def joinwords(sep=" ", quote='"')
334
+ self.collect do |s|
335
+ s = quote + s + quote if s =~ /[[:blank:]]/
336
+ s
337
+ end.join(sep)
338
+ end
339
+
340
+ def domino(tabellen, kolom=nil, onlymatchinglines=false)
341
+ links = self
342
+ res = []
343
+ res = self.dup unless onlymatchinglines
344
+
345
+ tabellen.each do |rechts|
346
+ tmp = []
347
+
348
+ links.each do |l|
349
+ if kolom.nil? or l.length == kolom
350
+ rechts.each do |r|
351
+ tmp << l + r[1..-1] if l[-1] == r[0]
352
+ end
353
+ end
354
+ end
355
+
356
+ links = tmp
357
+ res.concat(tmp)
358
+ end
359
+
360
+ res = res.sort.uniq
361
+ end
362
+
363
+ def dominoloop(tabellen)
364
+ lres = []
365
+ res = self.dup
366
+ kolom = 2
367
+
368
+ while lres.length != res.length do
369
+ lres = res.dup
370
+ res = res.domino(tabellen, kolom)
371
+
372
+ res.each do |line|
373
+ line << "*" if (line.length != line.uniq.length and line[-1] != "*")
374
+ end
375
+
376
+ $stderr.print "#{100*(res.length)/(lres.length)}% "
377
+
378
+ kolom += 1
379
+ end
380
+
381
+ $stderr.puts ""
382
+
383
+ return res
384
+ end
385
+
386
+ def buildtree
387
+ self.dominoloop([self])
388
+ end
389
+
390
+ def subset(fields, values, results, exact=true, emptyline=nil, joinwith=nil)
391
+ fields = [fields] unless fields.kind_of? Array
392
+ values = [values] unless values.kind_of? Array
393
+ results = [results] unless results.kind_of? Array
394
+ emptyline = emptyline.downcase unless emptyline.nil?
395
+ res = self.dup
396
+ res.delete_if {true}
397
+
398
+ self.each do |l|
399
+ ok = true
400
+
401
+ case l.class.to_s
402
+ when "String"
403
+ c = l.splitwords
404
+ correction = 1
405
+ joinwith = " " if joinwith.nil?
406
+ when "Array"
407
+ c = l
408
+ correction = 0
409
+ end
410
+
411
+ #catch :stop do
412
+ values2 = values.dup
413
+ fields.each do |f|
414
+ v = values2.shift
415
+ v = v.downcase unless v.nil?
416
+ if emptyline.nil? or (not v == emptyline)
417
+ if exact
418
+ unless (v.nil? or c[f-correction].downcase == v)
419
+ ok = false
420
+ #throw :stop
421
+ end
422
+ else
423
+ unless (v.nil? or c[f-correction].downcase.include?(v))
424
+ ok = false
425
+ #throw :stop
426
+ end
427
+ end
428
+ end
429
+ end
430
+ #end
431
+
432
+ if ok
433
+ res2 = []
434
+ results.each do |n|
435
+ res2 << c[n-1]
436
+ end
437
+ res2 = res2.join(joinwith) unless joinwith.nil?
438
+ res << res2
439
+ end
440
+ end
441
+
442
+ return res
443
+ end
444
+
445
+ def format(format)
446
+ format = format.gsub(/\s/, "")
447
+ res = []
448
+
449
+ [format.length, self.length].min.times do |n|
450
+ case format[n].chr.downcase
451
+ when "i" then res << self[n].to_i
452
+ when "s" then res << self[n].to_s
453
+ else res << self[n]
454
+ end
455
+ end
456
+
457
+ res
458
+ end
459
+
460
+ def to_i
461
+ collect{|c| c.to_i}
462
+ end
463
+
464
+ def to_par
465
+ dash = self.dup
466
+ alpha = self.dup
467
+ numeric = self.dup
468
+
469
+ dash.delete_if do |s|
470
+ not (s =~ /\A-/) or
471
+ (s =~ /\A-?[[:digit:]\.]+\z/) or
472
+ (s =~ /^-+$/)
473
+ end
474
+
475
+ alpha.delete_if do |s|
476
+ ((s =~ /\A-/) or
477
+ (s =~ /\A-?[[:digit:]\.]+\z/)) and
478
+ not ((s =~ /^\.+$/) or (s =~ /^-+$/))
479
+ end
480
+
481
+ numeric.delete_if do |s|
482
+ not (s =~ /\A-?[[:digit:]\.]+\z/) or
483
+ (s =~ /^\.+$/)
484
+ end
485
+
486
+ raise "Oops!" if dash.length + alpha.length + numeric.length != length
487
+
488
+ return dash, alpha, numeric
489
+ end
490
+
491
+ def self.file(file)
492
+ res = new
493
+
494
+ File.open(file) do |f|
495
+ f.readlines.uncomment.chomp.each do |line|
496
+ res << line
497
+ end
498
+ end
499
+
500
+ res
501
+ end
502
+
503
+ def numsort
504
+ sort do |a, b|
505
+ a2 = a.to_fs
506
+ b2 = b.to_fs
507
+
508
+ if a2.class != b2.class
509
+ a2 = a
510
+ b2 = b
511
+ end
512
+
513
+ a2 <=> b2
514
+ end
515
+ end
516
+
517
+ def to_fs
518
+ collect{|s| s.to_fs}
519
+ end
520
+
521
+ def chaos
522
+ res = self.dup
523
+
524
+ (length^2).times do
525
+ a = rand(length)
526
+ b = rand(length)
527
+
528
+ res[a], res[b] = res[b], res[a]
529
+ end
530
+
531
+ res
532
+ end
533
+
534
+ def any
535
+ if empty?
536
+ nil
537
+ else
538
+ self[rand(self.length)]
539
+ end
540
+ end
541
+
542
+ def minmax
543
+ min, value, max = self
544
+ [min, [value, max].min].max
545
+ end
546
+
547
+ def ids
548
+ collect{|e| e.ids}
549
+ end
550
+
551
+ def rotate
552
+ raise "Array has to be 2D (An Array of Arrays)." unless self.dup.delete_if{|a| a.kind_of?(Array)}.empty?
553
+
554
+ res = []
555
+
556
+ self[0].length.times do |x|
557
+ a = []
558
+
559
+ self.length.times do |y|
560
+ a << self[y][x]
561
+ end
562
+
563
+ res << a
564
+ end
565
+
566
+ res
567
+ end
568
+
569
+ def to_h
570
+ raise "Array has to be 2D (An Array of Arrays)." unless self.dup.delete_if{|a| a.kind_of?(Array)}.empty?
571
+
572
+ res = {}
573
+
574
+ self.each do |k, v, *rest|
575
+ res[k] = v
576
+ end
577
+
578
+ res
579
+ end
580
+ end
581
+
582
+ class Hash
583
+ def save(file, append=false)
584
+ org = {}
585
+ org = Hash.file(file) if (append and File.file?(file))
586
+
587
+ self.sort.each do |k, v|
588
+ org[k] = v
589
+ end
590
+
591
+ File.open(file, "w") do |f|
592
+ org.sort.each do |k, v|
593
+ f.puts "%s\t= %s" % [k, v]
594
+ end
595
+ end
596
+ end
597
+
598
+ def subset(fields, values, results=nil, exact=true, emptyline=nil, joinwith=nil)
599
+ fields = [fields] unless fields.kind_of? Array
600
+ values = [values] unless values.kind_of? Array
601
+ results = [results] unless results.kind_of? Array
602
+ emptyline = emptyline.downcase unless emptyline.nil?
603
+ res = self.dup
604
+ res.delete_if {true}
605
+
606
+ self.each do |k, l|
607
+ ok = true
608
+
609
+ case l.class.to_s
610
+ when "String"
611
+ c = l.splitwords
612
+ correction = 1
613
+ joinwith = " " if joinwith.nil?
614
+ when "Array"
615
+ c = l
616
+ correction = 0
617
+ end
618
+
619
+ #catch :stop do
620
+ values2 = values.dup
621
+ fields.each do |f|
622
+ v = values2.shift
623
+ v = v.downcase unless v.nil?
624
+ if emptyline.nil? or (not v == emptyline)
625
+ if exact
626
+ unless (v.nil? or c[f-correction].downcase == v)
627
+ ok = false
628
+ #throw :stop
629
+ end
630
+ else
631
+ unless (v.nil? or c[f-correction].downcase.include?(v))
632
+ ok = false
633
+ #throw :stop
634
+ end
635
+ end
636
+ end
637
+ end
638
+ #end
639
+
640
+ if ok
641
+ res2 = []
642
+ if results == [nil]
643
+ res2 = c
644
+ else
645
+ results.each do |n|
646
+ res2 << c[n-correction]
647
+ end
648
+ end
649
+ res2 = res2.join(joinwith) unless joinwith.nil?
650
+ res[k] = res2
651
+ end
652
+ end
653
+
654
+ return res
655
+ end
656
+
657
+ def to_i
658
+ collect{|k, v| v.to_i}
659
+ end
660
+
661
+ def self.file(file)
662
+ res = new
663
+
664
+ File.open(file) do |f|
665
+ #f.readlines.chomp.each do |line|
666
+ while line = f.gets do
667
+ line.chomp!
668
+
669
+ unless line.empty?
670
+ k, v = line.split(/\s*=\s*/, 2)
671
+ res[k] = v
672
+ end
673
+ end
674
+ end
675
+
676
+ res
677
+ end
678
+
679
+ def ids
680
+ collect{|k, v| [k, v].ids}
681
+ end
682
+ end
683
+
684
+ def id2ref(id)
685
+ ObjectSpace._id2ref(id)
686
+ end
687
+
688
+ def after(seconds, *args)
689
+ if not seconds.nil? and not seconds.zero?
690
+ Thread.new(*args) do |*args2|
691
+ sleep seconds
692
+ yield(*args2)
693
+ end
694
+ end
695
+ end
696
+
697
+ def every(seconds, *args)
698
+ if not seconds.nil? and not seconds.zero?
699
+ Thread.new(*args) do |*args2|
700
+ loop do
701
+ sleep seconds
702
+ yield(*args2)
703
+ end
704
+ end
705
+ end
706
+ end
707
+
708
+ def evtimeout(seconds)
709
+ begin
710
+ timeout(seconds) do
711
+ yield
712
+ end
713
+ rescue TimeoutError
714
+ end
715
+ end
716
+
717
+ def evtimeoutretry(seconds)
718
+ ok = false
719
+
720
+ while not ok
721
+ evtimeout(seconds) do
722
+ yield
723
+ ok = true
724
+ end
725
+ end
726
+ end
727
+
728
+ def trap(signal)
729
+ Kernel::trap(signal) do
730
+ yield
731
+ end
732
+
733
+ # Seems pointless, but it's for catching ^C under Windows...
734
+
735
+ every(1) {} if windows?
736
+ end
737
+
738
+ def linux?
739
+ not (target_os.downcase =~ /linux/).nil?
740
+ end
741
+
742
+ def darwin?
743
+ not (target_os.downcase =~ /darwin/).nil?
744
+ end
745
+
746
+ def windows?
747
+ not (target_os.downcase =~ /32/).nil?
748
+ end
749
+
750
+ def cygwin?
751
+ not (target_os.downcase =~ /cyg/).nil?
752
+ end
753
+
754
+ def target_os
755
+ Config::CONFIG["target_os"] or ""
756
+ end
757
+
758
+ def user
759
+ ENV["USER"] or ENV["USERNAME"]
760
+ end
761
+
762
+ def home
763
+ (ENV["HOME"] or ENV["USERPROFILE"] or (File.directory?("h:/") ? "h:" : "c:")).gsub(/\\/, "/")
764
+ end
765
+
766
+ def temp
767
+ (ENV["TMPDIR"] or ENV["TMP"] or ENV["TEMP"] or "/tmp").gsub(/\\/, "/")
768
+ end
769
+
770
+ def stdtmp
771
+ $stderr = $stdout = File.new("#{temp}/ruby.#{Process.pid}.log", "a")
772
+ end
773
+ stdtmp if defined?(RUBYSCRIPT2EXE) and (RUBYSCRIPT2EXE =~ /rubyw/i)
774
+
775
+ $nobm = false
776
+
777
+ def nobm
778
+ $nobm = true
779
+ end
780
+
781
+ def bm(label="")
782
+ if $nobm
783
+ if block_given?
784
+ return yield
785
+ else
786
+ return nil
787
+ end
788
+ end
789
+
790
+ label = label.inspect #unless label.kind_of?(String)
791
+ res = nil
792
+
793
+ $bm_mutex = ($bm_mutex or Mutex.new)
794
+
795
+ $bm_mutex.synchronize do
796
+ if $bm.nil?
797
+ require "ev/bm"
798
+
799
+ $bm = {}
800
+
801
+ at_exit do
802
+ l = $bm.keys.collect{|s| s.length}.max
803
+ #format1 = "%10s %10s %10s %10s %10s %10s %s"
804
+ #format2 = "%10.6f %10.6f %10.6f %10.6f %10.6f %10d %s"
805
+ #$stderr.puts format1 % ["USERCPU", "SYSCPU", "CUSERCPU", "CSYSCPU", "ELAPSED", "COUNT", "LABEL"]
806
+ #$bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v|
807
+ #$stderr.puts format2 % (v + [k])
808
+ #end
809
+
810
+ format1 = "%10s %10s %10s %s"
811
+ format2 = "%10.6f %10.6f %10d %s"
812
+ $bm.each do |k, v|
813
+ $bm[k] = [v[0]+v[1], v[4], v[5]]
814
+ end
815
+ $stderr.puts format1 % ["CPU", "ELAPSED", "COUNT", "LABEL"]
816
+ $bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v|
817
+ $stderr.puts format2 % (v + [k])
818
+ end
819
+ end
820
+ end
821
+
822
+ $bm[label] = [0.0]*5 + [0] unless $bm.include?(label)
823
+ $bm[label][5] += 1
824
+ end
825
+
826
+ if block_given?
827
+ bm = Benchmark.measure{res = yield}
828
+ bma = bm.to_a # [dummy label, user CPU time, system CPU time, childrens user CPU time, childrens system CPU time, elapsed real time]
829
+
830
+ $bm_last = bma
831
+
832
+ $bm_mutex.synchronize do
833
+ e = $bm[label]
834
+ 0.upto(4) do |n|
835
+ e[n] += bma[n+1]
836
+ end
837
+ end
838
+ end
839
+
840
+ res
841
+ end
842
+
843
+ def trace
844
+ res =nil
845
+
846
+ set_trace_func lambda { |event, file, line, id, binding, classname|
847
+ $stderr.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
848
+ }
849
+
850
+ if block_given?
851
+ res = yield
852
+
853
+ notrace
854
+ end
855
+
856
+ res
857
+ end
858
+
859
+ def notrace
860
+ set_trace_func nil
861
+ end
862
+
863
+ def lambda_cached(&block)
864
+ hash = {}
865
+ lambda do |*args|
866
+ res = hash[args]
867
+ if res.nil?
868
+ res = block.call(*args)
869
+ hash[args] = res
870
+ end
871
+ res
872
+ end
873
+ end
874
+
875
+ def ask(options, text=false)
876
+ i = 0
877
+ $stderr.puts ""
878
+ options.each do |s|
879
+ $stderr.puts " %d %s" % [i+=1, s]
880
+ end
881
+ $stderr.puts ""
882
+ $stderr.print "? "
883
+ res = $stdin.gets
884
+ unless res.nil?
885
+ res = res.strip
886
+ res = options[res.to_i-1] if text and not res.empty?
887
+ end
888
+ res
889
+ end