Rev 18 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 1 | pmbaty | 1 | |
| 2 | #include <stdlib.h> | 
        ||
| 3 | |||
| 4 | #ifdef _WIN32 | 
        ||
| 5 | #include <io.h> | 
        ||
| 6 | #include <stdio.h> | 
        ||
| 7 | #include <windows.h> | 
        ||
| 8 | #endif | 
        ||
| 9 | |||
| 20 | pmbaty | 10 | extern void Harness_Init(int* argc, char* argv[]);  | 
        
| 11 | extern int original_main(int pArgc, char* pArgv[]);  | 
        ||
| 1 | pmbaty | 12 | |
| 20 | pmbaty | 13 | int main(int argc, char* argv[]) {  | 
        
| 1 | pmbaty | 14 | #ifdef _WIN32 | 
        
| 15 |     /* Attach to the console that started us if any */ | 
        ||
| 20 | pmbaty | 16 | if (AttachConsole(ATTACH_PARENT_PROCESS)) {  | 
        
| 17 |         /* We attached successfully, lets redirect IO to the consoles handles if not already redirected */ | 
        ||
| 18 | if (_fileno(stdout) == -2 || _get_osfhandle(_fileno(stdout)) == -2) {  | 
        ||
| 19 | freopen("CONOUT$", "w", stdout);  | 
        ||
| 20 |         } | 
        ||
| 1 | pmbaty | 21 | |
| 20 | pmbaty | 22 | if (_fileno(stderr) == -2 || _get_osfhandle(_fileno(stderr)) == -2) {  | 
        
| 23 | freopen("CONOUT$", "w", stderr);  | 
        ||
| 24 |         } | 
        ||
| 1 | pmbaty | 25 | |
| 20 | pmbaty | 26 | if (_fileno(stdin) == -2 || _get_osfhandle(_fileno(stdin)) == -2) {  | 
        
| 27 | freopen("CONIN$", "r", stdin);  | 
        ||
| 28 |         } | 
        ||
| 29 |     } | 
        ||
| 1 | pmbaty | 30 | #endif | 
        
| 31 | |||
| 20 | pmbaty | 32 | Harness_Init(&argc, argv);  | 
        
| 1 | pmbaty | 33 | |
| 20 | pmbaty | 34 | return original_main(argc, argv);  | 
        
| 1 | pmbaty | 35 | } | 
        
| 36 | |||
| 37 | #ifdef _WIN32 // Pierre-Marie Baty -- missing entrypoint | 
        ||
| 38 | int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {  | 
        ||
| 39 | return main(__argc, __argv);  | 
        ||
| 40 | } | 
        ||
| 20 | pmbaty | 41 | #endif // _WIN32 |