home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Palm / PalmGlue / palmglue.c < prev    next >
C/C++ Source or Header  |  2000-12-21  |  2KB  |  88 lines

  1. /* 
  2.  
  3.    Contained are routines necessary for gluing a main palm
  4.    application to the python (.prc) GLib shared library.
  5.  
  6. */
  7.  
  8.  
  9.  
  10. #include <Python.h>
  11. #include <PalmTypes.h>
  12.  
  13. #ifdef PALMOS
  14. #include <node.h>
  15. #include <errcode.h>
  16. #include <grammar.h>
  17. #include <parsetok.h>
  18. #include <compile.h>
  19. #include "palmglue.h"
  20.  
  21. extern grammar _PyParser_Grammar; /* From graminit.c */
  22. struct _frozen *PyImport_FrozenModules;
  23.  
  24. Err errno = 0;
  25.  
  26. void set_flags(f_dbg, f_verbose, f_interact, f_nosite, f_except, 
  27.            f_frozen, f_optimize)
  28.     int f_dbg, f_verbose, f_interact, f_nosite;
  29.     int f_except, f_frozen, f_optimize;
  30. {
  31.     Py_DebugFlag                 = f_dbg;
  32.     Py_VerboseFlag               = f_verbose;
  33.     Py_InteractiveFlag           = f_interact;
  34.     Py_NoSiteFlag                = f_nosite;
  35.     Py_UseClassExceptionsFlag    = f_except;
  36.     Py_FrozenFlag                = f_frozen;
  37.     Py_OptimizeFlag              = f_optimize;
  38. }
  39.  
  40. void set_frozen_tab( struct _frozen *f)
  41. {
  42.     PyImport_FrozenModules = f;
  43. }
  44.  
  45. #ifndef WITHOUT_COMPILER
  46. int testcomplete(char *code)
  47.     /* code should end in \n */
  48.     /* return -1 for error, 0 for incomplete, 1 for complete */
  49. {
  50.     node *n;
  51.     perrdetail e;
  52.     
  53.     n = PyParser_ParseString(code, &_PyParser_Grammar,
  54.                  Py_file_input, &e);
  55.     if (n == NULL) {
  56.         if (e.error == E_EOF) 
  57.             return 0;
  58.         return -1;
  59.     }
  60.     
  61.     PyNode_Free(n);
  62.     return 1;
  63. }
  64.  
  65. int
  66. run_SimpleString(command)
  67.     char *command;
  68. {
  69.     PyObject *m, *d, *v;
  70.     m = PyImport_AddModule("__main__");
  71.     if (m == NULL)
  72.         return -1;
  73.     d = PyModule_GetDict(m);
  74.     v = PyRun_String(command, Py_single_input, d, d);
  75.     if (v == NULL) {
  76.         PyErr_Print();
  77.         return -1;
  78.     }
  79.     Py_DECREF(v);
  80.     if (Py_FlushLine())
  81.         PyErr_Clear();
  82.     return 0;
  83. }
  84. #endif /* WITHOUT_COMPILER */
  85.  
  86. #endif
  87.  
  88.