rio 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/ChangeLog +1273 -1482
  2. data/README +2 -2
  3. data/Rakefile +5 -5
  4. data/VERSION +1 -1
  5. data/{RUNME.1st.rb → build_doc.rb} +4 -10
  6. data/doc/ANNOUNCE +33 -80
  7. data/doc/RELEASE_NOTES +31 -1
  8. data/doc/generators/template/html/rio.rb +3 -3
  9. data/lib/rio/abstract_method.rb +2 -2
  10. data/lib/rio/argv.rb +2 -2
  11. data/lib/rio/arycopy.rb +2 -2
  12. data/lib/rio/assert.rb +2 -2
  13. data/lib/rio/base.rb +2 -2
  14. data/lib/rio/callstr.rb +47 -0
  15. data/lib/rio/const.rb +52 -0
  16. data/lib/rio/construct.rb +6 -24
  17. data/lib/rio/constructor.rb +12 -2
  18. data/lib/rio/context/autoclose.rb +73 -0
  19. data/lib/rio/context/copying.rb +2 -2
  20. data/lib/rio/context/cxx.rb +2 -2
  21. data/lib/rio/context/dir.rb +2 -2
  22. data/lib/rio/context/gzip.rb +2 -2
  23. data/lib/rio/context/methods.rb +6 -34
  24. data/lib/rio/context/skip.rb +2 -2
  25. data/lib/rio/context/stream.rb +2 -2
  26. data/lib/rio/context.rb +17 -2
  27. data/lib/rio/cp.rb +35 -9
  28. data/lib/rio/def.rb +54 -0
  29. data/lib/rio/dir.rb +19 -20
  30. data/lib/rio/doc/HOWTO.rb +23 -7
  31. data/lib/rio/doc/INTRO.rb +57 -23
  32. data/lib/rio/doc/MISC.rb +2 -2
  33. data/lib/rio/doc/OPTIONAL.rb +134 -0
  34. data/lib/rio/doc/SYNOPSIS.rb +11 -4
  35. data/lib/rio/doc.rb +2 -2
  36. data/lib/rio/entrysel.rb +25 -6
  37. data/lib/rio/exception/copy.rb +2 -2
  38. data/lib/rio/exception/notsupported.rb +47 -0
  39. data/lib/rio/exception/open.rb +2 -2
  40. data/lib/rio/exception/state.rb +2 -2
  41. data/lib/rio/exception.rb +2 -2
  42. data/lib/rio/ext/csv.rb +56 -11
  43. data/lib/rio/ext/yaml.rb +2 -2
  44. data/lib/rio/ext/zipfile.rb +91 -0
  45. data/lib/rio/ext.rb +38 -3
  46. data/lib/rio/factory.rb +17 -34
  47. data/lib/rio/file.rb +48 -8
  48. data/lib/rio/filter/closeoneof.rb +36 -16
  49. data/lib/rio/filter/gzip.rb +2 -2
  50. data/lib/rio/filter.rb +2 -2
  51. data/lib/rio/fs/base.rb +42 -0
  52. data/lib/rio/fs/impl.rb +123 -0
  53. data/lib/rio/fs/native.rb +76 -0
  54. data/lib/rio/{record.rb → fs/stream.rb} +21 -18
  55. data/lib/rio/fs/url.rb +64 -0
  56. data/lib/rio/ftp/{ioh.rb → conncache.rb} +38 -39
  57. data/lib/rio/ftp/dir.rb +95 -0
  58. data/lib/rio/ftp/fs.rb +173 -0
  59. data/lib/rio/ftp/ftpfile.rb +20 -0
  60. data/lib/rio/grande.rb +2 -2
  61. data/lib/rio/handle.rb +2 -2
  62. data/lib/rio/if/basic.rb +2 -2
  63. data/lib/rio/if/csv.rb +2 -2
  64. data/lib/rio/if/dir.rb +2 -2
  65. data/lib/rio/if/file.rb +26 -2
  66. data/lib/rio/if/fileordir.rb +44 -49
  67. data/lib/rio/if/grande.rb +32 -10
  68. data/lib/rio/if/grande_entry.rb +12 -2
  69. data/lib/rio/if/grande_stream.rb +17 -28
  70. data/lib/rio/if/internal.rb +2 -2
  71. data/lib/rio/if/path.rb +7 -6
  72. data/lib/rio/if/stream.rb +85 -29
  73. data/lib/rio/if/string.rb +2 -2
  74. data/lib/rio/if/temp.rb +2 -2
  75. data/lib/rio/if/test.rb +37 -4
  76. data/lib/rio/if/yaml.rb +2 -2
  77. data/lib/rio/if.rb +2 -2
  78. data/lib/rio/impl/path.rb +2 -2
  79. data/lib/rio/ioh.rb +17 -6
  80. data/lib/rio/iomode.rb +4 -3
  81. data/lib/rio/ios/fail.rb +107 -0
  82. data/lib/rio/ios/generic.rb +120 -0
  83. data/lib/rio/ios/mode.rb +61 -0
  84. data/lib/rio/ios/null.rb +120 -0
  85. data/lib/rio/iowrap.rb +129 -0
  86. data/lib/rio/kernel.rb +12 -3
  87. data/lib/rio/local.rb +2 -2
  88. data/lib/rio/match.rb +3 -3
  89. data/lib/rio/matchrecord.rb +2 -2
  90. data/lib/rio/no_warn.rb +50 -0
  91. data/lib/rio/{arrayio.rb → nullio.rb} +47 -86
  92. data/lib/rio/open3.rb +2 -2
  93. data/lib/rio/ops/construct.rb +20 -13
  94. data/lib/rio/ops/create.rb +10 -19
  95. data/lib/rio/ops/dir.rb +60 -54
  96. data/lib/rio/ops/either.rb +11 -9
  97. data/lib/rio/ops/file.rb +28 -24
  98. data/lib/rio/ops/path.rb +45 -43
  99. data/lib/rio/ops/stream/input.rb +12 -8
  100. data/lib/rio/ops/stream/output.rb +2 -2
  101. data/lib/rio/ops/stream/read.rb +35 -32
  102. data/lib/rio/ops/stream/write.rb +5 -5
  103. data/lib/rio/ops/stream.rb +7 -3
  104. data/lib/rio/ops/symlink.rb +12 -10
  105. data/lib/rio/path/reset.rb +5 -5
  106. data/lib/rio/path.rb +32 -24
  107. data/lib/rio/piper/cp.rb +2 -2
  108. data/lib/rio/piper.rb +2 -2
  109. data/lib/rio/prompt.rb +2 -2
  110. data/lib/rio/rectype.rb +9 -7
  111. data/lib/rio/rl/base.rb +5 -4
  112. data/lib/rio/rl/builder.rb +17 -5
  113. data/lib/rio/rl/ioi.rb +14 -4
  114. data/lib/rio/rl/path.rb +23 -15
  115. data/lib/rio/rl/pathmethods.rb +12 -2
  116. data/lib/rio/rl/uri.rb +13 -6
  117. data/lib/rio/scheme/aryio.rb +3 -3
  118. data/lib/rio/scheme/cmdio.rb +4 -3
  119. data/lib/rio/scheme/cmdpipe.rb +3 -35
  120. data/lib/rio/scheme/fd.rb +4 -3
  121. data/lib/rio/scheme/ftp.rb +36 -7
  122. data/lib/rio/scheme/http.rb +2 -2
  123. data/lib/rio/{context/closeoneof.rb → scheme/null.rb} +17 -11
  124. data/lib/rio/scheme/path.rb +28 -30
  125. data/lib/rio/scheme/stderr.rb +4 -4
  126. data/lib/rio/scheme/stdio.rb +6 -5
  127. data/lib/rio/scheme/strio.rb +10 -20
  128. data/lib/rio/scheme/sysio.rb +5 -2
  129. data/lib/rio/scheme/tcp.rb +4 -3
  130. data/lib/rio/scheme/temp.rb +14 -1
  131. data/lib/rio/state/error.rb +2 -2
  132. data/lib/rio/state.rb +80 -34
  133. data/lib/rio/stream/base.rb +7 -2
  134. data/lib/rio/stream/duplex.rb +13 -10
  135. data/lib/rio/stream/open.rb +74 -79
  136. data/lib/rio/stream.rb +15 -23
  137. data/lib/rio/symantics.rb +2 -2
  138. data/lib/rio/tempdir.rb +132 -132
  139. data/lib/rio/to_rio/all.rb +40 -0
  140. data/lib/rio/to_rio/array.rb +40 -0
  141. data/lib/rio/to_rio/io.rb +41 -0
  142. data/lib/rio/to_rio/object.rb +43 -0
  143. data/lib/rio/to_rio/string.rb +41 -0
  144. data/lib/rio/to_rio.rb +13 -2
  145. data/lib/rio/uri/file.rb +2 -2
  146. data/lib/rio/util.rb +2 -2
  147. data/lib/rio/version.rb +3 -3
  148. data/lib/rio.rb +16 -25
  149. data/test/bin/count_lines.rb +11 -0
  150. data/test/bin/find_lines.rb +13 -0
  151. data/test/bin/list_dir.rb +14 -0
  152. data/test/ftp/all.rb +9 -0
  153. data/test/ftp/anon_misc.rb +112 -0
  154. data/test/ftp/anon_read.rb +105 -0
  155. data/test/ftp/anon_special.rb +68 -0
  156. data/test/ftp/anon_write.rb +63 -0
  157. data/test/ftp/ftp2ftp.rb +51 -0
  158. data/test/ftp/initftpfiles.rb +14 -0
  159. data/test/ftp/testdef.rb +51 -0
  160. data/test/gem_runtests.rb +15 -15
  161. data/test/runalltests.rb +15 -0
  162. data/test/runftptests.rb +14 -0
  163. data/test/{1.rb → runhttptests.rb} +14 -14
  164. data/test/runtests.rb +14 -14
  165. data/test/tc/all.rb +36 -21
  166. data/test/tc/cmdpipe.rb +18 -15
  167. data/test/tc/copy-from-http.rb +89 -0
  168. data/test/tc/copy-from.rb +1 -52
  169. data/test/tc/copy.rb +19 -17
  170. data/test/tc/csv2.rb +6 -3
  171. data/test/tc/empty.rb +47 -0
  172. data/test/tc/emptyriodir.rb +129 -0
  173. data/test/tc/entsel.rb +110 -0
  174. data/test/tc/files_select.rb +92 -0
  175. data/test/tc/get.rb +7 -6
  176. data/test/tc/getrec.rb +2 -5
  177. data/test/tc/gzip.rb +82 -0
  178. data/test/tc/io_each_byte.rb +60 -0
  179. data/test/tc/io_read.rb +80 -0
  180. data/test/tc/iometh.rb +149 -0
  181. data/test/tc/likeio.rb +112 -0
  182. data/test/tc/methods.rb +10 -9
  183. data/test/tc/misc.rb +1 -37
  184. data/test/tc/null.rb +45 -0
  185. data/test/tc/pid.rb +31 -0
  186. data/test/tc/piper.rb +34 -37
  187. data/test/tc/programs_util.rb +24 -0
  188. data/test/tc/readline.rb +30 -0
  189. data/test/tc/rename.rb +12 -0
  190. data/test/tc/tempfile.rb +14 -0
  191. data/test/tc/testcase.rb +6 -0
  192. data/test/tc/tonl.rb +37 -0
  193. metadata +181 -144
  194. data/ex/colx.rb +0 -8
  195. data/ex/findinruby +0 -16
  196. data/ex/findruby +0 -15
  197. data/ex/passwd_report.rb +0 -8
  198. data/ex/prompt.rb +0 -25
  199. data/ex/rgb.txt.gz +0 -0
  200. data/ex/riocat +0 -35
  201. data/ex/riogunzip +0 -31
  202. data/ex/riogzip +0 -24
  203. data/ex/rioprompt.rb +0 -6
  204. data/ex/targz2zip +0 -17
  205. data/ex/tolf +0 -11
  206. data/lib/rio/ftp/conn.rb +0 -167
  207. data/lib/rio/ftp.rb +0 -275
  208. data/test/once.rb +0 -7
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -47,8 +47,10 @@ module RIO
47
47
  class RL < RL::IOIBase
