コード例 #1
0
ファイル: python.c プロジェクト: KnoooW/naclports
int nacl_main(int argc, char **argv) {
    if (nacl_startup_untar(argv[0], DATA_FILE, "/"))
      return -1;

    wchar_t **argv_copy;
    /* We need a second copy, as Python might modify the first one. */
    wchar_t **argv_copy2;
    int i, res;
    char *oldloc;
#ifdef __FreeBSD__
    fp_except_t m;
#endif

    argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
    argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
    if (!argv_copy || !argv_copy2) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    /* 754 requires that FP exceptions run in "no stop" mode by default,
     * and until C vendors implement C99's ways to control FP exceptions,
     * Python requires non-stop mode.  Alas, some platforms enable FP
     * exceptions by default.  Here we disable them.
     */
#ifdef __FreeBSD__
    m = fpgetmask();
    fpsetmask(m & ~FP_X_OFL);
#endif

    oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
    if (!oldloc) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    setlocale(LC_ALL, "");
    for (i = 0; i < argc; i++) {
        argv_copy[i] = _Py_char2wchar(argv[i], NULL);
        if (!argv_copy[i]) {
            PyMem_RawFree(oldloc);
            fprintf(stderr, "Fatal Python error: "
                            "unable to decode the command line argument #%i\n",
                            i + 1);
            return 1;
        }
        argv_copy2[i] = argv_copy[i];
    }
    argv_copy2[argc] = argv_copy[argc] = NULL;

    setlocale(LC_ALL, oldloc);
    PyMem_RawFree(oldloc);
    res = Py_Main(argc, argv_copy);
    for (i = 0; i < argc; i++) {
        PyMem_RawFree(argv_copy2[i]);
    }
    PyMem_RawFree(argv_copy);
    PyMem_RawFree(argv_copy2);
    return res;
}
コード例 #2
0
ファイル: nethack_pepper.c プロジェクト: bpd1069/naclports
static void setup_unix_environment(const char* arg0) {
    mkdir("/usr", 0777);
    mkdir("/usr/games", 0777);

    int ret = nacl_startup_untar(arg0, "nethack.tar", "/usr/games");
    if (ret != 0) {
        perror("Startup untar failed.");
        exit(1);
    }

    // Setup config file.
    ret = chdir(getenv("HOME"));
    if (ret != 0) {
        perror("Can change to HOME dir.");
        exit(1);
    }
    if (access(".nethackrc", R_OK) < 0) {
        int fh = open(".nethackrc", O_CREAT | O_WRONLY);
        const char config[] = "OPTIONS=color\n";
        write(fh, config, sizeof(config) - 1);
        close(fh);
    }

    ret = chdir("/usr/games");
    if (ret != 0) {
        perror("Can change to /usr/games.");
        exit(1);
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: KnoooW/naclports
int nacl_main(int argc, char **argv) {
  if (nacl_startup_untar(argv[0], DATA_ARCHIVE, "/"))
    return -1;

  if (argc == 2 && !strcmp(argv[1], "/bin/irb"))
    fprintf(stderr, "Launching irb ...\n");
  ruby_sysinit(&argc, &argv);
  {
    RUBY_INIT_STACK;
    ruby_init();
    return ruby_run_node(ruby_options(argc, argv));
  }
}
コード例 #4
0
ファイル: emacs_pepper.c プロジェクト: 888/naclports
int nacl_main(int argc, char* argv[]) {
  if (nacl_startup_untar(argv[0], "emacs.tar", "/"))
    return 1;
  return nacl_emacs_main(argc, argv);
}
コード例 #5
0
ファイル: nano_pepper.c プロジェクト: KnoooW/naclports
int nacl_main(int argc, char* argv[]) {
  if (nacl_startup_untar(argv[0], "nano.tar", "/"))
    return -1;
  return nacl_nano_main(argc, argv);
}