home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol07 / 03 / debug / figure3.txt < prev   
Text File  |  1992-05-01  |  3KB  |  121 lines

  1.  
  2. #define CHECK(p1,p2)            \
  3. if (42 != p1)                   \
  4.   {                             \
  5.   if (!wBadVariable)            \
  6.     {                           \
  7.     wBadValue = p1;             \
  8.     p1 = 42;                    \
  9.     wBadVariable = p2;          \
  10.     }                           \
  11.   }
  12.  
  13. void AssertTrashedDS ( WORD wAssertValue )
  14. {
  15.   static WORD wQueueValue;   // The next open spot in the queue
  16.   static WORD wQueue[10];    // The actual queue
  17.  
  18.          WORD wBadVariable;
  19.          WORD wBadValue;
  20.  
  21.   //
  22.   // These three lines add the passed in AssertionValue into the queue,
  23.   // and zero out the next spot (which will be displayed as an asterisk)
  24.   //
  25.  
  26.   wQueue[wQueueValue] = wAssertValue;
  27.   wQueueValue = (wQueueValue+1)%10;
  28.   wQueue[wQueueValue] = 0;
  29.  
  30.   //
  31.   // The CHECK macro above will only set the wBadValue and wBadVariable
  32.   // values if no asserion violation has occured.  Since it is possible
  33.   // that multiple assertion variables could have been trashed at the
  34.   // same time, we will continue this loop as long as *any* of the
  35.   // assertion variables are trashed.  Note that the CHECK macro restores
  36.   // the trashed assertion varaible once it has detected it.  This
  37.   // prevents inifinite loops.
  38.   //
  39.  
  40.   do
  41.     {
  42.     // Resetting this varaible makes the assumption that no trashing was done
  43.  
  44.     wBadVariable = 0;
  45.  
  46.     //
  47.     // Check all of the variables.  Remember that once one trashing has been
  48.     // found, the remaining trashed varaibles will remain trashed.  The next
  49.     // iteration of the do-loop will find the next trashed variable, and
  50.     // so on until all trashed variables have been reported.
  51.     //
  52.  
  53.     CHECK(asv1,1);
  54.     CHECK(asv2,2);
  55.     CHECK(asv3,3);
  56.     CHECK(asv4,4);
  57.     CHECK(asv5,5);
  58.     CHECK(asv6,6);
  59.     CHECK(asv7,7);
  60.     CHECK(asv8,8);
  61.     CHECK(asv9,9);
  62.     CHECK(asv10,10);
  63.     CHECK(asv11,11);
  64.  
  65.     //
  66.     // If we actually found a trashing, report it
  67.     //
  68.  
  69.     if (wBadVariable)
  70.       {
  71.       int i;
  72.       char szMsg[255];
  73.       char szMsg1[255];
  74.       char szMsg2[128];
  75.       char szNum[10];
  76.  
  77.       //
  78.       // Generate a string of the queue values, using a "*" for the zero
  79.       // value to indicate the end of the queue
  80.       //
  81.  
  82.       *szMsg1 = 0;
  83.       for ( i = 0; i < 10; i++ )
  84.         {
  85.         if (wQueue[i])
  86.           wsprintf ( szNum, "%d", wQueue[i]);
  87.         else
  88.           lstrcpy ( szNum, "*" );
  89.         if (i != 9)
  90.           lstrcat ( szNum, "," );
  91.         lstrcat ( szMsg1, szNum );
  92.         }
  93.  
  94.       //
  95.       // Create a cute string showing the programmer/unlucky enduser the list
  96.       //
  97.  
  98.       wsprintf ( szMsg, "%s (%s)",
  99.                  (LPSTR)"Assertion Failure",
  100.                  (LPSTR)szMsg1
  101.                );
  102.  
  103.       //
  104.       // Create a caption saying which varaible was trashed, and it's value
  105.       //
  106.  
  107.       wsprintf ( szMsg2, "Assertion Variable asv%d=%d", wBadVariable, wBadValue );
  108.  
  109.       //
  110.       // Alert the programmer/unlucky enduser
  111.       //
  112.  
  113.       MessageBox ( NULL, szMsg, szMsg2, MB_SYSTEMMODAL );
  114.  
  115.       }  // end if bad value
  116.     }
  117.   while (wBadVariable); // Keep doing this until assertion varaibles are clean
  118.  
  119. } // end function
  120.  
  121.