This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Switch most open() calls to three-argument form.
[perl5.git] / symbian / PerlBase.cpp
index 443ae0b..9312abe 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 2004-2005 Nokia. All rights reserved. */
+
 /* The CPerlBase class is licensed under the same terms as Perl itself. */
 
 /* See PerlBase.pod for documentation. */
@@ -55,6 +55,19 @@ CPerlBase::~CPerlBase()
     Destruct();
 }
 
+EXPORT_C CPerlBase* CPerlBase::NewInterpreter(TBool aCloseStdlib,
+                                               void (*aStdioInitFunc)(void*),
+                                               void *aStdioInitCookie)
+{
+   CPerlBase* self = new (ELeave) CPerlBase;
+   self->iCloseStdlib     = aCloseStdlib;
+   self->iStdioInitFunc   = aStdioInitFunc;
+   self->iStdioInitCookie = aStdioInitCookie;
+   self->ConstructL();
+   PERL_APPCTX_SET(self);
+   return self;
+}
+
 EXPORT_C CPerlBase* CPerlBase::NewInterpreterL(TBool aCloseStdlib,
                                                void (*aStdioInitFunc)(void*),
                                                void *aStdioInitCookie)
@@ -193,7 +206,7 @@ EXPORT_C TInt CPerlBase::RunScriptL(const TDesC& aFileName,
     Argv = 0;
     return error == 0 ? KErrNone : KErrGeneral;
 }
-    
+
 
 EXPORT_C int CPerlBase::Parse(int argc, char *argv[], char *envp[])
 {
@@ -230,7 +243,7 @@ EXPORT_C int CPerlBase::Run()
         iState = EPerlRunning;
         int ran = perl_run(iPerl);
         iState = (ran == 0) ? EPerlSuccess : EPerlFailure;
-        return ran; 
+        return ran;
     } else
         return -1;
 }
@@ -264,7 +277,7 @@ int CPerlBase::ConsoleReadLine()
                 iConsoleBuffer[offset++] = 0;
             }
             break;
-        } 
+        }
         else {
             TBool doBackward  = EFalse;
             TBool doBackspace = EFalse;
@@ -318,26 +331,26 @@ int CPerlBase::ConsoleRead(const int fd, char* buf, int n)
         errno = EIO;
         return -1;
     }
-   
+
     if (n < 0) {
         errno = EINVAL;
         return -1;
     }
-    
+
     if (n == 0)
         return 0;
+
     TBuf8<4 * KPerlConsoleBufferMaxTChars> aBufferUtf8;
     TBuf16<KPerlConsoleBufferMaxTChars>    aBufferUtf16;
     int length = ConsoleReadLine();
-    int i;    
+    int i;
 
     iConsoleUsed += length;
 
     aBufferUtf16.SetLength(length);
     for (i = 0; i < length; i++)
         aBufferUtf16[i] = iConsoleBuffer[i];
-    aBufferUtf8.SetLength(4 * length); 
+    aBufferUtf8.SetLength(4 * length);
 
     CnvUtfConverter::ConvertFromUnicodeToUtf8(aBufferUtf8, aBufferUtf16);
 
@@ -351,14 +364,16 @@ int CPerlBase::ConsoleRead(const int fd, char* buf, int n)
 #else
     dTHX;
     for (i = 0; i < nUtf8; i+= UTF8SKIP(pUtf8 + i)) {
-        unsigned long u = utf8_to_uvchr((U8*)(pUtf8 + i), 0);
+        unsigned long u = utf8_to_uvchr_buf((U8*)(pUtf8 + i),
+                                            (U8*)(pUtf8 + nUtf8),
+                                            0);
         if (u > 0xFF) {
             iConsole->Printf(_L("(keycode > 0xFF)\n"));
             buf[i] = 0;
             return -1;
         }
         buf[i] = u;
-    } 
+    }
 #endif
     if (nUtf8 < n)
         buf[nUtf8] = 0;
@@ -388,7 +403,7 @@ int CPerlBase::ConsoleWrite(const int fd, const char* buf, int n)
     dTHX;
     if (is_utf8_string((U8*)buf, n)) {
         for (int i = 0; i < n; i += UTF8SKIP(buf + i)) {
-            TChar u = utf8_to_uvchr((U8*)(buf + i), 0);
+            TChar u = valid_utf8_to_uvchr((U8*)(buf + i), 0);
             iConsole->Printf(_L("%c"), u);
             wrote++;
         }