mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-26 14:27:14 +00:00
SYMBIAN: Avoid deleting argv if no command line arguments have been set
Also apply style fixes from #3170.
This commit is contained in:
parent
9e67b1ef79
commit
4eb00e965a
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <bacline.h> // CCommandLineArguments
|
||||
#include <bacline.h> // CCommandLineArguments
|
||||
|
||||
#include "backends/platform/symbian/src/portdefs.h"
|
||||
#include "base/main.h"
|
||||
@ -29,32 +29,31 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
// Include the snprintf and vsnprintf implementations as 'C' code
|
||||
// Include the snprintf and vsnprintf implementations as 'C' code.
|
||||
#include "vsnprintf.h"
|
||||
}
|
||||
|
||||
// Symbian SDL_Main implementation
|
||||
// Redirects standard io, creates Symbian specific SDL backend (inherited from main SDL)
|
||||
// Symbian SDL_Main implementation.
|
||||
// Redirects standard io, creates Symbian specific SDL backend (inherited from main SDL).
|
||||
int main(int argc, char *argv[]) {
|
||||
//
|
||||
|
||||
// Set up redirects for stdout/stderr under Symbian.
|
||||
// Code copied from SDL_main.
|
||||
//
|
||||
|
||||
// Symbian does not like any output to the console through any *print* function
|
||||
char STDOUT_FILE[256], STDERR_FILE[256]; // shhh, don't tell anybody :)
|
||||
// Symbian does not like any output to the console through any *print* function.
|
||||
char STDOUT_FILE[256], STDERR_FILE[256]; // Shhh, don't tell anybody :)
|
||||
strcpy(STDOUT_FILE, Symbian::GetExecutablePath());
|
||||
strcpy(STDERR_FILE, Symbian::GetExecutablePath());
|
||||
strcat(STDOUT_FILE, "scummvm.stdout.txt");
|
||||
strcat(STDERR_FILE, "scummvm.stderr.txt");
|
||||
|
||||
/* Flush the output in case anything is queued */
|
||||
// Flush the output in case anything is queued.
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
|
||||
/* Redirect standard input and standard output */
|
||||
// Redirect standard input and standard output.
|
||||
FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
|
||||
if (newfp == NULL) { /* This happens on NT */
|
||||
if (newfp == NULL) { // This happens on NT.
|
||||
#if !defined(stdout)
|
||||
stdout = fopen(STDOUT_FILE, "w");
|
||||
#else
|
||||
@ -65,7 +64,7 @@ int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
}
|
||||
newfp = freopen(STDERR_FILE, "w", stderr);
|
||||
if (newfp == NULL) { /* This happens on NT */
|
||||
if (newfp == NULL) { // This happens on NT.
|
||||
#if !defined(stderr)
|
||||
stderr = fopen(STDERR_FILE, "w");
|
||||
#else
|
||||
@ -75,34 +74,34 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
setbuf(stderr, NULL); /* No buffering */
|
||||
setbuf(stderr, NULL); // No buffering.
|
||||
|
||||
// Create our OSystem instance
|
||||
// Create our OSystem instance.
|
||||
g_system = new OSystem_SDL_Symbian();
|
||||
assert(g_system);
|
||||
|
||||
// Pre initialize the backend
|
||||
// Pre initialize the backend.
|
||||
g_system->init();
|
||||
|
||||
#ifdef DYNAMIC_MODULES
|
||||
PluginManager::instance().addPluginProvider(new SDLPluginProvider());
|
||||
#endif
|
||||
|
||||
// catch input params and pass to argv/argc
|
||||
// Catch input params and pass to argv/argc.
|
||||
CCommandLineArguments *cmdline = CCommandLineArguments::NewL();
|
||||
if (!cmdline) {
|
||||
error("Failure to alloc CCommandLineArguments!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
argc = cmdline->Count();
|
||||
if (argc > 1) {
|
||||
debug("console arg count by CCommandLineArguments: %d", argc);
|
||||
argv = new char* [argc];
|
||||
HBufC8 *buf = HBufC8::NewMax(20); //this suffice for most cases
|
||||
HBufC8 *buf = HBufC8::NewMax(20); // This should suffice for most cases.
|
||||
for (TInt i = 0; i < argc; ++i) {
|
||||
TPtrC arg = cmdline->Arg(i);
|
||||
argv[i] = new char[arg.Length() + 1](); //hold zero terminated string
|
||||
argv[i] = new char[arg.Length() + 1](); // Hold zero terminated string.
|
||||
if (arg.Length() > buf->Length())
|
||||
buf->ReAlloc(arg.Length());
|
||||
|
||||
@ -117,14 +116,16 @@ int main(int argc, char *argv[]) {
|
||||
// Invoke the actual ScummVM main entry point:
|
||||
int res = scummvm_main(argc, argv);
|
||||
|
||||
// clear argv
|
||||
for (TInt i = 0; i < argc; ++i) {
|
||||
delete[] argv[i];
|
||||
// Clear argv.
|
||||
if (argc > 1) { //avoid multiple User 42 panics at exit
|
||||
for (TInt i = 0; i < argc; ++i) {
|
||||
delete[] argv[i];
|
||||
}
|
||||
delete[] argv;
|
||||
}
|
||||
delete[] argv;
|
||||
delete cmdline;
|
||||
|
||||
// Free OSystem
|
||||
// Free OSystem.
|
||||
g_system->destroy();
|
||||
|
||||
return res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user