rio 0.3.3 → 0.3.4

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.
Files changed (88) hide show
  1. data/ChangeLog +225 -0
  2. data/README +12 -0
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/doc/ANNOUNCE +160 -71
  6. data/doc/RELEASE_NOTES +71 -2
  7. data/ex/colx.rb +1 -1
  8. data/ex/passwd_report.rb +4 -8
  9. data/ex/riocat +5 -5
  10. data/ex/riogunzip +1 -1
  11. data/ex/riogzip +6 -6
  12. data/ex/rioprompt.rb +6 -0
  13. data/lib/rio.rb +3 -13
  14. data/lib/rio/arycopy.rb +1 -1
  15. data/lib/rio/base.rb +1 -5
  16. data/lib/rio/construct.rb +75 -0
  17. data/lib/rio/constructor.rb +42 -11
  18. data/lib/rio/context.rb +1 -1
  19. data/lib/rio/context/dir.rb +50 -23
  20. data/lib/rio/context/methods.rb +5 -3
  21. data/lib/rio/{cxdir.rb → context/skip.rb} +24 -36
  22. data/lib/rio/context/stream.rb +38 -16
  23. data/lib/rio/cp.rb +24 -5
  24. data/lib/rio/dir.rb +8 -7
  25. data/lib/rio/doc/HOWTO.rb +33 -33
  26. data/lib/rio/doc/INTRO.rb +416 -256
  27. data/lib/rio/doc/MISC.rb +3 -1
  28. data/lib/rio/doc/SYNOPSIS.rb +28 -33
  29. data/lib/rio/entrysel.rb +76 -9
  30. data/lib/rio/file.rb +2 -1
  31. data/lib/rio/filter.rb +95 -0
  32. data/lib/rio/filter/closeoneof.rb +1 -1
  33. data/lib/rio/grande.rb +0 -74
  34. data/lib/rio/if.rb +2 -1
  35. data/lib/rio/if/basic.rb +1 -1
  36. data/lib/rio/if/csv.rb +1 -1
  37. data/lib/rio/if/dir.rb +1 -220
  38. data/lib/rio/if/fileordir.rb +26 -12
  39. data/lib/rio/if/grande.rb +55 -6
  40. data/lib/rio/if/grande_entry.rb +355 -0
  41. data/lib/rio/if/{methods.rb → grande_stream.rb} +69 -88
  42. data/lib/rio/if/path.rb +25 -3
  43. data/lib/rio/if/stream.rb +62 -37
  44. data/lib/rio/if/temp.rb +2 -2
  45. data/lib/rio/if/test.rb +23 -0
  46. data/lib/rio/impl/path.rb +5 -0
  47. data/lib/rio/match.rb +6 -3
  48. data/lib/rio/matchrecord.rb +50 -46
  49. data/lib/rio/{filter/chomp.rb → ops/construct.rb} +12 -20
  50. data/lib/rio/ops/create.rb +3 -0
  51. data/lib/rio/ops/dir.rb +12 -6
  52. data/lib/rio/ops/either.rb +17 -3
  53. data/lib/rio/ops/path.rb +4 -1
  54. data/lib/rio/ops/stream/input.rb +6 -1
  55. data/lib/rio/ops/stream/read.rb +1 -3
  56. data/lib/rio/{context/chomp.rb → prompt.rb} +17 -13
  57. data/lib/rio/rl/base.rb +1 -1
  58. data/lib/rio/rl/builder.rb +3 -1
  59. data/lib/rio/state.rb +7 -13
  60. data/lib/rio/stream.rb +8 -5
  61. data/lib/rio/stream/open.rb +1 -1
  62. data/lib/rio/version.rb +1 -1
  63. data/test/mswin32.rb +1 -1
  64. data/test/runtests_gem.rb +1 -1
  65. data/test/tc/all.rb +3 -0
  66. data/test/tc/copy-from.rb +13 -13
  67. data/test/tc/copy-to.rb +1 -1
  68. data/test/tc/copy.rb +1 -1
  69. data/test/tc/copydir.rb +0 -24
  70. data/test/tc/copysymlink.rb +39 -0
  71. data/test/tc/csv.rb +2 -2
  72. data/test/tc/csv2.rb +4 -4
  73. data/test/tc/misc.rb +16 -16
  74. data/test/tc/nolines.rb +26 -26
  75. data/test/tc/noqae.rb +74 -74
  76. data/test/tc/overload.rb +28 -28
  77. data/test/tc/riorl.rb +36 -0
  78. data/test/tc/selnosel.rb +36 -0
  79. data/test/tc/skip.rb +58 -0
  80. data/test/tc/skiplines.rb +42 -0
  81. data/test/tc/symlink.rb +1 -1
  82. data/test/tc/symlink0.rb +1 -1
  83. data/test/tc/temp.rb +1 -1
  84. data/test/tc/tempdir.rb +1 -1
  85. data/test/tc/testcase.rb +7 -1
  86. metadata +14 -8
  87. data/lib/rio/matchcolumns.rb +0 -266
  88. data/lib/rio/rangemath.rb +0 -44
