summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-30 12:39:47 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-30 12:39:47 +0000
commit896c0dff6330d461ce428d61df0f60fb8bad07a7 (patch)
treeb35f3dbef1098666a4fb793259af98c5e22adc17
parent287810940070b1c7b0cc915e6728da2f0aaac5e2 (diff)
-e tempfile
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ruby.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/ruby.c b/ruby.c
index 1459ada1cf2..eed46d26575 100644
--- a/ruby.c
+++ b/ruby.c
@@ -81,6 +81,9 @@ extern char *sourcefile;
extern VALUE rb_load_path;
VALUE Frequire();
+static FILE *e_fp;
+static char *e_tmpname;
+
static void
addpath(path)
char *path;
@@ -163,6 +166,7 @@ proc_options(argcp, argvp)
version = FALSE;
do_search = FALSE;
script_given = 0;
+ e_tmpname = NULL;
for (argc--,argv++; argc > 0; argc--,argv++) {
if (argv[0][0] != '-' || !argv[0][1]) break;
@@ -226,15 +230,21 @@ proc_options(argcp, argvp)
case 'e':
forbid_setid("-e");
- script_given++;
- if (script == 0) script = "-e";
- if (argv[1]) {
- compile_string("-e", argv[1], strlen(argv[1]));
- argc--,argv++;
+ if (!e_fp) {
+ e_tmpname = strdup("rbXXXXXX");
+ mktemp(e_tmpname);
+ if (!*e_tmpname)
+ Fatal("Can't mktemp(%s)", e_tmpname);
+ e_fp = fopen(e_tmpname, "w");
+ if (!e_fp)
+ Fatal("Cannot open temporary file: %s", e_tmpname);
+ if (script == 0) script = e_tmpname;
}
- else {
- compile_string("-e", "", 0);
+ if (argv[1]) {
+ fputs(argv[1], e_fp);
+ argc--, argv++;
}
+ putc('\n', e_fp);
break;
case 'r':
@@ -363,6 +373,14 @@ proc_options(argcp, argvp)
switch_end:
if (*argvp[0] == 0) return;
+ if (e_fp) {
+ if (fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
+ Fatal("Cannot write to temp file for -e");
+ e_fp = NULL;
+ argc++, argv--;
+ argv[0] = e_tmpname;
+ }
+
if (version) {
show_version();
exit(0);
@@ -785,4 +803,12 @@ ruby_process_options(argc, argv)
if (do_loop) {
yywhile_loop(do_line, do_split);
}
+ if (e_tmpname) {
+ unlink(e_tmpname);
+ e_tmpname = NULL;
+ }
+ if (e_fp) {
+ fclose(e_fp);
+ e_fp = NULL;
+ }
}