48
48
  RIOSCHEME = 'strio'
49
49
  RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
50
+ attr_accessor :str
50
51
  def initialize(str="")
51
52
  @str = str
53
+ super
52
54
  end
53
55
 
54
56
  def opaque() sprintf('0x%08x',@str.object_id) end
@@ -67,32 +69,20 @@ module RIO
67
69
  end
68
70
 
69
71
  def open(m,*args)
70
- ::StringIO.new(@str,m.to_s,*args)
72
+ super(::StringIO.new(@str,m.to_s,*args))
71
73
  end
72
74
  end
73
75
  module Stream
74
- class Open < RIO::Stream::Open
75
- def input() stream_state('StrIO::Stream::Input') end
76
- def output() stream_state('StrIO::Stream::Output') end
77
- def inout() stream_state('StrIO::Stream::InOut') end
78
- end
79
-
80
76
  module Ops
81
77
  def string() ioh.string end
82
78
  def string=(p1) ioh.string = p1 end
83
79
  end
84
-
85
- class Input < RIO::Stream::Input
86
- include Ops
87
- end
88
-
89
- class Output < RIO::Stream::Output
90
- include Ops
91
- end
92
-
93
- class InOut < RIO::Stream::InOut
94
- include Ops
80
+ class Open < RIO::Stream::Open
81
+ def string=(p1) rl.str = p1 end
82
+ def string() rl.str end
83
+ def stream_state(*args) super.extend(Ops) end
95
84
  end
