mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b3b3ff29b5
commit
552badf29f
5 changed files with 106 additions and 29 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
Sun Feb 24 06:13:02 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Sun Feb 24 05:25:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ruby.c (proc_options): check if argument for -E exists.
|
* ruby.c (proc_options): check if argument for -E exists.
|
||||||
|
|
29
debug.c
29
debug.c
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
|
#include "ruby/util.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
|
|
||||||
|
@ -121,31 +122,25 @@ ruby_debug_breakpoint(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RUBY_DEBUG_ENV
|
#ifdef RUBY_DEBUG_ENV
|
||||||
#include <ctype.h>
|
static void
|
||||||
|
set_debug_option(const char *str, int len, void *arg)
|
||||||
void
|
|
||||||
ruby_set_debug_option(const char *str)
|
|
||||||
{
|
{
|
||||||
const char *end;
|
#define SET_WHEN(name, var) do { \
|
||||||
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) \
|
|
||||||
if (len == sizeof(name) - 1 && \
|
if (len == sizeof(name) - 1 && \
|
||||||
strncmp(str, name, len) == 0) { \
|
strncmp(str, name, len) == 0) { \
|
||||||
extern int ruby_##var; \
|
extern int ruby_##var; \
|
||||||
ruby_##var = 1; \
|
ruby_##var = 1; \
|
||||||
continue; \
|
return; \
|
||||||
}
|
} \
|
||||||
|
} while (0)
|
||||||
SET_WHEN("gc_stress", gc_stress);
|
SET_WHEN("gc_stress", gc_stress);
|
||||||
SET_WHEN("core", enable_coredump);
|
SET_WHEN("core", enable_coredump);
|
||||||
fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
|
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
|
#endif
|
||||||
|
|
|
@ -70,6 +70,8 @@ double ruby_strtod(const char *, char **);
|
||||||
#undef strtod
|
#undef strtod
|
||||||
#define strtod(s,e) ruby_strtod(s,e)
|
#define strtod(s,e) ruby_strtod(s,e)
|
||||||
|
|
||||||
|
void ruby_each_words(const char *, void (*)(const char*, int, void*), void *);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#if 0
|
#if 0
|
||||||
{ /* satisfy cc-mode */
|
{ /* satisfy cc-mode */
|
||||||
|
|
64
ruby.c
64
ruby.c
|
@ -65,6 +65,12 @@ VALUE rb_parser_set_yydebug(VALUE, VALUE);
|
||||||
|
|
||||||
char *ruby_inplace_mode = 0;
|
char *ruby_inplace_mode = 0;
|
||||||
|
|
||||||
|
#define DISABLE_BIT(bit) (1U << disable_##bit)
|
||||||
|
enum disable_flag_bits {
|
||||||
|
disable_gems,
|
||||||
|
disable_rubyopt,
|
||||||
|
};
|
||||||
|
|
||||||
struct cmdline_options {
|
struct cmdline_options {
|
||||||
int sflag, xflag;
|
int sflag, xflag;
|
||||||
int do_loop, do_print;
|
int do_loop, do_print;
|
||||||
|
@ -73,7 +79,7 @@ struct cmdline_options {
|
||||||
int usage;
|
int usage;
|
||||||
int version;
|
int version;
|
||||||
int copyright;
|
int copyright;
|
||||||
int disable_gems;
|
int disable;
|
||||||
int verbose;
|
int verbose;
|
||||||
int yydebug;
|
int yydebug;
|
||||||
char *script;
|
char *script;
|
||||||
|
@ -132,7 +138,8 @@ usage(const char *name)
|
||||||
"-w turn warnings on for your script",
|
"-w turn warnings on for your script",
|
||||||
"-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)",
|
"-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",
|
"-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",
|
"--copyright print the copyright",
|
||||||
"--version print the version",
|
"--version print the version",
|
||||||
NULL
|
NULL
|
||||||
|
@ -536,6 +543,34 @@ moreswitches(const char *s, struct cmdline_options *opt)
|
||||||
return (char *)s;
|
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
|
static int
|
||||||
proc_options(int argc, char **argv, struct cmdline_options *opt)
|
proc_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
{
|
{
|
||||||
|
@ -792,8 +827,20 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
ruby_debug = Qtrue;
|
ruby_debug = Qtrue;
|
||||||
ruby_verbose = Qtrue;
|
ruby_verbose = Qtrue;
|
||||||
}
|
}
|
||||||
else if (strcmp("disable-gems", s) == 0)
|
else if (strncmp("enable", s, n = 6) == 0 &&
|
||||||
opt->disable_gems = 1;
|
(!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] == '=')) {
|
else if (strncmp("encoding", s, n = 8) == 0 && (!s[n] || s[n] == '=')) {
|
||||||
s += n;
|
s += n;
|
||||||
if (!*s++) {
|
if (!*s++) {
|
||||||
|
@ -854,11 +901,11 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
void Init_prelude(void);
|
void Init_prelude(void);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ruby_init_gems(struct cmdline_options *opt)
|
ruby_init_gems(int enable)
|
||||||
{
|
{
|
||||||
VALUE gem;
|
VALUE gem;
|
||||||
gem = rb_define_module("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();
|
Init_prelude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,7 +942,8 @@ process_options(VALUE arg)
|
||||||
argc -= i;
|
argc -= i;
|
||||||
argv += 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 src_enc_name = opt->src.enc.name;
|
||||||
VALUE ext_enc_name = opt->ext.enc.name;
|
VALUE ext_enc_name = opt->ext.enc.name;
|
||||||
|
|
||||||
|
@ -990,7 +1038,7 @@ process_options(VALUE arg)
|
||||||
process_sflag(opt);
|
process_sflag(opt);
|
||||||
|
|
||||||
ruby_init_loadpath();
|
ruby_init_loadpath();
|
||||||
ruby_init_gems(opt);
|
ruby_init_gems(!(opt->disable && DISABLE_BIT(gems)));
|
||||||
parser = rb_parser_new();
|
parser = rb_parser_new();
|
||||||
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
|
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
|
||||||
if (opt->ext.enc.name != 0) {
|
if (opt->ext.enc.name != 0) {
|
||||||
|
|
18
util.c
18
util.c
|
@ -3936,6 +3936,24 @@ ret1:
|
||||||
*rve = s;
|
*rve = s;
|
||||||
return s0;
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue