From 8d1e910e8640660e1b50df1ce4657b3b1de91aaa Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Tue, 19 Nov 2013 03:33:03 -0500 Subject: [PATCH] clean up app entry a bit --- src/freespace2/freespace.cpp | 27 +---------------------- src/freespace2/unixmain.cpp | 42 +++++++++++++++++++++++++----------- src/freespace2/winmain.cpp | 35 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 src/freespace2/winmain.cpp diff --git a/src/freespace2/freespace.cpp b/src/freespace2/freespace.cpp index cdd7401..7d90176 100644 --- a/src/freespace2/freespace.cpp +++ b/src/freespace2/freespace.cpp @@ -6999,7 +6999,7 @@ DCF(pofspew, "") game_spew_pof_info(); } -int PASCAL WinMainSub(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) +int game_main(const char *szCmdLine) { int state, i; @@ -7216,31 +7216,6 @@ int PASCAL WinMainSub(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCm return 1; } -int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) -{ - int result = -1; -#ifndef PLAT_UNIX - __try - { - result = WinMainSub(hInst, hPrev, szCmdLine, nCmdShow); - } - __except(RecordExceptionInfo(GetExceptionInformation(), "Freespace 2 Main Thread")) - { - // Do nothing here - RecordExceptionInfo() has already done - // everything that is needed. Actually this code won't even - // get called unless you return EXCEPTION_EXECUTE_HANDLER from - // the __except clause. - } - return result; -#else - nprintf(("WinMain", "exceptions shall fall through")); - - result = WinMainSub(hInst, hPrev, szCmdLine, nCmdShow); - - return result; -#endif -} - // launcher the fslauncher program on exit void game_launch_launcher_on_exit() { diff --git a/src/freespace2/unixmain.cpp b/src/freespace2/unixmain.cpp index 308a2a5..0452d5b 100644 --- a/src/freespace2/unixmain.cpp +++ b/src/freespace2/unixmain.cpp @@ -1,3 +1,11 @@ +/* + * Copyright (C) Volition, Inc. 1999. All rights reserved. + * + * All source code herein is the property of Volition, Inc. You may not sell + * or otherwise commercially exploit the source or things you created based on + * the source. + */ + #include #include "pstypes.h" @@ -7,7 +15,7 @@ #undef malloc #undef free -int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow); +extern int game_main(const char *szCmdLine); void vm_dump(); @@ -17,28 +25,38 @@ int main(int argc, char **argv) char *argptr = NULL; int i; int len = 0; + int retr = 0; for (i = 1; i < argc; i++) { len += strlen(argv[i]) + 1; } - argptr = (char *)malloc(len+5); + if (len > 0) { + argptr = (char *)malloc(len+5); - if (argptr == NULL) { - fprintf(stderr, "ERROR: out of memory in main!\n"); - exit(1); - } + if (argptr == NULL) { + fprintf(stderr, "ERROR: out of memory in main!\n"); + exit(1); + } - memset(argptr, 0, len+5); + memset(argptr, 0, len+5); - for (i = 1; i < argc; i++) { - strcat(argptr, argv[i]); - strcat(argptr, " "); + for (i = 1; i < argc; i++) { + strcat(argptr, argv[i]); + strcat(argptr, " "); + } } - int retr = WinMain(1, 0, argptr, 0); + try { + retr = game_main(argptr); + } catch(...) { + mprintf(("ERROR!! Exception caught in main()")); + fprintf(stderr, "ERROR!! Exception caught in main()"); + } - free(argptr); + if (argptr) { + free(argptr); + } vm_dump(); diff --git a/src/freespace2/winmain.cpp b/src/freespace2/winmain.cpp new file mode 100644 index 0000000..888ceee --- /dev/null +++ b/src/freespace2/winmain.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) Volition, Inc. 1999. All rights reserved. + * + * All source code herein is the property of Volition, Inc. You may not sell + * or otherwise commercially exploit the source or things you created based on + * the source. + */ + +#include +#include +#include +#include + + +extern int game_main(const char *szCmdLine); + + +int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) +{ + int result = -1; + + __try + { + result = game_main(szCmdLine); + } + __except(RecordExceptionInfo(GetExceptionInformation(), "Freespace 2 Main Thread")) + { + // Do nothing here - RecordExceptionInfo() has already done + // everything that is needed. Actually this code won't even + // get called unless you return EXCEPTION_EXECUTE_HANDLER from + // the __except clause. + } + + return result; +} -- 2.39.2