96
85
  end
97
86
  end
98
87
  end
88
+ __END__
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -44,6 +44,9 @@ module RIO
44
44
  RIOSCHEME = 'sysio'
45
45
  RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
46
46
  def opaque() sprintf('0x%08x',self.ios.object_id) end
47
+ def open(*args)
48
+ super(*args)
49
+ end
47
50
  # must be able to process both
48
51
  # parse('rio:sysio',ios)
49
52
  # parse('rio:sysio:0xHEXIOS')
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -46,6 +46,7 @@ module RIO
46
46
  def initialize(host,port)
47
47
  @host = host
48
48
  @port = port
49
+ super
49
50
  end
50
51
  def opaque()
51
52
  sprintf('//%s:%s',@host,@port)
@@ -53,7 +54,7 @@ module RIO
53
54
  require 'socket'
54
55
  def open(*args)
55
56
  # @host = 'localhost' if @host.nil? or @host.empty?
56
- ::TCPSocket.new(@host || 'localhost',@port)
57
+ super(::TCPSocket.new(@host || 'localhost',@port))
57
58
  end
58
59
  def to_s() self.url end
59
60
 
@@ -50,6 +50,7 @@ module RIO
50
50
  #puts "initialize(#{file_prefix.inspect},#{temp_dir.inspect})"
