mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 02:30:46 +00:00
Fix program entry point on win32, allows debugging SDL builds under MSVC.
git-svn-id: https://svn.eduke32.com/eduke32@4983 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
5595d41ccd
commit
97f04d8083
3 changed files with 89 additions and 0 deletions
|
@ -30,3 +30,4 @@ extern LPTSTR GetWindowsErrorMsg(DWORD code);
|
|||
extern int32_t addsearchpath_ProgramFiles(const char *p);
|
||||
|
||||
extern int32_t G_GetVersionFromWebsite(char *buffer);
|
||||
extern int32_t win_buildargs(char **argvbuf);
|
|
@ -327,7 +327,11 @@ static void sighandler(int signum)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int32_t nCmdShow)
|
||||
#else
|
||||
int32_t main(int32_t argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int32_t r;
|
||||
|
||||
|
@ -346,6 +350,11 @@ int32_t main(int32_t argc, char *argv[])
|
|||
signal(SIGFPE, sighandler);
|
||||
|
||||
#ifdef _WIN32
|
||||
UNREFERENCED_PARAMETER(hInst);
|
||||
UNREFERENCED_PARAMETER(hPrevInst);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
UNREFERENCED_PARAMETER(nCmdShow);
|
||||
|
||||
win_open();
|
||||
|
||||
if (!CheckWinVersion())
|
||||
|
@ -366,7 +375,23 @@ int32_t main(int32_t argc, char *argv[])
|
|||
maybe_redirect_outputs();
|
||||
baselayer_init();
|
||||
|
||||
#ifdef _WIN32
|
||||
char *argvbuf;
|
||||
int32_t buildargc = win_buildargs(&argvbuf);
|
||||
const char **buildargv = (const char **) Bmalloc(sizeof(char *)*(buildargc+1));
|
||||
char *wp = argvbuf;
|
||||
|
||||
for (int i=0; i<buildargc; i++, wp++)
|
||||
{
|
||||
buildargv[i] = wp;
|
||||
while (*wp) wp++;
|
||||
}
|
||||
buildargv[buildargc] = NULL;
|
||||
|
||||
r = app_main(buildargc, (const char **)buildargv);
|
||||
#else
|
||||
r = app_main(argc, (const char **)argv);
|
||||
#endif
|
||||
|
||||
startwin_close();
|
||||
|
||||
|
|
|
@ -303,6 +303,69 @@ int32_t addsearchpath_ProgramFiles(const char *p)
|
|||
return returncode;
|
||||
}
|
||||
|
||||
int32_t win_buildargs(char **argvbuf)
|
||||
{
|
||||
int32_t buildargc = 0;
|
||||
|
||||
*argvbuf = Bstrdup(GetCommandLine());
|
||||
|
||||
if (*argvbuf)
|
||||
{
|
||||
char quoted = 0, instring = 0, swallownext = 0;
|
||||
char *wp;
|
||||
for (const char *p = wp = *argvbuf; *p; p++)
|
||||
{
|
||||
if (*p == ' ')
|
||||
{
|
||||
if (instring)
|
||||
{
|
||||
if (!quoted)
|
||||
{
|
||||
// end of a string
|
||||
*(wp++) = 0;
|
||||
instring = 0;
|
||||
}
|
||||
else
|
||||
*(wp++) = *p;
|
||||
}
|
||||
}
|
||||
else if (*p == '"' && !swallownext)
|
||||
{
|
||||
if (instring)
|
||||
{
|
||||
if (quoted && p[1] == ' ')
|
||||
{
|
||||
// end of a string
|
||||
*(wp++) = 0;
|
||||
instring = 0;
|
||||
}
|
||||
quoted = !quoted;
|
||||
}
|
||||
else
|
||||
{
|
||||
instring = 1;
|
||||
quoted = 1;
|
||||
buildargc++;
|
||||
}
|
||||
}
|
||||
else if (*p == '\\' && p[1] == '"' && !swallownext)
|
||||
swallownext = 1;
|
||||
else
|
||||
{
|
||||
if (!instring)
|
||||
buildargc++;
|
||||
|
||||
instring = 1;
|
||||
*(wp++) = *p;
|
||||
swallownext = 0;
|
||||
}
|
||||
}
|
||||
*wp = 0;
|
||||
}
|
||||
|
||||
return buildargc;
|
||||
}
|
||||
|
||||
|
||||
// Workaround for a bug in mingwrt-4.0.0 and up where a function named main() in misc/src/libcrt/gdtoa/qnan.c takes precedence over the proper one in src/libcrt/crt/main.c.
|
||||
#if (defined __MINGW32__ && EDUKE32_GCC_PREREQ(4,8)) || EDUKE32_CLANG_PREREQ(3,4)
|
||||
|
|
Loading…
Reference in a new issue