home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / a_debug.cpp next >
C/C++ Source or Header  |  2002-12-08  |  1KB  |  45 lines

  1. /* a_debug.h */
  2. /* Σπ¡¬µ¿¿ ñ½∩ πßΓαá¿óá¡¿∩ «τ¡δσ ßΓá󫬠*/
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. static char DebugFname[]="debug.log";
  7. static int mode = 0; /* 0- ºá»¿ß∞, 1- »α«óÑα¬á */
  8. static FILE *fp = NULL;
  9.  
  10. void _Optlink DebugClose(void)
  11. {  fclose(fp);
  12. }
  13.  
  14. static int OpenDebug(void)
  15. {  if(mode==0)
  16.        fp = fopen(DebugFname,"wb");
  17.    else
  18.        fp = fopen(DebugFname,"rb");
  19.    if(fp == NULL)
  20.       perror("Could not open file");
  21.    atexit(DebugClose);
  22.    return 0;
  23. }
  24.  
  25. int debug_write(int *buff, int n)
  26. {  static int raz=0;
  27.    if(fp == NULL) OpenDebug();
  28.    if(mode == 0)
  29.    {  fwrite(buff,sizeof(int),n,fp);
  30.       fflush(fp);
  31.    } else {
  32.       int i, buff1[1024];
  33.       fread(buff1,sizeof(int),n,fp);
  34.       for(i=0;i<n;i++)
  35.       {  if(buff[i] != buff1[i])
  36.          {  printf("Diff!!!! at %i element of %i iteration %i != %i\n",i,raz,buff[i],buff1[i]);
  37.             exit(1);
  38.          }
  39.       }
  40.    }
  41.    printf("%i\n",raz); fflush(stdout);
  42.    raz++;
  43.    return 0;
  44. }
  45.