home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-04  |  2.0 KB  |  98 lines

  1. /*
  2.  * Debug ermöglicht das Debuggen von GEM-Programmen.
  3.  * Dazu wird eines der möglichen DEBUGDEVICEs geöffnet und dann
  4.  * kann es wie eine normale Datei für Ausgaben benutzt werden.
  5.  *
  6.  */
  7. #include <stdarg.h>
  8.  
  9. #include "intern.h"
  10.  
  11. int gl_debug = FALSE;
  12.  
  13. static FILE            *debug_handle = NULL;
  14. static DEBUGDEV    device;
  15. static char            progName[25];
  16.                 
  17. void    debug_init(char *prog, DEBUGDEV dev, char *file)
  18. {
  19.     char    devicename[20] = "";
  20.     
  21.     strcpy(progName, prog);
  22.     device = dev;
  23.     switch (dev)
  24.     {
  25.         case Con :
  26.             debug_handle = stdout;
  27.             break;
  28.         case TCon :
  29.             if (appl_find("T-CON   ") > 0)
  30.                 debug_handle = stdout;
  31.             else
  32.                 device = null;
  33.             break;
  34.         case Datei:
  35.             strcpy(devicename, file);
  36.             break;
  37.         case Terminal :
  38.             strcpy(devicename, "u:\\dev\\modem1");
  39.             break;
  40.         case Modem1:
  41.             strcpy(devicename, "u:\\dev\\modem1");
  42.             break;
  43.         case Modem2:
  44.             strcpy(devicename, "u:\\dev\\modem2");
  45.             break;
  46.         case Seriell1:
  47.             strcpy(devicename, "u:\\dev\\serial1");
  48.             break;
  49.         case Seriell2:
  50.             strcpy(devicename, "u:\\dev\\serial2");
  51.             break;
  52.         case Prn:
  53.             strcpy(devicename, "u:\\dev\\prn");
  54.             break;
  55.         default:
  56.             device = null;
  57.             break;
  58.     }
  59.     if (device != null)
  60.         gl_debug = TRUE;
  61.     if (device != null && device != Con && device != TCon)
  62.     {
  63.         if (device == Datei)
  64.             debug_handle = fopen(devicename, "a");
  65.         else
  66.             debug_handle = fopen(devicename, "w");
  67.         if (debug_handle != NULL)
  68.             setvbuf(debug_handle, NULL, _IONBF, 0);
  69.     }
  70.     if (device == Terminal)
  71.         debug("\33[2J\33[0;0H");            /* VT100-Terminal an Modem 1 */
  72. }
  73.  
  74.  
  75. void debug_exit(void)
  76. {
  77.     if (debug_handle != NULL && debug_handle != stdout)
  78.         fclose(debug_handle);
  79.     debug_handle = NULL;
  80.     gl_debug = FALSE;
  81. }
  82.  
  83.  
  84. void debug(char *FormatString, ...)
  85. {
  86.     va_list    arg_ptr;
  87.  
  88.     if (gl_debug)
  89.     {
  90.         fprintf(debug_handle, "%s: ", progName);
  91.         va_start(arg_ptr, FormatString);
  92.         vfprintf(debug_handle, FormatString, arg_ptr);
  93.         va_end(arg_ptr);
  94.         if (device == Datei)
  95.             fflush(debug_handle);
  96.     }
  97. }
  98.