Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rtmain.h

Go to the documentation of this file.
00001 /*
00002  * rtmain.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  * 
00014  */
00015 
00026 #include "rtsystem.h"
00027 #include "rtstring.h"
00028 #include "rtcollect.h"
00029 #include "rtfile.h"
00030 
00031 // fwd declare: user main function
00039 int rtMain(const lrt::Array<lrt::String> &args);
00040 
00041 
00042 #ifdef __SYMBIAN32__
00043 #include <e32base.h>
00044 #include <e32std.h>
00045 
00046 #include "rtetools.h"
00047 
00048 void ExceptionHandler(TExcType exc)
00049 {
00050         const TText* name; 
00051         switch(exc) {
00052                 case EExcGeneral:               name = _S("Exc-General"); break; 
00053                 case EExcIntegerDivideByZero:   name = _S("Exc-IntDivBy0"); break;
00054                 case EExcSingleStep:            name = _S("Exc-SingleStep"); break; 
00055                 case EExcBreakPoint:            name = _S("Exc-BreakPoint"); break;
00056                 case EExcIntegerOverflow:       name = _S("Exc-IntOverflow"); break; 
00057                 case EExcBoundsCheck:                   name = _S("Exc-BoundsCk"); break; 
00058                 case EExcInvalidOpCode:                 name = _S("Exc-InvOpCode"); break; 
00059                 case EExcDoubleFault:                   name = _S("Exc-DoubleFault"); break; 
00060                 case EExcStackFault:                    name = _S("Exc-StackFault"); break; 
00061                 case EExcAccessViolation:               name = _S("Exc-AccViol"); break; 
00062                 case EExcPrivInstruction:               name = _S("Exc-PrivInst"); break; 
00063                 case EExcAlignment:                     name = _S("Exc-Alignment"); break; 
00064                 case EExcPageFault:                     name = _S("Exc-PageFault"); break; 
00065                 case EExcFloatDenormal:                 name = _S("Exc-FDenorm"); break; 
00066                 case EExcFloatDivideByZero:     name = _S("Exc-FDivBy0"); break; 
00067                 case EExcFloatInexactResult:    name = _S("Exc-FInexRes"); break; 
00068                 case EExcFloatInvalidOperation: name = _S("Exc-FInvOp"); break; 
00069                 case EExcFloatOverflow:                 name = _S("Exc-FOverflow"); break; 
00070                 case EExcFloatStackCheck:               name = _S("Exc-FStackCk"); break; 
00071                 case EExcFloatUnderflow:                name = _S("Exc-FUnderflow"); break; 
00072                 case EExcAbort:                                 name = _S("Exc-Abort"); break; 
00073                 case EExcKill:                                  name = _S("Exc-Kill"); break; 
00074                 case EExcUserInterrupt:                 name = _S("Exc-UserIntr"); break; 
00075                 default: name = _S("Exc-Unknown"); break; 
00076         };
00077         TBuf<16> buf = name;    
00078         
00079         User::Panic(buf, 0); 
00080 }
00081 
00082 GLDEF_C TInt E32Main() // main function called by E32
00083 {
00084         RThread myThread;
00085         myThread.SetExceptionHandler(&ExceptionHandler, 
00086                 KExceptionAbort | KExceptionKill | KExceptionUserInterrupt 
00087                 | KExceptionFpe | KExceptionDebug | KExceptionFault 
00088                 | KExceptionInteger); 
00089         
00090         
00091         lrt::System::cleanup=CTrapCleanup::New(); // get clean-up stack
00092 
00093         RProcess myProcess;
00094         TFileName fn = myProcess.FileName();
00095 #ifndef _UNICODE    // actually: #if Epoc Version 5, but that's impossible
00096         TCommand cmd = myProcess.CommandLine();
00097 #else
00098         TBuf<0x100> cmd;
00099         myProcess.CommandLine(cmd);
00100 #endif
00101         lrt::String cmdLine = MYSTRING(cmd);
00102         cmdLine = cmdLine.trim();
00103         lrt::String file = MYSTRING(fn);
00104         file = file.trim();
00105         if(!file.compareIgnoreCase(cmdLine)) // started (tapped) from System 
00106         {
00107                 cmdLine = lrt::System::readLine("Arguments: ");
00108         }
00109         lrt::File::initialize(file);
00110         lrt::File::setCurrentFolder(lrt::File(file));
00111         lrt::Array<lrt::String> args = cmdLine.split(" ");
00112 
00113         int retval = 0;
00114         TRAPD(error,retval = rtMain(args));
00115         __ASSERT_ALWAYS(!error,User::Panic(_L("LibRT Error"),error));
00116 
00117         if(lrt::System::isInteractive()) {
00118                 lrt::System::println("--- Press any key to exit ---");
00119                 lrt::System::read();
00120         }
00121         lrt::System::exit(retval);
00122 
00123         return 0; // unreachable
00124 }
00125 
00126 #else
00127 
00132 int main(int argn, char **argv) // main function called by Windows et al.
00133 { 
00134         lrt::File::initialize(argv[0]);
00135         lrt::Array<lrt::String>* arr 
00136             = new lrt::Array<lrt::String>(lrt::Math::max(argn-1,0));
00137         for(int i = 1; i < argn; i++)
00138                 (*arr)[i-1] = lrt::String(argv[i]);
00139 
00140         int ret = rtMain(*arr);
00141         delete arr;
00142         lrt::System::exit(ret);
00143         return 0; // unreachable
00144 }
00145 #endif

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer