diff --git a/src/Global.cpp b/src/Global.cpp index 64ad0124..b89d307a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -156,76 +156,6 @@ static const char *g_lamexp_version_raw_time = __TIME__; //Console attached flag static bool g_lamexp_console_attached = false; -//Compiler detection -//The following code was borrowed from MPC-HC project: http://mpc-hc.sf.net/ -#if defined(__INTEL_COMPILER) - #if (__INTEL_COMPILER >= 1300) - static const char *g_lamexp_version_compiler = "ICL 13." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE); - #elif (__INTEL_COMPILER >= 1200) - static const char *g_lamexp_version_compiler = "ICL 12." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE); - #elif (__INTEL_COMPILER >= 1100) - static const char *g_lamexp_version_compiler = "ICL 11.x"; - #elif (__INTEL_COMPILER >= 1000) - static const char *g_lamexp_version_compiler = "ICL 10.x"; - #else - #error Compiler is not supported! - #endif -#elif defined(_MSC_VER) - #if (_MSC_VER == 1700) - #if (_MSC_FULL_VER < 170050727) - static const char *g_lamexp_version_compiler = "MSVC 2012-Beta"; - #elif (_MSC_FULL_VER < 170051020) - static const char *g_lamexp_version_compiler = "MSVC 2012-RTM"; - #elif (_MSC_FULL_VER < 170051106) - static const char *g_lamexp_version_compiler = "MSVC 2012-U1 CTP"; - #elif (_MSC_FULL_VER < 170060315) - static const char *g_lamexp_version_compiler = "MSVC 2012-U1"; - #elif (_MSC_FULL_VER < 170060610) - static const char *g_lamexp_version_compiler = "MSVC 2012-U2"; - #elif (_MSC_FULL_VER == 170060610) - static const char *g_lamexp_version_compiler = "MSVC 2012-U3"; - #else - #error Compiler version is not supported yet! - #endif - #elif (_MSC_VER == 1600) - #if (_MSC_FULL_VER < 160040219) - static const char *g_lamexp_version_compiler = "MSVC 2010-RTM"; - #elif (_MSC_FULL_VER == 160040219) - static const char *g_lamexp_version_compiler = "MSVC 2010-SP1"; - #else - #error Compiler version is not supported yet! - #endif - #elif (_MSC_VER == 1500) - #if (_MSC_FULL_VER >= 150030729) - static const char *g_lamexp_version_compiler = "MSVC 2008-SP1"; - #else - static const char *g_lamexp_version_compiler = "MSVC 2008"; - #endif - #else - #error Compiler is not supported! - #endif - - // Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform - #if !defined(_M_X64) && defined(_M_IX86_FP) - #if (_M_IX86_FP == 1) - LAMEXP_COMPILER_WARNING("SSE instruction set is enabled!") - #elif (_M_IX86_FP == 2) - LAMEXP_COMPILER_WARNING("SSE2 instruction set is enabled!") - #endif - #endif -#else - #error Compiler is not supported! -#endif - -//Architecture detection -#if defined(_M_X64) - static const char *g_lamexp_version_arch = "x64"; -#elif defined(_M_IX86) - static const char *g_lamexp_version_arch = "x86"; -#else - #error Architecture is not supported! -#endif - //Official web-site URL static const char *g_lamexp_website_url = "http://lamexp.sourceforge.net/"; static const char *g_lamexp_support_url = "http://forum.doom9.org/showthread.php?t=157726"; @@ -361,6 +291,83 @@ static FILE *g_lamexp_log_file = NULL; const char* LAMEXP_DEFAULT_LANGID = "en"; const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm"; +/////////////////////////////////////////////////////////////////////////////// +// COMPILER INFO +/////////////////////////////////////////////////////////////////////////////// + +/* + * Disclaimer: Parts of the following code were borrowed from MPC-HC project: http://mpc-hc.sf.net/ + */ + +//Compiler detection +#if defined(__INTEL_COMPILER) + #if (__INTEL_COMPILER >= 1300) + static const char *g_lamexp_version_compiler = "ICL 13." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE); + #elif (__INTEL_COMPILER >= 1200) + static const char *g_lamexp_version_compiler = "ICL 12." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE); + #elif (__INTEL_COMPILER >= 1100) + static const char *g_lamexp_version_compiler = "ICL 11.x"; + #elif (__INTEL_COMPILER >= 1000) + static const char *g_lamexp_version_compiler = "ICL 10.x"; + #else + #error Compiler is not supported! + #endif +#elif defined(_MSC_VER) + #if (_MSC_VER == 1700) + #if (_MSC_FULL_VER < 170050727) + static const char *g_lamexp_version_compiler = "MSVC 2012-Beta"; + #elif (_MSC_FULL_VER < 170051020) + static const char *g_lamexp_version_compiler = "MSVC 2012"; + #elif (_MSC_FULL_VER < 170051106) + static const char *g_lamexp_version_compiler = "MSVC 2012.1-CTP"; + #elif (_MSC_FULL_VER < 170060315) + static const char *g_lamexp_version_compiler = "MSVC 2012.1"; + #elif (_MSC_FULL_VER < 170060610) + static const char *g_lamexp_version_compiler = "MSVC 2012.2"; + #elif (_MSC_FULL_VER == 170060610) + static const char *g_lamexp_version_compiler = "MSVC 2012.3"; + #else + #error Compiler version is not supported yet! + #endif + #elif (_MSC_VER == 1600) + #if (_MSC_FULL_VER < 160040219) + static const char *g_lamexp_version_compiler = "MSVC 2010"; + #elif (_MSC_FULL_VER == 160040219) + static const char *g_lamexp_version_compiler = "MSVC 2010-SP1"; + #else + #error Compiler version is not supported yet! + #endif + #elif (_MSC_VER == 1500) + #if (_MSC_FULL_VER >= 150030729) + static const char *g_lamexp_version_compiler = "MSVC 2008-SP1"; + #else + static const char *g_lamexp_version_compiler = "MSVC 2008"; + #endif + #else + #error Compiler is not supported! + #endif + + // Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform + #if !defined(_M_X64) && defined(_M_IX86_FP) + #if (_M_IX86_FP == 1) + LAMEXP_COMPILER_WARNING("SSE instruction set is enabled!") + #elif (_M_IX86_FP == 2) + LAMEXP_COMPILER_WARNING("SSE2 (or higher) instruction set is enabled!") + #endif + #endif +#else + #error Compiler is not supported! +#endif + +//Architecture detection +#if defined(_M_X64) + static const char *g_lamexp_version_arch = "x64"; +#elif defined(_M_IX86) + static const char *g_lamexp_version_arch = "x86"; +#else + #error Architecture is not supported! +#endif + /////////////////////////////////////////////////////////////////////////////// // GLOBAL FUNCTIONS /////////////////////////////////////////////////////////////////////////////// @@ -414,37 +421,63 @@ QDate lamexp_version_expires(void) return lamexp_version_date().addDays(LAMEXP_DEBUG ? 7 : 30); } +/* + * Convert month string to integer value + */ +static int lamexp_month2int(const char *str) +{ + int ret = 0; + + for(int j = 0; j < 12; j++) + { + if(!_strcmpi(str, g_lamexp_months[j])) + { + ret = j+1; + break; + } + } + + return ret; +} + /* * Get build date date */ const QDate &lamexp_version_date(void) { + //Format of __DATE__ is defined as: "MMM DD YYYY" if(!g_lamexp_version_date.isValid()) { - int date[3] = {0, 0, 0}; char temp[12] = {'\0'}; - strncpy_s(temp, 12, g_lamexp_version_raw_date, _TRUNCATE); + int date[3] = {0, 0, 0}; + char temp_m[4], temp_d[3], temp_y[5]; - if(strlen(temp) == 11) + temp_m[0] = g_lamexp_version_raw_date[0x0]; + temp_m[1] = g_lamexp_version_raw_date[0x1]; + temp_m[2] = g_lamexp_version_raw_date[0x2]; + temp_m[3] = 0x00; + + temp_d[0] = g_lamexp_version_raw_date[0x4]; + temp_d[1] = g_lamexp_version_raw_date[0x5]; + temp_d[2] = 0x00; + + temp_y[0] = g_lamexp_version_raw_date[0x7]; + temp_y[1] = g_lamexp_version_raw_date[0x8]; + temp_y[2] = g_lamexp_version_raw_date[0x9]; + temp_y[3] = g_lamexp_version_raw_date[0xA]; + temp_y[4] = 0x00; + + date[0] = atoi(temp_y); + date[1] = lamexp_month2int(temp_m); + date[2] = atoi(temp_d); + + if((date[0] > 0) && (date[1] > 0) && (date[2] > 0)) { - temp[3] = temp[6] = '\0'; - date[2] = atoi(&temp[4]); - date[0] = atoi(&temp[7]); - - for(int j = 0; j < 12; j++) - { - if(!_strcmpi(&temp[0], g_lamexp_months[j])) - { - date[1] = j+1; - break; - } - } g_lamexp_version_date = QDate(date[0], date[1], date[2]); } - - if(!g_lamexp_version_date.isValid()) + else { - qFatal("Internal error: Date format could not be recognized!"); + throw "Internal error: Date format could not be recognized!"; } }