diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-01 00:13:48 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-01 00:13:48 +0000 |
commit | 33fa9defffed4fa759d47e93c7c61a705780f1c5 (patch) | |
tree | 5a3a3cdbd84f387bb4ed5419b1b8d480e91fa597 | |
parent | a83947140c22f35af11ea0284ccbe8e10dcdbd25 (diff) | |
download | ruby-33fa9defffed4fa759d47e93c7c61a705780f1c5.tar.gz |
* ruby.c (process_sflag): replace '-' in variable names with '_'.
[ruby-dev:26107]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ruby.c | 45 |
2 files changed, 39 insertions, 11 deletions
@@ -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 @@ -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); |