mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@63 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de0e5e35ae
commit
01bb9da7ac
12 changed files with 288 additions and 115 deletions
99
ruby.c
99
ruby.c
|
@ -56,12 +56,25 @@ static void forbid_setid _((char *));
|
|||
static VALUE do_loop = FALSE, do_print = FALSE;
|
||||
static VALUE do_check = FALSE, do_line = FALSE;
|
||||
static VALUE do_split = FALSE;
|
||||
|
||||
static int do_search = FALSE;
|
||||
static char *script;
|
||||
static char *e_body;
|
||||
|
||||
static int origargc;
|
||||
static char **origargv;
|
||||
|
||||
#if defined(NeXT) && defined(__DYNAMIC__)
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
extern char *** environ_pointer;
|
||||
#define environ (*environ_pointer)
|
||||
#else
|
||||
#ifndef NT
|
||||
extern char **environ;
|
||||
#endif
|
||||
#endif
|
||||
static char **origenviron;
|
||||
|
||||
extern int sourceline;
|
||||
extern char *sourcefile;
|
||||
|
||||
|
@ -124,7 +137,7 @@ add_modules(mod)
|
|||
}
|
||||
|
||||
void
|
||||
rb_require_modules()
|
||||
ruby_require_modules()
|
||||
{
|
||||
struct req_list *list = req_list;
|
||||
struct req_list *tmp;
|
||||
|
@ -145,7 +158,7 @@ proc_options(argcp, argvp)
|
|||
{
|
||||
int argc = *argcp;
|
||||
char **argv = *argvp;
|
||||
int script_given, do_search;
|
||||
int script_given;
|
||||
char *s;
|
||||
|
||||
if (argc == 0) return;
|
||||
|
@ -219,11 +232,11 @@ proc_options(argcp, argvp)
|
|||
script_given++;
|
||||
if (script == 0) script = "-e";
|
||||
if (argv[1]) {
|
||||
compile_string("-e", argv[1], strlen(argv[1]));
|
||||
e_body = argv[1];
|
||||
argc--,argv++;
|
||||
}
|
||||
else {
|
||||
compile_string("-e", "", 0);
|
||||
e_body = "";
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -365,35 +378,20 @@ proc_options(argcp, argvp)
|
|||
if (argc == 0) { /* no more args */
|
||||
if (verbose == 3) exit(0);
|
||||
script = "-";
|
||||
load_stdin();
|
||||
}
|
||||
else {
|
||||
script = argv[0];
|
||||
if (script[0] == '\0') {
|
||||
script = "-";
|
||||
load_stdin();
|
||||
}
|
||||
else {
|
||||
if (do_search) {
|
||||
char *path = getenv("RUBYPATH");
|
||||
|
||||
script = 0;
|
||||
if (path) {
|
||||
script = dln_find_file(argv[0], path);
|
||||
}
|
||||
if (!script) {
|
||||
script = dln_find_file(argv[0], getenv("PATH"));
|
||||
}
|
||||
if (!script) script = argv[0];
|
||||
}
|
||||
load_file(script, 1);
|
||||
script = argv[0];
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
}
|
||||
if (verbose) verbose = TRUE;
|
||||
|
||||
xflag = FALSE;
|
||||
*argvp = argv;
|
||||
*argcp = argc;
|
||||
|
||||
|
@ -420,6 +418,41 @@ proc_options(argcp, argvp)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
ruby_load_script()
|
||||
{
|
||||
if (script[0] == '-') {
|
||||
if (script[1] == '\0') {
|
||||
load_stdin();
|
||||
}
|
||||
else if (script[1] == 'e') {
|
||||
compile_string("-e", e_body, strlen(e_body));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (do_search) {
|
||||
char *path = getenv("RUBYPATH");
|
||||
char *s = 0;
|
||||
|
||||
if (path) {
|
||||
s = dln_find_file(script, path);
|
||||
}
|
||||
if (!s) {
|
||||
s = dln_find_file(script, getenv("PATH"));
|
||||
}
|
||||
if (s) script = s;
|
||||
}
|
||||
load_file(script, 1);
|
||||
}
|
||||
xflag = FALSE;
|
||||
if (do_print) {
|
||||
yyappend_print();
|
||||
}
|
||||
if (do_loop) {
|
||||
yywhile_loop(do_line, do_split);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_file(fname, script)
|
||||
char *fname;
|
||||
|
@ -514,6 +547,9 @@ load_file(fname, script)
|
|||
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
|
||||
argc = 2; argv[0] = 0; argv[1] = p + 5;
|
||||
proc_options(&argc, &argvp);
|
||||
#if 0
|
||||
proc_sflag(&argc, &argvp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -553,7 +589,7 @@ set_arg0(val, id)
|
|||
int i;
|
||||
static int len;
|
||||
|
||||
if (origargv == 0) Fail("$0 not initialized");
|
||||
if (origargv == 0) ArgError("$0 not initialized");
|
||||
Check_Type(val, T_STRING);
|
||||
if (len == 0) {
|
||||
s = origargv[0];
|
||||
|
@ -563,6 +599,14 @@ set_arg0(val, id)
|
|||
if (origargv[i] == s + 1)
|
||||
s += strlen(++s); /* this one is ok too */
|
||||
}
|
||||
/* can grab env area too? */
|
||||
if (origenviron && origenviron[0] == s + 1) {
|
||||
setenv("NoNe SuCh", "Ruby Compiler :-)", 1);
|
||||
/* force copy of environment */
|
||||
for (i = 0; origenviron[i]; i++)
|
||||
if (origenviron[i] == s + 1)
|
||||
s += strlen(++s);
|
||||
}
|
||||
len = s - origargv[0];
|
||||
}
|
||||
s = RSTRING(val)->ptr;
|
||||
|
@ -729,6 +773,11 @@ ruby_process_options(argc, argv)
|
|||
int i;
|
||||
|
||||
origargc = argc; origargv = argv;
|
||||
#if defined(NeXT) && defined(__DYNAMIC__)
|
||||
_dyld_lookup_and_bind("__environ", (unsigned long*)&environ_pointer, NULL);
|
||||
#endif /* environ */
|
||||
origenviron = environ;
|
||||
|
||||
ruby_script(argv[0]); /* for the time being */
|
||||
rb_argv0 = str_taint(str_new2(argv[0]));
|
||||
#if defined(USE_DLN_A_OUT)
|
||||
|
@ -742,10 +791,4 @@ ruby_process_options(argc, argv)
|
|||
printf("Syntax OK\n");
|
||||
exit(0);
|
||||
}
|
||||
if (do_print) {
|
||||
yyappend_print();
|
||||
}
|
||||
if (do_loop) {
|
||||
yywhile_loop(do_line, do_split);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue