Top Level Namespace

Defined Under Namespace

Modules: BugFix, EVMime, Enumerable, IOExtras, Kernel, ParseTree, Rconftool, TextArray, Zip, Zlib Classes: Array, CloseTag, Comment, Dir, EVTable, EVURI, FakeThread, File, HTTPClient, HTTPServer, HTTPServerException, Hash, IE, Instruction, Integer, Module, Numeric, Object, OpenTag, RWDDone, RWDError, RWDLogin, RWDMessage, RWDProgressBar, RWDServer, RWDSession, RWDTimeOut, RWDTree, RWDWindow, RWDialog, Request, RequestGet, RequestPost, RequestRequest, Response, SGML, SGMLObject, SessionCleanup, Sessions, Special, String, TCPServer, Tag, Text, Thread, ThreadLimiter, Time, Tree, TreeObject, XML, ZipList

Constant Summary collapse

RWDEmptyline =
"..."
AL =
"align='left'"
AC =
"align='center'"
AR =
"align='right'"
VA =
"valign='middle'"
Format =
"\n<!-- %-10s %-10s -->\t"
Tempfile =
BugFix::Tempfile
RegExpStringWord =
"([#{tekens11}]+)"
RegExpWord =
Regexp.new(RegExpStringWord)
RegExpStringWord2 =
"([#{tekens21}]([#{tekens22}]*[#{tekens23}])?)"
RegExpWord2 =
Regexp.new(RegExpStringWord2)
RegExpStringText =
"([#{tekens31}]+)"
RegExpText =
Regexp.new(RegExpStringText)
RegExpStringFile =
'(\w[\w\.\-]*)'
RegExpFile =
Regexp.new(RegExpStringFile)
RegExpStringEmail =
'([\w\-\.][email protected][\w\-\.]+)'
RegExpEmail =
Regexp.new(RegExpStringEmail)
RegExpStringURL =
'(\w+:\/\/[\w\.\-]+(:\d*)?\/[\w\.\-\/\#\?\=\%]*)'
RegExpURL =
Regexp.new(RegExpStringURL)
RegExpStringPrint =
'([\w \t\r\n\`\~\!\@\#\$\%\^\&\*\(\)\-\+\=\[\]\{\}\;\:\'\"\,\.\/\<\>\?\\\|]+)'
RegExpPrint =
Regexp.new(RegExpStringPrint)
RegExpStringDiff =
'(^[\-\+]([^\-\+].*)?)'
RegExpDiff =
Regexp.new(RegExpStringDiff)
'(`[\w\,]*\ba\b[^`]*`)'
Regexp.new(RegExpStringHTHLink)
RegExpStringHTHSpecial =
'(`[^`]*`)'
RegExpHTHSpecial =
Regexp.new(RegExpStringHTHSpecial)
Same =
0
Down =
1
Up =
2
Dummy =
3

Instance Method Summary collapse

Instance Method Details

#after(seconds, *args) ⇒ Object


688
689
690
691
692
693
694
695
# File 'lib/rwd/ruby.rb', line 688

def after(seconds, *args)
  if not seconds.nil? and not seconds.zero?
    Thread.new(*args) do |*args2|
      sleep seconds
      yield(*args2)
    end
  end
end

#ask(options, text = false) ⇒ Object


875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'lib/rwd/ruby.rb', line 875

def ask(options, text=false)
  i	= 0
  $stderr.puts ""
  options.each do |s|
    $stderr.puts " %d %s" % [i+=1, s]
  end
  $stderr.puts ""
  $stderr.print "? "
  res	= $stdin.gets
  unless res.nil?
    res	= res.strip
    res	= options[res.to_i-1]	if text and not res.empty?
  end
  res
end

#bm(label = "") ⇒ Object


781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
# File 'lib/rwd/ruby.rb', line 781