51
51
  @prefix = file_prefix || DFLT_PREFIX
52
52
  @tmpdir = temp_dir || DFLT_TMPDIR
53
+ super
53
54
  end
54
55
  #def path() nil end
55
56
  def scheme() self.class.const_get(:RIOSCHEME) end
@@ -90,6 +91,10 @@ module RIO
90
91
  @td = ::Tempdir.new( @prefix.to_s, @tmpdir.to_s)
91
92
  super(@td.to_s)
92
93
  end
94
+ def dir_rl()
95
+ RIO::Dir::RL.new(self.uri, {:fs => self.fs})
96
+ #self
97
+ end
93
98
  SPLIT_RE = Temp::RL::SPLIT_RE
94
99
  def self.splitrl(s)
95
100
  Temp::RL.splitrl(s)
@@ -112,6 +117,10 @@ module RIO
112
117
  @tf = ::Tempfile.new( @prefix.to_s, @tmpdir.to_s)
113
118
  super(@tf.path)
114
119
  end
120
+ def file_rl()
121
+ RIO::File::RL.new(self.uri,{:fs => self.fs})
122
+ #self
123
+ end
115
124
  def open(mode='ignored')
116
125
  #p callstr('open',mode)
117
126
  @tf
@@ -133,6 +142,10 @@ module RIO
133
142
  #p args
134
143
  @tempobj = nil
135
144
  end
145
+ def self.default_cx
146
+ Cx::Vars.new( { 'closeoneof' => false, 'closeoncopy' => false } )
147
+ end
148
+
136
149
  def check?() true end
