rwdhypernote 0.03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Notes/changes.lnk +1 -0
- data/Notes/changes.txt +1 -0
- data/Notes/hypernote/hypernote01.txt +1 -0
- data/Notes/hypernote/hypernote02.txt +1 -0
- data/Notes/hypernote/newnote3.txt +2 -0
- data/Notes/rwdtinker/RwdtinkerProgrammingQuickStart.lnk +1 -0
- data/Notes/rwdtinker/RwdtinkerProgrammingQuickStart.txt +11 -0
- data/Notes/rwdtinker/newnote.txt +1 -0
- data/Notes/rwdtinker/rwdtinker01.txt +9 -0
- data/Notes/rwdtinker/testnote2.txt +1 -0
- data/Readme.txt +97 -0
- data/bin/rwdhypernote +19 -0
- data/code/01rwdcore/01rwdcore.rb +20 -0
- data/code/01rwdcore/02helptexthashbegin.rb +4 -0
- data/code/01rwdcore/03helptexthash.rb +31 -0
- data/code/01rwdcore/04helptextend.rb +6 -0
- data/code/01rwdcore/openhelpwindow.rb +31 -0
- data/code/01rwdcore/returntomain.rb +10 -0
- data/code/01rwdcore/rwdtinkerversion.rb +15 -0
- data/code/01rwdcore/rwdwindowreturn.rb +11 -0
- data/code/superant.com.hypernote/archiveevent.rb +14 -0
- data/code/superant.com.hypernote/changehypernotename.rb +21 -0
- data/code/superant.com.hypernote/clearhypernotescreendisplay.rb +8 -0
- data/code/superant.com.hypernote/clearlinkscreendisplay.rb +8 -0
- data/code/superant.com.hypernote/copyfilename.rb +10 -0
- data/code/superant.com.hypernote/createnewnote.rb +14 -0
- data/code/superant.com.hypernote/deletehypernoterecord.rb +20 -0
- data/code/superant.com.hypernote/helptexthashrwdhypernote.rb +60 -0
- data/code/superant.com.hypernote/hyperlinkcreatelinkfile.rb +19 -0
- data/code/superant.com.hypernote/listhypernotelinks.rb +52 -0
- data/code/superant.com.hypernote/listhypernotes.rb +55 -0
- data/code/superant.com.hypernote/listlinknotes.rb +33 -0
- data/code/superant.com.hypernote/loadconfigurationrecord.rb +34 -0
- data/code/superant.com.hypernote/loadconfigurationvariables.rb +13 -0
- data/code/superant.com.hypernote/loadlinksrecord.rb +21 -0
- data/code/superant.com.hypernote/loadnoterecord.rb +24 -0
- data/code/superant.com.hypernote/openhelpwindowrwdhyernote.rb +23 -0
- data/code/superant.com.hypernote/returntomain.rb +10 -0
- data/code/superant.com.hypernote/rwdhypernotehelpabout.rb +14 -0
- data/code/superant.com.hypernote/saveconfigurationrecord.rb +18 -0
- data/code/superant.com.hypernote/savehypernoterecord.rb +20 -0
- data/code/superant.com.hypernote/savelinkrecord.rb +23 -0
- data/code/superant.com.hypernote/viewrwdschedulesconfiguration.rb +21 -0
- data/code/superant.com.rwdtinkerbackwindow/controlclient.rb +99 -0
- data/code/superant.com.rwdtinkerbackwindow/diagnostictab.rb +21 -0
- data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +58 -0
- data/code/superant.com.rwdtinkerbackwindow/installapplet.rb +22 -0
- data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +20 -0
- data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +19 -0
- data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
- data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +54 -0
- data/code/superant.com.rwdtinkerbackwindow/listinstalledfiles.rb +11 -0
- data/code/superant.com.rwdtinkerbackwindow/listzips.rb +31 -0
- data/code/superant.com.rwdtinkerbackwindow/loadconfigurationrecord.rb +32 -0
- data/code/superant.com.rwdtinkerbackwindow/loadconfigurationvariables.rb +13 -0
- data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
- data/code/superant.com.rwdtinkerbackwindow/openappletname.rb +18 -0
- data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +42 -0
- data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
- data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +28 -0
- data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +12 -0
- data/code/superant.com.rwdtinkerbackwindow/rwdtinkerwin2version.rb +14 -0
- data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +18 -0
- data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +21 -0
- data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +21 -0
- data/code/zz0applicationend/zz0end.rb +4 -0
- data/configuration/language.cnf +5 -0
- data/configuration/rwdapplicationidentity.cnf +3 -0
- data/configuration/rwdhypernote.cnf +9 -0
- data/configuration/rwdhypernoteversion.cnf +3 -0
- data/configuration/rwdtinker.cnf +16 -0
- data/configuration/rwdtinkerversion.cnf +2 -0
- data/configuration/tinkerwin2variables.cnf +12 -0
- data/configuration/tinkerwin2version.cnf +3 -0
- data/ev/browser.rb +109 -0
- data/ev/ftools.rb +170 -0
- data/ev/net.rb +750 -0
- data/ev/ruby.rb +819 -0
- data/ev/rwd.rb +1849 -0
- data/ev/sgml.rb +236 -0
- data/ev/thread.rb +63 -0
- data/ev/tree.rb +343 -0
- data/ev/xml.rb +4 -0
- data/extras/zip/ioextras.rb +114 -0
- data/extras/zip/stdrubyext.rb +111 -0
- data/extras/zip/tempfile_bugfixed.rb +195 -0
- data/extras/zip/zip.rb +1376 -0
- data/extras/zip/zipfilesystem.rb +558 -0
- data/extras/zip/ziprequire.rb +61 -0
- data/gui/00coreguibegin/applicationguitop.rwd +4 -0
- data/gui/frontwindow0/superant.com.hypernote/10viewnote.rwd +32 -0
- data/gui/frontwindow0/superant.com.hypernote/20editlinks.rwd +34 -0
- data/gui/frontwindow0/superant.com.hypernote/30noteutilities.rwd +27 -0
- data/gui/frontwindowselectionbegin/selectiontabbegin/selectiontabbegin.rwd +16 -0
- data/gui/frontwindowselections/superant.com.rwdtinkerwin2selectiontab/rwdwin2selectiontab.rwd +12 -0
- data/gui/frontwindowselectionzend/viewselectionzend/viewselectionend.rwd +3 -0
- data/gui/frontwindowtdocumentbegin/superant.com.documentsbegin/tt0documentbegin.rwd +6 -0
- data/gui/frontwindowtdocuments/superant.com.documents/uu5documents.rwd +15 -0
- data/gui/frontwindowtdocuments/superant.com.rwdhypernotedocument/rwdhypernotedocument.rwd +5 -0
- data/gui/frontwindowtdocuments/superant.com.tinkerwin2documents/uu5documents.rwd +6 -0
- data/gui/frontwindowtdocumentzend/superant.com.documentsend/ww0documentend.rwd +12 -0
- data/gui/frontwindowz1end/frontwindowend/xx0rwdfirsttab.rwd +6 -0
- data/gui/helpaboutbegin/superant.com.helpaboutbegin/ya0helpscreenstart.rwd +3 -0
- data/gui/helpaboutinstalled/superant.com.rwdhypernotehelpabout/1versionname.rwd +6 -0
- data/gui/helpaboutinstalled/superant.com.rwdhypernotehelpabout/5version.rwd +9 -0
- data/gui/helpaboutinstalled/superant.com.rwdwin2helpabout/1appname.rwd +4 -0
- data/gui/helpaboutinstalled/superant.com.rwdwin2helpabout/3copyright.rwd +3 -0
- data/gui/helpaboutinstalled/superant.com.rwdwin2helpabout/5version.rwd +10 -0
- data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/1appname.rwd +4 -0
- data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/3copyright.rwd +3 -0
- data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/5version.rwd +10 -0
- data/gui/helpaboutzend/superant.com.helpaboutend/helpscreenend.rwd +3 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/1appname.rwd +5 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +42 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +44 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +38 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/70rwddiagnostics.rwd +33 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/75rwdcontrol.rwd +33 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/80tab1.rwd +11 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/9backend.rwd +6 -0
- data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +31 -0
- data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/9end.rwd +4 -0
- data/gui/tinkerbackwindows/superant.com.versionwindow/1appname.rwd +19 -0
- data/gui/zzcoreguiend/tinkerapplicationguiend/yy9rwdend.rwd +4 -0
- data/init.rb +269 -0
- data/lang/alanguagehashbegin.rb +4 -0
- data/lang/en/rwdcore/languagefile.rb +16 -0
- data/lang/es/rwdcore/languagefile-es.rb +14 -0
- data/lang/jp/rwdcore/languagefile.rb +9 -0
- data/lang/languagehash.rb +4 -0
- data/lang/nl/rwdcore/languagefile.rb +19 -0
- data/lang/templangfile.rb +16 -0
- data/lang/vlanguagehashend.rb +6 -0
- data/lang/wlocallangstart.rb +5 -0
- data/lang/xlocallangfile.rb +16 -0
- data/lang/zlocallangend.rb +2 -0
- data/lib/temp.rb +1 -0
- data/rwd_files/HowTo_HyperNote.txt +97 -0
- data/rwd_files/HowTo_Tinker.txt +375 -0
- data/rwd_files/HowTo_TinkerWin2.txt +202 -0
- data/rwd_files/Readme.txt +57 -0
- data/rwd_files/favicon.ico +0 -0
- data/rwd_files/rdoc-style.css +175 -0
- data/rwd_files/rwdapplications.html +54 -0
- data/rwd_files/rwdindex.html +6 -0
- data/rwd_files/tinker.png +0 -0
- data/zips/rwdahelloworld-0.5.zip +0 -0
- metadata +202 -0
data/ev/ruby.rb
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
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
|
+
|
|
30
|
+
module Enumerable
|
|
31
|
+
def deep_dup
|
|
32
|
+
Marshal::load(Marshal::dump(dup))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def deep_clone
|
|
36
|
+
Marshal::load(Marshal::dump(clone))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Thread
|
|
41
|
+
def self.background(*args)
|
|
42
|
+
new(*args) do |*args|
|
|
43
|
+
Thread.pass
|
|
44
|
+
|
|
45
|
+
yield(*args)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class Object
|
|
51
|
+
alias deep_dup :dup
|
|
52
|
+
alias deep_clone :clone
|
|
53
|
+
|
|
54
|
+
def to_fs
|
|
55
|
+
to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def ids
|
|
59
|
+
id
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class Numeric
|
|
64
|
+
def to_fs
|
|
65
|
+
to_f
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class Integer
|
|
70
|
+
def oct
|
|
71
|
+
n = self
|
|
72
|
+
res = []
|
|
73
|
+
|
|
74
|
+
while n > 8
|
|
75
|
+
n, x = n.divmod(8)
|
|
76
|
+
res << x
|
|
77
|
+
end
|
|
78
|
+
res << n
|
|
79
|
+
|
|
80
|
+
res.reverse.join("")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
class String
|
|
85
|
+
def chomp!(dummy=nil)
|
|
86
|
+
self.gsub!(/[\r\n]*\z/, "")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def chomp(dummy=nil)
|
|
90
|
+
self.gsub(/[\r\n]*\z/, "")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def lf
|
|
94
|
+
self.gsub(/\r*\n/, "\n").gsub(/\n\z/, "") + "\n"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def crlf
|
|
98
|
+
self.gsub(/\r*\n/, "\r\n").gsub(/\r\n\z/, "") + "\r\n"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def strip
|
|
102
|
+
self.stripbefore.stripafter
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def stripbefore
|
|
106
|
+
self.gsub(/\A[[:blank:]\r\n]*/, "")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def stripafter
|
|
110
|
+
self.gsub(/[[:blank:]\r\n]*\z/, "")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def compress
|
|
114
|
+
self.gsub(/[[:blank:]\r\n]+/, " ").strip
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def compressspaces
|
|
118
|
+
self.gsub(/[[:blank:]]+/, " ")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def compressperline
|
|
122
|
+
res = self.split(/\n/)
|
|
123
|
+
res.collect!{|line| line.compress}
|
|
124
|
+
res.delete_if{|line| line.empty?}
|
|
125
|
+
res.join("\n")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def numeric?
|
|
129
|
+
d, a, n = [self].to_par
|
|
130
|
+
|
|
131
|
+
not n.empty?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def exec(input=nil, output=true)
|
|
135
|
+
res = []
|
|
136
|
+
|
|
137
|
+
IO.popen(self, "w+") do |f|
|
|
138
|
+
f.puts input unless input.nil?
|
|
139
|
+
f.close_write
|
|
140
|
+
|
|
141
|
+
res = f.readlines if output
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
res.join("")
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def eval
|
|
148
|
+
Kernel::eval(self)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def speak
|
|
152
|
+
require "drb"
|
|
153
|
+
|
|
154
|
+
DRb.start_service
|
|
155
|
+
DRbObject.new(nil, "druby://localhost:3100").speak(self)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def splitblocks(*delimiters)
|
|
159
|
+
begindelimiters = []
|
|
160
|
+
enddelimiters = []
|
|
161
|
+
|
|
162
|
+
delimiters.each do |k, v|
|
|
163
|
+
begindelimiters << k.downcase
|
|
164
|
+
enddelimiters << v.downcase
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
bd = begindelimiters.collect {|s| Regexp.escape(s)}
|
|
168
|
+
ed = enddelimiters.collect {|s| Regexp.escape(s)}
|
|
169
|
+
|
|
170
|
+
be = bd.join("|")
|
|
171
|
+
ee = ed.join("|")
|
|
172
|
+
|
|
173
|
+
res = []
|
|
174
|
+
type = 0
|
|
175
|
+
tmp = ""
|
|
176
|
+
bs = ""
|
|
177
|
+
es = ""
|
|
178
|
+
|
|
179
|
+
self.split(/(#{ee}|#{be})/i).each do |s|
|
|
180
|
+
if type == 0
|
|
181
|
+
if begindelimiters.include?(s.downcase)
|
|
182
|
+
i = begindelimiters.index(s.downcase)
|
|
183
|
+
type = i+1
|
|
184
|
+
tmp = s
|
|
185
|
+
bs = s.downcase
|
|
186
|
+
es = enddelimiters[i]
|
|
187
|
+
else
|
|
188
|
+
res << [0, s] unless s.empty?
|
|
189
|
+
end
|
|
190
|
+
else
|
|
191
|
+
if s.downcase == es
|
|
192
|
+
res << [type, tmp + s]
|
|
193
|
+
type = 0
|
|
194
|
+
tmp = ""
|
|
195
|
+
bs = ""
|
|
196
|
+
es = ""
|
|
197
|
+
else
|
|
198
|
+
if s.downcase == bs
|
|
199
|
+
res << [0, tmp]
|
|
200
|
+
tmp = s
|
|
201
|
+
else
|
|
202
|
+
tmp = tmp + s
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
res << [0, tmp] unless tmp.empty?
|
|
209
|
+
|
|
210
|
+
return res
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def splitwords(tokens=[])
|
|
214
|
+
tokens = [tokens] unless tokens.kind_of?(Array)
|
|
215
|
+
res = []
|
|
216
|
+
|
|
217
|
+
self.splitblocks(["'", "'"], ['"', '"']).each do |type, s|
|
|
218
|
+
case type
|
|
219
|
+
when 0
|
|
220
|
+
tokens.each do |token|
|
|
221
|
+
token2 = token
|
|
222
|
+
token2 = Regexp.escape(token2) if token2.kind_of?(String)
|
|
223
|
+
s.gsub!(/#{token2}/, " #{token} ")
|
|
224
|
+
end
|
|
225
|
+
s.split().each do |w|
|
|
226
|
+
res << w
|
|
227
|
+
end
|
|
228
|
+
when 1, 2
|
|
229
|
+
res << s[1..-2]
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
return res
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def uncomment
|
|
237
|
+
res = []
|
|
238
|
+
|
|
239
|
+
self.splitblocks(["'", "'"], ['"', '"'], ["#", "\n"]).each do |type, s|
|
|
240
|
+
case type
|
|
241
|
+
when 0, 1, 2 then res << s
|
|
242
|
+
when 3 then res << "\n"
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
res.join("")
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def noquotes
|
|
250
|
+
self.sub(/\A['"]/, "").sub(/['"]\z/, "")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def to_html(eolconversion=true)
|
|
254
|
+
s = CGI.escapeHTML(self)
|
|
255
|
+
|
|
256
|
+
s.gsub!(/\"/, "\"")
|
|
257
|
+
s.gsub!(/\'/, "\´")
|
|
258
|
+
|
|
259
|
+
if eolconversion
|
|
260
|
+
s.gsub!(/\n/ , "<br>")
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
s
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def from_html(eolconversion=true)
|
|
267
|
+
s = self
|
|
268
|
+
|
|
269
|
+
s.gsub!(/"/ , "\"")
|
|
270
|
+
s.gsub!(/´/, "\'")
|
|
271
|
+
|
|
272
|
+
s = CGI.unescapeHTML(self)
|
|
273
|
+
|
|
274
|
+
if eolconversion
|
|
275
|
+
s.gsub!(/<br>/, "\n")
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
s
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def to_fs
|
|
282
|
+
if numeric?
|
|
283
|
+
to_f
|
|
284
|
+
else
|
|
285
|
+
to_s
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
class Array
|
|
291
|
+
def chomp!
|
|
292
|
+
self.collect!{|s| s.chomp}
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def chomp
|
|
296
|
+
self.collect{|s| s.chomp}
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def compress
|
|
300
|
+
self.collect{|s| s.compress}
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def uncomment
|
|
304
|
+
self.join("\0").uncomment.split("\0")
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def strip
|
|
308
|
+
self.collect{|s| s.strip}
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def sum
|
|
312
|
+
res = 0
|
|
313
|
+
self.each do |n|
|
|
314
|
+
res += n
|
|
315
|
+
end
|
|
316
|
+
res
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def product
|
|
320
|
+
res = 1
|
|
321
|
+
self.each do |n|
|
|
322
|
+
res *= n
|
|
323
|
+
end
|
|
324
|
+
res
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def joinwords(sep=" ", quote='"')
|
|
328
|
+
self.collect do |s|
|
|
329
|
+
s = quote + s + quote if s =~ /[[:blank:]]/
|
|
330
|
+
s
|
|
331
|
+
end.join(sep)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def domino(tabellen, kolom=nil, onlymatchinglines=false)
|
|
335
|
+
links = self
|
|
336
|
+
res = []
|
|
337
|
+
res = self.dup unless onlymatchinglines
|
|
338
|
+
|
|
339
|
+
tabellen.each do |rechts|
|
|
340
|
+
tmp = []
|
|
341
|
+
|
|
342
|
+
links.each do |l|
|
|
343
|
+
if kolom.nil? or l.length == kolom
|
|
344
|
+
rechts.each do |r|
|
|
345
|
+
tmp << l + r[1..-1] if l[-1] == r[0]
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
links = tmp
|
|
351
|
+
res.concat(tmp)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
res = res.sort.uniq
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def dominoloop(tabellen)
|
|
358
|
+
lres = []
|
|
359
|
+
res = self.dup
|
|
360
|
+
kolom = 2
|
|
361
|
+
|
|
362
|
+
while lres.length != res.length do
|
|
363
|
+
lres = res.dup
|
|
364
|
+
res = res.domino(tabellen, kolom)
|
|
365
|
+
|
|
366
|
+
res.each do |line|
|
|
367
|
+
line << "*" if (line.length != line.uniq.length and line[-1] != "*")
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
$stderr.print "#{100*(res.length)/(lres.length)}% "
|
|
371
|
+
|
|
372
|
+
kolom += 1
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
$stderr.puts ""
|
|
376
|
+
|
|
377
|
+
return res
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
def buildtree
|
|
381
|
+
self.dominoloop([self])
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def subset(fields, values, results, exact=true, emptyline=nil, joinwith=nil)
|
|
385
|
+
fields = [fields] unless fields.kind_of? Array
|
|
386
|
+
values = [values] unless values.kind_of? Array
|
|
387
|
+
results = [results] unless results.kind_of? Array
|
|
388
|
+
emptyline = emptyline.downcase unless emptyline.nil?
|
|
389
|
+
res = self.dup
|
|
390
|
+
res.delete_if {true}
|
|
391
|
+
|
|
392
|
+
self.each do |l|
|
|
393
|
+
ok = true
|
|
394
|
+
|
|
395
|
+
case l.class.to_s
|
|
396
|
+
when "String"
|
|
397
|
+
c = l.splitwords
|
|
398
|
+
correction = 1
|
|
399
|
+
joinwith = " " if joinwith.nil?
|
|
400
|
+
when "Array"
|
|
401
|
+
c = l
|
|
402
|
+
correction = 0
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
#catch :stop do
|
|
406
|
+
values2 = values.dup
|
|
407
|
+
fields.each do |f|
|
|
408
|
+
v = values2.shift
|
|
409
|
+
v = v.downcase unless v.nil?
|
|
410
|
+
if emptyline.nil? or (not v == emptyline)
|
|
411
|
+
if exact
|
|
412
|
+
unless (v.nil? or c[f-correction].downcase == v)
|
|
413
|
+
ok = false
|
|
414
|
+
#throw :stop
|
|
415
|
+
end
|
|
416
|
+
else
|
|
417
|
+
unless (v.nil? or c[f-correction].downcase.include?(v))
|
|
418
|
+
ok = false
|
|
419
|
+
#throw :stop
|
|
420
|
+
end
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
#end
|
|
425
|
+
|
|
426
|
+
if ok
|
|
427
|
+
res2 = []
|
|
428
|
+
results.each do |n|
|
|
429
|
+
res2 << c[n-1]
|
|
430
|
+
end
|
|
431
|
+
res2 = res2.join(joinwith) unless joinwith.nil?
|
|
432
|
+
res << res2
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
return res
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
def format(format)
|
|
440
|
+
res = []
|
|
441
|
+
|
|
442
|
+
[format.length, self.length].min.times do |n|
|
|
443
|
+
case format[n].chr
|
|
444
|
+
when "i" then res << self[n].to_i
|
|
445
|
+
when "s" then res << self[n].to_s
|
|
446
|
+
when "x" then res << self[n]
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
res
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def to_i
|
|
454
|
+
collect{|c| c.to_i}
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
def to_par
|
|
458
|
+
dash = self.dup
|
|
459
|
+
alpha = self.dup
|
|
460
|
+
numeric = self.dup
|
|
461
|
+
|
|
462
|
+
dash.delete_if do |s|
|
|
463
|
+
not (s =~ /\A-/) or
|
|
464
|
+
(s =~ /\A-?[[:digit:]\.]+\z/) or
|
|
465
|
+
(s =~ /^-+$/)
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
alpha.delete_if do |s|
|
|
469
|
+
((s =~ /\A-/) or
|
|
470
|
+
(s =~ /\A-?[[:digit:]\.]+\z/)) and
|
|
471
|
+
not ((s =~ /^\.+$/) or (s =~ /^-+$/))
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
numeric.delete_if do |s|
|
|
475
|
+
not (s =~ /\A-?[[:digit:]\.]+\z/) or
|
|
476
|
+
(s =~ /^\.+$/)
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
raise "Oops!" if dash.length + alpha.length + numeric.length != length
|
|
480
|
+
|
|
481
|
+
return dash, alpha, numeric
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
def self.file(file)
|
|
485
|
+
res = new
|
|
486
|
+
|
|
487
|
+
File.open(file) do |f|
|
|
488
|
+
f.readlines.uncomment.chomp.each do |line|
|
|
489
|
+
res << line
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
res
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
def numsort
|
|
497
|
+
sort do |a, b|
|
|
498
|
+
a2 = a.to_fs
|
|
499
|
+
b2 = b.to_fs
|
|
500
|
+
|
|
501
|
+
if a2.class != b2.class
|
|
502
|
+
a2 = a
|
|
503
|
+
b2 = b
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
a2 <=> b2
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
def to_fs
|
|
511
|
+
collect{|s| s.to_fs}
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
def chaos
|
|
515
|
+
res = self.dup
|
|
516
|
+
|
|
517
|
+
(length^2).times do
|
|
518
|
+
a = rand(length)
|
|
519
|
+
b = rand(length)
|
|
520
|
+
|
|
521
|
+
res[a], res[b] = res[b], res[a]
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
res
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
def any
|
|
528
|
+
if empty?
|
|
529
|
+
nil
|
|
530
|
+
else
|
|
531
|
+
self[rand(self.length)]
|
|
532
|
+
end
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
def minmax
|
|
536
|
+
min, value, max = self
|
|
537
|
+
[min, [value, max].min].max
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
def ids
|
|
541
|
+
collect{|e| e.ids}
|
|
542
|
+
end
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
class Hash
|
|
546
|
+
def save(file, append=false)
|
|
547
|
+
org = {}
|
|
548
|
+
org = Hash.file(file) if (append and File.file?(file))
|
|
549
|
+
|
|
550
|
+
self.sort.each do |k, v|
|
|
551
|
+
org[k] = v
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
File.open(file, "w") do |f|
|
|
555
|
+
org.sort.each do |k, v|
|
|
556
|
+
f.puts "%s\t= %s" % [k, v]
|
|
557
|
+
end
|
|
558
|
+
end
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
def subset(fields, values, results=nil, exact=true, emptyline=nil, joinwith=nil)
|
|
562
|
+
fields = [fields] unless fields.kind_of? Array
|
|
563
|
+
values = [values] unless values.kind_of? Array
|
|
564
|
+
results = [results] unless results.kind_of? Array
|
|
565
|
+
emptyline = emptyline.downcase unless emptyline.nil?
|
|
566
|
+
res = self.dup
|
|
567
|
+
res.delete_if {true}
|
|
568
|
+
|
|
569
|
+
self.each do |k, l|
|
|
570
|
+
ok = true
|
|
571
|
+
|
|
572
|
+
case l.class.to_s
|
|
573
|
+
when "String"
|
|
574
|
+
c = l.splitwords
|
|
575
|
+
correction = 1
|
|
576
|
+
joinwith = " " if joinwith.nil?
|
|
577
|
+
when "Array"
|
|
578
|
+
c = l
|
|
579
|
+
correction = 0
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
#catch :stop do
|
|
583
|
+
values2 = values.dup
|
|
584
|
+
fields.each do |f|
|
|
585
|
+
v = values2.shift
|
|
586
|
+
v = v.downcase unless v.nil?
|
|
587
|
+
if emptyline.nil? or (not v == emptyline)
|
|
588
|
+
if exact
|
|
589
|
+
unless (v.nil? or c[f-correction].downcase == v)
|
|
590
|
+
ok = false
|
|
591
|
+
#throw :stop
|
|
592
|
+
end
|
|
593
|
+
else
|
|
594
|
+
unless (v.nil? or c[f-correction].downcase.include?(v))
|
|
595
|
+
ok = false
|
|
596
|
+
#throw :stop
|
|
597
|
+
end
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
end
|
|
601
|
+
#end
|
|
602
|
+
|
|
603
|
+
if ok
|
|
604
|
+
res2 = []
|
|
605
|
+
if results == [nil]
|
|
606
|
+
res2 = c
|
|
607
|
+
else
|
|
608
|
+
results.each do |n|
|
|
609
|
+
res2 << c[n-correction]
|
|
610
|
+
end
|
|
611
|
+
end
|
|
612
|
+
res2 = res2.join(joinwith) unless joinwith.nil?
|
|
613
|
+
res[k] = res2
|
|
614
|
+
end
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
return res
|
|
618
|
+
end
|
|
619
|
+
|
|
620
|
+
def to_i
|
|
621
|
+
collect{|k, v| v.to_i}
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
def self.file(file)
|
|
625
|
+
res = new
|
|
626
|
+
|
|
627
|
+
File.open(file) do |f|
|
|
628
|
+
#f.readlines.chomp.each do |line|
|
|
629
|
+
while line = f.gets do
|
|
630
|
+
line.chomp!
|
|
631
|
+
|
|
632
|
+
unless line.empty?
|
|
633
|
+
k, v = line.split(/\s*=\s*/, 2)
|
|
634
|
+
res[k] = v
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
end
|
|
638
|
+
|
|
639
|
+
res
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
def ids
|
|
643
|
+
collect{|k, v| [k, v].ids}
|
|
644
|
+
end
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
def id2ref(id)
|
|
648
|
+
ObjectSpace._id2ref(id)
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
def after(seconds, *args)
|
|
652
|
+
if not seconds.nil? and not seconds.zero?
|
|
653
|
+
Thread.new(*args) do |*args2|
|
|
654
|
+
sleep seconds
|
|
655
|
+
yield(*args2)
|
|
656
|
+
end
|
|
657
|
+
end
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
def every(seconds, *args)
|
|
661
|
+
if not seconds.nil? and not seconds.zero?
|
|
662
|
+
Thread.new(*args) do |*args2|
|
|
663
|
+
loop do
|
|
664
|
+
sleep seconds
|
|
665
|
+
yield(*args2)
|
|
666
|
+
end
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
def evtimeout(seconds)
|
|
672
|
+
begin
|
|
673
|
+
timeout(seconds) do
|
|
674
|
+
yield
|
|
675
|
+
end
|
|
676
|
+
rescue TimeoutError
|
|
677
|
+
end
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
def evtimeoutretry(seconds)
|
|
681
|
+
ok = false
|
|
682
|
+
|
|
683
|
+
while not ok
|
|
684
|
+
evtimeout(seconds) do
|
|
685
|
+
yield
|
|
686
|
+
ok = true
|
|
687
|
+
end
|
|
688
|
+
end
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
def trap(signal)
|
|
692
|
+
Kernel::trap(signal) do
|
|
693
|
+
yield
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
# Seems pointless, but it's for catching ^C under Windows...
|
|
697
|
+
|
|
698
|
+
every(1) {} if windows?
|
|
699
|
+
end
|
|
700
|
+
|
|
701
|
+
def linux?
|
|
702
|
+
not windows? and not cygwin?
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
def windows?
|
|
706
|
+
not (target_os.downcase =~ /32/).nil?
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
def cygwin?
|
|
710
|
+
not (target_os.downcase =~ /cyg/).nil?
|
|
711
|
+
end
|
|
712
|
+
|
|
713
|
+
def target_os
|
|
714
|
+
Config::CONFIG["target_os"] or ""
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
def user
|
|
718
|
+
ENV["USER"] or ENV["USERNAME"]
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
def home
|
|
722
|
+
(ENV["HOME"] or ENV["USERPROFILE"] or (File.directory?("h:/") ? "h:" : "c:")).gsub(/\\/, "/")
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
def temp
|
|
726
|
+
(ENV["TMPDIR"] or ENV["TMP"] or ENV["TEMP"] or "/tmp").gsub(/\\/, "/")
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
def stdtmp
|
|
730
|
+
$stderr = $stdout = File.new("#{temp}/ruby.#{Process.pid}.log", "a") unless ARGV.include?("--rwd-exit")
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
$nobm = false
|
|
734
|
+
|
|
735
|
+
def nobm
|
|
736
|
+
$nobm = true
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
def bm(label="")
|
|
740
|
+
if $nobm
|
|
741
|
+
if block_given?
|
|
742
|
+
return yield
|
|
743
|
+
else
|
|
744
|
+
return nil
|
|
745
|
+
end
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
label = label.to_s
|
|
749
|
+
res = nil
|
|
750
|
+
|
|
751
|
+
$bm_mutex = ($bm_mutex or Mutex.new)
|
|
752
|
+
|
|
753
|
+
$bm_mutex.synchronize do
|
|
754
|
+
if $bm.nil?
|
|
755
|
+
require "ev/bm"
|
|
756
|
+
|
|
757
|
+
$bm = {}
|
|
758
|
+
|
|
759
|
+
at_exit do
|
|
760
|
+
format1 = "%10s %10s %10s %10s %10s %10s %10s"
|
|
761
|
+
format2 = "%10s %10.6f %10.6f %10.6f %10.6f %10.6f %10d"
|
|
762
|
+
|
|
763
|
+
$stderr.puts format1 % ["LABEL", "USERCPU", "SYSCPU", "CUSERCPU", "CSYSCPU", "ELAPSED", "TIMES"]
|
|
764
|
+
$bm.sort{|a, b| [a[1], a[0]] <=> [b[1], b[0]]}.each do |k, v|
|
|
765
|
+
$stderr.puts format2 % [k, *v]
|
|
766
|
+
end
|
|
767
|
+
end
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
$bm[label] = [0.0]*5 + [0] unless $bm.include?(label)
|
|
771
|
+
end
|
|
772
|
+
|
|
773
|
+
if block_given?
|
|
774
|
+
bm = Benchmark.measure{res = yield}
|
|
775
|
+
bma = bm.to_a # [dummy label, user CPU time, system CPU time, childrens user CPU time, childrens system CPU time, elapsed real time]
|
|
776
|
+
|
|
777
|
+
$bm_mutex.synchronize do
|
|
778
|
+
0.upto(4) do |n|
|
|
779
|
+
$bm[label][n] += bma[n+1]
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
$bm[label][5] += 1
|
|
783
|
+
end
|
|
784
|
+
end
|
|
785
|
+
|
|
786
|
+
res
|
|
787
|
+
end
|
|
788
|
+
|
|
789
|
+
def trace
|
|
790
|
+
res =nil
|
|
791
|
+
|
|
792
|
+
set_trace_func lambda { |event, file, line, id, binding, classname|
|
|
793
|
+
$stderr.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if block_given?
|
|
797
|
+
res = yield
|
|
798
|
+
|
|
799
|
+
notrace
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
res
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
def notrace
|
|
806
|
+
set_trace_func nil
|
|
807
|
+
end
|
|
808
|
+
|
|
809
|
+
def lambda_cached(&block)
|
|
810
|
+
hash = {}
|
|
811
|
+
lambda do |*args|
|
|
812
|
+
res = hash[args]
|
|
813
|
+
if res.nil?
|
|
814
|
+
res = block.call(*args)
|
|
815
|
+
hash[args] = res
|
|
816
|
+
end
|
|
817
|
+
res
|
|
818
|
+
end
|
|
819
|
+
end
|