def bm(label="")
  if $nobm
    if block_given?
      return yield
    else
      return nil
    end
  end

  label	= label.inspect	#unless label.kind_of?(String)
  res	= nil

  $bm_mutex	= ($bm_mutex or Mutex.new)

  $bm_mutex.synchronize do
    if $bm.nil?
      require "ev/bm"

      $bm		= {}

      at_exit do
        l	= $bm.keys.collect{|s| s.length}.max
	#format1	= "%10s %10s %10s %10s %10s %10s   %s"
	#format2	= "%10.6f %10.6f %10.6f %10.6f %10.6f %10d   %s"
	#$stderr.puts format1 % ["USERCPU", "SYSCPU", "CUSERCPU", "CSYSCPU", "ELAPSED", "COUNT", "LABEL"]
	#$bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v|
	  #$stderr.puts format2 % (v + [k])
	#end

	format1	= "%10s %10s %10s   %s"
	format2	= "%10.6f %10.6f %10d   %s"
        $bm.each do |k, v|
          $bm[k]	= [v[0]+v[1], v[4], v[5]]
        end
	$stderr.puts format1 % ["CPU", "ELAPSED", "COUNT", "LABEL"]
	$bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v|
	  $stderr.puts format2 % (v + [k])
	end
      end
    end

    $bm[label] = [0.0]*5 + [0]	unless $bm.include?(label)
    $bm[label][5] += 1
  end

  if block_given?
    bm	= Benchmark.measure{res = yield}
    bma	= bm.to_a	# [dummy label, user CPU time, system CPU time, childrens user CPU time, childrens system CPU time, elapsed real time]

    $bm_last	= bma

    $bm_mutex.synchronize do
      e	= $bm[label]
      0.upto(4) do |n|
        e[n] += bma[n+1]
      end
    end
  end

  res
end

#cygwin?Boolean

Returns:

  • (Boolean)

750
751
752
# File 'lib/rwd/ruby.rb', line 750

def cygwin?
  not (target_os.downcase =~ /cyg/).nil?
end

#cygwinbrowserObject


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rwd/browser.rb', line 33

def cygwinbrowser
  browser, *args	= windowsbrowser.splitwords
  browser		= browser.gsub(/\\/, "/")
  #browser		= browser

  args.collect!{|a| a.gsub(/\\/, "/")}
  #args.collect!{|a| "\"%s\"" % [a.gsub(/\\/, "/")]}
  #args.collect!{|a| "\"%s\"" % [a]}

  res	= "\"%s\" %s" % [browser, args.join(" ")]
  res
end

#darwin?Boolean

Returns:

  • (Boolean)

742
743
744
# File 'lib/rwd/ruby.rb', line 742

def darwin?
  not (target_os.downcase =~ /darwin/).nil?
end

#defaultbrowserObject


60
61
62
63
64
65
66
# File 'lib/rwd/browser.rb', line 60

def defaultbrowser
  res	= nil
  res	= windowsbrowser	if windows?
  res	= cygwinbrowser		if cygwin?
  res	= linuxbrowser		if linux?
  res
end

#every(seconds, *args) ⇒ Object


697
698
699
700
701
702
703
704
705
706
# File 'lib/rwd/ruby.rb', line 697

def every(seconds, *args)
  if not seconds.nil? and not seconds.zero?
    Thread.new(*args) do |*args2|
      loop do
        sleep seconds
        yield(*args2)
      end
    end
  end
end

#evtimeout(seconds) ⇒ Object


708
709
710
711
712
713
714
715
# File 'lib/rwd/ruby.rb', line 708

def evtimeout(seconds)
  begin
    timeout(seconds) do
      yield
    end
  rescue TimeoutError
  end
end

#evtimeoutretry(seconds) ⇒ Object


717
718
719
720
721
722
723
724
725
726
# File 'lib/rwd/ruby.rb', line 717

def evtimeoutretry(seconds)
  ok	= false

  while not ok
    evtimeout(seconds) do
      yield
      ok	= true
    end
  end
end

#homeObject


762
763
764
# File 'lib/rwd/ruby.rb', line 762

def home
  (ENV["HOME"] or ENV["USERPROFILE"] or (File.directory?("h:/") ? "h:" : "c:")).gsub(/\\/, "/")
end

#id2ref(id) ⇒ Object


684
685
686
# File 'lib/rwd/ruby.rb', line 684

def id2ref(id)
  ObjectSpace._id2ref(id)
end

#lambda_cached(&block) ⇒ Object


863
864
865
866
867
868
869
870
871
872
873
# File 'lib/rwd/ruby.rb', line 863

def lambda_cached(&block)
  hash	= {}
  lambda do |*args|
    res	= hash[args]
    if res.nil?
      res		= block.call(*args)
      hash[args]	= res
    end
    res
  end
end

#linux?Boolean

Returns:

  • (Boolean)

738
739
740
# File 'lib/rwd/ruby.rb', line 738

def linux?
  not (target_os.downcase =~ /linux/).nil?
end

#linuxbrowserObject


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rwd/browser.rb', line 46

def linuxbrowser
  application	= ""

  application	= `which galeon		2> /dev/null`.chomp	if application.empty?
  application	= `which mozilla	2> /dev/null`.chomp	if application.empty?
  application	= `which firefox	2> /dev/null`.chomp	if application.empty?
  application	= `which opera		2> /dev/null`.chomp	if application.empty?
  application	= `which konqueror	2> /dev/null`.chomp	if application.empty?
  application	= `which htmlview	2> /dev/null`.chomp	if application.empty?
  application	= nil						if application.empty?

  application
