From 01bb9da7acfeb868eeec4fc20061c57d85b26cf8 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 3 Feb 1998 10:02:57 +0000 Subject: *** empty log message *** git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@63 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 28 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 03b29ff7b8..ed4e653190 100644 --- a/ruby.c +++ b/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 +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); - } } -- cgit v1.2.3