1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (set_option_encoding_once): dry.

* ruby.c (proc_options): checks extra argument for -E/--encoding.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-12-08 01:32:36 +00:00
parent a41eedddd3
commit ecc83033ba
3 changed files with 46 additions and 34 deletions

View file

@ -1,3 +1,9 @@
Mon Dec 8 10:32:33 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (set_option_encoding_once): dry.
* ruby.c (proc_options): checks extra argument for -E/--encoding.
Sun Dec 7 23:47:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Dec 7 23:47:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (LIBPATHFLAG): use numbered specifier if RPATHFLAG * configure.in (LIBPATHFLAG): use numbered specifier if RPATHFLAG

68
ruby.c
View file

@ -622,36 +622,27 @@ dump_option(const char *str, int len, void *arg)
} }
static void static void
set_internal_encoding_once(struct cmdline_options *opt, const char *e, int elen) set_option_encoding_once(const char *type, VALUE *name, const char *e, int elen)
{ {
VALUE ename; VALUE ename;
if (!elen) elen = strlen(e); if (!elen) elen = strlen(e);
ename = rb_str_new(e, elen); ename = rb_str_new(e, elen);
if (opt->intern.enc.name && if (*name &&
rb_funcall(ename, rb_intern("casecmp"), 1, opt->intern.enc.name) != INT2FIX(0)) { rb_funcall(ename, rb_intern("casecmp"), 1, *name) != INT2FIX(0)) {
rb_raise(rb_eRuntimeError, rb_raise(rb_eRuntimeError,
"default_internal already set to %s", RSTRING_PTR(opt->intern.enc.name)); "%s already set to %s", type, RSTRING_PTR(*name));
} }
opt->intern.enc.name = ename; *name = ename;
} }
static void #define set_internal_encoding_once(opt, e, elen) \
set_external_encoding_once(struct cmdline_options *opt, const char *e, int elen) set_option_encoding_once("default_intenal", &opt->intern.enc.name, e, elen)
{ #define set_external_encoding_once(opt, e, elen) \
VALUE ename; set_option_encoding_once("default_extenal", &opt->ext.enc.name, e, elen)
#define set_source_encoding_once(opt, e, elen) \
if (!elen) elen = strlen(e); set_option_encoding_once("source", &opt->src.enc.name, e, elen)
ename = rb_str_new(e, elen);
if (opt->ext.enc.name &&
rb_funcall(ename, rb_intern("casecmp"), 1, opt->ext.enc.name) != INT2FIX(0)) {
rb_raise(rb_eRuntimeError,
"default_external already set to %s", RSTRING_PTR(opt->ext.enc.name));
}
opt->ext.enc.name = ename;
}
static int static int
proc_options(int argc, char **argv, struct cmdline_options *opt, int envopt) proc_options(int argc, char **argv, struct cmdline_options *opt, int envopt)
@ -663,10 +654,11 @@ proc_options(int argc, char **argv, struct cmdline_options *opt, int envopt)
return 0; return 0;
for (argc--, argv++; argc > 0; argc--, argv++) { for (argc--, argv++; argc > 0; argc--, argv++) {
if (argv[0][0] != '-' || !argv[0][1]) const char *const arg = argv[0];
if (arg[0] != '-' || !arg[1])
break; break;
s = argv[0] + 1; s = arg + 1;
reswitch: reswitch:
switch (*s) { switch (*s) {
case 'a': case 'a':
@ -955,15 +947,29 @@ proc_options(int argc, char **argv, struct cmdline_options *opt, int envopt)
else if (is_option_with_arg("encoding", Qfalse, Qtrue)) { else if (is_option_with_arg("encoding", Qfalse, Qtrue)) {
char *p; char *p;
encoding: encoding:
p = strchr(s, ':'); do {
if (p) { # define set_encoding_part(type) \
if (p > s) if (!(p = strchr(s, ':'))) { \
set_external_encoding_once(opt, s, p-s); set_##type##_encoding_once(opt, s, 0); \
if (*++p) break; \
set_internal_encoding_once(opt, p, 0); } \
} else if (p > s) { \
else set_##type##_encoding_once(opt, s, p-s); \
set_external_encoding_once(opt, s, 0); }
set_encoding_part(external);
if (!*(s = ++p)) break;
set_encoding_part(internal);
if (!*(s = ++p)) break;
rb_raise(rb_eRuntimeError, "extra argument for %s: %s",
(arg[1] == '-' ? "--encoding" : "-E"), s);
# undef set_encoding_part
} while (0);
}
else if (is_option_with_arg("internal-encoding", Qfalse, Qtrue)) {
set_internal_encoding_once(opt, s, 0);
}
else if (is_option_with_arg("external-encoding", Qfalse, Qtrue)) {
set_external_encoding_once(opt, s, 0);
} }
else if (strcmp("version", s) == 0) { else if (strcmp("version", s) == 0) {
if (envopt) goto noenvopt_long; if (envopt) goto noenvopt_long;

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.1" #define RUBY_VERSION "1.9.1"
#define RUBY_RELEASE_DATE "2008-12-07" #define RUBY_RELEASE_DATE "2008-12-08"
#define RUBY_VERSION_CODE 191 #define RUBY_VERSION_CODE 191
#define RUBY_RELEASE_CODE 20081207 #define RUBY_RELEASE_CODE 20081208
#define RUBY_PATCHLEVEL 5000 #define RUBY_PATCHLEVEL 5000
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 1 #define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_YEAR 2008
#define RUBY_RELEASE_MONTH 12 #define RUBY_RELEASE_MONTH 12
#define RUBY_RELEASE_DAY 7 #define RUBY_RELEASE_DAY 8
#ifdef RUBY_EXTERN #ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];