end

#nobmObject


777
778
779
# File 'lib/rwd/ruby.rb', line 777

def nobm
  $nobm	= true
end

#notraceObject


859
860
861
# File 'lib/rwd/ruby.rb', line 859

def notrace
  set_trace_func nil
end

#showinbrowser(html, browser = defaultbrowser) ⇒ Object


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rwd/browser.rb', line 74

def showinbrowser(html, browser=defaultbrowser)
  port, io	= TCPServer.freeport(7701, 7709)

  unless browser.nil?
    Thread.new do
      begin
	Thread.pass

        showurlinbrowser("http://localhost:#{port}/", browser)
      rescue
      end
    end
  end

  HTTPServer.serve([port, io]) do |req, resp|
    resp << html

    resp.stop
  end
end

#showurlinbrowser(url, browser = defaultbrowser) ⇒ Object


68
69
70
71
72
# File 'lib/rwd/browser.rb', line 68

def showurlinbrowser(url, browser=defaultbrowser)
  command	= "#{browser} \"#{url}\""

  system(command)	or $stderr.puts "Starting of the browser failed, or the browser terminated abnormally.\nCommand => #{command}"
end

#stdtmpObject


770
771
772
# File 'lib/rwd/ruby.rb', line 770

def stdtmp
  $stderr = $stdout = File.new("#{temp}/ruby.#{Process.pid}.log", "a")
end

#tab2html(tab) ⇒ Object


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rwd/browser.rb', line 95

def tab2html(tab)
  res	= ""

  tab	= tab.to_html(false)

  res << "<html>\n"
  res << "<body>\n"
  res << "<table align='center' border='1' cellspacing='0' cellpadding='3'>\n"
  res << "<tbody>\n"

  tab.split(/\r*\n/).each do |line|
    res << "<tr>\n"

    line.split(/\t/, -1).each do |veld|
      veld	= "&nbsp;"	if veld.compress.empty?

      res << "<td>%s</td>\n" % veld
    end

    res << "</tr>\n"
  end

  res << "</tbody>\n"
  res << "</table>\n"
  res << "</body>\n"
  res << "</html>\n"

  res
end

#target_osObject


754
755
756
# File 'lib/rwd/ruby.rb', line 754

def target_os
  Config::CONFIG["target_os"] or ""
end

#tempObject


766
767
768
# File 'lib/rwd/ruby.rb', line 766

def temp
  (ENV["TMPDIR"] or ENV["TMP"] or ENV["TEMP"] or "/tmp").gsub(/\\/, "/")
end

#traceObject


843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'lib/rwd/ruby.rb', line 843

def trace
  res	=nil

  set_trace_func lambda { |event, file, line, id, binding, classname|
    $stderr.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
  }

  if block_given?
    res	= yield

    notrace
  end

  res
end

#trap(signal) ⇒ Object


728
729
730
731
732
733
734
735
736
# File 'lib/rwd/ruby.rb', line 728

def trap(signal)
  Kernel::trap(signal) do
    yield
  end

	# Seems pointless, but it's for catching ^C under Windows...

  every(1)	{}	if windows?
end

#uri2txt(s) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'lib/rwd/net.rb', line 20

def uri2txt(s)
	# ??? Werkt niet goed
  i	= s.index(/%[[:digit:]]{2}/)
  while not i.nil?
    s	= s[0..(i-1)] + s[(i+1)..(i+2)].unpack('H2').shift.to_i.chr + s[(i+3)..-1]
    i	= s.index(/%[[:digit:]]{2}/)
  end
  s
end

#userObject


758
759
760
# File 'lib/rwd/ruby.rb', line 758

def user
  ENV["USER"] or ENV["USERNAME"]
end

#windows?Boolean

Returns:

  • (Boolean)

746
747
748
# File 'lib/rwd/ruby.rb', line 746

def windows?
  not (target_os.downcase =~ /32/).nil?
end

#windowsbrowserObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rwd/browser.rb', line 12

def windowsbrowser
  $stderr.puts "Looking for default browser..."

  filetype	= "htmlfile"
  application	= nil

  begin
    Win32::Registry::HKEY_CLASSES_ROOT.open(".html") do |reg|
      filetype		= reg[""]
    end

    Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + "\\shell\\open\\command") do |reg|
      application	= reg[""]
    end
  rescue NameError
    $stderr.puts "Only available for Windows and Cygwin."
  end

  application
end