@@ -1,266 +0,0 @@
1
- #--
2
- # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
4
- # All rights reserved
5
- #
6
- # This file is part of the Rio library for ruby.
7
- #
8
- # Rio is free software; you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation; either version 2 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Rio is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with Rio; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # ===============================================================================
22
- #++
23
- #
24
- # To create the documentation for Rio run the command
25
- # rake rdoc
26
- # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
- #
28
- # Suggested Reading
29
- # * RIO::Doc::SYNOPSIS
30
- # * RIO::Doc::INTRO
31
- # * RIO::Doc::HOWTO
32
- # * RIO::Rio
33
- #
34
- # <b>Rio is pre-alpha software.
35
- # The documented interface and behavior is subject to change without notice.</b>
36
-
37
-
38
- module RIO
39
- module Match #:nodoc: all
40
- module Column
41
-
42
- class Base
43
- def initialize(arg)
44
- @select_arg = arg
45
- end
46
- def inspect
47
- @select_arg.inspect
48
- end
49
- def val()
50
- @select_arg
51
- end
52
- def match_all?() false end
53
- def match_none?() false end
54
- end
55
- class All < Base
56
- def match?(colno) true end
57
- def match_all?() true end
58
- def =~(colno) true end
59
- end
60
- class None < Base
61
- def match?(colno) false end
62
- def match_none?() true end
63
- def =~(colno) false end
64
- end
65
-
66
- class Range < Base
67
- def match?(colno)
68
- #p "match?(#{val},#{recno}) select_arg=#{@select_arg}"
69
- @select_arg === colno
70
- end
71
- def =~(colno)
72
- #p "=~(#{record},#{record.recno}) select_arg=#{@select_arg}"
73
- @select_arg === colno
74
- end
75
- end
76
- class Fixnum < Base
77
- def match?(val,recno)
78
- #p "match?(#{val},#{recno}) select_arg=#{@select_arg}"
79
- @select_arg === recno
80
- end
81
- def =~(record)
82
- #p "=~(#{record},#{record.recno}) select_arg=#{@select_arg}"
83
- @select_arg === record.recno
84
- end
85
- end
86
- class Proc < Base
87
- def initialize(arg,therio)
88
- super(arg)
89
- @therio = therio
90
- end
91
- def match?(val,recno)
92
- #p "match?(#{val},#{recno}) select_arg=#{@select_arg}"
93
- @select_arg.call(val,recno,@therio)
94
- end
95
- def =~(record)
96
- @select_arg.call(record,record.recno,@therio)
97
- end
98
- end
99
- class Symbol < Base
100
- def match?(val,recno)
101
- #p "match?(#{val},#{recno}) select_arg=#{@select_arg}"
102
- val.__send__(@select_arg)
103
- end
104
- def =~(record)
105
- record.__send__(@select_arg)
106
- end
107
- end
108
- end
109
- end
110
-
111
- module Match
112
- module Record
113
- # for a sellist
114
- # nil indicates no call was made, so nothing selected
115
- # empty indicates a call was made, so all selected
116
- # contents should be checked for matches
117
- # if contents are removed the list should become nil, not empty
118
- class SelList
119
- def initialize(therio,args)
120
- if args.nil?
121
- @list = nil
122
- else
123
- @list = []
124
- args.each do |arg|
125
- @list << create_sel(therio,arg)
126
- end
127
- end
128
- #p "SelList(#{args.inspect},#{@list.inspect})"
129
- end
130
- def inspect
131
- @list.inspect
132
- end
133
- def size() @list.size unless @list.nil? end
134
- def only_one_fixnum?()
135
- @list && @list.size == 1 && @list[0].kind_of?(Match::Record::Fixnum)
136
- end
137
- def delete_at(index)
138
- @list.delete_at(index)
139
- @list = nil if @list.empty?
140
- end
141
- def self.create(therio,args)
142
- new(therio,args) unless args.nil?
143
- end
144
- def ranges()
145
- @list.nil? ? [] : @list.select { |sel| sel.kind_of?(Record::Range) }
146
- end
147
- def remove_passed_ranges(n)
148
- return nil if @list.nil?
149
- return self if @list.empty?
150
- newlist = []
151
- @list.each do |sel|
152
- newlist << sel unless sel.kind_of?(Match::Record::Range) and sel.val.max < n
153
- end
154
- @list = (newlist.empty? ? nil : newlist) if newlist.length != @list.length
155
- @list.nil? ? nil : self
156
- end
157
- def create_sel(therio,arg)
158
- case arg
159
- when ::Regexp
160
- Match::Record::RegExp.new(arg)
161
- when ::Range
162
- Match::Record::Range.new(arg)
163
- when ::Proc
164
- Match::Record::Proc.new(arg,therio)
165
- when ::Symbol
166
- Match::Record::Symbol.new(arg)
167
- when ::Fixnum
168
- Match::Record::Fixnum.new(arg)
169
- else
170
- raise ArgumentError,"Argument must be a Regexp,Range,Fixnum,Proc, or Symbol"
171
- end
172
- end
173
- def match?(val,recno)
174
- # !@list.nil? && (@list.empty? || @list.detect { |sel| sel.match?(val,recno) } || false) && true
175
- return false if @list.nil?
176
- return true if @list.empty?
177
- as = nil
178
- al = @list.detect { |sel| as = sel.match?(val,recno)
179
- #p "1: #{$1} as[match?]: #{as.inspect}"
180
- as
181
- }
182
- #p "[SelList.match?] as:#{as.inspect} al:#{al.inspect}"
183
- return as if al
184
- return false
185
- end
186
- def =~(el)
187
- !@list.nil? && (@list.empty? || @list.detect { |sel| sel =~ el } || false) && true
188
- end
189
- def always?() !@list.nil? && @list.empty? end
190
- def never?() @list.nil? end
191
- end
192
-
193
-
194
- class SelRej
195
- def initialize(therio,sel_args,rej_args)
196
- @sel = SelList.create(therio,sel_args)
197
- @rej = SelList.create(therio,rej_args)
198
- @always = init_always()
199
- end
200
- def only_one_fixnum?()
201
- @rej.nil? && @sel && @sel.only_one_fixnum?
202
- end
203
- def init_always(reset=false)
204
- if @sel.nil? and @rej.nil?
205
- !reset
206
- elsif @rej.nil? and @sel.always?
207
- true
208
- elsif @sel.nil?
209
- false
210
- elsif !@rej.nil? and @rej.always?
211
- false
212
- else
213
- nil
214
- end
215
- end
216
- def remove_passed_ranges(n)
217
- @sel = @sel.remove_passed_ranges(n) unless @sel.nil?
218
- @rej = @rej.remove_passed_ranges(n) unless @rej.nil?
219
- @always = init_always(true)
220
- self
221
- end
222
- def rangetops()
223
- rtops = ranges.map { |r| r.val.max }.sort.uniq
224
- rtops.empty? ? nil : rtops
225
- end
226
- def ranges()
227
- (@sel.nil? ? [] : @sel.ranges) + (@rej.nil? ? [] : @rej.ranges)
228
- end
229
- def class_tail
230
- self.class.to_s.sub(/^.+::/,'')
231
- end
232
- def inspect
233
- sprintf("#<%s:0x%08x @always=%s @sel=%s @rej=%s>",self.class_tail,self.object_id,@always.inspect,
234
- @sel.inspect,@rej.inspect)
235
- end
236
- def always?()
237
- @always == true
238
- end
239
- def never?()
240
- @always == false
241
- end
242
- def match?(val,recno)
243
- #p "match?(#{val},#{recno}) #{self.inspect}"
244
- return @always unless @always.nil?
245
- as = nil
246
- ok = ((!@sel.nil? && (as = @sel.match?(val,recno))) && !(!@rej.nil? && @rej.match?(val,recno)))
247
- return (ok ? as : ok)
248
- end
249
- def =~(el)
250
- return @always unless @always.nil?
251
- (!@sel.nil? && (@sel =~ el)) && !(!@rej.nil? && (@rej =~ el))
252
-
253
- #yes = (!@sel.nil? && (@sel =~ el))
254
- #no = (!@rej.nil? && (@rej =~ el))
255
- #p "yes=#{yes} no=#{no} el=#{el}"
256
- #return yes && !no
257
- #(@sel =~ el) && !(@rej =~ el)
258
- end
259
- end
260
- end
261
- end
262
- end
263
-
264
-
265
-
266
-
@@ -1,44 +0,0 @@
1
- module RIO
2
- class Ranges
3
- def initialize(*args)
4
- @ranges = []
5
- args.each { |arg|
6
- case arg
7
- when ::Range then @ranges << arg
8
- else @ranges << Range.new(arg,arg)
9
- end
10
- }
11
- end
12
- def merge()
13
- return [] if @ranges.empty
14
- @ranges.sort_by { |r| r.first }
15
- st = @ranges[0].start
16
- en = @ranges[0].end
17
- @ranges.each { |r|
18
- break if r.start > en
19
- en = [en,r.end].max
20
- }
21
-
22
- end
23
- end
24
- module RangeMath
25
- def ceil
26
- return last - 1 if exclude_end?
27
- last
28
- end
29
- def -(other)
30
- if include?(other.first) and !include?(other.ceil)
31
- [Range.new(first,other.first,true)]
32
- elsif include?(other.ceil) and !include?(other.first)
33
- [Range.new(other.ceil+1,last,exclude_end?)]
34
- elsif include?(other.ceil) and include?(other.first)
35
- [Range.new(first,other.first,true),Range.new(other.ceil+1,last,exclude_end?)]
36
- else
37
- [self]
38
- end
39
- end
40
- end
41
- end
42
- class Range
43
- include RIO::RangeMath
44
- end