137
150
  def mkdir(prefix=rl.prefix,tmpdir=rl.tmpdir)
138
151
  self.rl = RIO::Temp::Dir::RL.new(prefix, tmpdir)
@@ -170,7 +183,7 @@ module RIO
170
183
  module Stream
171
184
  class Open < RIO::Stream::Open
172
185
  def iostate(sym)
173
- mode('w+').noautoclose_.open_.inout()
186
+ mode_('w+').open_.inout()
174
187
  end
175
188
  # def inout() stream_state('Temp::Stream::InOut') end
176
189
  end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
data/lib/rio/state.rb CHANGED
@@ -41,6 +41,7 @@ require 'rio/context/methods'
41
41
  require 'rio/ext'
42
42
  require 'rio/symantics'
43
43
  require 'rio/filter'
44
+ require 'rio/fs/native'
44
45
 
45
46
  module RIO
46
47
 
@@ -54,29 +55,55 @@ module RIO
54
55
  # * the state changing mechanism
55
56
  # * and some basic error handling stubs
56
57
  class Base
57
- KIOSYMS = [:gets,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,:split,
58
+ KIOSYMS = [:gets,:getc,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,:split,
58
59
  :=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!,:load]
59
60
  @@kernel_cleaned ||= KIOSYMS.each { |sym| undef_method(sym) }
61
+ undef_method(:rio)
60
62
  end
61
63
 
62
64
  class Base
65
+ attr_accessor :try_state
66
+ #attr_accessor :handled_by
67
+
63
68
  attr_accessor :rl
64
69
  attr_accessor :ioh
65
- attr_accessor :try_state
66
- attr_accessor :cx
70
+ #attr_accessor :fs
67
71
 
68
- attr_accessor :handled_by
72
+ attr_accessor :cx
69
73
 
70
74
  # Context handling
71
75
  include Cx::Methods
72
-
73
76
  include RIO::Ext::Cx
74
77
 
75
78
 
76
- def initialize()
77
- @rl = @cx = @ioh = nil
78
- # @handled_by = self.class.to_s
79
+ def initialize(rl=nil,cx=nil,ioh=nil)
80
+ cx ||= self.class.default_cx
81
+ _init(rl,cx,ioh)
82
+ # @handled_by = self.class.to_s
83
+ end
84
+ # def initialize(rl=nil,cx=nil,ioh=nil,fs=nil)
85
+ # fs ||= RIO::FS::Native.create()
86
+ # cx ||= self.class.default_cx
87
+ # _init(rl,cx,ioh,fs)
88
+ # # @handled_by = self.class.to_s
89
+ # end
90
+
91
+ def _init(riorl,cntx,iohandle=nil)
92
+ @rl = riorl
93
+ @cx = cntx
94
+ @ioh = iohandle
95
+ # raise Exception::FailedCheck.new(self) unless check?
96
+ self
79
97
  end
98
+ # def _init(riorl,cntx,iohandle=nil,fs=nil)
99
+ # @rl = riorl
100
+ # @cx = cntx
101
+ # @ioh = iohandle
102
+ # @fs = fs
103
+ # # raise Exception::FailedCheck.new(self) unless check?
104
+ # self
105
+ # end
106
+ private :_init
80
107
 
81
108
  def initialize_copy(*args)
82
109
  #p callstr('initialize_copy',args[0].inspect)
@@ -84,36 +111,32 @@ module RIO
84
111
  @rl = @rl.clone unless @rl.nil?
85
112
  @cx = @cx.clone unless @cx.nil?
86
113
  @ioh = @ioh.clone unless @ioh.nil?
114
+ # @fs = @fs
87
115
  end
88
116
 
89
- def self.new_r(riorl)
90
- new.init(riorl,Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } ))
91
- end
92
- def clone_rio()
93
- cp = Rio.new(self.rl)
94
- cp.cx = self.cx
95
- cp.ioh = self.ioh.clone unless self.ioh.nil?
96
- cp
117
+ def self.default_cx
118
+ Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } )
97
119
  end
98
- def init(riorl,cntx,iohandle=nil)
99
- @rl = riorl
100
- @cx = cntx
101
- @ioh = iohandle
102
- # raise Exception::FailedCheck.new(self) unless check?
103
- self
104
- end
105
-
106
120
  def self.new_other(other)
