This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update CPANPLUS-Dist-Build to CPAN version 0.52
[perl5.git] / symbian / symbian_utils.cpp
index 4fb13ac..9749361 100644 (file)
@@ -9,14 +9,21 @@
 #define SYMBIAN_UTILS_CPP
 #include <e32base.h>
 #include <e32std.h>
-// #include <textresolver.h> // textresolver not used since seems not to work
 #include <utf.h>
 #include <hal.h>
 
+#include <eikenv.h>
+
 #include <string.h>
 #include <ctype.h>
 
+#include "PerlUi.h"
 #include "PerlBase.h"
+#include "PerlUtil.h"
+
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
 
 extern "C" {
     EXPORT_C int symbian_sys_init(int *argcp, char ***argvp)
@@ -27,11 +34,50 @@ extern "C" {
         (void)times(&PL_timesbase);
         return 0;
     }
+    XS(XS_PerlApp_TextQuery) // Can't be made static because of XS().
+    {
+        dXSARGS;
+       if (items != 0)
+           Perl_croak(aTHX_ "PerlApp::TextQuery: no arguments, please");
+       SP -= items;
+       // TODO: parse arguments for title, prompt, and maxsize.
+       // Suggested syntax:
+       // TextQuery(title => ..., prompt => ..., maxsize => ...)
+       // For an example see e.g. universal.c:XS_PerlIO_get_layers().
+       _LIT(KTitle,  "Title");
+       _LIT(KPrompt, "Prompt");
+        HBufC* cData = HBufC::New(KPerlUiOneLinerSize);
+       TBool cSuccess = EFalse;
+       if (cData) {
+           TPtr cPtr(cData->Des());
+           if (CPerlUi::TextQueryDialogL(KTitle,
+                                         KPrompt,
+                                         cPtr,
+                                         KPerlUiOneLinerSize)) {
+               ST(0) = sv_2mortal(PerlUtil::newSvPVfromTDesC16(*cData));
+               cSuccess = ETrue;
+           }
+           delete cData;
+       }
+       if (cSuccess)
+           XSRETURN(1);
+       else
+           XSRETURN_UNDEF;
+    }
+    EXPORT_C void init_os_extras(void)
+    {
+        dTHX;
+       char *file = __FILE__;
+       dXSUB_SYS;
+       newXS("PerlApp::TextQuery", XS_PerlApp_TextQuery, file);
+    }
     EXPORT_C SSize_t symbian_read_stdin(const int fd, char *b, int n)
     {
 #ifdef PERL_GLOBAL_STRUCT /* Avoid unused variable warning. */
         dVAR;
 #endif
+        if(!PL_appctx)
+               ((CPerlBase*)PL_appctx) = CPerlBase::NewInterpreter();
         return ((CPerlBase*)PL_appctx)->ConsoleRead(fd, b, n);
     }
     EXPORT_C SSize_t symbian_write_stdout(const int fd, const char *b, int n)
@@ -39,6 +85,8 @@ extern "C" {
 #ifdef PERL_GLOBAL_STRUCT /* Avoid unused variable warning. */
         dVAR;
 #endif
+        if(!PL_appctx)
+               ((CPerlBase*)PL_appctx) = CPerlBase::NewInterpreter();
         return ((CPerlBase*)PL_appctx)->ConsoleWrite(fd, b, n);
     }
     static const char NullErr[] = "";
@@ -156,8 +204,13 @@ extern "C" {
         tick -= PL_timesbase.tms_utime;
         TInt64 tickus = TInt64(tick) * TInt64(periodus);
         TInt64 tmps   = tickus / 1000000;
+#ifdef __SERIES60_3X__
+        if (sec)  *sec  = I64LOW(tmps);
+        if (usec) *usec = I64LOW(tickus) - I64LOW(tmps) * 1000000;
+#else
         if (sec)  *sec  = tmps.Low();
         if (usec) *usec = tickus.Low() - tmps.Low() * 1000000;
+#endif //__SERIES60_3X__
         return 0;
     }
     EXPORT_C int symbian_usleep(unsigned int usec)
@@ -185,10 +238,10 @@ extern "C" {
             return tmsbuf->tms_utime;
         }
     }
-    class CE32ProcessWait : public CActive
+    class CProcessWait : public CActive
     {
     public:
-        CE32ProcessWait() : CActive(EPriorityStandard) {
+        CProcessWait() : CActive(EPriorityStandard) {
           CActiveScheduler::Add(this);
         }
 #ifdef __WINS__
@@ -208,7 +261,6 @@ extern "C" {
       void RunL() {
           CActiveScheduler::Stop();
       }
-      CActiveSchedulerWait iWait;
     };
     class CSpawnIoRedirect : public CBase
     {
@@ -244,11 +296,17 @@ extern "C" {
                 error = proc.Create(aFilename,
                                     func,
                                     KStackSize,
+#ifdef __SERIES60_3X__                                    
+                                    KHeapMin,
+                                    KHeapMax,
+                                    (TAny*)command,
+#else
                                     (TAny*)command,
                                     &lib,
                                     RThread().Heap(),
                                     KHeapMin,
                                     KHeapMax,
+#endif                                    
                                     EOwnerProcess);
             else
                 error = KErrNotFound;
@@ -262,7 +320,7 @@ extern "C" {
 #endif
         if (error == KErrNone) {
             if ((TInt)aFlag & (TInt)ESpawnWait) {
-              CE32ProcessWait* w = new CE32ProcessWait();
+              CProcessWait* w = new CProcessWait();
               if (w) {
                   error = w->Wait(proc);
                   delete w;