/Python/frozenmain.c

http://unladen-swallow.googlecode.com/ · C · 68 lines · 52 code · 14 blank · 2 comment · 14 complexity · d56c9c5b1d6541e7138cfb0271551087 MD5 · raw file

  1. /* Python interpreter main program for frozen scripts */
  2. #include "Python.h"
  3. #ifdef MS_WINDOWS
  4. extern void PyWinFreeze_ExeInit(void);
  5. extern void PyWinFreeze_ExeTerm(void);
  6. extern int PyInitFrozenExtensions(void);
  7. #endif
  8. /* Main program */
  9. int
  10. Py_FrozenMain(int argc, char **argv)
  11. {
  12. char *p;
  13. int n, sts;
  14. int inspect = 0;
  15. int unbuffered = 0;
  16. Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
  17. if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
  18. inspect = 1;
  19. if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
  20. unbuffered = 1;
  21. if (unbuffered) {
  22. setbuf(stdin, (char *)NULL);
  23. setbuf(stdout, (char *)NULL);
  24. setbuf(stderr, (char *)NULL);
  25. }
  26. #ifdef MS_WINDOWS
  27. PyInitFrozenExtensions();
  28. #endif /* MS_WINDOWS */
  29. Py_SetProgramName(argv[0]);
  30. Py_Initialize();
  31. #ifdef MS_WINDOWS
  32. PyWinFreeze_ExeInit();
  33. #endif
  34. if (Py_VerboseFlag)
  35. fprintf(stderr, "Python %s\n%s\n",
  36. Py_GetVersion(), Py_GetCopyright());
  37. PySys_SetArgv(argc, argv);
  38. n = PyImport_ImportFrozenModule("__main__");
  39. if (n == 0)
  40. Py_FatalError("__main__ not frozen");
  41. if (n < 0) {
  42. PyErr_Print();
  43. sts = 1;
  44. }
  45. else
  46. sts = 0;
  47. if (inspect && isatty((int)fileno(stdin)))
  48. sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
  49. #ifdef MS_WINDOWS
  50. PyWinFreeze_ExeTerm();
  51. #endif
  52. Py_Finalize();
  53. return sts;
  54. }