107
- new.copy_state(other)
108
- end
109
-
110
- def copy_state(other)
111
- init(other.rl,other.cx,other.ioh)
121
+ new(other.rl,other.cx,other.ioh)
122
+ #new.copy_state(other)
112
123
  end
124
+ # def self.new_other(other)
125
+ # new(other.rl,other.cx,other.ioh,other.fs)
126
+ # #new.copy_state(other)
127
+ # end
113
128
 
114
129
  alias :ior :ioh
115
130
  alias :iow :ioh
116
131
 
132
+ # def copy_state(other)
133
+ # _init(other.rl,other.cx,other.ioh,other.fs)
134
+ # end
135
+
136
+ # def self.new_r(riorl)
137
+ # #new(riorl,default_cx)
138
+ # new(riorl)
139
+ # end
117
140
 
118
141
 
119
142
  # Section: State Switching
@@ -127,15 +150,20 @@ module RIO
127
150
  return self if new_class == self.class
128
151
 
129
152
  begin
130
- try_state[new_class,*args]
153
+ new_state = try_state[new_class,*args]
131
154
  rescue Exception::FailedCheck => ex
132
155
  p "not a valid "+new_class.to_s+": "+ex.to_s+" '"+self.to_s+"'"
133
156
  raise
134
157
  end
158
+ became(new_state)
159
+ new_state
160
+ end
161
+ def became(obj)
162
+ RIO::Ext.became(obj)
135
163
  end
136
-
137
164
  def method_missing_trace_str(sym,*args)
138
- "missing: "+self.class.to_s+'['+self.to_url+']'+'.'+sym.to_s+'('+args.join(',')+')'
165
+ "missing: "+self.class.to_s+'['+self.to_url+" {#{self.rl.fs}}"+']'+'.'+sym.to_s+'('+args.join(',')+')'
166
+ #"missing: "+self.class.to_s+'['+self.to_url+""+']'+'.'+sym.to_s+'('+args.join(',')+')'
139
167
  end
140
168
 
141
169
  def method_missing(sym,*args,&block)
@@ -177,7 +205,7 @@ module RIO
177
205
  end
178
206
 
179
207
  def to_rl() self.rl.rl end
180
-
208
+ def fs() self.rl.fs end
181
209
 
182
210
  extend Forwardable
183
211
  def_instance_delegators(:rl,:path,:to_s,:fspath,:urlpath,:length)
@@ -199,13 +227,31 @@ module RIO
199
227
  # (should this be here???)
200
228
  def new_rio(arg0,*args,&block)
201
229
  #return arg0 if arg0.nil? # watch out for dir.read! if you remove this line
202
- Rio.rio(arg0,*args,&block)
230
+ nrio = Rio.rio(arg0,*args,&block)
231
+ #nrio.fs = self.fs
232
+ nrio
203
233
  end
204
234
  def new_rio_cx(*args)
205
235
  n = new_rio(*args)
206
236
  n.cx = self.cx.bequeath
237
+ #n.fs = self.fs
207
238
  n
208
239
  end
240
+ def clone_rio()
241
+ cp = Rio.new(self.rl)
242
+ cp.cx = self.cx
243
+ cp.ioh = self.ioh.clone unless self.ioh.nil?
244
+ #cp.fs = self.fs
245
+ cp
246
+ end
247
+
248
+ # def rio(*args)
249
+ # if zipfile?
250
+ # open_.dstream.rio(*args)
251
+ # else
252
+ # new_rio_cx(*args)
253
+ # end
254
+ # end
209
255
  def ensure_rio(arg0)
210
256
  return arg0 if arg0.kind_of?(::RIO::Rio)
211
257
  new_rio(arg0)
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -43,6 +43,11 @@ module RIO
43
43
  def iostate(*args) self end
44
44
  def stream?() true end
45
45
  def recno() nil end
46
+
47
+ # The copy code requires a directory test
48
+ # Streams are never directories
49
+ def dir?() false end
50
+
46
51
  end
47
52
 
48
53
  end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -41,12 +41,6 @@ require 'rio/stream/open'
41
41
  module RIO
42
42
  module Stream
43
43
  module Duplex
