SDL-1.2.14
[sdl_omap.git] / src / main / symbian / EKA1 / SDL_main.cpp
CommitLineData
e14743d1 1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21*/
22
23/*
24 SDL_main.cpp
25 The Epoc executable startup functions
26
27 Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
28*/
29
30#include <e32std.h>
31#include <e32def.h>
32#include <e32svr.h>
33#include <e32base.h>
34#include <estlib.h>
35#include <stdlib.h>
36#include <stdio.h>
37#include <w32std.h>
38#include <apgtask.h>
39
40#include "SDL_error.h"
41
42#if defined(__WINS__)
43#include <estw32.h>
44IMPORT_C void RegisterWsExe(const TDesC &aName);
45#endif
46
47/* The prototype for the application's main() function */
48#define main SDL_main
49extern "C" int main (int argc, char *argv[], char *envp[]);
50extern "C" void exit (int ret);
51
52
53/* Epoc main function */
54
55#ifdef __WINS__
56
57
58void GetCmdLine(int& aArgc, char**& aArgv)
59 {
60 RChunk chunk;
61
62 if(chunk.OpenGlobal(RThread().Name(), ETrue) != KErrNone)
63 return;
64
65 TUint* ptr = (TUint*) chunk.Base();
66 if(ptr != NULL)
67 {
68 aArgc = (int) *(ptr); // count
69 aArgv = (char**) *(ptr + 1);
70 }
71 chunk.Close();
72 }
73
74#endif
75
76
77TInt E32Main()
78 {
79 /* Get the clean-up stack */
80 CTrapCleanup* cleanup = CTrapCleanup::New();
81
82 /* Arrange for multi-threaded operation */
83 SpawnPosixServerThread();
84
85 /* Get args and environment */
86 int argc=0;
87 char** argv=0;
88 char** envp=0;
89
90#ifndef __WINS__
91 __crt0(argc,argv,envp);
92#else
93 GetCmdLine(argc, argv);
94#endif
95 /* Start the application! */
96
97 /* Create stdlib */
98 _REENT;
99
100 /* Set process and thread priority and name */
101
102 RThread currentThread;
103 RProcess thisProcess;
104 TParse exeName;
105 exeName.Set(thisProcess.FileName(), NULL, NULL);
106 currentThread.Rename(exeName.Name());
107 currentThread.SetProcessPriority(EPriorityLow);
108 currentThread.SetPriority(EPriorityMuchLess);
109
110 /* Call stdlib main */
111 int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */
112
113 /* Call exit */
114 //exit(ret); /* !! process exits here! */
115 //Markus: I do not understand above
116 //I commented it at let this function
117 //to return ret value - was it purpose
118 //that cleanup below is not called at all - why?
119
120 /* Free resources and return */
121
122 _cleanup(); //this is normally called at exit, I call it here, Markus
123
124 CloseSTDLIB();
125 delete cleanup;
126#ifdef __WINS__
127// User::Panic(_L("exit"), ret);
128 // RThread().Kill(ret); //Markus get rid of this thread
129 // RThread().RaiseException(EExcKill);
130#endif
131 return ret;//Markus, or exit(ret); ??
132 //return(KErrNone);
133 }
134
135
136#ifdef __WINS__
137EXPORT_C TInt WinsMain()
138 {
139 return E32Main();
140 // return WinsMain(0, 0, 0);
141 }
142#endif
143
144/* Epoc dll entry point */
145#if defined(__WINS__)
146GLDEF_C TInt E32Dll(TDllReason)
147 {
148 return(KErrNone);
149 }
150#endif
151
152