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

ruby-changes:25760

From: nobu <ko1@a...>
Date: Fri, 23 Nov 2012 17:32:09 +0900 (JST)
Subject: [ruby-changes:25760] nobu:r37817 (trunk): * ruby.c, test/ruby/test_rubyoptions.rb: revert r37815:r37816.

nobu	2012-11-23 17:31:52 +0900 (Fri, 23 Nov 2012)

  New Revision: 37817

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

  Log:
    * ruby.c, test/ruby/test_rubyoptions.rb: revert r37815:r37816.

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37816)
+++ ChangeLog	(revision 37817)
@@ -1,12 +1,3 @@
-Fri Nov 23 12:33:01 2012  Tadayoshi Funaba  <tadf@d...>
-
-	* ruby.c: revert r37298.
-
-Fri Nov 23 11:40:13 2012  Tadayoshi Funaba  <tadf@d...>
-
-	* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_usage2):
-	  revert the previous.
-
 Fri Nov 23 11:13:46 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_usage2): refine
Index: ruby.c
===================================================================
--- ruby.c	(revision 37816)
+++ ruby.c	(revision 37817)
@@ -52,6 +52,14 @@
 char *getenv();
 #endif
 
+#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
+
+#if defined DISABLE_RUBYGEMS && DISABLE_RUBYGEMS
+#define DEFAULT_RUBYGEMS_ENABLED "disabled"
+#else
+#define DEFAULT_RUBYGEMS_ENABLED "enabled"
+#endif
+
 #define DISABLE_BIT(bit) (1U << disable_##bit)
 enum disable_flag_bits {
     disable_gems,
@@ -65,6 +73,7 @@
     dump_version_v,
     dump_copyright,
     dump_usage,
+    dump_help,
     dump_yydebug,
     dump_syntax,
     dump_parsetree,
@@ -123,42 +132,73 @@
 } origarg;
 
 static void
-usage(const char *name)
+usage(const char *name, int help)
 {
     /* This message really ought to be max 23 lines.
      * Removed -h because the user already knows that option. Others? */
 
-    static const char *const usage_msg[] = {
-	"-0[octal]       specify record separator (\\0, if no argument)",
-	"-a              autosplit mode with -n or -p (splits $_ into $F)",
-	"-c              check syntax only",
-	"-Cdirectory     cd to directory, before executing your script",
-	"-d              set debugging flags (set $DEBUG to true)",
-	"-e 'command'    one line of script. Several -e's allowed. Omit [programfile]",
-	"-Eex[:in]       specify the default external and internal character encodings",
-	"-Fpattern       split() pattern for autosplit (-a)",
-	"-i[extension]   edit ARGV files in place (make backup if extension supplied)",
-	"-Idirectory     specify $LOAD_PATH directory (may be used more than once)",
-	"-l              enable line ending processing",
-	"-n              assume 'while gets(); ... end' loop around your script",
-	"-p              assume loop like -n but print line also like sed",
-	"-rlibrary       require the library, before executing your script",
-	"-s              enable some switch parsing for switches after script name",
-	"-S              look for the script using PATH environment variable",
-	"-T[level=1]     turn on tainting checks",
-	"-v              print version number, then turn on verbose mode",
-	"-w              turn warnings on for your script",
-	"-W[level=2]     set warning level; 0=silence, 1=medium, 2=verbose",
-	"-x[directory]   strip off text before #!ruby line and perhaps cd to directory",
-	"--copyright     print the copyright",
-	"--version       print the version",
-	NULL
+    struct message {
+	const char *str;
+	unsigned short namelen, secondlen;
     };
-    const char *const *p = usage_msg;
+#define M(shortopt, longopt, desc) { \
+    shortopt " " longopt " " desc, \
+    (unsigned short)sizeof(shortopt), \
+    (unsigned short)sizeof(longopt), \
+}
+    static const struct message usage_msg[] = {
+	M("-0[octal]",	   "",			   "specify record separator (\\0, if no argument)"),
+	M("-a",		   "",			   "autosplit mode with -n or -p (splits $_ into $F)"),
+	M("-c",		   "",			   "check syntax only"),
+	M("-Cdirectory",   "",			   "cd to directory before executing your script"),
+	M("-d",		   ", --debug",		   "set debugging flags (set $DEBUG to true)"),
+	M("-e 'command'",  "",			   "one line of script. Several -e's allowed. Omit [programfile]"),
+	M("-Eex[:in]",     ", --encoding=ex[:in]", "specify the default external and internal character encodings"),
+	M("-Fpattern",	   "",			   "split() pattern for autosplit (-a)"),
+	M("-i[extension]", "",			   "edit ARGV files in place (make backup if extension supplied)"),
+	M("-Idirectory",   "",			   "specify $LOAD_PATH directory (may be used more than once)"),
+	M("-l",		   "",			   "enable line ending processing"),
+	M("-n",		   "",			   "assume 'while gets(); ... end' loop around your script"),
+	M("-p",		   "",			   "assume loop like -n but print line also like sed"),
+	M("-rlibrary",	   "",			   "require the library before executing your script"),
+	M("-s",		   "",			   "enable some switch parsing for switches after script name"),
+	M("-S",		   "",			   "look for the script using PATH environment variable"),
+	M("-T[level=1]",   "",			   "turn on tainting checks"),
+	M("-v",		   ", --verbose",	   "print version number, then turn on verbose mode"),
+	M("-w",		   "",			   "turn warnings on for your script"),
+	M("-W[level=2]",   "",			   "set warning level; 0=silence, 1=medium, 2=verbose"),
+	M("-x[directory]", "",			   "strip off text before #!ruby line and perhaps cd to directory"),
+	M("-h",		   "",			   "show this message, --help for more info"),
+    };
+    static const struct message help_msg[] = {
+	M("--copyright",                   "", "print the copyright"),
+	M("--enable=feature[,...]",        "", "enable features"),
+	M("--disable=feature[,...]",       "", "disable features"),
+	M("--internal-encoding=encoding",  "", "specify the default internal character encoding"),
+	M("--external-encoding=encoding",  "", "specify the default external character encoding"),
+	M("--version",                     "", "print the version"),
+	M("--help",			   "", "show this message, -h for short message"),
+    };
+    static const struct message features[] = {
+	M("gems",    "",        "rubygems (default: "DEFAULT_RUBYGEMS_ENABLED")"),
+	M("rubyopt", "",        "RUBYOPT environment variable (default: enabled)"),
+    };
+    int i, w = help ? 32 : 16, num = numberof(usage_msg) - (help ? 1 : 0);
+#define SHOW(m) printf("  %.*s%-*.*s%s\n", (m).namelen-1, (m).str, \
+		       w - (m).namelen + 1, (help ? (m).secondlen-1 : 0), (m).str + (m).namelen, \
+		       (m).str + (m).namelen + (m).secondlen)
 
     printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name);
