| 1 | /* Copyright (c) 2004-2005 Nokia. All rights reserved. */ |
| 2 | |
| 3 | /* The CPerlBase class is licensed under the same terms as Perl itself. */ |
| 4 | |
| 5 | /* See PerlBase.pod for documentation. */ |
| 6 | |
| 7 | #ifndef __PerlBase_h__ |
| 8 | #define __PerlBase_h__ |
| 9 | |
| 10 | #include <e32base.h> |
| 11 | |
| 12 | #if !defined(PERL_MINIPERL) && !defined(PERL_PERL) |
| 13 | # ifndef PERL_IMPLICIT_CONTEXT |
| 14 | # define PERL_IMPLICIT_CONTEXT |
| 15 | # endif |
| 16 | # ifndef PERL_MULTIPLICITY |
| 17 | # define PERL_MULTIPLICITY |
| 18 | # endif |
| 19 | # ifndef PERL_GLOBAL_STRUCT |
| 20 | # define PERL_GLOBAL_STRUCT |
| 21 | # endif |
| 22 | # ifndef PERL_GLOBAL_STRUCT_PRIVATE |
| 23 | # define PERL_GLOBAL_STRUCT_PRIVATE |
| 24 | # endif |
| 25 | #endif |
| 26 | |
| 27 | #include "EXTERN.h" |
| 28 | #include "perl.h" |
| 29 | |
| 30 | typedef enum { |
| 31 | EPerlNone, |
| 32 | EPerlAllocated, |
| 33 | EPerlConstructed, |
| 34 | EPerlParsed, |
| 35 | EPerlRunning, |
| 36 | EPerlTerminated, |
| 37 | EPerlPaused, |
| 38 | EPerlSuccess, |
| 39 | EPerlFailure, |
| 40 | EPerlDestroying |
| 41 | } TPerlState; |
| 42 | |
| 43 | class PerlConsole; |
| 44 | |
| 45 | class CPerlBase : public CBase |
| 46 | { |
| 47 | public: |
| 48 | CPerlBase(); |
| 49 | IMPORT_C virtual ~CPerlBase(); |
| 50 | IMPORT_C static CPerlBase* NewInterpreter(TBool aCloseStdlib = ETrue, |
| 51 | void (*aStdioInitFunc)(void*) = NULL, |
| 52 | void *aStdioInitCookie = NULL); |
| 53 | IMPORT_C static CPerlBase* NewInterpreterL(TBool aCloseStdlib = ETrue, |
| 54 | void (*aStdioInitFunc)(void*) = NULL, |
| 55 | void *aStdioInitCookie = NULL); |
| 56 | IMPORT_C static CPerlBase* NewInterpreterLC(TBool iCloseStdlib = ETrue, |
| 57 | void (*aStdioInitFunc)(void*) = NULL, |
| 58 | void *aStdioInitCookie = NULL); |
| 59 | IMPORT_C TInt RunScriptL(const TDesC& aFileName, int argc = 2, char **argv = NULL, char *envp[] = NULL); |
| 60 | IMPORT_C int Parse(int argc = 0, char *argv[] = NULL, char *envp[] = NULL); |
| 61 | IMPORT_C void SetupExit(); |
| 62 | IMPORT_C int Run(); |
| 63 | IMPORT_C int ParseAndRun(int argc = 0, char *argv[] = 0, char *envp[] = 0); |
| 64 | IMPORT_C void Destruct(); |
| 65 | |
| 66 | IMPORT_C PerlInterpreter* GetInterpreter(); |
| 67 | |
| 68 | // These two really should be private but when not using PERLIO |
| 69 | // certain C callback functions of STDLIB need to be able to call |
| 70 | // these. In general, all the console related functionality is |
| 71 | // intentionally hidden and underdocumented. |
| 72 | int ConsoleRead(const int fd, char* buf, int n); |
| 73 | int ConsoleWrite(const int fd, const char* buf, int n); |
| 74 | |
| 75 | // Having these public does not feel right, but maybe someone needs |
| 76 | // to do creative things with them. |
| 77 | int (*iReadFunc)(const int fd, char *buf, int n); |
| 78 | int (*iWriteFunc)(const int fd, const char *buf, int n); |
| 79 | |
| 80 | protected: |
| 81 | PerlInterpreter* iPerl; |
| 82 | #ifdef PERL_GLOBAL_STRUCT |
| 83 | struct perl_vars* iVars; |
| 84 | #else |
| 85 | void* iAppCtx; |
| 86 | #endif |
| 87 | TPerlState iState; |
| 88 | |
| 89 | private: |
| 90 | void ConstructL(); |
| 91 | CConsoleBase* iConsole; /* The screen. */ |
| 92 | TUint16* iConsoleBuffer; /* The UTF-16 characters. */ |
| 93 | TUint iConsoleUsed; /* How many in iConsoleBuffer. */ |
| 94 | TBool iCloseStdlib; /* Close STDLIB on exit? */ |
| 95 | |
| 96 | void (*iStdioInitFunc)(void *); |
| 97 | void* iStdioInitCookie; |
| 98 | |
| 99 | int ConsoleReadLine(); |
| 100 | void StdioRewire(void*); |
| 101 | }; |
| 102 | |
| 103 | #define diTHX PerlInterpreter* my_perl = iPerl |
| 104 | #define diVAR struct perl_vars* my_vars = iVars |
| 105 | |
| 106 | #ifdef PERL_GLOBAL_STRUCT |
| 107 | # define PERL_APPCTX_SET(c) ((c)->iVars->Gappctx = (c)) |
| 108 | #else |
| 109 | # define PERL_APPCTX_SET(c) (PL_appctx = (c)) |
| 110 | #endif |
| 111 | |
| 112 | #undef Copy |
| 113 | #undef CopyD /* For symmetry, not for Symbian reasons. */ |
| 114 | #undef New |
| 115 | #define PerlCopy(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))) |
| 116 | #define PerlCopyD(s,d,n,t) (MEM_WRAP_CHECK(n,t), memcpy((char*)(d),(char*)(s), (n) * sizeof(t))) |
| 117 | #define PerlNew(x,v,n,t) (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))) |
| 118 | |
| 119 | // This is like the Symbian _LIT() but without the embedded L prefix, |
| 120 | // which enables using #defined constants (which need to carry their |
| 121 | // own L prefix). |
| 122 | #ifndef _LIT_NO_L |
| 123 | # define _LIT_NO_L(n, s) static const TLitC<sizeof(s)/2> n={sizeof(s)/2-1,s} |
| 124 | #endif // #ifndef _LIT_NO_L |
| 125 | |
| 126 | #endif /* #ifndef __PerlBase_h__ */ |
| 127 | |