Rev 18 | Go to most recent revision | Details | 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 | |||
| 10 | extern void Harness_Init(int* argc, char* argv[]); |
||
| 11 | extern int original_main(int pArgc, char* pArgv[]); |
||
| 12 | |||
| 13 | int main(int argc, char* argv[]) { |
||
| 14 | #ifdef _WIN32 |
||
| 15 | /* Attach to the console that started us if any */ |
||
| 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 | } |
||
| 21 | |||
| 22 | if (_fileno(stderr) == -2 || _get_osfhandle(_fileno(stderr)) == -2) { |
||
| 23 | freopen("CONOUT$", "w", stderr); |
||
| 24 | } |
||
| 25 | |||
| 26 | if (_fileno(stdin) == -2 || _get_osfhandle(_fileno(stdin)) == -2) { |
||
| 27 | freopen("CONIN$", "r", stdin); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | #endif |
||
| 31 | |||
| 32 | Harness_Init(&argc, argv); |
||
| 33 | |||
| 34 | return original_main(argc, argv); |
||
| 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 | } |
||
| 41 | #endif // _WIN32 |