Sha256: 7005e8fe3761614d29746db51e3942dc1bf6a5f33dd96f9fd4b73d030337215c

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8
#
# USAGE: calc [options] str0 str1 files ...

require "pp"
require "optparse"
require "stringio"
#require "rubygems"
#require "tempfile"
require "tefil"

## option analysis
options = {}
op = OptionParser.new
op.banner = [
  "Usage: #{File.basename("#{__FILE__}")} old_str new_str [options] [files]",
].join("\n")
op.on("-o"    , "--overwrite"    , "Overwrite."){    options[:overwrite] = true}
op.on("-g"    , "--global"    , "Globally substitute."){    options[:global] = true}
op.on("-p"    , "--preserve"    , "Preserve equation with '='."){ options[:preserve] = true}
op.on("-r"    , "--ruby"    , "Use Ruby 'eval' in spite of 'bc -l', powerful but security weakness."){ options[:ruby] = true} #Math::PI や実数乗ができる。
op.parse!(ARGV)

options[:overwrite] ||= false

tf = Tefil::Calculator.new(options)
if ARGV.empty?
  tf.filter(ARGV)
else
  ## for command line argument
  io = StringIO.new
  ARGV.each do |str|
    io.puts str
  end
  io.rewind
  tf.process_stream(io, $stdout)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tefil-0.1.3 bin/calc