static int load_file(mrb_state *mrb, struct mrbc_args *args) { mrbc_context *c; mrb_value result; char *input = args->argv[args->idx]; FILE *infile; c = mrbc_context_new(mrb); if (args->verbose) c->dump_result = 1; c->no_exec = 1; if (input[0] == '-' && input[1] == '\0') { infile = stdin; } else if ((infile = fopen(input, "r")) == NULL) { fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, input); return EXIT_FAILURE; } mrbc_filename(mrb, c, input); args->idx++; if (args->idx < args->argc) { mrbc_partial_hook(mrb, c, partial_hook, (void*)args); } result = mrb_load_file_cxt(mrb, infile, c); if (mrb_undef_p(result) || mrb_fixnum(result) < 0) { mrbc_context_free(mrb, c); return EXIT_FAILURE; } mrbc_context_free(mrb, c); return EXIT_SUCCESS; }
static mrb_value load_file(mrb_state *mrb, struct mrbc_args *args) { mrbc_context *c; mrb_value result; char *input = args->argv[args->idx]; FILE *infile; mrb_bool need_close = FALSE; c = mrbc_context_new(mrb); if (args->verbose) c->dump_result = TRUE; c->no_exec = TRUE; if (input[0] == '-' && input[1] == '\0') { infile = stdin; } else { need_close = TRUE; if ((infile = fopen(input, "r")) == NULL) { fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, input); return mrb_nil_value(); } } mrbc_filename(mrb, c, input); args->idx++; if (args->idx < args->argc) { need_close = FALSE; mrbc_partial_hook(mrb, c, partial_hook, (void*)args); } result = mrb_load_file_cxt(mrb, infile, c); if (need_close) fclose(infile); mrbc_context_free(mrb, c); if (mrb_undef_p(result)) { return mrb_nil_value(); } return result; }