home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Python / frozenmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  1.4 KB  |  78 lines

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