Guest User

Untitled

a guest
Apr 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. extern "C"
  2. int
  3. macruby_main(const char *path, int argc, char **argv)
  4. {
  5. char **newargv;
  6. int newargc = 0;
  7.  
  8. char *resourcePath;
  9. char *scriptPath;
  10.  
  11. // get enough memory to add 'resourcePath' and 'scriptPath' to argv
  12. newargv = (char **)malloc(sizeof(char *) * (argc + 2));
  13.  
  14. // we want to remove any arguments that begin with -psn_
  15. // because ..
  16. // TODO: find out why
  17. for (int i = 0; i < argc; ++i) {
  18. if (!(strncmp(argv[i], "-psn_", 5) == 0)) {
  19. // arg doesn't begin with "-psn_" so add it
  20. newargv[newargc] = argv[i];
  21. ++newargc;
  22. }
  23. }
  24.  
  25. // add the bundle resources directory to 'newargc' prefixed with -I
  26. resourcePath = (char *)malloc(PATH_MAX);
  27. newargv[newargc] = (char *)resources_path(resourcePath, PATH_MAX);
  28. ++newargc;
  29.  
  30. // locate the main script in the resources directory
  31. // unless an absolute path is given
  32. scriptPath = (char *)malloc(PATH_MAX);
  33. int pathIsAbsolute = (path[0] == '/');
  34. if (pathIsAbsolute) {
  35. strncpy(scriptPath, path, PATH_MAX);
  36. } else {
  37. // take into account that resourcePath is prefix with -I
  38. snprintf(scriptPath, PATH_MAX, "%s/%s", &resourcePath[2], path);
  39. }
  40. newargv[newargc] = scriptPath;
  41. ++newargc;
  42.  
  43. argv = newargv;
  44. argc = newargc;
  45.  
  46. try {
  47. ruby_sysinit(&argc, &argv);
  48. ruby_init();
  49. void *tree = ruby_options(argc, argv);
  50. rb_vm_init_compiler();
  51. free(newargv);
  52. free(p1);
  53. free(p2);
  54. return ruby_run_node(tree);
  55. }
  56. catch (...) {
  57. rb_vm_print_current_exception();
  58. exit(1);
  59. }
  60. }
Add Comment
Please, Sign In to add comment