Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern "C"
- int
- macruby_main(const char *path, int argc, char **argv)
- {
- char **newargv;
- int newargc = 0;
- char *resourcePath;
- char *scriptPath;
- // get enough memory to add 'resourcePath' and 'scriptPath' to argv
- newargv = (char **)malloc(sizeof(char *) * (argc + 2));
- // we want to remove any arguments that begin with -psn_
- // because ..
- // TODO: find out why
- for (int i = 0; i < argc; ++i) {
- if (!(strncmp(argv[i], "-psn_", 5) == 0)) {
- // arg doesn't begin with "-psn_" so add it
- newargv[newargc] = argv[i];
- ++newargc;
- }
- }
- // add the bundle resources directory to 'newargc' prefixed with -I
- resourcePath = (char *)malloc(PATH_MAX);
- newargv[newargc] = (char *)resources_path(resourcePath, PATH_MAX);
- ++newargc;
- // locate the main script in the resources directory
- // unless an absolute path is given
- scriptPath = (char *)malloc(PATH_MAX);
- int pathIsAbsolute = (path[0] == '/');
- if (pathIsAbsolute) {
- strncpy(scriptPath, path, PATH_MAX);
- } else {
- // take into account that resourcePath is prefix with -I
- snprintf(scriptPath, PATH_MAX, "%s/%s", &resourcePath[2], path);
- }
- newargv[newargc] = scriptPath;
- ++newargc;
- argv = newargv;
- argc = newargc;
- try {
- ruby_sysinit(&argc, &argv);
- ruby_init();
- void *tree = ruby_options(argc, argv);
- rb_vm_init_compiler();
- free(newargv);
- free(p1);
- free(p2);
- return ruby_run_node(tree);
- }
- catch (...) {
- rb_vm_print_current_exception();
- exit(1);
- }
- }
Add Comment
Please, Sign In to add comment