[前][次][番号順一覧][スレッド一覧]

ruby-changes:27474

From: nobu <ko1@a...>
Date: Wed, 27 Feb 2013 17:11:21 +0900 (JST)
Subject: [ruby-changes:27474] nobu:r39526 (trunk): * ruby.c (is_option_with_optarg): macro for optional argument option.

nobu	2013-02-27 17:08:10 +0900 (Wed, 27 Feb 2013)

  New Revision: 39526

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39526

  Log:
    * ruby.c (is_option_with_optarg): macro for optional argument option.

  Modified files:
    trunk/ruby.c

Index: ruby.c
===================================================================
--- ruby.c	(revision 39525)
+++ ruby.c	(revision 39526)
@@ -1056,13 +1056,16 @@ proc_options(long argc, char **argv, str https://github.com/ruby/ruby/blob/trunk/ruby.c#L1056
 #	define check_envopt(name, allow_envopt) \
 	    (((allow_envopt) || !envopt) ? (void)0 : \
 	     rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name))
-#	define need_argument(name, s) \
-	    ((*(s)++ ? !*(s) : (!--argc || !((s) = *++argv))) ?		\
+#	define need_argument(name, s, needs_arg) \
+	    ((*(s)++ ? !*(s) : (!--argc || !((s) = *++argv))) && (needs_arg) ? \
 	     rb_raise(rb_eRuntimeError, "missing argument for --" name) \
 	     : (void)0)
-#	define is_option_with_arg(name, allow_hyphen, allow_envopt) \
+#	define is_option_with_arg(name, allow_hyphen, allow_envopt)	\
+	    is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue)
+#	define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg) \
 	    (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \
-	     (check_envopt(name, (allow_envopt)), s += n, need_argument(name, s), 1) : 0)
+	     (check_envopt(name, (allow_envopt)), s += n, \
+		need_argument(name, s, needs_arg), 1) : 0)
 
 	    if (strcmp("copyright", s) == 0) {
 		if (envopt) goto noenvopt_long;
@@ -1174,6 +1177,7 @@ proc_options(long argc, char **argv, str https://github.com/ruby/ruby/blob/trunk/ruby.c#L1177
 #	undef check_envopt
 #	undef need_argument
 #	undef is_option_with_arg
+#	undef is_option_with_optarg
 	}
     }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]