From 86e3cd0c5ac9d6e8e80306f9f5fdcce4a4c38dc5 Mon Sep 17 00:00:00 2001 From: YX Hao Date: Wed, 15 Feb 2017 21:58:35 +0800 Subject: Add support for Unicode entries 'wmain' and 'wWinMain' on Windows '-run' suported. argvs are converted. But don't use compliled Unicode CLI exe-file to get inputs interactively in other codepage! Please add other compliling supports than 'build-tcc.bat' (Who is good at them). --- win32/lib/crt1.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'win32/lib/crt1.c') diff --git a/win32/lib/crt1.c b/win32/lib/crt1.c index 7a2d765..1e2bd17 100644 --- a/win32/lib/crt1.c +++ b/win32/lib/crt1.c @@ -1,6 +1,9 @@ // ============================================= // crt1.c +// _UNICODE for tchar.h, UNICODE for API +#include + #include #include @@ -18,20 +21,32 @@ typedef struct int newmode; } _startupinfo; -int __cdecl __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*); +#ifdef _UNICODE +#define __tgetmainargs __wgetmainargs +#define _tstart _wstart +#define _tmain wmain +#define _runtmain _runwmain +#else +#define __tgetmainargs __getmainargs +#define _tstart _start +#define _tmain main +#define _runtmain _runmain +#endif + +int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); void __cdecl __set_app_type(int apptype); unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask); -int main(int argc, char * argv[], char * env[]); +extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ int _dowildcard; -void _start(void) +void _tstart(void) { __TRY__ int argc, ret; - char **argv; - char **env; + _TCHAR **argv; + _TCHAR **env; _startupinfo start_info; // Sets the current application type @@ -45,8 +60,28 @@ void _start(void) #endif start_info.newmode = 0; - __getmainargs( &argc, &argv, &env, _dowildcard, &start_info); - ret = main(argc, argv, env); + __tgetmainargs( &argc, &argv, &env, _dowildcard, &start_info); + ret = _tmain(argc, argv, env); + exit(ret); +} + +void _runtmain(int argc0, /* as tcc passed in */ char **argv0) +{ + __TRY__ + int argc, ret; + _TCHAR **argv; + _TCHAR **env; + _startupinfo start_info; + + __set_app_type(_CONSOLE_APP); + +#ifdef __i386 + _controlfp(_PC_53, _MCW_PC); +#endif + + start_info.newmode = 0; + __tgetmainargs( &argc, &argv, &env, _dowildcard, &start_info); + ret = _tmain(argc0, argv + argc - argc0, env); exit(ret); } -- cgit v1.3.1