@@ -2099,6 +2099,37 @@ process_script(ruby_cmdline_options_t *opt)
2099
2099
return ast_value ;
2100
2100
}
2101
2101
2102
+ static uint8_t
2103
+ prism_script_command_line (ruby_cmdline_options_t * opt )
2104
+ {
2105
+ uint8_t command_line = 0 ;
2106
+ if (opt -> do_split ) command_line |= PM_OPTIONS_COMMAND_LINE_A ;
2107
+ if (opt -> do_line ) command_line |= PM_OPTIONS_COMMAND_LINE_L ;
2108
+ if (opt -> do_loop ) command_line |= PM_OPTIONS_COMMAND_LINE_N ;
2109
+ if (opt -> do_print ) command_line |= PM_OPTIONS_COMMAND_LINE_P ;
2110
+ if (opt -> xflag ) command_line |= PM_OPTIONS_COMMAND_LINE_X ;
2111
+ return command_line ;
2112
+ }
2113
+
2114
+ static void
2115
+ prism_script_shebang_callback (pm_options_t * options , const uint8_t * source , size_t length , void * data )
2116
+ {
2117
+ ruby_cmdline_options_t * opt = (ruby_cmdline_options_t * ) data ;
2118
+ opt -> warning = 0 ;
2119
+
2120
+ char * switches = malloc (length + 1 );
2121
+ memcpy (switches , source , length );
2122
+ switches [length ] = '\0' ;
2123
+
2124
+ moreswitches (switches , opt , 0 );
2125
+ free (switches );
2126
+
2127
+ pm_options_command_line_set (options , prism_script_command_line (opt ));
2128
+ if (opt -> ext .enc .name != 0 ) {
2129
+ pm_options_encoding_set (options , StringValueCStr (opt -> ext .enc .name ));
2130
+ }
2131
+ }
2132
+
2102
2133
/**
2103
2134
* Process the command line options and parse the script into the given result.
2104
2135
* Raise an error if the script cannot be parsed.
@@ -2115,17 +2146,13 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
2115
2146
pm_options_encoding_set (options , StringValueCStr (opt -> ext .enc .name ));
2116
2147
}
2117
2148
2118
- uint8_t command_line = 0 ;
2119
- if (opt -> do_split ) command_line |= PM_OPTIONS_COMMAND_LINE_A ;
2120
- if (opt -> do_line ) command_line |= PM_OPTIONS_COMMAND_LINE_L ;
2121
- if (opt -> do_loop ) command_line |= PM_OPTIONS_COMMAND_LINE_N ;
2122
- if (opt -> do_print ) command_line |= PM_OPTIONS_COMMAND_LINE_P ;
2123
-
2149
+ uint8_t command_line = prism_script_command_line (opt );
2124
2150
VALUE error ;
2151
+
2125
2152
if (strcmp (opt -> script , "-" ) == 0 ) {
2126
- if (opt -> xflag ) command_line |= PM_OPTIONS_COMMAND_LINE_X ;
2127
2153
pm_options_command_line_set (options , command_line );
2128
2154
pm_options_filepath_set (options , "-" );
2155
+ pm_options_shebang_callback_set (options , prism_script_shebang_callback , (void * ) opt );
2129
2156
2130
2157
ruby_opt_init (opt );
2131
2158
error = pm_parse_stdin (result );
@@ -2138,16 +2165,17 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
2138
2165
}
2139
2166
}
2140
2167
else if (opt -> e_script ) {
2141
- command_line |= PM_OPTIONS_COMMAND_LINE_E ;
2168
+ command_line = ( uint8_t ) (( command_line | PM_OPTIONS_COMMAND_LINE_E ) & ~ PM_OPTIONS_COMMAND_LINE_X ) ;
2142
2169
pm_options_command_line_set (options , command_line );
2143
2170
2144
2171
ruby_opt_init (opt );
2145
2172
result -> node .coverage_enabled = 0 ;
2146
2173
error = pm_parse_string (result , opt -> e_script , rb_str_new2 ("-e" ));
2147
2174
}
2148
2175
else {
2149
- if (opt -> xflag ) command_line |= PM_OPTIONS_COMMAND_LINE_X ;
2150
2176
pm_options_command_line_set (options , command_line );
2177
+ pm_options_shebang_callback_set (options , prism_script_shebang_callback , (void * ) opt );
2178
+
2151
2179
error = pm_load_file (result , opt -> script_name , true);
2152
2180
2153
2181
// If reading the file did not error, at that point we load the command
0 commit comments