tccpp: tcc_warning("extra tokens after directive")
[tinycc.git] / win32 / lib / crt1.c
blobe1910813f9ef8729da59743275121b7a766629fb
1 // =============================================
2 // crt1.c
4 // _UNICODE for tchar.h, UNICODE for API
5 #include <tchar.h>
7 #include <windows.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 #define _UNKNOWN_APP 0
12 #define _CONSOLE_APP 1
13 #define _GUI_APP 2
15 #define _MCW_PC 0x00030000 // Precision Control
16 #define _PC_24 0x00020000 // 24 bits
17 #define _PC_53 0x00010000 // 53 bits
18 #define _PC_64 0x00000000 // 64 bits
20 #ifdef _UNICODE
21 #define __tgetmainargs __wgetmainargs
22 #define _tstart _wstart
23 #define _tmain wmain
24 #define _runtmain _runwmain
25 #else
26 #define __tgetmainargs __getmainargs
27 #define _tstart _start
28 #define _tmain main
29 #define _runtmain _runmain
30 #endif
32 typedef struct { int newmode; } _startupinfo;
33 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
34 void __cdecl __set_app_type(int apptype);
35 unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
36 extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
38 #include "crtinit.c"
40 /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
41 int _dowildcard;
43 static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
45 return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
48 void _tstart(void)
50 int ret;
52 _startupinfo start_info = {0};
53 SetUnhandledExceptionFilter(catch_sig);
54 // Sets the current application type
55 __set_app_type(_CONSOLE_APP);
57 // Set default FP precision to 53 bits (8-byte double)
58 // _MCW_PC (Precision control) is not supported on ARM
59 #if defined __i386__ || defined __x86_64__
60 _controlfp(_PC_53, _MCW_PC);
61 #endif
63 __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
64 run_ctors(__argc, __targv, _tenviron);
65 ret = _tmain(__argc, __targv, _tenviron);
66 run_dtors();
67 exit(ret);
70 // =============================================
71 // for 'tcc -run ,,,'
73 __attribute__((weak)) extern int __run_on_exit();
75 int _runtmain(int argc, /* as tcc passed in */ char **argv)
77 int ret;
78 #ifdef UNICODE
79 _startupinfo start_info = {0};
81 __tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info);
82 /* may be wrong when tcc has received wildcards (*.c) */
83 if (argc < __argc) {
84 __targv += __argc - argc;
85 __argc = argc;
87 #else
88 __argc = argc;
89 __targv = argv;
90 #endif
91 #if defined __i386__ || defined __x86_64__
92 _controlfp(_PC_53, _MCW_PC);
93 #endif
94 run_ctors(__argc, __targv, _tenviron);
95 ret = _tmain(__argc, __targv, _tenviron);
96 run_dtors();
97 __run_on_exit(ret);
98 return ret;
101 // =============================================