This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Old hosts like NeXT Classic don't have sort -k,
[perl5.git] / epoc / epocish.c
1 /*
2  *    Copyright (c) 1999 Olaf Flebbe o.flebbe@gmx.de
3  *    
4  *    You may distribute under the terms of either the GNU General Public
5  *    License or the Artistic License, as specified in the README file.
6  *
7  */
8
9 /* This is C++ Code !! */
10
11 #include <e32std.h>
12 #include <stdlib.h>
13 #include <estlib.h>
14 #include <string.h>
15
16 extern "C" { 
17
18 #if 1
19 int
20 epoc_spawn( char *cmd, char *cmdline) {
21   RProcess p;
22   TRequestStatus status;
23   TInt rc;
24
25   rc = p.Create( _L( cmd), _L( cmdline));
26   if (rc != KErrNone) {
27     return -1;
28   }
29
30   p.Resume();
31   
32   p.Logon( status);
33   User::WaitForRequest( status);
34   p.Kill( 0);
35   if (status!=KErrNone) {
36     return -1;
37   }
38   return 0;
39 }
40 #else 
41 int
42 epoc_spawn( char *cmd, char *cmdline) {
43   int len = strlen(cmd) + strlen(cmdline) + 4;
44   char *n = (char *) malloc( len);
45   int r;
46   strcpy( n, cmd);
47   strcat( n, " ");
48   strcat( n, cmdline);
49   r = system( n);
50   free( n);
51   return r;
52 }
53 #endif 
54
55 /* Workaround for defect strtoul(). Values with leading + are zero */
56
57 unsigned long int epoc_strtoul(const char *nptr, char **endptr,
58                                int base) {
59   if (nptr && *nptr == '+')
60     nptr++;
61   return strtoul( nptr, endptr, base);
62 }
63
64 /* Workaround for defect atof(), see java defect list for epoc */
65 double epoc_atof( char* str) {
66     TReal64 aRes;
67     
68     while (TChar( *str).IsSpace()) {
69       str++;
70     }
71
72     TLex lex( _L( str));
73     TInt err = lex.Val( aRes, TChar( '.'));
74     return aRes;
75 }
76
77 void epoc_gcvt( double x, int digits, unsigned char *buf) {
78     TRealFormat trel;
79
80     trel.iPlaces = digits;
81     trel.iPoint = TChar( '.');
82
83     TPtr result( buf, 80);
84
85     result.Num( x, trel);
86     result.Append( TChar( 0));
87   }
88 }
89
90 #if 0
91 void epoc_spawn_posix_server() {
92   SpawnPosixServerThread(); 
93 }
94 #endif