44
- class Open < RIO::Stream::Open
45
- def input() stream_state('Stream::Duplex::Input') end
46
- def output() stream_state('Stream::Duplex::Output') end
47
- def inout() stream_state('Stream::Duplex::InOut') end
48
- end
49
-
50
44
  module Ops
51
45
  module Output
52
46
  def wclose()
@@ -56,9 +50,18 @@ module RIO
56
50
  self
57
51
  end
58
52
  end
59
- module Input
60
- end
61
53
  end
54
+ class Open < RIO::Stream::Open
55
+ def output() super.extend(Ops::Output) end
56
+ def inout() super.extend(Ops::Output) end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ __END__
62
+ module RIO
63
+ module Stream
64
+ module Duplex
62
65
 
63
66
  class Input < RIO::Stream::Input
64
67
  include Ops::Input
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -41,14 +41,14 @@ require 'rio/ops/stream'
41
41
  require 'rio/ops/path'
42
42
  require 'rio/cp'
43
43
  require 'rio/piper/cp'
44
+ require 'rio/util'
45
+
44
46
 
45
47
  module RIO
46
48
  module Stream
47
49
  class Open < Base
48
50
  include Ops::Stream::Status
49
- #include Ops::Path::Status
50
51
  include Ops::Path::URI
51
- #include Ops::Path::Query
52
52
  include Cp::Open::Output
53
53
  include Cp::Open::Input
54
54
  include Piper::Cp::Input
@@ -58,44 +58,77 @@ module RIO
58
58
  def open(m=nil,*args)
59
59
  #p callstr('open',m,*args)
60
60
  case
61
-
62
61
  when open? then open_(*args)
63
62
  when m.nil? then open_(*args)
64
63
  else mode(m).open_(*args)
65
64
  end
66
65
  end
66
+
67
+ protected
68
+
67
69
  def open_(*args)
68
70
  #p callstr('open_',args.inspect)+" mode='#{mode?}' (#{mode?.class}) ioh=#{self.ioh} open?=#{open?}"
69
- unless open?
70
- ios = self.rl.open(mode?,*args)
71
- noautoclose_(false) if ios.tty?
72
- self.ioh = IOH::Stream.new(ios)
73
- end
71
+ self.ioh = self.rl.open(mode?,*args) unless open?
74
72
  self
75
73
  end
76
74
 
77
- protected :open_
78
75
 
79
76
  end
80
77
  end
81
78
  end
82
79
 
83
80
 
84
- require 'rio/util'
85
81
  module RIO
86
82
  module Stream
87
83
  class Open < Base
88
- def size()
89
- self.contents.size
84
+
85
+ public
86
+
87
+ #def size() self.contents.size end
88
+ #def empty?() self.eof? end
89
+
90
+ def iostate(sym)
91
+ if mode? && mode?.allows_both?
92
+ open_.inout()
93
+ else
94
+ implicit_state(sym)
95
+ end
90
96
  end
97
+
98
+ protected
99
+
91
100
  OUTPUT_SYMS = Util::build_sym_hash([:print,:printf,:puts,:putc,:write,
92
101
  :print!,:printf!,:puts!,:putc!,:write!,
93
102
  :put_,:putrec,:putrec!,:<,:<< ])
94
103
 
104
+ def when_missing(sym,*args)
105
+ #p callstr('when_missing',sym,*args)+" mode?(#{mode?.class})=#{mode?}"
106
+ nobj = iostate(sym)
107
+ return nobj unless nobj.nil?
108
+ gofigure(sym,*args)
109
+ end
110
+
111
+ def stream_state(cl)
112
+ #p callstr('stream_state',cl)
113
+ #p "LOOP: retry:#{cx['retrystate']} => #{cl}"
114
+ return nil if cx['retrystate'] == cl
115
+ cx['retrystate'] = cl
116
+
117
+ become(cl).add_rec_methods.add_extensions.add_filters.setup
118
+ #become(cl).add_rec_methods.add_filters.add_extensions.setup
119
+ #become(cl).add_extensions.add_rec_methods.add_filters.setup
120
+ #next_state.extend(Ops::Symlink::Existing) if symlink?
121
+ #next_state
122
+ end
123
+ def output() stream_state('Stream::Output') end
124
+ def input() stream_state('Stream::Input') end
125
+ def inout() stream_state('Stream::InOut') end
126
+
127
+ private
128
+
95
129
  def sym_state(sym,im,om)
