summaryrefslogtreecommitdiff
path: root/lib/shell/builtin-command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/shell/builtin-command.rb')
-rw-r--r--lib/shell/builtin-command.rb81
1 files changed, 37 insertions, 44 deletions
diff --git a/lib/shell/builtin-command.rb b/lib/shell/builtin-command.rb
index 02025c5d42..e419a68c33 100644
--- a/lib/shell/builtin-command.rb
+++ b/lib/shell/builtin-command.rb
@@ -1,19 +1,19 @@
+# frozen_string_literal: false
#
-# shell/builtin-command.rb -
-# $Release Version: 0.6.0 $
-# $Revision: 1.1 $
-# $Date: 2001/05/17 10:02:48 $
-# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+# shell/builtin-command.rb -
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
-#
+#
#
require "shell/filter"
class Shell
- class BuiltInCommand<Filter
+ class BuiltInCommand < Filter
def wait?
false
end
@@ -22,16 +22,26 @@ class Shell
end
end
+ class Void < BuiltInCommand
+ def initialize(sh, *opts)
+ super sh
+ end
+
+ def each(rs = nil)
+ # do nothing
+ end
+ end
+
class Echo < BuiltInCommand
def initialize(sh, *strings)
super sh
@strings = strings
end
-
+
def each(rs = nil)
rs = @shell.record_separator unless rs
for str in @strings
- yield str + rs
+ yield str + rs
end
end
end
@@ -44,11 +54,11 @@ class Shell
def each(rs = nil)
if @cat_files.empty?
- super
+ super
else
- for src in @cat_files
- @shell.foreach(src, rs){|l| yield l}
- end
+ for src in @cat_files
+ @shell.foreach(src, rs){|l| yield l}
+ end
end
end
end
@@ -58,39 +68,22 @@ class Shell
super sh
@pattern = pattern
- Thread.critical = true
- back = Dir.pwd
- begin
- Dir.chdir @shell.cwd
- @files = Dir[pattern]
- ensure
- Dir.chdir back
- Thread.critical = false
- end
end
def each(rs = nil)
+ if @pattern[0] == ?/
+ @files = Dir[@pattern]
+ else
+ prefix = @shell.pwd+"/"
+ @files = Dir[prefix+@pattern].collect{|p| p.sub(prefix, "")}
+ end
rs = @shell.record_separator unless rs
- for f in @files
- yield f+rs
+ for f in @files
+ yield f+rs
end
end
end
-# class Sort < Cat
-# def initialize(sh, *filenames)
-# super
-# end
-#
-# def each(rs = nil)
-# ary = []
-# super{|l| ary.push l}
-# for l in ary.sort!
-# yield l
-# end
-# end
-# end
-
class AppendIO < BuiltInCommand
def initialize(sh, io, filter)
super sh
@@ -101,7 +94,7 @@ class Shell
def input=(filter)
@input.input=filter
for l in @input
- @io << l
+ @io << l
end
end
@@ -116,9 +109,9 @@ class Shell
def input=(filter)
begin
- super
+ super
ensure
- @io.close
+ @io.close
end
end
end
@@ -132,9 +125,9 @@ class Shell
def each(rs = nil)
to = @shell.open(@to_filename, "w")
begin
- super{|l| to << l; yield l}
+ super{|l| to << l; yield l}
ensure
- to.close
+ to.close
end
end
end
@@ -147,7 +140,7 @@ class Shell
def each(rs = nil)
while job = @jobs.shift
- job.each{|l| yield l}
+ job.each{|l| yield l}
end
end
end