From 57ef222d3a3c54336ba77630eb1031ab32883479 Mon Sep 17 00:00:00 2001 From: tadf Date: Sat, 25 Sep 2004 23:10:36 +0000 Subject: synchronized with date2 3.6.1 git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/cal.rb | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'sample') diff --git a/sample/cal.rb b/sample/cal.rb index fa20352f7..197cdfe3a 100644 --- a/sample/cal.rb +++ b/sample/cal.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby # cal.rb: Written by Tadayoshi Funaba 1998-2004 -# $Id: cal.rb,v 2.7 2004-01-10 23:52:51+09 tadf Exp $ +# $Id: cal.rb,v 2.8 2004-09-25 12:50:10+09 tadf Exp $ require 'date' @@ -121,17 +121,36 @@ end if __FILE__ == $0 - require 'getopts' + require 'getoptlong' def usage warn 'usage: cal [-c iso3166] [-jmty] [[month] year]' exit 1 end - usage unless getopts('jmty', "c:#{Cal::DEFAULT_START}") + cal = Cal.new + + begin + GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT], + ['-j', GetoptLong::NO_ARGUMENT], + ['-m', GetoptLong::NO_ARGUMENT], + ['-t', GetoptLong::NO_ARGUMENT], + ['-y', GetoptLong::NO_ARGUMENT]). + each do |opt, arg| + case opt + when '-c'; cal.opt_c(arg) || raise + when '-j'; cal.opt_j(true) + when '-m'; cal.opt_m(true) + when '-t'; cal.opt_t(true) + when '-y'; cal.opt_y(true) + end + end + rescue + usage + end y, m = ARGV.values_at(1, 0).compact.collect{|x| x.to_i} - $OPT_y ||= (y and not m) + cal.opt_y(true) if y and not m to = Date.today y ||= to.year @@ -139,15 +158,6 @@ if __FILE__ == $0 usage unless m >= 1 and m <= 12 usage unless y >= -4712 - usage if Cal::START[$OPT_c].nil? - - cal = Cal.new - - cal.opt_j($OPT_j) - cal.opt_m($OPT_m) - cal.opt_t($OPT_t) - cal.opt_y($OPT_y) - cal.opt_c($OPT_c) print cal.print(y, m) -- cgit