Skip to content

Commit

Permalink
script file name should not be in ARGV
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Oct 4, 2012
1 parent 0d9b910 commit 70916d0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tools/mruby/mruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void mrb_show_copyright(mrb_state *);
struct _args {
FILE *rfp;
char* cmdline;
int fname : 1;
int mrbfile : 1;
int check_syntax : 1;
int verbose : 1;
Expand Down Expand Up @@ -131,9 +132,14 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)

if (args->rfp == NULL && args->cmdline == NULL) {
if (*argv == NULL) args->rfp = stdin;
else if ((args->rfp = fopen(*argv, args->mrbfile ? "rb" : "r")) == NULL) {
printf("%s: Cannot open program file. (%s)\n", *origargv, *argv);
return 0;
else {
args->rfp = fopen(argv[0], args->mrbfile ? "rb" : "r");
if (args->rfp == NULL) {
printf("%s: Cannot open program file. (%s)\n", *origargv, *argv);
return 0;
}
args->fname = 1;
argc--; argv++;
}
}
args->argv = (char **)mrb_realloc(mrb, args->argv, sizeof(char*) * (argc + 1));
Expand Down Expand Up @@ -202,13 +208,13 @@ main(int argc, char **argv)
if (args.check_syntax)
c->no_exec = 1;

if (args.cmdline) {
mrbc_filename(mrb, c, "-e");
v = mrb_load_string_cxt(mrb, (char*)args.cmdline, c);
if (args.rfp) {
mrbc_filename(mrb, c, args.cmdline ? args.cmdline : "-");
v = mrb_load_file_cxt(mrb, args.rfp, c);
}
else {
mrbc_filename(mrb, c, args.argv[0]);
v = mrb_load_file_cxt(mrb, args.rfp, c);
mrbc_filename(mrb, c, "-e");
v = mrb_load_string_cxt(mrb, args.cmdline, c);
}
mrbc_context_free(mrb, c);
if (mrb->exc) {
Expand Down

0 comments on commit 70916d0

Please sign in to comment.