16#include <sys/cygwin.h>
31#if (defined(LOAD_RELATIVE) || defined(__MACH__)) && defined(HAVE_DLADDR)
38#if defined(HAVE_FCNTL_H)
40#elif defined(HAVE_SYS_FCNTL_H)
43#ifdef HAVE_SYS_PARAM_H
44# include <sys/param.h>
47# define MAXPATHLEN 1024
50# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
63#ifndef DISABLE_RUBYGEMS
64# define DISABLE_RUBYGEMS 0
67#define DEFAULT_RUBYGEMS_ENABLED "disabled"
69#define DEFAULT_RUBYGEMS_ENABLED "enabled"
75#define FEATURE_BIT(bit) (1U << feature_##bit)
76#define EACH_FEATURES(X, SEP) \
83 X(frozen_string_literal) \
87#define EACH_DEBUG_FEATURES(X, SEP) \
88 X(frozen_string_literal) \
90#define AMBIGUOUS_FEATURE_NAMES 0
91#define DEFINE_FEATURE(bit) feature_##bit
92#define DEFINE_DEBUG_FEATURE(bit) feature_debug_##bit
101#define DEBUG_BIT(bit) (1U << feature_debug_##bit)
103#define DUMP_BIT(bit) (1U << dump_##bit)
104#define DEFINE_DUMP(bit) dump_##bit
105#define EACH_DUMPS(X, SEP) \
120 X(parsetree_with_comment) \
140rb_feature_set_to(
ruby_features_t *feat,
unsigned int bit_mask,
unsigned int bit_set)
142 feat->
mask |= bit_mask;
143 feat->
set = (feat->
set & ~bit_mask) | bit_set;
146#define FEATURE_SET_TO(feat, bit_mask, bit_set) \
147 rb_feature_set_to(&(feat), bit_mask, bit_set)
148#define FEATURE_SET(feat, bits) FEATURE_SET_TO(feat, bits, bits)
149#define FEATURE_SET_RESTORE(feat, save) FEATURE_SET_TO(feat, (save).mask, (save).set & (save).mask)
150#define FEATURE_SET_P(feat, bits) ((feat).set & (bits))
182#define src_encoding_index GET_VM()->src_encoding_index
195 & ~FEATURE_BIT(frozen_string_literal)
209#ifdef MJIT_FORCE_ENABLE
217static VALUE open_load_file(
VALUE fname_v,
int *xflag);
219#define forbid_setid(s) forbid_setid((s), opt)
227show_usage_line(
const char *
str,
unsigned int namelen,
unsigned int secondlen,
int help)
229 const unsigned int w = 16;
230 const int wrap = help && namelen + secondlen - 1 > w;
231 printf(
" %.*s%-*.*s%-*s%s\n", namelen-1,
str,
232 (wrap ? 0 : w - namelen + 1),
233 (help ? secondlen-1 : 0),
str + namelen,
234 (wrap ? w + 3 : 0), (wrap ?
"\n" :
""),
235 str + namelen + secondlen);
239usage(
const char *
name,
int help)
246 unsigned short namelen, secondlen;
248#define M(shortopt, longopt, desc) { \
249 shortopt " " longopt " " desc, \
250 (unsigned short)sizeof(shortopt), \
251 (unsigned short)sizeof(longopt), \
253 static const struct message usage_msg[] = {
254 M(
"-0[octal]",
"",
"specify record separator (\\0, if no argument)"),
255 M(
"-a",
"",
"autosplit mode with -n or -p (splits $_ into $F)"),
256 M(
"-c",
"",
"check syntax only"),
257 M(
"-Cdirectory",
"",
"cd to directory before executing your script"),
258 M(
"-d",
", --debug",
"set debugging flags (set $DEBUG to true)"),
259 M(
"-e 'command'",
"",
"one line of script. Several -e's allowed. Omit [programfile]"),
260 M(
"-Eex[:in]",
", --encoding=ex[:in]",
"specify the default external and internal character encodings"),
261 M(
"-Fpattern",
"",
"split() pattern for autosplit (-a)"),
262 M(
"-i[extension]",
"",
"edit ARGV files in place (make backup if extension supplied)"),
263 M(
"-Idirectory",
"",
"specify $LOAD_PATH directory (may be used more than once)"),
264 M(
"-l",
"",
"enable line ending processing"),
265 M(
"-n",
"",
"assume 'while gets(); ... end' loop around your script"),
266 M(
"-p",
"",
"assume loop like -n but print line also like sed"),
267 M(
"-rlibrary",
"",
"require the library before executing your script"),
268 M(
"-s",
"",
"enable some switch parsing for switches after script name"),
269 M(
"-S",
"",
"look for the script using PATH environment variable"),
270 M(
"-v",
"",
"print the version number, then turn on verbose mode"),
271 M(
"-w",
"",
"turn warnings on for your script"),
272 M(
"-W[level=2|:category]",
"",
"set warning level; 0=silence, 1=medium, 2=verbose"),
273 M(
"-x[directory]",
"",
"strip off text before #!ruby line and perhaps cd to directory"),
274 M(
"--jit",
"",
"enable JIT with default options (experimental)"),
275 M(
"--jit-[option]",
"",
"enable JIT with an option (experimental)"),
276 M(
"-h",
"",
"show this message, --help for more info"),
278 static const struct message help_msg[] = {
279 M(
"--copyright",
"",
"print the copyright"),
280 M(
"--dump={insns|parsetree|...}[,...]",
"",
281 "dump debug information. see below for available dump list"),
282 M(
"--enable={gems|rubyopt|...}[,...]",
", --disable={gems|rubyopt|...}[,...]",
283 "enable or disable features. see below for available features"),
284 M(
"--external-encoding=encoding",
", --internal-encoding=encoding",
285 "specify the default external or internal character encoding"),
286 M(
"--verbose",
"",
"turn on verbose mode and disable script from stdin"),
287 M(
"--version",
"",
"print the version number, then exit"),
288 M(
"--help",
"",
"show this message, -h for short message"),
290 static const struct message dumps[] = {
291 M(
"insns",
"",
"instruction sequences"),
292 M(
"yydebug",
"",
"yydebug of yacc parser generator"),
293 M(
"parsetree",
"",
"AST"),
294 M(
"parsetree_with_comment",
"",
"AST with comments"),
296 static const struct message features[] = {
299 M(
"rubyopt",
"",
"RUBYOPT environment variable (default: enabled)"),
300 M(
"frozen-string-literal",
"",
"freeze all string literals (default: disabled)"),
301 M(
"jit",
"",
"JIT compiler (default: disabled)"),
303 static const struct message warn_categories[] = {
304 M(
"deprecated",
"",
"deprecated features"),
305 M(
"experimental",
"",
"experimental features"),
308 M(
"--jit-warnings",
"",
"Enable printing JIT warnings"),
309 M(
"--jit-debug",
"",
"Enable JIT debugging (very slow), or add cflags if specified"),
310 M(
"--jit-wait",
"",
"Wait until JIT compilation finishes every time (for testing)"),
311 M(
"--jit-save-temps",
"",
"Save JIT temporary files in $TMP or /tmp (for testing)"),
312 M(
"--jit-verbose=num",
"",
"Print JIT logs of level num or less to stderr (default: 0)"),
313 M(
"--jit-max-cache=num",
"",
"Max number of methods to be JIT-ed in a cache (default: 100)"),
314 M(
"--jit-min-calls=num",
"",
"Number of calls to trigger JIT (for testing, default: 10000)"),
317 const int num =
numberof(usage_msg) - (help ? 1 : 0);
318#define SHOW(m) show_usage_line((m).str, (m).namelen, (m).secondlen, help)
320 printf(
"Usage: %s [switches] [--] [programfile] [arguments]\n",
name);
321 for (
i = 0;
i < num; ++
i)
334 puts(
"Warning categories:");
336 SHOW(warn_categories[
i]);
337 puts(
"JIT options (experimental):");
342#define rubylib_path_new rb_str_new
356 for (s = p; *s && *s != sep; s =
CharNext(s));
376 for (s = p; *s && *s !=
';'; s =
CharNext(s));
388#ifdef HAVE_CYGWIN_CONV_PATH
389#define CONV_TO_POSIX_PATH(p, lib) \
390 cygwin_conv_path(CCP_WIN_A_TO_POSIX|CCP_RELATIVE, (p), (lib), sizeof(lib))
392# error no cygwin_conv_path
394 if (CONV_TO_POSIX_PATH(p, rubylib) == 0)
396 push_include(p, filter);
402#define push_include push_include_cygwin
410 push_include(
path, filter);
437 if (*p ==
'.' && p[1] ==
'/')
449#if defined _WIN32 || defined __CYGWIN__
450static HMODULE libruby;
453DllMain(HINSTANCE dll,
DWORD reason, LPVOID reserved)
455 if (reason == DLL_PROCESS_ATTACH)
461rb_libruby_handle(
void)
467translit_char_bin(
char *p,
int from,
int to)
470 if ((
unsigned char)*p == from)
485# define IF_UTF8_PATH(t, f) t
487# define IF_UTF8_PATH(t, f) f
499# define str_conv_enc(str, from, to) (str)
504#if defined(LOAD_RELATIVE) || defined(__MACH__)
506runtime_libruby_path(
void)
508#if defined _WIN32 || defined __CYGWIN__
516 ret = GetModuleFileNameW(libruby, wlibpath,
len),
522 if (!ret || ret >
len)
rb_fatal(
"failed to get module file name");
523#if defined __CYGWIN__
525 const int win_to_posix = CCP_WIN_W_TO_POSIX | CCP_RELATIVE;
526 size_t newsize = cygwin_conv_path(win_to_posix, wlibpath, 0, 0);
527 if (!newsize)
rb_fatal(
"failed to convert module path to cygwin");
530 if (cygwin_conv_path(win_to_posix, wlibpath, libpath, newsize)) {
538 if (wlibpath[
i] ==
L'\\') {
544 len = WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret,
NULL, 0,
NULL,
NULL);
547 WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret, libpath,
len,
NULL,
NULL);
551#elif defined(HAVE_DLADDR)
554 const void* addr = (
void *)(
VALUE)expand_include_path;
556 if (!dladdr((
void *)addr, &dli)) {
560 else if (origarg.argc > 0 && origarg.argv && dli.dli_fname == origarg.argv[0]) {
572# error relative load path is not supported on this platform.
577#define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index")
582VALUE rb_libruby_selfpath;
588 VALUE load_path, archlibdir = 0;
589 ID id_initial_load_path_mark;
591#if defined(LOAD_RELATIVE) || defined(__MACH__)
592 VALUE libruby_path = runtime_libruby_path();
593# if defined(__MACH__)
594 rb_libruby_selfpath = libruby_path;
599#if defined LOAD_RELATIVE
600#if !defined ENABLE_MULTIARCH
601# define RUBY_ARCH_PATH ""
602#elif defined RUBY_ARCH
603# define RUBY_ARCH_PATH "/"RUBY_ARCH
605# define RUBY_ARCH_PATH "/"RUBY_PLATFORM
612 sopath = libruby_path;
617 static const char libdir[] =
"/"
618#ifdef LIBDIR_BASENAME
626 static const char bindir[] =
"/bin";
629 const char *p2 =
NULL;
631#ifdef ENABLE_MULTIARCH
634 if (p - libpath >= bindir_len && !
STRNCASECMP(p - bindir_len, bindir, bindir_len)) {
640 else if (p - libpath >= libdir_len && !
strncmp(p - libdir_len, libdir, libdir_len)) {
641 archlibdir =
rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath);
645#ifdef ENABLE_MULTIARCH
652 if (p)
goto multiarch;
657 baselen = p - libpath;
660#define PREFIX_PATH() sopath
661#define BASEPATH() rb_str_buf_cat(rb_str_buf_new(baselen+len), libpath, baselen)
662#define RUBY_RELATIVE(path, len) rb_str_buf_cat(BASEPATH(), (path), (len))
665#define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len))
666#define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)
675 load_path =
GET_VM()->load_path;
693add_modules(
VALUE *req_list,
const char *
mod)
706require_libraries(
VALUE *req_list)
731process_sflag(
int *sflag)
749 if (s[1] ==
'-' && s[2] ==
'\0')
754 for (p = s + 1; *p; p++) {
763 else if (*p !=
'_' && !
ISALNUM(*p)) {
766 rb_str_new2(
"invalid name for global variable - ");
767 if (!(p =
strchr(p,
'='))) {
773 name_error[1] = args[-1];
779 for (p = s + 1; *p; ++p) {
802 VALUE argstr, argary;
811 if (envopt) *p++ =
' ';
818 while (*p && !
ISSPACE(*p)) ++p;
829 while ((
i = proc_options(
argc,
argv, opt, envopt)) > 1 && envopt && (
argc -=
i) > 0) {
847name_match_p(
const char *
name,
const char *
str,
size_t len)
849 if (
len == 0)
return 0;
852 if (!--
len || !*++
str)
return 1;
855 if (*
str !=
'-' && *
str !=
'_')
return 0;
857 if (*
name !=
'-' && *
name !=
'_')
return 0;
863#define NAME_MATCH_P(name, str, len) \
864 ((len) < (int)sizeof(name) && name_match_p((name), (str), (len)))
866#define UNSET_WHEN(name, bit, str, len) \
867 if (NAME_MATCH_P((name), (str), (len))) { \
868 *(unsigned int *)arg &= ~(bit); \
872#define SET_WHEN(name, bit, str, len) \
873 if (NAME_MATCH_P((name), (str), (len))) { \
874 *(unsigned int *)arg |= (bit); \
878#define LITERAL_NAME_ELEMENT(name) #name
881feature_option(
const char *
str,
int len,
void *
arg,
const unsigned int enable)
885 unsigned int mask = ~0
U;
886 unsigned int set = 0
U;
887#if AMBIGUOUS_FEATURE_NAMES
889# define FEATURE_FOUND ++matched
891# define FEATURE_FOUND goto found
893#define SET_FEATURE(bit) \
894 if (NAME_MATCH_P(#bit, str, len)) {set |= mask = FEATURE_BIT(bit); FEATURE_FOUND;}
901#if AMBIGUOUS_FEATURE_NAMES
902 if (matched == 1)
goto found;
905#define ADD_FEATURE_NAME(bit) \
906 if (FEATURE_BIT(bit) & set) { \
907 rb_str_cat_cstr(mesg, #bit); \
908 if (--matched) rb_str_cat_cstr(mesg, ", "); \
913#undef ADD_FEATURE_NAME
916 rb_warn(
"unknown argument for --%s: `%.*s'",
917 enable ?
"enable" :
"disable",
len,
str);
922enable_option(
const char *
str,
int len,
void *
arg)
928disable_option(
const char *
str,
int len,
void *
arg)
937debug_option(
const char *
str,
int len,
void *
arg)
941#define SET_WHEN_DEBUG(bit) \
942 if (NAME_MATCH_P(#bit, str, len)) { \
943 FEATURE_SET(*argp, DEBUG_BIT(bit)); \
955dump_option(
const char *
str,
int len,
void *
arg)
958#define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len)
965set_option_encoding_once(
const char *
type,
VALUE *
name,
const char *e,
long elen)
969 if (!elen) elen =
strlen(e);
980#define set_internal_encoding_once(opt, e, elen) \
981 set_option_encoding_once("default_internal", &(opt)->intern.enc.name, (e), (elen))
982#define set_external_encoding_once(opt, e, elen) \
983 set_option_encoding_once("default_external", &(opt)->ext.enc.name, (e), (elen))
984#define set_source_encoding_once(opt, e, elen) \
985 set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))
989setup_mjit_options(
const char *s,
struct mjit_options *mjit_opt)
992 else if (
strcmp(s,
"-warnings") == 0) {
995 else if (
strncmp(s,
"-debug=", 7) == 0) {
998 else if (
strcmp(s,
"-debug") == 0) {
1001 else if (
strcmp(s,
"-wait") == 0) {
1004 else if (
strcmp(s,
"-save-temps") == 0) {
1007 else if (
strncmp(s,
"-verbose=", 9) == 0) {
1010 else if (
strncmp(s,
"-max-cache=", 11) == 0) {
1013 else if (
strncmp(s,
"-min-calls=", 11) == 0) {
1018 "invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1);
1026 long n, argc0 =
argc;
1034 const char *
const arg =
argv[0];
1042 if (envopt)
goto noenvopt;
1048 if (envopt)
goto noenvopt;
1052 if (envopt)
goto noenvopt;
1064 if (envopt)
goto noenvopt;
1087 unsigned int bits = 0;
1088 static const char no_prefix[] =
"no-";
1089 int enable =
strncmp(s += 2, no_prefix,
sizeof(no_prefix)-1) != 0;
1090 if (!enable) s +=
sizeof(no_prefix)-1;
1099 rb_warn(
"unknown warning category: `%s'", s);
1143 if (envopt)
goto noenvopt;
1149 if (envopt)
goto noenvopt;
1156 if (envopt)
goto noenvopt;
1161 if (envopt)
goto noenvopt;
1168 if (envopt)
goto noenvopt;
1175 if (envopt)
goto noenvopt;
1196 else if (
argc > 1) {
1203 if (envopt)
goto noenvopt;
1209 if (envopt)
goto noenvopt;
1213 if (*s &&
chdir(s) < 0) {
1220 if (envopt)
goto noenvopt;
1221 if (!*++s && (!--
argc || !(s = *++
argv) || !*s)) {
1230 if (envopt)
goto noenvopt;
1237 if (!*++s && (!--
argc || !(s = *++
argv))) {
1249 const char *enc_name = 0;
1252 enc_name =
"EUC-JP";
1255 enc_name =
"Windows-31J";
1260 case 'N':
case 'n':
case 'A':
case 'a':
1261 enc_name =
"ASCII-8BIT";
1282 rb_warn(
"ruby -T will be removed in Ruby 3.0");
1289 else if (
argc > 1) {
1296 if (envopt)
goto noenvopt;
1306 else if (
v == 0 && numlen >= 2) {
1317 if (!s[1] || (s[1] ==
'\r' && !s[2])) {
1323# define is_option_end(c, allow_hyphen) \
1324 (!(c) || ((allow_hyphen) && (c) == '-') || (c) == '=')
1325# define check_envopt(name, allow_envopt) \
1326 (((allow_envopt) || !envopt) ? (void)0 : \
1327 rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name))
1328# define need_argument(name, s, needs_arg, next_arg) \
1329 ((*(s) ? !*++(s) : (next_arg) && (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \
1330 rb_raise(rb_eRuntimeError, "missing argument for --" name) \
1332# define is_option_with_arg(name, allow_hyphen, allow_envopt) \
1333 is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue)
1334# define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg) \
1335 (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \
1336 (check_envopt(name, (allow_envopt)), s += n, \
1337 need_argument(name, s, needs_arg, next_arg), 1) : 0)
1339 if (
strcmp(
"copyright", s) == 0) {
1340 if (envopt)
goto noenvopt_long;
1362# define set_encoding_part(type) \
1363 if (!(p = strchr(s, ':'))) { \
1364 set_##type##_encoding_once(opt, s, 0); \
1368 set_##type##_encoding_once(opt, s, p-s); \
1371 if (!*(s = ++p))
break;
1373 if (!*(s = ++p))
break;
1374#if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
1376 if (!*(s = ++p))
break;
1379 (
arg[1] ==
'-' ?
"--encoding" :
"-E"), s);
1380# undef set_encoding_part
1389#if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
1394 else if (
strcmp(
"version", s) == 0) {
1395 if (envopt)
goto noenvopt_long;
1398 else if (
strcmp(
"verbose", s) == 0) {
1402 else if (
strncmp(
"jit", s, 3) == 0) {
1405 setup_mjit_options(s + 3, &opt->mjit);
1407 rb_warn(
"MJIT support is disabled.");
1410 else if (
strcmp(
"yydebug", s) == 0) {
1411 if (envopt)
goto noenvopt_long;
1417 else if (
strcmp(
"help", s) == 0) {
1418 if (envopt)
goto noenvopt_long;
1424 "invalid option --%s (-h will show valid options)", s);
1435 "invalid option -%c (-h will show valid options)",
1436 (
int)(
unsigned char)*s);
1451# undef is_option_end
1453# undef need_argument
1454# undef is_option_with_arg
1455# undef is_option_with_optarg
1460 if (warning) opt->
warning = warning;
1461 return argc0 -
argc;
1467ruby_init_prelude(
void)
1474opt_enc_index(
VALUE enc_name)
1488#define rb_progname (GET_VM()->progname)
1489#define rb_orig_progname (GET_VM()->orig_progname)
1505#define rb_define_readonly_boolean(name, val) \
1506 rb_define_virtual_variable((name), (val) ? true_value : false_value, 0)
1613 const char *
const progname =
1615 origarg.argc > 0 && origarg.argv && origarg.argv[0] ? origarg.argv[0] :
1632 moreswitches(s, opt, 1);
1644 rb_warning(
"-K is specified; it is for 1.8 compatibility and may cause odd behavior");
1648 opt->mjit.on =
TRUE;
1762 int modifiable =
FALSE;
1770 if (newpath ==
path)
continue;
1796 ruby_init_prelude();
1799#define SET_COMPILE_OPTION(h, o, name) \
1800 rb_hash_aset((h), ID2SYM(rb_intern_const(#name)), \
1801 (FEATURE_SET_P(o->features, FEATURE_BIT(name)) ? Qtrue : Qfalse));
1805#undef SET_COMPILE_OPTION
1808 process_sflag(&opt->
sflag);
1821 if (ienc) eenc = ienc;
1841 f = open_load_file(script_name, &opt->
xflag);
1847 if (!dump)
return Qtrue;
1872 process_sflag(&opt->
sflag);
1877 dump &= ~DUMP_BIT(syntax);
1878 if (!dump)
return Qtrue;
1891 dump &= ~DUMP_BIT(parsetree)&~DUMP_BIT(parsetree_with_comment);
1915 const struct rb_block *base_block = toplevel_context(toplevel_binding);
1923 dump &= ~DUMP_BIT(insns);
1924 if (!dump)
return Qtrue;
1941 rb_exec_event_hook_script_compiled(ec,
iseq, opt->
e_script);
1945 rb_exec_event_hook_script_compiled(ec,
iseq,
Qnil);
1953warn_cr_in_shebang(
const char *
str,
long len)
1956 rb_warn(
"shebang line ending with \\r may cause problems");
1960#define warn_cr_in_shebang(str, len) (void)0
1972load_file_internal(
VALUE argp_v)
1985 CONST_ID(set_encoding,
"set_encoding");
2004 if (
len > 2 &&
str[0] ==
'#' &&
str[1] ==
'!') {
2005 if (line_start == 1) warn_cr_in_shebang(
str,
len);
2019 warn_cr_in_shebang(
str,
len);
2022 goto search_shebang;
2027 if (*
str ==
'\n') *
str-- =
'\0';
2028 if (*
str ==
'\r') *
str-- =
'\0';
2030 if ((p =
strstr(p,
" -")) != 0) {
2032 moreswitches(p + 1,
opt, 0);
2038 else if (!
NIL_P(c)) {
2053 else if (!
NIL_P(c)) {
2103open_load_file(
VALUE fname_v,
int *xflag)
2111 if (flen == 1 &&
fname[0] ==
'-') {
2118#if defined O_NONBLOCK && HAVE_FCNTL && !(O_NONBLOCK & O_ACCMODE)
2120# define MODE_TO_LOAD (O_RDONLY | O_NONBLOCK)
2121#elif defined O_NDELAY && HAVE_FCNTL && !(O_NDELAY & O_ACCMODE)
2122# define MODE_TO_LOAD (O_RDONLY | O_NDELAY)
2124# define MODE_TO_LOAD (O_RDONLY)
2127#if defined DOSISH || defined __CYGWIN__
2128# define isdirsep(x) ((x) == '/' || (x) == '\\')
2130 static const char exeext[] =
".exe";
2131 enum {extlen =
sizeof(exeext)-1};
2151#if defined HAVE_FCNTL && MODE_TO_LOAD != O_RDONLY
2221 VALUE f = open_load_file(fname_v, &cmdline_options_init(&
opt)->xflag);
2222 return load_file(
parser, fname_v,
f, 0, &
opt);
2237proc_argv0(
VALUE process)
2264 return ruby_setproctitle(title);
2268ruby_setproctitle(
VALUE title)
2278 if (origarg.argv == 0)
2285external_str_new_cstr(
const char *p)
2350opt_W_getter(
ID id,
VALUE *variable)
2352 switch (*variable) {
2396#if defined(USE_DLN_A_OUT)
2397 if (origarg.argc > 0 && origarg.argv)
2398 dln_argv0 = origarg.argv[0];
2400 dln_argv0 =
argv[0];
2418 if (!origarg.argv || origarg.argc <= 0) {
2419 origarg.argc =
argc;
2420 origarg.argv =
argv;
2427#ifndef HAVE_SETPROCTITLE
2435fill_standard_fds(
void)
2437 int f0, f1, f2, fds[2];
2443 if (
pipe(fds) == 0) {
2452 if (
pipe(fds) == 0) {
2454 if (f1 && fds[1] != 1)
2456 if (f2 && fds[1] != 2)
2458 if (fds[1] != 1 && fds[1] != 2)
2478 origarg.argc = *
argc;
2479 origarg.argv = *
argv;
2480#if defined(USE_DLN_A_OUT)
2481 dln_argv0 = origarg.argv[0];
2484 fill_standard_fds();
#define ruby_show_copyright()
struct rb_encoding_entry * list
int rb_enc_dummy_p(rb_encoding *enc)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
rb_encoding * rb_utf8_encoding(void)
rb_encoding * rb_ascii8bit_encoding(void)
rb_encoding * rb_enc_from_index(int index)
rb_encoding * rb_default_internal_encoding(void)
void rb_enc_copy(VALUE obj1, VALUE obj2)
void rb_enc_set_default_internal(VALUE encoding)
rb_encoding * rb_default_external_encoding(void)
rb_encoding * rb_locale_encoding(void)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
void rb_enc_set_default_external(VALUE encoding)
int rb_enc_find_index(const char *name)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
#define ECONV_UNDEF_REPLACE
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
#define ENCODING_GET(obj)
#define ECONV_INVALID_REPLACE
char str[HTML_ESCAPE_MAX_LEN+1]
char * rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
VALUE rb_define_module(const char *)
VALUE rb_cObject
Object class.
void ruby_set_argv(int argc, char **argv)
void ruby_incpush(const char *path)
void ruby_script(const char *name)
Sets the current script name to this value.
void ruby_set_script_name(VALUE name)
Sets the current script name to this value.
void ruby_init_loadpath(void)
void * ruby_process_options(int argc, char **argv)
void ruby_prog_init(void)
Defines built-in variables.
void rb_raise(VALUE exc, const char *fmt,...)
void rb_warning_category_update(unsigned int mask, unsigned int bits)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_fatal(const char *fmt,...)
void rb_load_fail(VALUE path, const char *err)
void rb_warn(const char *fmt,...)
VALUE rb_exc_new_str(VALUE, VALUE)
void rb_loaderror(const char *fmt,...)
VALUE rb_ensure(VALUE(*)(VALUE), VALUE, VALUE(*)(VALUE), VALUE)
An equivalent to ensure clause.
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
void ruby_sysinit(int *argc, char ***argv)
Initializes the process for libruby.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define INITIAL_LOAD_PATH_MARK
#define str_conv_enc(str, from, to)
int ruby_env_debug_option(const char *str, int len, void *arg)
#define set_source_encoding_once(opt, e, elen)
#define src_encoding_index
void ruby_incpush_expand(const char *path)
#define rb_define_readonly_boolean(name, val)
#define EACH_DEBUG_FEATURES(X, SEP)
#define IF_UTF8_PATH(t, f)
#define is_option_with_arg(name, allow_hyphen, allow_envopt)
@ feature_debug_flag_first
@ feature_debug_flag_begin
void Init_builtin_features(void)
#define RUBY_RELATIVE(path, len)
#define SET_WHEN_DEBUG(bit)
VALUE ruby_archlibdir_path
RUBY_EXTERN const int ruby_patchlevel
#define FEATURE_SET_RESTORE(feat, save)
#define DEFINE_DEBUG_FEATURE(bit)
#define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg)
#define FEATURE_SET_TO(feat, bit_mask, bit_set)
#define FEATURE_SET(feat, bits)
#define NAME_MATCH_P(name, str, len)
void * rb_load_file_str(VALUE fname_v)
#define DEFINE_FEATURE(bit)
#define EACH_FEATURES(X, SEP)
void Init_ruby_description(void)
#define SET_COMPILE_OPTION(h, o, name)
#define SET_WHEN_DUMP(bit)
#define M(shortopt, longopt, desc)
void * rb_parser_load_file(VALUE parser, VALUE fname_v)
#define set_internal_encoding_once(opt, e, elen)
#define EACH_DUMPS(X, SEP)
#define set_encoding_part(type)
void * rb_load_file(const char *fname)
void ruby_push_include(const char *path, VALUE(*filter)(VALUE))
#define DEFAULT_RUBYGEMS_ENABLED
#define set_external_encoding_once(opt, e, elen)
#define LITERAL_NAME_ELEMENT(name)
ruby_cmdline_options_t * opt
const struct rb_block block
struct ruby_cmdline_options::@217::@218 enc
struct ruby_cmdline_options::@217 intern
struct ruby_cmdline_options::@217 src
struct ruby_cmdline_options::@217 ext
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
#define scan_oct(s, l, e)
VALUE rb_vm_top_self(void)
VALUE rb_readlink(VALUE path, rb_encoding *resultenc)
void rb_w32_sysinit(int *, char ***)