ruby-changes:4100
From: ko1@a...
Date: Sun, 24 Feb 2008 06:13:23 +0900 (JST)
Subject: [ruby-changes:4100] nobu - Ruby:r15590 (trunk): * debug.c (ruby_set_debug_option): separated ruby_each_words().
nobu 2008-02-24 06:13:05 +0900 (Sun, 24 Feb 2008) New Revision: 15590 Modified files: trunk/ChangeLog trunk/debug.c trunk/include/ruby/util.h trunk/ruby.c trunk/util.c Log: * debug.c (ruby_set_debug_option): separated ruby_each_words(). * util.c (ruby_each_words): extracted from ruby_set_debug_option(). * ruby.c (proc_options): generalized enable/disable options. * ruby.c (ruby_init_gems): take enabled flag. [ruby-core:14840] * ruby.c (process_options): added --disable-rubyopt flag. * include/ruby/util.h (ruby_each_words): prototype. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=15590&r2=15589&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15590&r2=15589&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/util.h?r1=15590&r2=15589&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/debug.c?r1=15590&r2=15589&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/util.c?r1=15590&r2=15589&diff_format=u Index: debug.c =================================================================== --- debug.c (revision 15589) +++ debug.c (revision 15590) @@ -11,6 +11,7 @@ #include "ruby/ruby.h" #include "ruby/encoding.h" +#include "ruby/util.h" #include "debug.h" #include "vm_core.h" @@ -121,31 +122,25 @@ } #ifdef RUBY_DEBUG_ENV -#include <ctype.h> - -void -ruby_set_debug_option(const char *str) +static void +set_debug_option(const char *str, int len, void *arg) { - const char *end; - int len; - - if (!str) return; - for (; *str; str = end) { - while (ISSPACE(*str) || *str == ',') str++; - if (!*str) break; - end = str; - while (*end && !ISSPACE(*end) && *end != ',') end++; - len = end - str; -#define SET_WHEN(name, var) \ +#define SET_WHEN(name, var) do { \ if (len == sizeof(name) - 1 && \ strncmp(str, name, len) == 0) { \ extern int ruby_##var; \ ruby_##var = 1; \ - continue; \ - } - SET_WHEN("gc_stress", gc_stress); - SET_WHEN("core", enable_coredump); - fprintf(stderr, "unexpected debug option: %.*s\n", len, str); - } + return; \ + } \ + } while (0) + SET_WHEN("gc_stress", gc_stress); + SET_WHEN("core", enable_coredump); + fprintf(stderr, "unexpected debug option: %.*s\n", len, str); } + +void +ruby_set_debug_option(const char *str) +{ + ruby_each_words(str, set_debug_option, 0); +} #endif Index: include/ruby/util.h =================================================================== --- include/ruby/util.h (revision 15589) +++ include/ruby/util.h (revision 15590) @@ -70,6 +70,8 @@ #undef strtod #define strtod(s,e) ruby_strtod(s,e) +void ruby_each_words(const char *, void (*)(const char*, int, void*), void *); + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ Index: ChangeLog =================================================================== --- ChangeLog (revision 15589) +++ ChangeLog (revision 15590) @@ -1,3 +1,17 @@ +Sun Feb 24 06:13:02 2008 Nobuyoshi Nakada <nobu@r...> + + * debug.c (ruby_set_debug_option): separated ruby_each_words(). + + * util.c (ruby_each_words): extracted from ruby_set_debug_option(). + + * ruby.c (proc_options): generalized enable/disable options. + + * ruby.c (ruby_init_gems): take enabled flag. [ruby-core:14840] + + * ruby.c (process_options): added --disable-rubyopt flag. + + * include/ruby/util.h (ruby_each_words): prototype. + Sun Feb 24 05:25:26 2008 Nobuyoshi Nakada <nobu@r...> * ruby.c (proc_options): check if argument for -E exists. Index: util.c =================================================================== --- util.c (revision 15589) +++ util.c (revision 15590) @@ -3936,6 +3936,24 @@ *rve = s; return s0; } + +void +ruby_each_words(const char *str, void (*func)(const char*, int, void*), void *arg) +{ + const char *end; + int len; + + if (!str) return; + for (; *str; str = end) { + while (ISSPACE(*str) || *str == ',') str++; + if (!*str) break; + end = str; + while (*end && !ISSPACE(*end) && *end != ',') end++; + len = end - str; + (*func)(str, len, arg); + } +} + #ifdef __cplusplus } #endif Index: ruby.c =================================================================== --- ruby.c (revision 15589) +++ ruby.c (revision 15590) @@ -65,6 +65,12 @@ char *ruby_inplace_mode = 0; +#define DISABLE_BIT(bit) (1U << disable_##bit) +enum disable_flag_bits { + disable_gems, + disable_rubyopt, +}; + struct cmdline_options { int sflag, xflag; int do_loop, do_print; @@ -73,7 +79,7 @@ int usage; int version; int copyright; - int disable_gems; + int disable; int verbose; int yydebug; char *script; @@ -132,7 +138,8 @@ "-w turn warnings on for your script", "-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)", "-x[directory] strip off text before #!ruby line and perhaps cd to directory", - "--disable-gems disable gem libraries", + "--enable/--disable-FEATURE --enable/--disable=FEATURE enable/disable FEATUREs", + " gems: gem libraries, rubyopt: RUBYOPT env", "--copyright print the copyright", "--version print the version", NULL @@ -536,6 +543,34 @@ return (char *)s; } +#define UNSET_WHEN(bit) \ + if (len < sizeof(#bit) && strncmp(str, #bit, len) == 0) { \ + *(unsigned int *)arg &= ~DISABLE_BIT(bit); \ + return; \ + } + +#define SET_WHEN(bit) \ + if (len < sizeof(#bit) && strncmp(str, #bit, len) == 0) { \ + *(unsigned int *)arg |= DISABLE_BIT(bit); \ + return; \ + } + +static void +enable_option(const char *str, int len, void *arg) +{ + UNSET_WHEN(gems); + UNSET_WHEN(rubyopt); + rb_warn("unknown argument for --enable: `%.*s'", len, str); +} + +static void +disable_option(const char *str, int len, void *arg) +{ + SET_WHEN(gems); + SET_WHEN(rubyopt); + rb_warn("unknown argument for --disable: `%.*s'", len, str); +} + static int proc_options(int argc, char **argv, struct cmdline_options *opt) { @@ -792,8 +827,20 @@ ruby_debug = Qtrue; ruby_verbose = Qtrue; } - else if (strcmp("disable-gems", s) == 0) - opt->disable_gems = 1; + else if (strncmp("enable", s, n = 6) == 0 && + (!s[n] || s[n] == '-' || s[n] == '=')) { + if (!(s += n + 1)[-1] && (!--argc || !(s = *++argv))) { + rb_raise(rb_eRuntimeError, "missing argument for --enable"); + } + ruby_each_words(s, enable_option, &opt->disable); + } + else if (strncmp("disable", s, n = 7) == 0 && + (!s[n] || s[n] == '-' || s[n] == '=')) { + if (!(s += n + 1)[-1] && (!--argc || !(s = *++argv))) { + rb_raise(rb_eRuntimeError, "missing argument for --disable"); + } + ruby_each_words(s, disable_option, &opt->disable); + } else if (strncmp("encoding", s, n = 8) == 0 && (!s[n] || s[n] == '=')) { s += n; if (!*s++) { @@ -854,11 +901,11 @@ void Init_prelude(void); static void -ruby_init_gems(struct cmdline_options *opt) +ruby_init_gems(int enable) { VALUE gem; gem = rb_define_module("Gem"); - rb_const_set(gem, rb_intern("Enable"), opt->disable_gems ? Qfalse : Qtrue); + rb_const_set(gem, rb_intern("Enable"), enable ? Qtrue : Qfalse); Init_prelude(); } @@ -895,7 +942,8 @@ argc -= i; argv += i; - if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) { + if (!(opt->disable & DISABLE_BIT(rubyopt)) && + rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) { VALUE src_enc_name = opt->src.enc.name; VALUE ext_enc_name = opt->ext.enc.name; @@ -990,7 +1038,7 @@ process_sflag(opt); ruby_init_loadpath(); - ruby_init_gems(opt); + ruby_init_gems(!(opt->disable && DISABLE_BIT(gems))); parser = rb_parser_new(); if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); if (opt->ext.enc.name != 0) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/