2005-04-17 17:11:15 +04:00
|
|
|
//+---------------------------------------------------------------------------
|
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
// _UNICODE for tchar.h, UNICODE for API
|
|
|
|
#include <tchar.h>
|
|
|
|
|
2005-04-17 17:11:15 +04:00
|
|
|
#include <windows.h>
|
2013-02-04 19:12:17 +04:00
|
|
|
#include <stdlib.h>
|
2005-04-17 17:11:15 +04:00
|
|
|
|
|
|
|
#define __UNKNOWN_APP 0
|
|
|
|
#define __CONSOLE_APP 1
|
|
|
|
#define __GUI_APP 2
|
|
|
|
void __set_app_type(int);
|
|
|
|
void _controlfp(unsigned a, unsigned b);
|
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
#ifdef _UNICODE
|
|
|
|
#define __tgetmainargs __wgetmainargs
|
|
|
|
#define _twinstart _wwinstart
|
|
|
|
#define _runtwinmain _runwwinmain
|
|
|
|
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
|
|
|
|
#else
|
|
|
|
#define __tgetmainargs __getmainargs
|
|
|
|
#define _twinstart _winstart
|
|
|
|
#define _runtwinmain _runwinmain
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int newmode;
|
|
|
|
} _startupinfo; // CLI Vs GUI
|
|
|
|
|
|
|
|
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
|
|
|
|
|
|
|
|
int _twinstart(void)
|
2005-04-17 17:11:15 +04:00
|
|
|
{
|
2010-10-19 15:15:06 +04:00
|
|
|
__TRY__
|
2017-02-15 16:58:35 +03:00
|
|
|
_TCHAR *szCmd;
|
2009-07-19 00:07:10 +04:00
|
|
|
STARTUPINFO startinfo;
|
|
|
|
int fShow;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
__set_app_type(__GUI_APP);
|
|
|
|
_controlfp(0x10000, 0x30000);
|
|
|
|
|
|
|
|
szCmd = GetCommandLine();
|
|
|
|
if (szCmd) {
|
2017-02-15 16:58:35 +03:00
|
|
|
while (__T(' ') == *szCmd)
|
2009-07-19 00:07:10 +04:00
|
|
|
szCmd++;
|
2017-02-15 16:58:35 +03:00
|
|
|
if (__T('\"') == *szCmd) {
|
2009-07-19 00:07:10 +04:00
|
|
|
while (*++szCmd)
|
2017-02-15 16:58:35 +03:00
|
|
|
if (__T('\"') == *szCmd) {
|
2009-07-19 00:07:10 +04:00
|
|
|
szCmd++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-15 16:58:35 +03:00
|
|
|
while (*szCmd && __T(' ') != *szCmd)
|
2009-07-19 00:07:10 +04:00
|
|
|
szCmd++;
|
|
|
|
}
|
2017-02-15 16:58:35 +03:00
|
|
|
while (__T(' ') == *szCmd)
|
2009-07-19 00:07:10 +04:00
|
|
|
szCmd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetStartupInfo(&startinfo);
|
|
|
|
fShow = startinfo.wShowWindow;
|
|
|
|
if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW))
|
|
|
|
fShow = SW_SHOWDEFAULT;
|
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
ret = _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
|
2009-07-19 00:07:10 +04:00
|
|
|
exit(ret);
|
2005-04-17 17:11:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-18 11:51:23 +03:00
|
|
|
int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
|
2005-04-17 17:11:15 +04:00
|
|
|
{
|
2017-02-15 16:58:35 +03:00
|
|
|
_TCHAR *szCmd, *p;
|
|
|
|
|
2017-02-18 11:51:23 +03:00
|
|
|
#ifdef UNICODE
|
|
|
|
int wargc;
|
|
|
|
_TCHAR **wargv, **wenv;
|
|
|
|
_startupinfo start_info = {0};
|
2017-02-15 16:58:35 +03:00
|
|
|
|
2017-02-18 11:51:23 +03:00
|
|
|
__tgetmainargs(&wargc, &wargv, &wenv, 0, &start_info);
|
|
|
|
if (argc < wargc)
|
|
|
|
wargv += wargc - argc;
|
2017-02-20 20:58:08 +03:00
|
|
|
else
|
|
|
|
argc = wargc;
|
2017-02-18 11:51:23 +03:00
|
|
|
#define argv wargv
|
|
|
|
#endif
|
2009-07-19 00:07:10 +04:00
|
|
|
|
|
|
|
p = GetCommandLine();
|
|
|
|
szCmd = NULL;
|
2017-02-18 11:51:23 +03:00
|
|
|
if (argc > 1)
|
|
|
|
szCmd = _tcsstr(p, argv[1]);
|
2009-07-19 00:07:10 +04:00
|
|
|
if (NULL == szCmd)
|
2017-02-15 16:58:35 +03:00
|
|
|
szCmd = __T("");
|
|
|
|
else if (szCmd > p && szCmd[-1] == __T('\"'))
|
2009-07-19 00:07:10 +04:00
|
|
|
--szCmd;
|
2013-08-29 00:55:05 +04:00
|
|
|
_controlfp(0x10000, 0x30000);
|
2017-02-15 16:58:35 +03:00
|
|
|
return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT);
|
2005-04-17 17:11:15 +04:00
|
|
|
}
|