lib/rio/state.rb in rio-0.3.8 vs lib/rio/state.rb in rio-0.3.9

- old
+ new

@@ -1,8 +1,8 @@ #-- # =============================================================================== -# Copyright (c) 2005, Christopher Kleckner +# Copyright (c) 2005,2006,2007 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -20,21 +20,20 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # =============================================================================== #++ # # To create the documentation for Rio run the command -# rake rdoc -# from the distribution directory. Then point your browser at the 'doc/rdoc' directory. +# ruby build_doc.rb +# from the distribution directory. # # Suggested Reading # * RIO::Doc::SYNOPSIS # * RIO::Doc::INTRO # * RIO::Doc::HOWTO +# * RIO::Doc::EXAMPLES # * RIO::Rio # -# <b>Rio is pre-alpha software. -# The documented interface and behavior is subject to change without notice.</b> require 'rio/exception/state' require 'rio/context' require 'rio/context/methods' @@ -53,11 +52,12 @@ # * some basic house keeping methods # * the methods to communicate with the rio object # * the state changing mechanism # * and some basic error handling stubs class Base - KIOSYMS = [:gets,:getc,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,:split, + KIOSYMS = [:gets,:getc,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf, + #:split, :=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!,:load] @@kernel_cleaned ||= KIOSYMS.each { |sym| undef_method(sym) } undef_method(:rio) end @@ -65,11 +65,10 @@ attr_accessor :try_state #attr_accessor :handled_by attr_accessor :rl attr_accessor :ioh - #attr_accessor :fs attr_accessor :cx # Context handling include Cx::Methods @@ -79,32 +78,18 @@ def initialize(rl=nil,cx=nil,ioh=nil) cx ||= self.class.default_cx _init(rl,cx,ioh) # @handled_by = self.class.to_s end -# def initialize(rl=nil,cx=nil,ioh=nil,fs=nil) -# fs ||= RIO::FS::Native.create() -# cx ||= self.class.default_cx -# _init(rl,cx,ioh,fs) -# # @handled_by = self.class.to_s -# end def _init(riorl,cntx,iohandle=nil) @rl = riorl @cx = cntx @ioh = iohandle # raise Exception::FailedCheck.new(self) unless check? self end -# def _init(riorl,cntx,iohandle=nil,fs=nil) -# @rl = riorl -# @cx = cntx -# @ioh = iohandle -# @fs = fs -# # raise Exception::FailedCheck.new(self) unless check? -# self -# end private :_init def initialize_copy(*args) #p callstr('initialize_copy',args[0].inspect) super @@ -117,38 +102,26 @@ def self.default_cx Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } ) end def self.new_other(other) new(other.rl,other.cx,other.ioh) - #new.copy_state(other) end -# def self.new_other(other) -# new(other.rl,other.cx,other.ioh,other.fs) -# #new.copy_state(other) -# end alias :ior :ioh alias :iow :ioh -# def copy_state(other) -# _init(other.rl,other.cx,other.ioh,other.fs) -# end -# def self.new_r(riorl) -# #new(riorl,default_cx) -# new(riorl) -# end # Section: State Switching # the method for changing states # it's job is create an instance of the next state # and change the value in the handle that is shared with the rio object def become(new_class,*args) p "become : #{self.class.to_s} => #{new_class.to_s} (#{self.mode?})" if $trace_states -# + #p "BECOME #{new_class}: #{cx['ss_type']}" return self if new_class == self.class begin new_state = try_state[new_class,*args] rescue Exception::FailedCheck => ex @@ -157,11 +130,11 @@ end became(new_state) new_state end def became(obj) - RIO::Ext.became(obj) + #RIO::Ext.became(obj) end def method_missing_trace_str(sym,*args) "missing: "+self.class.to_s+'['+self.to_url+" {#{self.rl.fs}}"+']'+'.'+sym.to_s+'('+args.join(',')+')' #"missing: "+self.class.to_s+'['+self.to_url+""+']'+'.'+sym.to_s+'('+args.join(',')+')' end @@ -231,31 +204,30 @@ #nrio.fs = self.fs nrio end def new_rio_cx(*args) n = new_rio(*args) - n.cx = self.cx.bequeath + #p "new_rio_cx 1: #{n.cx.inspect}" + n.cx = self.cx.bequeath(n.cx) + #p "new_rio_cx 2: #{n.cx.inspect}" #n.fs = self.fs n end def clone_rio() cp = Rio.new(self.rl) - cp.cx = self.cx + cp.cx = self.cx.clone cp.ioh = self.ioh.clone unless self.ioh.nil? + cp.rl = self.rl.clone #cp.fs = self.fs cp end -# def rio(*args) -# if zipfile? -# open_.dstream.rio(*args) -# else -# new_rio_cx(*args) -# end -# end def ensure_rio(arg0) - return arg0 if arg0.kind_of?(::RIO::Rio) - new_rio(arg0) + case arg0 + when RIO::Rio then arg0 + when RIO::State::Base then arg0.clone_rio + else new_rio(arg0) + end end def ensure_cmd_rio(arg) case arg when ::String then new_rio(:cmdio,arg) when ::Fixnum then new_rio(arg)