summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ruby.c45
2 files changed, 39 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 70496ee..526a181 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun May 1 09:13:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ruby.c (process_sflag): replace '-' in variable names with '_'.
+ [ruby-dev:26107]
+
Wed Apr 27 23:42:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/Makefile.sub (OPTFLAGS): default global optimization to
diff --git a/ruby.c b/ruby.c
index 9e167f6..a45a0d1 100644
--- a/ruby.c
+++ b/ruby.c
@@ -192,7 +192,7 @@ ruby_incpush(path)
p = path;
while (*p) {
while (*p == sep) p++;
- if (s = strchr(p, sep)) {
+ if ((s = strchr(p, sep)) != 0) {
rb_ary_push(ary, rubylib_mangled_path(p, (int)(s-p)));
p = s + 1;
}
@@ -379,20 +379,43 @@ process_sflag()
VALUE v = *args++;
char *s = StringValuePtr(v);
char *p;
+ int hyphen = Qfalse;
if (s[0] != '-') break;
n--;
if (s[1] == '-' && s[2] == '\0') break;
- s[0] = '$';
- if (p = strchr(s, '=')) {
- *p++ = '\0';
- rb_gv_set(s, rb_str_new2(p));
+ v = Qtrue;
+ /* check if valid name before replacing - with _ */
+ for (p = s + 1; *p; p++) {
+ if (*p == '=') {
+ *p++ = '\0';
+ v = rb_str_new2(p);
+ break;
+ }
+ if (*p == '-') {
+ hyphen = Qtrue;
+ }
+ else if (*p != '_' && !ISALNUM(*p)) {
+ VALUE name_error[2];
+ name_error[0] = rb_str_new2("invalid name for global variable - ");
+ if (!(p = strchr(p, '='))) {
+ rb_str_cat2(name_error[0], s);
+ }
+ else {
+ rb_str_cat(name_error[0], s, p - s);
+ }
+ name_error[1] = args[-1];
+ rb_exc_raise(rb_class_new_instance(2, name_error, rb_eNameError));
+ }
}
- else {
- rb_gv_set(s, Qtrue);
+ s[0] = '$';
+ if (hyphen) {
+ for (p = s + 1; *p; ++p) {
+ if (*p == '-') *p = '_';
+ }
}
- s[0] = '-';
+ rb_gv_set(s, v);
}
n = RARRAY(rb_argv)->len - n;
while (n--) {
@@ -704,7 +727,7 @@ proc_options(argc, argv)
if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
while (ISSPACE(*s)) s++;
- if (*s == 'T' || *s == '-' && *(s+1) == 'T') {
+ if (*s == 'T' || (*s == '-' && *(s+1) == 'T')) {
int numlen;
int v = 1;
@@ -848,7 +871,7 @@ load_file(fname, script)
if (RSTRING(line)->len > 2
&& RSTRING(line)->ptr[0] == '#'
&& RSTRING(line)->ptr[1] == '!') {
- if (p = strstr(RSTRING(line)->ptr, "ruby")) {
+ if ((p = strstr(RSTRING(line)->ptr, "ruby")) != 0) {
goto start_read;
}
}
@@ -900,7 +923,7 @@ load_file(fname, script)
RSTRING(line)->ptr[RSTRING(line)->len-1] = '\0';
if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
- if (p = strstr(p, " -")) {
+ if ((p = strstr(p, " -")) != 0) {
p++; /* skip space before `-' */
while (*p == '-') {
p = moreswitches(p+1);