home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmodf.zip / CNTNRPRT.ZIP / DEBUG.CPP < prev    next >
C/C++ Source or Header  |  1994-09-13  |  3KB  |  130 lines

  1. // for the sake of a strcpy, include string.h
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #define INCL_WIN
  6. #define INCL_BASE
  7. //#define INCL_DOSERRORS
  8.  
  9. //#ifndef _ODTYPES_
  10. //#include "ODTypes.h"
  11. //#endif
  12. #include <os2.h>
  13.  
  14. #include "debug.hpp"
  15.  
  16. extern "C" {
  17.    int staticlinkdebughelper;
  18.  
  19.    //--------------------------------------------------------
  20.    VOID EXPENTRY fappend(char* FileName, char* Data)
  21.    {
  22.       HFILE NewFileHandle;
  23.       ULONG ActionTaken=1;
  24.       ULONG BytesWritten;
  25.    
  26.       ULONG  NewLocation;
  27.       if(DosOpen((PSZ)FileName,&NewFileHandle,&ActionTaken,0L,0,0x11,0x00A1,0L)) return;
  28.       DosChgFilePtr(NewFileHandle,0L,2,&NewLocation);
  29.    
  30.         {
  31.         ULONG size =strlen((char*)&Data[0]);
  32.         DosWrite(NewFileHandle,
  33.                  (char*)&Data[0],
  34.                  size,
  35.                  &BytesWritten);
  36.         }
  37.    
  38.       DosClose(NewFileHandle);
  39.    }
  40.    #ifdef SYNCH_CLIB
  41.       CHAR CLibrary;
  42.    #endif
  43.    
  44.    //--------------------------------------------------------
  45.    VOID EXPENTRY vfappendf(char* FileName, char* Format, va_list args)
  46.    {
  47.       char string[270];
  48.    
  49.       string[0]='\0';
  50.       #ifdef SYNCH_CLIB
  51.          EnterMonitor(&CLibrary, 1);
  52.          vsprintf(string,Format,args);
  53.          ExitMonitor(&CLibrary);
  54.       #else
  55.          vsprintf( (char*)string,Format,args);
  56.       #endif
  57.       fappend( FileName, string);
  58.    }
  59.    
  60.    //--------------------------------------------------------
  61.    VOID fprintf2(char* FileName, char* Format, ...)
  62.    {
  63.       va_list args;
  64.    
  65.       va_start(args, Format);
  66.          vfappendf(FileName, Format, args);
  67.       va_end(args);
  68.    }
  69.    
  70.    //--------------------------------------------------------
  71.    VOID EXPENTRY fappenddate( char* FileName)
  72.    {
  73.       DATETIME DateTime;
  74.       USHORT rc;
  75.    
  76.       rc = DosGetDateTime(&DateTime);
  77.       fprintf2(FileName, "[%d-%02d-%02d %2d:%02d:%02d] ",
  78.                       DateTime.year,
  79.                       DateTime.month,
  80.                       DateTime.day,
  81.                       DateTime.hours,
  82.                       DateTime.minutes,
  83.                       DateTime.seconds);
  84.    }
  85.    
  86.    
  87.    
  88.    //--------------------------------------------------------
  89.    VOID rrprintf(char* Format, ...)    /*debug*/
  90.    {
  91.       va_list args;
  92.       char xxx[300];
  93.       strcpy( xxx, Format);
  94.    
  95.       {
  96.          strcat( xxx, "\r\n");
  97.          fappenddate("opendoc.log");
  98.       }
  99.       fappenddate("opendoc.log");
  100.       va_start(args, Format);
  101.          vfappendf("opendoc.log", xxx, args);
  102.       va_end(args);
  103.    }
  104.    
  105.    //--------------------------------------------------------
  106.    VOID beepprintf(char* Format, ...)    /*debug*/
  107.    {
  108.       va_list args;
  109.       char xxx[300];
  110.       strcpy( xxx, Format);
  111.    
  112.       {
  113.          strcat( xxx, "\r\n");
  114.          fappenddate("opendoc.log");
  115.       }
  116.       va_start(args, Format);
  117.          vfappendf("opendoc.log", xxx, args);
  118.       va_end(args);
  119.       DosBeep(200,30);
  120.    }
  121.    void EXPENTRY WinMBox( char* msg )
  122.    {
  123.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
  124.                  (PSZ)msg, /*caption:*/(PSZ)"", /*id?*/5,
  125.                  MB_OK | MB_ERROR
  126.                  );
  127.    }
  128. };
  129.  
  130.