@@ -90,7 +90,6 @@ struct cmdline_options {
90
90
const char * script ;
91
91
VALUE script_name ;
92
92
VALUE e_script ;
93
- VALUE e_script_pos ;
94
93
struct {
95
94
struct {
96
95
VALUE name ;
@@ -717,14 +716,12 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
717
716
rb_raise (rb_eRuntimeError , "no code specified for -e" );
718
717
}
719
718
if (!opt -> e_script ) {
720
- opt -> e_script = rb_str_new ( 0 , 0 );
719
+ opt -> e_script = rb_ary_new ( );
721
720
if (opt -> script == 0 )
722
721
opt -> script = "-e" ;
723
- opt -> e_script_pos = rb_ary_new ();
724
722
}
725
- rb_str_cat2 (opt -> e_script , s );
726
- rb_str_cat2 (opt -> e_script , "\n" );
727
- rb_ary_push (opt -> e_script_pos , INT2FIX (argc0 - argc ));
723
+ rb_ary_push (opt -> e_script ,
724
+ rb_ary_new3 (2 , INT2FIX (argc0 - argc ), rb_str_new2 (s )));
728
725
break ;
729
726
730
727
case 'r' :
@@ -1104,13 +1101,11 @@ process_options(VALUE arg)
1104
1101
#ifdef _WIN32
1105
1102
if (enc != lenc &&
1106
1103
(argc = rb_w32_parse_cmdline (& argv , rb_enc_name (enc ))) != 0 ) {
1107
- if (opt -> e_script && opt -> e_script_pos ) {
1108
- opt -> e_script = rb_str_new (0 , 0 );
1109
- for (i = 0 ; i < RARRAY_LEN (opt -> e_s
10000
cript_pos ); ++ i ) {
1110
- int pos = FIX2INT (RARRAY_PTR (opt -> e_script_pos )[i ]);
1111
- rb_enc_str_buf_cat (opt -> e_script , argv [pos ], strlen (argv [pos ]),
1112
- enc );
1113
- rb_str_cat2 (opt -> e_script , "\n" );
1104
+ if (opt -> e_script ) {
1105
+ for (i = 0 ; i < RARRAY_LEN (opt -> e_script ); ++ i ) {
1106
+ int pos = FIX2INT (RARRAY_PTR (RARRAY_PTR (opt -> e_script )[i ])[0 ]);
1107
+ RARRAY_PTR (RARRAY_PTR (opt -> e_script )[i ])[1 ] =
1108
+ rb_enc_str_new (argv [pos ], strlen (argv [pos ]), enc );
1114
1109
}
1115
1110
}
1116
1111
argc -= opnum ;
@@ -1124,15 +1119,22 @@ process_options(VALUE arg)
1124
1119
rb_set_safe_level_force (safe );
1125
1120
if (opt -> e_script ) {
1126
1121
rb_encoding * eenc ;
1122
+ VALUE script = rb_str_new (0 , 0 );
1127
1123
if (opt -> src .enc .index >= 0 ) {
1128
1124
eenc = rb_enc_from_index (opt -> src .enc .index );
1129
1125
}
1130
1126
else {
1131
1127
eenc = lenc ;
1132
1128
}
1133
- rb_enc_associate (opt -> e_script , eenc );
1129
+ for (i = 0 ; i < RARRAY_LEN (opt -> e_script ); ++ i ) {
1130
+ VALUE str = RARRAY_PTR (RARRAY_PTR (opt -> e_script )[i ])[1 ];
1131
+ if (rb_enc_get_index (str ) == 0 )
1132
+ rb_enc_associate (str , eenc );
1133
+ rb_str_buf_append (script , str );
1134
+ rb_str_cat2 (script , "\n" );
1135
+ }
1134
1136
require_libraries (opt );
1135
- tree = rb_parser_compile_string (parser , opt -> script , opt -> e_script , 1 );
1137
+ tree = rb_parser_compile_string (parser , opt -> script , script , 1 );
1136
1138
}
1137
1139
else {
1138
1140
if (opt -> script [0 ] == '-' && !opt -> script [1 ]) {
0 commit comments