16 #include <sys/cygwin.h> 23 #include <sys/types.h> 27 #include <sys/pstat.h> 29 #if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR) 36 #if defined(HAVE_FCNTL_H) 38 #elif defined(HAVE_SYS_FCNTL_H) 39 #include <sys/fcntl.h> 41 #ifdef HAVE_SYS_PARAM_H 42 # include <sys/param.h> 45 # define MAXPATHLEN 1024 48 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 57 #ifndef DISABLE_RUBYGEMS 58 # define DISABLE_RUBYGEMS 0 61 #define DEFAULT_RUBYGEMS_ENABLED "disabled" 63 #define DEFAULT_RUBYGEMS_ENABLED "enabled" 67 #define FEATURE_BIT(bit) (1U << feature_##bit) 68 #define EACH_FEATURES(X, SEP) \ 75 X(frozen_string_literal) \ 77 #define EACH_DEBUG_FEATURES(X, SEP) \ 78 X(frozen_string_literal) \ 80 #define AMBIGUOUS_FEATURE_NAMES 0 81 #define DEFINE_FEATURE(bit) feature_##bit 82 #define DEFINE_DEBUG_FEATURE(bit) feature_debug_##bit 91 #define DEBUG_BIT(bit) (1U << feature_debug_##bit) 93 #define DUMP_BIT(bit) (1U << dump_##bit) 94 #define DEFINE_DUMP(bit) dump_##bit 95 #define EACH_DUMPS(X, SEP) \ 110 X(parsetree_with_comment) \ 151 #define src_encoding_index GET_VM()->src_encoding_index 184 #define forbid_setid(s) forbid_setid((s), opt) 192 show_usage_line(
const char *str,
unsigned int namelen,
unsigned int secondlen,
int help)
194 const unsigned int w = 16;
195 const int wrap = help && namelen + secondlen - 2 > w;
196 printf(
" %.*s%-*.*s%-*s%s\n", namelen-1, str,
197 (wrap ? 0 : w - namelen + 1),
198 (help ? secondlen-1 : 0), str + namelen,
199 (wrap ? w + 3 : 0), (wrap ?
"\n" :
""),
200 str + namelen + secondlen);
204 usage(
const char *
name,
int help)
211 unsigned short namelen, secondlen;
213 #define M(shortopt, longopt, desc) { \ 214 shortopt " " longopt " " desc, \ 215 (unsigned short)sizeof(shortopt), \ 216 (unsigned short)sizeof(longopt), \ 218 static const struct message usage_msg[] = {
219 M(
"-0[octal]",
"",
"specify record separator (\\0, if no argument)"),
220 M(
"-a",
"",
"autosplit mode with -n or -p (splits $_ into $F)"),
221 M(
"-c",
"",
"check syntax only"),
222 M(
"-Cdirectory",
"",
"cd to directory before executing your script"),
223 M(
"-d",
", --debug",
"set debugging flags (set $DEBUG to true)"),
224 M(
"-e 'command'",
"",
"one line of script. Several -e's allowed. Omit [programfile]"),
225 M(
"-Eex[:in]",
", --encoding=ex[:in]",
"specify the default external and internal character encodings"),
226 M(
"-Fpattern",
"",
"split() pattern for autosplit (-a)"),
227 M(
"-i[extension]",
"",
"edit ARGV files in place (make backup if extension supplied)"),
228 M(
"-Idirectory",
"",
"specify $LOAD_PATH directory (may be used more than once)"),
229 M(
"-l",
"",
"enable line ending processing"),
230 M(
"-n",
"",
"assume 'while gets(); ... end' loop around your script"),
231 M(
"-p",
"",
"assume loop like -n but print line also like sed"),
232 M(
"-rlibrary",
"",
"require the library before executing your script"),
233 M(
"-s",
"",
"enable some switch parsing for switches after script name"),
234 M(
"-S",
"",
"look for the script using PATH environment variable"),
235 M(
"-T[level=1]",
"",
"turn on tainting checks"),
236 M(
"-v",
", --verbose",
"print version number, then turn on verbose mode"),
237 M(
"-w",
"",
"turn warnings on for your script"),
238 M(
"-W[level=2]",
"",
"set warning level; 0=silence, 1=medium, 2=verbose"),
239 M(
"-x[directory]",
"",
"strip off text before #!ruby line and perhaps cd to directory"),
240 M(
"-h",
"",
"show this message, --help for more info"),
242 static const struct message help_msg[] = {
243 M(
"--copyright",
"",
"print the copyright"),
244 M(
"--dump={insns|parsetree|...}[,...]",
"",
245 "dump debug information. see below for available dump list"),
246 M(
"--enable={gems|rubyopt|...}[,...]",
", --disable={gems|rubyopt|...}[,...]",
247 "enable or disable features. see below for available features"),
248 M(
"--external-encoding=encoding",
", --internal-encoding=encoding",
249 "specify the default external or internal character encoding"),
250 M(
"--version",
"",
"print the version"),
251 M(
"--help",
"",
"show this message, -h for short message"),
253 static const struct message dumps[] = {
254 M(
"insns",
"",
"instruction sequences"),
255 M(
"yydebug",
"",
"yydebug of yacc parser generator"),
256 M(
"parsetree",
"",
"AST"),
257 M(
"parsetree_with_comment",
"",
"AST with comments"),
259 static const struct message features[] = {
262 M(
"rubyopt",
"",
"RUBYOPT environment variable (default: enabled)"),
263 M(
"frozen-string-literal",
"",
"freeze all string literals (default: disabled)"),
266 const int num =
numberof(usage_msg) - (help ? 1 : 0);
267 #define SHOW(m) show_usage_line((m).str, (m).namelen, (m).secondlen, help) 269 printf(
"Usage: %s [switches] [--] [programfile] [arguments]\n", name);
270 for (i = 0; i < num; ++i)
275 for (i = 0; i <
numberof(help_msg); ++i)
278 for (i = 0; i <
numberof(dumps); ++i)
281 for (i = 0; i <
numberof(features); ++i)
285 #define rubylib_path_new rb_str_new 288 push_include(
const char *path,
VALUE (*filter)(
VALUE))
299 for (s = p; *s && *s != sep; s =
CharNext(s));
307 push_include_cygwin(
const char *path,
VALUE (*filter)(
VALUE))
310 char rubylib[FILENAME_MAX];
319 for (s = p; *s && *s !=
';'; s =
CharNext(s));
331 #ifdef HAVE_CYGWIN_CONV_PATH 332 #define CONV_TO_POSIX_PATH(p, lib) \ 333 cygwin_conv_path(CCP_WIN_A_TO_POSIX|CCP_RELATIVE, (p), (lib), sizeof(lib)) 335 # error no cygwin_conv_path 337 if (CONV_TO_POSIX_PATH(p, rubylib) == 0)
339 push_include(p, filter);
345 #define push_include push_include_cygwin 353 push_include(path, filter);
357 identical_path(
VALUE path)
362 locale_path(
VALUE path)
375 expand_include_path(
VALUE path)
380 if (*p ==
'.' && p[1] ==
'/')
392 #if defined _WIN32 || defined __CYGWIN__ 393 static HMODULE libruby;
396 DllMain(HINSTANCE dll,
DWORD reason, LPVOID reserved)
398 if (reason == DLL_PROCESS_ATTACH)
404 rb_libruby_handle(
void)
410 translit_char_bin(
char *p,
int from,
int to)
413 if ((
unsigned char)*p == from)
428 # define IF_UTF8_PATH(t, f) t 430 # define IF_UTF8_PATH(t, f) f 442 # define str_conv_enc(str, from, to) (str) 453 #if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR) && !defined(__CYGWIN__) 455 dladdr_path(
const void* addr)
460 if (!dladdr(addr, &dli)) {
464 else if (origarg.argc > 0 && origarg.argv && dli.dli_fname == origarg.argv[0]) {
478 #define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index") 484 ID id_initial_load_path_mark;
486 #if defined LOAD_RELATIVE 487 # if defined HAVE_DLADDR || defined __CYGWIN__ || defined _WIN32 488 # define VARIABLE_LIBPATH 1 490 # define VARIABLE_LIBPATH 0 492 # if VARIABLE_LIBPATH 501 #if defined _WIN32 || defined __CYGWIN__ 507 ret = GetModuleFileNameW(libruby, wlibpath, len),
513 if (!ret || ret > len)
rb_fatal(
"failed to get module file name");
514 for (len = ret, i = 0; i <
len; ++i) {
515 if (wlibpath[i] == L
'\\') {
520 len = WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret,
NULL, 0,
NULL,
NULL);
523 WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret, libpath, len,
NULL,
NULL);
526 #elif defined(HAVE_DLADDR) 527 sopath = dladdr_path((
void *)(
VALUE)expand_include_path);
531 #if !VARIABLE_LIBPATH 532 libpath[
sizeof(libpath) - 1] =
'\0';
534 #if defined DOSISH && !defined _WIN32 535 translit_char(libpath,
'\\',
'/');
536 #elif defined __CYGWIN__ 538 const int win_to_posix = CCP_WIN_A_TO_POSIX | CCP_RELATIVE;
539 size_t newsize = cygwin_conv_path(win_to_posix, libpath, 0, 0);
543 if (cygwin_conv_path(win_to_posix, libpath, p, newsize) == 0) {
553 static const char bindir[] =
"/bin";
554 #ifdef LIBDIR_BASENAME 555 static const char libdir[] =
"/"LIBDIR_BASENAME;
557 static const char libdir[] =
"/lib";
559 const ptrdiff_t bindir_len = (ptrdiff_t)
sizeof(bindir) - 1;
560 const ptrdiff_t libdir_len = (ptrdiff_t)
sizeof(libdir) - 1;
562 #ifdef ENABLE_MULTIARCH 567 if (p - libpath >= bindir_len && !
STRNCASECMP(p - bindir_len, bindir, bindir_len)) {
570 else if (p - libpath >= libdir_len && !strncmp(p - libdir_len, libdir, libdir_len)) {
573 #ifdef ENABLE_MULTIARCH 580 if (p)
goto multiarch;
584 #if !VARIABLE_LIBPATH 588 #if !VARIABLE_LIBPATH 590 strlcpy(libpath,
".",
sizeof(libpath));
593 baselen = p - libpath;
594 #define PREFIX_PATH() rb_str_new(libpath, baselen) 596 baselen = p - libpath;
599 #define PREFIX_PATH() sopath 602 #define BASEPATH() rb_str_buf_cat(rb_str_buf_new(baselen+len), libpath, baselen) 604 #define RUBY_RELATIVE(path, len) rb_str_buf_cat(BASEPATH(), (path), (len)) 607 #define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len)) 608 #define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len) 610 load_path =
GET_VM()->load_path;
612 if (safe_level == 0) {
620 rb_ivar_set(path, id_initial_load_path_mark, path);
645 require_libraries(
VALUE *req_list)
670 process_sflag(
int *
sflag)
688 if (s[1] ==
'-' && s[2] ==
'\0')
693 for (p = s + 1; *p; p++) {
702 else if (*p !=
'_' && !
ISALNUM(*p)) {
705 rb_str_new2(
"invalid name for global variable - ");
706 if (!(p =
strchr(p,
'='))) {
712 name_error[1] = args[-1];
718 for (p = s + 1; *p; ++p) {
741 VALUE argstr, argary;
749 if (envopt) *p++ =
' ';
750 memcpy(p, s, len + 1);
756 while (*p && !
ISSPACE(*p)) ++p;
766 while ((i = proc_options(argc, argv, opt, envopt)) > 1 && envopt && (argc -= i) > 0) {
783 name_match_p(
const char *name,
const char *str,
size_t len)
785 if (len == 0)
return 0;
787 while (
TOLOWER(*str) == *name) {
788 if (!--len || !*++str)
return 1;
791 if (*str !=
'-' && *str !=
'_')
return 0;
793 if (*name !=
'-' && *name !=
'_')
return 0;
800 #define NAME_MATCH_P(name, str, len) \ 801 ((len) < (int)sizeof(name) && name_match_p((name), (str), (len))) 803 #define UNSET_WHEN(name, bit, str, len) \ 804 if (NAME_MATCH_P((name), (str), (len))) { \ 805 *(unsigned int *)arg &= ~(bit); \ 809 #define SET_WHEN(name, bit, str, len) \ 810 if (NAME_MATCH_P((name), (str), (len))) { \ 811 *(unsigned int *)arg |= (bit); \ 815 #define LITERAL_NAME_ELEMENT(name) #name 818 feature_option(
const char *str,
int len,
void *arg,
const unsigned int enable)
821 unsigned int *argp = arg;
822 unsigned int mask = ~0
U;
823 #if AMBIGUOUS_FEATURE_NAMES 824 unsigned int set = 0
U;
826 #define SET_FEATURE(bit) \ 827 if (NAME_MATCH_P(#bit, str, len)) {set |= mask = FEATURE_BIT(bit); ++matched;} 829 #define SET_FEATURE(bit) \ 830 if (NAME_MATCH_P(#bit, str, len)) {mask = FEATURE_BIT(bit); goto found;} 835 *argp = (*argp & ~mask) | (mask & enable);
838 #if AMBIGUOUS_FEATURE_NAMES 839 if (matched == 1)
goto found;
842 #define ADD_FEATURE_NAME(bit) \ 843 if (FEATURE_BIT(bit) & set) { \ 844 rb_str_cat_cstr(mesg, #bit); \ 845 if (--matched) rb_str_cat_cstr(mesg, ", "); \ 850 #undef ADD_FEATURE_NAME 853 rb_warn(
"unknown argument for --%s: `%.*s'",
854 enable ?
"enable" :
"disable", len, str);
859 enable_option(
const char *str,
int len,
void *arg)
861 feature_option(str, len, arg, ~0
U);
865 disable_option(
const char *str,
int len,
void *arg)
867 feature_option(str, len, arg, 0
U);
874 debug_option(
const char *str,
int len,
void *arg)
877 #define SET_WHEN_DEBUG(bit) SET_WHEN(#bit, DEBUG_BIT(bit), str, len) 882 rb_warn(
"unknown argument for --debug: `%.*s'", len, str);
883 rb_warn(
"debug features are [%.*s].", (
int)
strlen(list), list);
887 dump_option(
const char *str,
int len,
void *arg)
890 #define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len) 892 rb_warn(
"don't know how to dump `%.*s',", len, str);
897 set_option_encoding_once(
const char *
type,
VALUE *name,
const char *e,
long elen)
901 if (!elen) elen =
strlen(e);
907 "%s already set to %"PRIsVALUE, type, *name);
912 #define set_internal_encoding_once(opt, e, elen) \ 913 set_option_encoding_once("default_internal", &(opt)->intern.enc.name, (e), (elen)) 914 #define set_external_encoding_once(opt, e, elen) \ 915 set_option_encoding_once("default_external", &(opt)->ext.enc.name, (e), (elen)) 916 #define set_source_encoding_once(opt, e, elen) \ 917 set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen)) 922 long n, argc0 =
argc;
926 if (argc <= 0 || !argv)
929 for (argc--, argv++; argc > 0; argc--, argv++) {
930 const char *
const arg = argv[0];
931 if (!arg || arg[0] !=
'-' || !arg[1])
938 if (envopt)
goto noenvopt;
944 if (envopt)
goto noenvopt;
948 if (envopt)
goto noenvopt;
960 if (envopt)
goto noenvopt;
1009 if (envopt)
goto noenvopt;
1015 if (envopt)
goto noenvopt;
1022 if (envopt)
goto noenvopt;
1027 if (envopt)
goto noenvopt;
1034 if (envopt)
goto noenvopt;
1041 if (envopt)
goto noenvopt;
1062 else if (argc > 1) {
1063 add_modules(&opt->
req_list, argv[1]);
1069 if (envopt)
goto noenvopt;
1075 if (envopt)
goto noenvopt;
1079 if (*s && chdir(s) < 0) {
1086 if (envopt)
goto noenvopt;
1087 if (!*++s && (!--argc || !(s = *++argv) || !*s)) {
1096 if (envopt)
goto noenvopt;
1103 if (!*++s && (!--argc || !(s = *++argv))) {
1115 const char *enc_name = 0;
1118 enc_name =
"EUC-JP";
1121 enc_name =
"Windows-31J";
1126 case 'N':
case 'n':
case 'A':
case 'a':
1127 enc_name =
"ASCII-8BIT";
1158 else if (argc > 1) {
1165 if (envopt)
goto noenvopt;
1175 else if (v == 0 && numlen >= 2) {
1186 if (!s[1] || (s[1] ==
'\r' && !s[2])) {
1192 # define is_option_end(c, allow_hyphen) \ 1193 (!(c) || ((allow_hyphen) && (c) == '-') || (c) == '=') 1194 # define check_envopt(name, allow_envopt) \ 1195 (((allow_envopt) || !envopt) ? (void)0 : \ 1196 rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name)) 1197 # define need_argument(name, s, needs_arg, next_arg) \ 1198 ((*(s) ? !*++(s) : (next_arg) && (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \ 1199 rb_raise(rb_eRuntimeError, "missing argument for --" name) \ 1201 # define is_option_with_arg(name, allow_hyphen, allow_envopt) \ 1202 is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue) 1203 # define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg) \ 1204 (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \ 1205 (check_envopt(name, (allow_envopt)), s += n, \ 1206 need_argument(name, s, needs_arg, next_arg), 1) : 0) 1208 if (strcmp(
"copyright", s) == 0) {
1209 if (envopt)
goto noenvopt_long;
1231 # define set_encoding_part(type) \ 1232 if (!(p = strchr(s, ':'))) { \ 1233 set_##type##_encoding_once(opt, s, 0); \ 1237 set_##type##_encoding_once(opt, s, p-s); \ 1240 if (!*(s = ++p))
break;
1242 if (!*(s = ++p))
break;
1243 #if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING 1245 if (!*(s = ++p))
break;
1248 (arg[1] ==
'-' ?
"--encoding" :
"-E"), s);
1249 # undef set_encoding_part 1258 #if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING 1263 else if (strcmp(
"version", s) == 0) {
1264 if (envopt)
goto noenvopt_long;
1267 else if (strcmp(
"verbose", s) == 0) {
1271 else if (strcmp(
"yydebug", s) == 0) {
1272 if (envopt)
goto noenvopt_long;
1278 else if (strcmp(
"help", s) == 0) {
1279 if (envopt)
goto noenvopt_long;
1285 "invalid option --%s (-h will show valid options)", s);
1297 "invalid option -%c (-h will show valid options)",
1298 (
int)(
unsigned char)*s);
1302 "invalid option -\\x%02X (-h will show valid options)",
1303 (
int)(
unsigned char)*s);
1319 # undef is_option_end 1320 # undef check_envopt 1321 # undef need_argument 1322 # undef is_option_with_arg 1323 # undef is_option_with_optarg 1329 return argc0 -
argc;
1333 ruby_init_prelude(
void)
1340 opt_enc_index(
VALUE enc_name)
1354 #define rb_progname (GET_VM()->progname) 1355 #define rb_orig_progname (GET_VM()->orig_progname) 1370 #define rb_define_readonly_boolean(name, val) \ 1371 rb_define_virtual_variable((name), (val) ? true_value : false_value, 0) 1397 rb_f_sub(
int argc,
VALUE *argv)
1416 rb_f_gsub(
int argc,
VALUE *argv)
1454 rb_f_chomp(
int argc,
VALUE *argv)
1474 int i = (int)proc_options(argc, argv, opt, 0);
1480 const char *
const progname =
1481 (argc > 0 && argv && argv[0] ? argv[0] :
1482 origarg.argc > 0 && origarg.argv && origarg.argv[0] ? origarg.argv[0] :
1498 moreswitches(s, opt, 1);
1500 opt->
src.
enc.name = src_enc_name;
1502 opt->
ext.
enc.name = ext_enc_name;
1508 rb_warning(
"-K is specified; it is for 1.8 compatibility and may cause odd behavior");
1531 char *path =
getenv(
"RUBYPATH");
1556 #elif defined DOSISH 1570 if (opt->
ext.
enc.name != 0) {
1576 if (opt->
src.
enc.name != 0) {
1580 if (opt->
ext.
enc.index >= 0) {
1609 for (i = 0; i <
RARRAY_LEN(load_path); ++i) {
1611 int mark =
rb_attr_get(path, id_initial_load_path_mark) == path;
1614 if (newpath == path)
continue;
1619 if (mark)
rb_ivar_set(path, id_initial_load_path_mark, path);
1630 ruby_init_prelude();
1633 #define SET_COMPILE_OPTION(h, o, name) \ 1634 rb_hash_aset((h), ID2SYM(rb_intern_const(#name)), \ 1635 ((o)->features & FEATURE_BIT(name) ? Qtrue : Qfalse)); 1639 #undef SET_COMPILE_OPTION 1642 process_sflag(&opt->
sflag);
1652 if (opt->
src.
enc.index >= 0) {
1658 if (ienc) eenc = ienc;
1673 base_block = toplevel_context(toplevel_binding);
1679 base_block = toplevel_context(toplevel_binding);
1681 f = open_load_file(script_name, &opt->
xflag);
1682 tree = load_file(parser, opt->
script_name, f, 1, opt);
1687 if (!dump)
return Qtrue;
1690 if (opt->
ext.
enc.index >= 0) {
1707 if (!tree)
return Qfalse;
1709 process_sflag(&opt->
sflag);
1713 printf(
"Syntax OK\n");
1715 if (!dump)
return Qtrue;
1733 if (!dump)
return Qtrue;
1746 base_block = toplevel_context(toplevel_binding);
1754 if (!dump)
return Qtrue;
1769 warn_cr_in_shebang(
const char *str,
long len)
1771 if (str[len-1] ==
'\n' && str[len-2] ==
'\r') {
1772 rb_warn(
"shebang line ending with \\r may cause problems");
1776 #define warn_cr_in_shebang(str, len) (void)0 1788 load_file_internal(
VALUE argp_v)
1793 int script = argp->
script;
1801 CONST_ID(set_encoding,
"set_encoding");
1807 int no_src_enc = !opt->
src.
enc.name;
1808 int no_ext_enc = !opt->
ext.
enc.name;
1820 if (len > 2 && str[0] ==
'#' && str[1] ==
'!') {
1821 if (line_start == 1) warn_cr_in_shebang(str, len);
1839 warn_cr_in_shebang(str, len);
1842 goto search_shebang;
1847 if (*str ==
'\n') *str-- =
'\0';
1848 if (*str ==
'\r') *str-- =
'\0';
1850 if ((p =
strstr(p,
" -")) != 0) {
1852 moreswitches(p + 1, opt, 0);
1858 else if (!
NIL_P(c)) {
1862 if (no_src_enc && opt->
src.
enc.name) {
1866 if (no_ext_enc && opt->
ext.
enc.name) {
1869 if (no_int_enc && opt->
intern.
enc.name) {
1873 else if (!
NIL_P(c)) {
1884 if (opt->
src.
enc.index >= 0) {
1921 open_load_file(
VALUE fname_v,
int *xflag)
1929 if (flen == 1 && fname[0] ==
'-') {
1936 #if defined O_NONBLOCK && HAVE_FCNTL && !(O_NONBLOCK & O_ACCMODE) 1938 # define MODE_TO_LOAD (O_RDONLY | O_NONBLOCK) 1939 #elif defined O_NDELAY && HAVE_FCNTL && !(O_NDELAY & O_ACCMODE) 1940 # define MODE_TO_LOAD (O_RDONLY | O_NDELAY) 1942 # define MODE_TO_LOAD (O_RDONLY) 1945 #if defined DOSISH || defined __CYGWIN__ 1946 # define isdirsep(x) ((x) == '/' || (x) == '\\') 1948 static const char exeext[] =
".exe";
1949 enum {extlen =
sizeof(exeext)-1};
1950 if (flen > extlen && !
isdirsep(fname[flen-extlen-1]) &&
1951 STRNCASECMP(fname+flen-extlen, exeext, extlen) == 0) {
1969 #if defined HAVE_FCNTL && MODE_TO_LOAD != O_RDONLY 1998 restore_load_file(
VALUE arg)
2019 restore_load_file, (
VALUE)&arg);
2039 VALUE f = open_load_file(fname_v, &cmdline_options_init(&opt)->xflag);
2040 return load_file(parser, fname_v, f, 0, &opt);
2055 proc_argv0(
VALUE process)
2080 proc_setproctitle(
VALUE process,
VALUE title)
2082 return ruby_setproctitle(title);
2086 ruby_setproctitle(
VALUE title)
2096 if (origarg.argv == 0)
2103 external_str_new_cstr(
const char *p)
2146 if (uid != euid) opt->
setids |= 1;
2147 if (egid != gid) opt->
setids |= 2;
2148 if (uid && opt->
setids) {
2166 verbose_setter(
VALUE val,
ID id,
void *data)
2168 VALUE *variable = data;
2173 opt_W_getter(
ID id,
void *data)
2175 VALUE *variable = data;
2176 switch (*variable) {
2220 #if defined(USE_DLN_A_OUT) 2221 if (origarg.argc > 0 && origarg.argv)
2222 dln_argv0 = origarg.argv[0];
2223 else if (argc > 0 && argv)
2224 dln_argv0 = argv[0];
2227 for (i = 0; i <
argc; i++) {
2228 VALUE arg = external_str_new_cstr(argv[i]);
2242 if (!origarg.argv || origarg.argc <= 0) {
2243 origarg.argc =
argc;
2244 origarg.argv =
argv;
2249 iseq = process_options(argc, argv, cmdline_options_init(&opt));
2251 #ifndef HAVE_SETPROCTITLE 2255 return (
void*)(
struct RData*)iseq;
2259 fill_standard_fds(
void)
2261 int f0, f1, f2, fds[2];
2267 if (pipe(fds) == 0) {
2276 if (pipe(fds) == 0) {
2278 if (f1 && fds[1] != 1)
2280 if (f2 && fds[1] != 2)
2282 if (fds[1] != 1 && fds[1] != 2)
2301 if (*argc >= 0 && *argv) {
2302 origarg.argc = *
argc;
2303 origarg.argv = *
argv;
2304 #if defined(USE_DLN_A_OUT) 2305 dln_argv0 = origarg.argv[0];
2308 fill_standard_fds();
#define STRNCASECMP(s1, s2, n)
RUBY_EXTERN VALUE rb_cString
void rb_define_global_const(const char *, VALUE)
#define RBASIC_CLEAR_CLASS(obj)
void rb_fatal(const char *fmt,...)
RUBY_EXTERN VALUE rb_mProcess
VALUE rb_parser_dump_tree(NODE *node, int comment)
void rb_warn(const char *fmt,...)
NODE * rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
size_t strlen(const char *)
void rb_update_max_fd(int fd)
#define scan_oct(s, l, e)
const char ruby_exec_prefix[]
void * rb_parser_load_file(VALUE parser, VALUE fname_v)
void ruby_set_inplace_mode(const char *)
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_str_cat(VALUE, const char *, long)
#define INITIAL_LOAD_PATH_MARK
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
NODE * rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
VALUE rb_ary_shift(VALUE ary)
VALUE rb_parser_end_seen_p(VALUE vparser)
#define SET_WHEN_DEBUG(bit)
int rb_enc_dummy_p(rb_encoding *enc)
struct ruby_cmdline_options::@112 ext
VALUE rb_enc_from_encoding(rb_encoding *encoding)
#define DEFINE_DEBUG_FEATURE(bit)
RUBY_EXTERN VALUE rb_stdin
rb_encoding * rb_default_internal_encoding(void)
VALUE rb_ary_push(VALUE ary, VALUE item)
RUBY_EXTERN const int ruby_patchlevel
rb_iseq_t * rb_iseq_new_main(NODE *node, VALUE path, VALUE realpath, const rb_iseq_t *parent)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_str_set_len(VALUE, long)
int rb_gc_for_fd(int err)
void ruby_init_loadpath_safe(int safe_level)
struct ruby_cmdline_options::@112 intern
#define RSTRING_GETMEM(str, ptrvar, lenvar)
void rb_enc_set_default_external(VALUE encoding)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_io_getbyte(VALUE)
VALUE rb_ary_clear(VALUE ary)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
VALUE rb_readlink(VALUE path, rb_encoding *resultenc)
#define M(shortopt, longopt, desc)
#define str_conv_enc(str, from, to)
VALUE rb_io_write(VALUE, VALUE)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
VALUE rb_utf8_str_new_cstr(const char *)
rb_encoding * rb_utf8_encoding(void)
VALUE rb_str_tmp_new(long)
void rb_load_fail(VALUE path, const char *err)
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
VALUE rb_external_str_new_cstr(const char *)
VALUE rb_parser_set_yydebug(VALUE self, VALUE flag)
const char * rb_obj_classname(VALUE)
VALUE rb_gv_set(const char *, VALUE)
void ruby_incpush(const char *path)
VALUE rb_utf8_str_new(const char *, long)
#define RBASIC_SET_CLASS_RAW(obj, cls)
#define RB_TYPE_P(obj, type)
#define set_external_encoding_once(opt, e, elen)
#define MEMZERO(p, type, n)
void rb_set_safe_level(int)
VALUE rb_lastline_get(void)
rb_encoding * rb_default_external_encoding(void)
RUBY_EXTERN VALUE rb_output_rs
VALUE rb_str_encode_ospath(VALUE path)
#define is_option_with_arg(name, allow_hyphen, allow_envopt)
#define RUBY_RELATIVE(path, len)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_parser_encoding(VALUE vparser)
#define SET_WHEN_DUMP(bit)
RUBY_EXTERN char * strstr(const char *, const char *)
#define DEFINE_FEATURE(bit)
#define GetBindingPtr(obj, ptr)
VALUE rb_str_cat2(VALUE, const char *)
#define ECONV_INVALID_REPLACE
void ruby_incpush_expand(const char *path)
#define DEFAULT_RUBYGEMS_ENABLED
void rb_lastline_set(VALUE)
#define IF_UTF8_PATH(t, f)
NODE * rb_parser_append_print(VALUE vparser, NODE *node)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
VALUE rb_parser_set_context(VALUE vparser, const struct rb_block *base, int main)
void rb_gc_register_mark_object(VALUE obj)
void ruby_push_include(const char *path, VALUE(*filter)(VALUE))
ruby_cmdline_options_t * opt
#define LITERAL_NAME_ELEMENT(name)
VALUE rb_str_resize(VALUE, long)
void ruby_set_script_name(VALUE name)
Sets the current script name to this value.
VALUE rb_const_get(VALUE, ID)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_io_fdopen(int, int, const char *)
#define RARRAY_CONST_PTR(a)
VALUE rb_reg_new(const char *, long, int)
VALUE rb_obj_freeze(VALUE)
call-seq: obj.freeze -> obj
VALUE rb_sprintf(const char *format,...)
int ruby_is_fd_loadable(int fd)
void rb_gvar_readonly_setter(VALUE v, ID id, void *d, struct rb_global_variable *g)
void ruby_prog_init(void)
Defines built-in variables.
#define EACH_DEBUG_FEATURES(X, SEP)
void rb_str_modify_expand(VALUE, long)
VALUE rb_ivar_set(VALUE, ID, VALUE)
unsigned char buf[MIME_BUF_SIZE]
void rb_thread_wait_fd(int)
void rb_const_set(VALUE, ID, VALUE)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_vm_top_self(void)
#define set_encoding_part(type)
rb_encoding * rb_locale_encoding(void)
#define EACH_DUMPS(X, SEP)
char * strchr(char *, char)
const char ruby_initial_load_paths[]
#define NAME_MATCH_P(name, str, len)
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
VALUE rb_str_new_cstr(const char *)
struct ruby_cmdline_options::@112 src
VALUE rb_io_ungetbyte(VALUE, VALUE)
void ruby_gc_set_params(int safe_level)
void rb_define_hooked_variable(const char *, VALUE *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
register unsigned int len
#define StringValueCStr(v)
#define ECONV_UNDEF_REPLACE
#define RARRAY_ASET(a, i, v)
VALUE rb_iseq_disasm(const rb_iseq_t *iseq)
#define set_source_encoding_once(opt, e, elen)
VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE *)
#define SET_COMPILE_OPTION(h, o, name)
#define RARRAY_AREF(a, i)
void * ruby_process_options(int argc, char **argv)
void ruby_script(const char *name)
Sets the current script name to this value.
VALUE rb_file_expand_path(VALUE fname, VALUE dname)
void ruby_init_loadpath(void)
void rb_enc_set_default_internal(VALUE encoding)
RUBY_EXTERN char * strerror(int)
void ruby_set_argv(int argc, char **argv)
void rb_warning(const char *fmt,...)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
struct rb_encoding_entry * list
void rb_define_variable(const char *, VALUE *)
VALUE rb_str_cat_cstr(VALUE, const char *)
#define set_internal_encoding_once(opt, e, elen)
#define src_encoding_index
void rb_vm_set_progname(VALUE filename)
VALUE rb_parser_new(void)
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
char * rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
#define StringValuePtr(v)
void ruby_sysinit(int *argc, char ***argv)
Initializes the process for libruby.
void * rb_load_file_str(VALUE fname_v)
RUBY_EXTERN int dup2(int, int)
VALUE rb_str_new_frozen(VALUE)
#define EACH_FEATURES(X, SEP)
#define ruby_show_copyright()
rb_encoding * rb_ascii8bit_encoding(void)
int rb_enc_find_index(const char *name)
#define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg)
#define RSTRING_LENINT(str)
#define CONST_ID(var, str)
RUBY_EXTERN VALUE rb_stdout
#define rb_intern_const(str)
VALUE rb_define_module(const char *name)
void rb_stdio_set_default_encoding(void)
void ruby_init_setproctitle(int argc, char *argv[])
VALUE rb_const_remove(VALUE, ID)
#define rb_define_readonly_boolean(name, val)
struct ruby_cmdline_options::@112::@113 enc
RUBY_EXTERN void setproctitle(const char *fmt,...)
const struct rb_block block
NODE * rb_parser_while_loop(VALUE vparser, NODE *node, int chomp, int split)
void rb_loaderror(const char *fmt,...)
NODE * rb_parser_compile_string(VALUE vparser, const char *f, VALUE s, int line)
int ruby_env_debug_option(const char *str, int len, void *arg)
void rb_w32_sysinit(int *, char ***)
VALUE rb_attr_get(VALUE, ID)
char * strrchr(const char *, const char)
rb_encoding * rb_enc_from_index(int index)
void * rb_load_file(const char *fname)
VALUE rb_str_new(const char *, long)