fs/sys/fsAssert.cpp

Go to the documentation of this file.
00001 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
00002 /*                          _______      ______    ______          __      */
00003 /*  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~    / ____(_)___ / ___ /)  / ____/___  ____/ /__    */
00004 /*      [fsAssert]        / /_  / / __ \\__ \|/  / /   / __ \/ __  / _ \   */
00005 /*       rev. 32         / __/ / / /_/ /__/ /   / /___/ /_/ / /_/ /  __/   */
00006 /*    25th Jan 2007     /_/   /_/ ,___/____/    \____/\____/\__,_/\___/    */
00007 /*     [x] stable              /_/ (c) 2004-7 Filip STOKLAS (FipS)         */
00008 /*  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~       http://HOLE.4FipS.com/fips_code.php          */
00009 /*                                                                         */
00010 /* This code is free for personal and commercial use. You may redistribute */
00011 /* it by any means. If you use the code for your own projects please give  */
00012 /* me credit. Please send a bug report. Don't alter or remove this header! */
00013 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
00014 #include <fs/sys/fsAssert.h>
00015 //---------------------------------------------------------------------------
00016 #if defined(_WIN32)
00017 #   if defined(FS_ASSERT_ENABLE_BOX)
00018 #       include <stdio.h> // string stuff
00019 #   endif
00020 #endif
00021 //---------------------------------------------------------------------------
00022 #if defined(_WIN32)
00023 #   if defined(FS_ASSERT_ENABLE_BOX) || defined(FS_ASSERT_ENABLE_BEEP)
00024 #       include <windows.h> // MessageBox, Beep, process stuff
00025 #   endif
00026 #endif
00027 //---------------------------------------------------------------------------
00028 #if (_MSC_VER >= 1400) // MSVC8
00029 #   pragma warning(disable : 4996) // function was marked as deprecated
00030 #endif
00031 //---------------------------------------------------------------------------
00032 #if defined(_WIN32) && defined(FS_ASSERT_ENABLE_BOX)
00033 namespace {
00035 const char * StripFn(const char *pszPath)
00036 {
00037     const char *p1 = strrchr(pszPath, '/');
00038     const char *p2 = strrchr(pszPath, '\\');
00039     return p1 > p2 ? p1 + 1 : p2 > p1 ? p2 + 1 : pszPath;
00040 }}
00041 #endif
00042 //---------------------------------------------------------------------------
00043 #if defined(_WIN32) && defined(FS_ASSERT_ENABLE_BOX)
00044 bool fs::sys::asr::BoxWin(const char *pszExp, const char *pszMsg,
00045  const char *pszFunc, const char *pszFile, int nLine)
00046 {
00047 #if defined(FS_ASSERT_LABEL)
00048     const char *pszLabel = FS_ASSERT_LABEL;
00049 #else
00050     const char pszLabel[] = "???";
00051 #endif
00052 
00053     char szBuf[1024]; sprintf(szBuf,
00054     
00055      "%s\n" // label
00056      "------------------------------------        \n"
00057      "msg:\t%s\n"
00058      "exp:\t%s\n"
00059      "func:\t%s\n"
00060      "file:\t%s\n"
00061      "line:\t%d\n"
00062      "------------------------------------        \n"
00063      "Would you like to debug now?",
00064      
00065      pszLabel,
00066      pszMsg ? pszMsg : "-",
00067      pszExp ? pszExp : "???",
00068      pszFunc ? pszFunc : "???",
00069      pszFile ? StripFn(pszFile) : "???",
00070      nLine
00071      
00072     );
00073 
00074 #if defined(UNICODE) // especially WinCE
00075 
00076     wchar_t wszBuf[1024]; size_t i = 0; while(i < 1024) { char ch =
00077      szBuf[i]; wszBuf[i] = ch; if(ch == '\0') break; ++i; }
00078 
00079 
00080     if(MessageBox(0, wszBuf, L"ASSERT WARNING",
00081      MB_ICONWARNING | MB_YESNO) == IDYES)
00082         return true;
00083 
00084 #else
00085 
00086     if(MessageBoxA(0, szBuf, "ASSERT WARNING",
00087      MB_ICONWARNING | MB_YESNO) == IDYES)
00088         return true;
00089 
00090 #endif
00091                 
00092     return false;
00093 }
00094 #endif
00095 //---------------------------------------------------------------------------
00096 #if defined(_WIN32) && defined(FS_ASSERT_ENABLE_BEEP)
00097 void fs::sys::asr::BeepWin()
00098 {
00099 #if !defined(UNDER_CE)
00100     Beep(300, 100);
00101 #else
00103     MessageBeep(0xFFFFFFFF);
00104 #endif
00105 }
00106 #endif
00107 //---------------------------------------------------------------------------
00108 #if defined(UNDER_CE) && defined(FS_ASSERT_ENABLE_BOX)
00109 void fs::sys::asr::BreakWce()
00110 {
00111     TerminateProcess(GetCurrentProcess(), 0);
00112 }
00113 #endif
00114 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]