1 /************************************************************************** 2 Copyright: 3 (C) 2008 - 2012 Alexander Shaduri <ashaduri 'at' gmail.com> 4 License: See LICENSE_gsmartcontrol.txt 5 ***************************************************************************/ 6 /// \file 7 /// \author Alexander Shaduri 8 /// \ingroup gsc 9 /// \weakgroup gsc 10 /// @{ 11 12 #include <iostream> // cerr 13 #include <exception> // std::exception, std::set_terminate() 14 #include <cstdlib> // EXIT_* 15 16 #include "hz/hz_config.h" // HAVE_VERBOSE_TERMINATE_HANDLER 17 #include "hz/win32_tools.h" // hz::win32_* 18 19 #include "gsc_init.h" // app_init_and_loop() 20 21 22 23 /// Application main function main(int argc,char * argv[])24int main(int argc, char* argv[]) 25 { 26 // we still leave __GNUC__ for autoconf-less setups. 27 #if defined HAVE_VERBOSE_TERMINATE_HANDLER && HAVE_VERBOSE_TERMINATE_HANDLER 28 // Verbose uncaught exception handler 29 std::set_terminate(__gnu_cxx::__verbose_terminate_handler); 30 #else 31 try { 32 #endif 33 34 // disable "Send to MS..." dialog box in non-debug builds 35 #if defined _WIN32 && !(defined DEBUG_BUILD && DEBUG_BUILD) 36 SetErrorMode(SEM_FAILCRITICALERRORS); 37 #endif 38 39 // debug builds already have a console, no need to create one. 40 #if defined _WIN32 && !(defined DEBUG_BUILD && DEBUG_BUILD) 41 // if the console is not open, or unsupported (win2k), use files. 42 if (!hz::win32_redirect_stdio_to_console()) { // redirect stdout/stderr to console (if open and supported) 43 hz::win32_redirect_stdio_to_files(); // redirect stdout/stderr to output files 44 } 45 #endif 46 47 // initialize stuff and enter the main loop 48 if (!app_init_and_loop(argc, argv)) 49 return EXIT_FAILURE; 50 51 52 // print uncaught exceptions for non-gcc-compatible 53 #if !(defined HAVE_VERBOSE_TERMINATE_HANDLER && HAVE_VERBOSE_TERMINATE_HANDLER) 54 } 55 catch(std::exception& e) { 56 // don't use anything other than cerr here, it's the most safe option. 57 std::cerr << "main(): Unhandled exception: " << e.what() << std::endl; 58 59 return EXIT_FAILURE; 60 } 61 catch(...) { // this guarantees proper unwinding in case of unhandled exceptions (win32 I think) 62 std::cerr << "main(): Unhandled unknown exception." << std::endl; 63 64 return EXIT_FAILURE; 65 } 66 #endif 67 68 return EXIT_SUCCESS; 69 } 70 71 72 73 74 75 76 77 /// @} 78