From 29a7a36d0631e06d3c9c35a0c422c6b3a9192932 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 21 Oct 1999 07:52:15 +0000 Subject: RUBYOPT git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 12aa708fb0..0fa3cb5282 100644 --- a/ruby.c +++ b/ruby.c @@ -292,6 +292,26 @@ process_sflag() } } +static void proc_options _((int argc, char **argv)); + +static char* +moreswitches(s) + char *s; +{ + int argc; char *argv[3]; char **argvp = argv; + char *p = s; + + argc = 2; argv[0] = argv[2] = 0; + while (*s && !ISSPACE(*s)) + s++; + argv[1] = ALLOCA_N(char, s - p + 2); + sprintf(argv[1], "-%s", p); + proc_options(argc, argv); + while (*s && ISSPACE(*s)) + s++; + return s; +} + static void proc_options(argc, argv) int argc; @@ -528,6 +548,34 @@ proc_options(argc, argv) switch_end: if (argv0 == 0) return; + if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) { + while (ISSPACE(*s)) s++; + if (*s == '-' && *(s+1) == 'T') { + int numlen; + int v = 1; + + s += 2; + if (*++s) { + v = scan_oct(s, 2, &numlen); + if (numlen == 0) v = 1; + } + rb_set_safe_level(v); + } + else { + while (s && *s) { + while (ISSPACE(*s)) s++; + if (*s == '-') { + s++; + if (ISSPACE(*s)) continue; + } + if (!*s) break; + if (!strchr("IdvwrK", *s)) + rb_raise(rb_eRuntimeError, "Illegal switch in RUBYOPT: -%c", *s); + s = moreswitches(s); + } + } + } + if (e_script) { argc++, argv--; argv[0] = script; @@ -681,19 +729,8 @@ load_file(fname, script) if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r') RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0'; if (p = strstr(p, " -")) { - int argc; char *argv[3]; char **argvp = argv; - char *s = ++p; - - argc = 2; argv[0] = argv[2] = 0; while (*p == '-') { - while (*s && !ISSPACE(*s)) - s++; - *s = '\0'; - argv[1] = p; - proc_options(argc, argv); - p = ++s; - while (*p && ISSPACE(*p)) - p++; + p = moreswitches(p+1); } } } -- cgit v1.2.3