-    while (*p)
-	printf("  %s\n", *p++);
+    for (i = 0; i < num; ++i)
+	SHOW(usage_msg[i]);
+
+    if (!help) return;
+
+    for (i = 0; i < numberof(help_msg); ++i)
+	SHOW(help_msg[i]);
+    puts("Features:");
+    for (i = 0; i < numberof(features); ++i)
+	SHOW(features[i]);
 }
 
 #ifdef MANGLED_PATH
@@ -686,6 +726,7 @@
     SET_WHEN_DUMP(version);
     SET_WHEN_DUMP(copyright);
     SET_WHEN_DUMP(usage);
+    SET_WHEN_DUMP(help);
     SET_WHEN_DUMP(yydebug);
     SET_WHEN_DUMP(syntax);
     SET_WHEN_DUMP(parsetree);
@@ -1070,7 +1111,7 @@
 	    }
 	    else if (strcmp("help", s) == 0) {
 		if (envopt) goto noenvopt_long;
-		opt->dump |= DUMP_BIT(usage);
+		opt->dump |= DUMP_BIT(help);
 		goto switch_end;
 	    }
 	    else {
@@ -1267,8 +1308,8 @@
     argc -= i;
     argv += i;
 
-    if (opt->dump & DUMP_BIT(usage)) {
-	usage(origarg.argv[0]);
+    if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) {
+	usage(origarg.argv[0], (opt->dump & DUMP_BIT(help)));
 	return Qtrue;
     }
 
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 37816)
+++ test/ruby/test_rubyoptions.rb	(revision 37817)
@@ -1,3 +1,4 @@
+# -*- coding: us-ascii -*-
 require 'test/unit'
 
 require 'tmpdir'
@@ -35,13 +36,10 @@
 
   def test_usage2
     assert_in_out_err(%w(-h)) do |r, e|
-      assert_operator(r[1..-1].collect{|x| x.size}.max, :<=, 80)
+      longer = r[1..-1].select {|x| x.size > 80}
+      assert_equal([], longer)
       assert_equal([], e)
     end
-    assert_in_out_err(%w(--help)) do |r, e|
-      assert_operator(r[1..-1].collect{|x| x.size}.max, :<=, 80)
-      assert_equal([], e)
-    end
   end
 
   def test_option_variables

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

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