96
130
  if OUTPUT_SYMS[sym.to_s] or RIO::Ext::OUTPUT_SYMS[sym.to_s]
97
131
  om ||= (sym.to_s == '<<' ? 'a' : 'w')
98
- #p "HEREHEREHERE om=#{om.inspect}"
99
132
  mode_(om).open_.output()
100
133
  else
101
134
  im ||= 'r'
@@ -126,55 +159,31 @@ module RIO
126
159
  sym_state(sym,inputmode?,outputmode?)
127
160
  end
128
161
  end
129
- def iostate(sym)
130
- #p callstr('iostate',sym)
131
- if mode? && mode?.allows_both?
132
- open_.inout()
133
- else
134
- implicit_state(sym)
135
- end
136
- end
137
- def when_missing(sym,*args)
138
- #p callstr('when_missing',sym,*args)+" mode?(#{mode?.class})=#{mode?}"
139
- nobj = iostate(sym)
140
- return nobj unless nobj.nil?
141
- gofigure(sym,*args)
142
- end
143
- # TEMP
144
- def dir?() false end
145
- def stream_state(cl)
146
- #p callstr('stream_state',cl)
147
- #p "LOOP: retry:#{cx['retrystate']} => #{cl}"
148
- return nil if cx['retrystate'] == cl
149
- cx['retrystate'] = cl
150
162
 
151
- become(cl).add_rec_methods.add_extensions.add_filters.setup
152
- #become(cl).add_rec_methods.add_filters.add_extensions.setup
153
- #become(cl).add_extensions.add_rec_methods.add_filters.setup
154
- #next_state.extend(Ops::Symlink::Existing) if symlink?
155
- #next_state
156
- end
157
- def output()
158
- stream_state('Stream::Output')
159
- end
160
- def input()
161
- stream_state('Stream::Input')
162
- end
163
- def inout()
164
- stream_state('Stream::InOut')
165
- end
166
-
167
- def gofigure(sym,*args)
168
- super
169
- end
163
+
170
164
  end
165
+
171
166
  class Close < State::Base
172
167
  include Ops::Stream::Status
173
- def clear_selection()
174
- cx.delete('stream_sel')
175
- cx.delete('stream_nosel')
168
+
169
+ def check?() true end
170
+ def close()
171
+ #p callstr('close')+" mode='#{mode?}' ioh=#{self.ioh} open?=#{open?}"
172
+ return self unless self.open?
173
+ self.close_
174
+ cx['retrystate'] = nil
176
175
  self
177
176
  end
177
+
178
+ def reopen(*args) self.close.softreset.open(*args) end
179
+
180
+ protected
181
+
182
+ def base_state() 'Stream::Reset' end
183
+ def when_missing(sym,*args)
184
+ self.close_.retryreset()
185
+ end
186
+
178
187
  def close_()
179
188
  #p callstr('close_')+" mode='#{mode?}' ioh=#{self.ioh} open?=#{open?}"
180
189
  return self unless self.open?
@@ -184,29 +193,15 @@ module RIO
184
193
  self.rl.close
185
194
  self
186
195
  end
187
- protected :close_
188
- def close()
189
- #p callstr('close')+" mode='#{mode?}' ioh=#{self.ioh} open?=#{open?}"
190
- return self unless self.open?
191
- self.close_
192
- cx['retrystate'] = nil
196
+
197
+ private
198
+
199
+ def clear_selection()
200
+ cx.delete('stream_sel')
201
+ cx.delete('stream_nosel')
193
202
  self
194
203
  end
195
- def get()
196
- self.close_.softreset
197
- nil
198
- end
199
- alias :getline :get
200
- alias :getrow :get
201
- alias :getrec :get
202
204
 
203
- def check?() true end
204
- def base_state() 'Stream::Reset' end
205
- def when_missing(sym,*args)
206
- # p callstr('when_missing',sym,*args)
207
- self.close_.retryreset()
208
- end
209
205
  end
210
-
211
206
  end
212
- end # module RIO
207
+ end