This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to CPAN-1.83_66.
[perl5.git] / symbian / PerlBase.h
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* NewInterpreterL(TBool aCloseStdlib = ETrue,
51                                                void (*aStdioInitFunc)(void*) = NULL,
52                                                void *aStdioInitCookie = NULL);
53     IMPORT_C static CPerlBase* NewInterpreterLC(TBool iCloseStdlib = ETrue,
54                                                 void (*aStdioInitFunc)(void*) = NULL,
55                                                 void *aStdioInitCookie = NULL);
56     IMPORT_C TInt RunScriptL(const TDesC& aFileName, int argc = 2, char **argv = NULL, char *envp[] = NULL);
57     IMPORT_C int  Parse(int argc = 0, char *argv[] = NULL, char *envp[] = NULL);
58     IMPORT_C void SetupExit();
59     IMPORT_C int  Run();
60     IMPORT_C int  ParseAndRun(int argc = 0, char *argv[] = 0, char *envp[] = 0);
61     IMPORT_C void Destruct();
62
63     IMPORT_C PerlInterpreter* GetInterpreter();
64
65     // These two really should be private but when not using PERLIO
66     // certain C callback functions of STDLIB need to be able to call
67     // these.  In general, all the console related functionality is
68     // intentionally hidden and underdocumented.
69     int               ConsoleRead(const int fd, char* buf, int n);
70     int               ConsoleWrite(const int fd, const char* buf, int n);
71
72     // Having these public does not feel right, but maybe someone needs
73     // to do creative things with them.
74     int               (*iReadFunc)(const int fd, char *buf, int n);
75     int               (*iWriteFunc)(const int fd, const char *buf, int n);
76
77    protected:
78     PerlInterpreter*  iPerl;
79 #ifdef PERL_GLOBAL_STRUCT
80     struct perl_vars* iVars;
81 #else
82     void*             iAppCtx;
83 #endif
84     TPerlState        iState;
85
86    private:
87     void              ConstructL();
88     CConsoleBase*     iConsole;         /* The screen. */
89     TUint16*          iConsoleBuffer;   /* The UTF-16 characters. */
90     TUint             iConsoleUsed;     /* How many in iConsoleBuffer. */
91     TBool             iCloseStdlib;     /* Close STDLIB on exit? */
92
93     void              (*iStdioInitFunc)(void *);
94     void*             iStdioInitCookie;
95
96     int               ConsoleReadLine();
97     void              StdioRewire(void*);
98 };
99
100 #define diTHX PerlInterpreter*  my_perl = iPerl
101 #define diVAR struct perl_vars* my_vars = iVars
102
103 #ifdef PERL_GLOBAL_STRUCT
104 #  define PERL_APPCTX_SET(c) ((c)->iVars->Gappctx = (c))
105 #else
106 #  define PERL_APPCTX_SET(c) (PL_appctx = (c))
107 #endif
108
109 #undef Copy
110 #undef CopyD /* For symmetry, not for Symbian reasons. */
111 #undef New
112 #define PerlCopy(s,d,n,t)       (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
113 #define PerlCopyD(s,d,n,t)      (MEM_WRAP_CHECK(n,t), memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
114 #define PerlNew(x,v,n,t)        (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))))
115
116 // This is like the Symbian _LIT() but without the embedded L prefix,
117 // which enables using #defined constants (which need to carry their
118 // own L prefix).
119 #ifndef _LIT_NO_L
120 # define _LIT_NO_L(n, s) static const TLitC<sizeof(s)/2> n={sizeof(s)/2-1,s}
121 #endif // #ifndef _LIT_NO_L
122
123 #endif /* #ifndef __PerlBase_h__ */
124