home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / xpk / xpk_source / xpkmaster / debug.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  3KB  |  142 lines

  1. #ifndef XPKMASTER_DEBUF_C
  2. #define XPKMASTER_DEBUG_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        debug.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: debug.c 1.7 (21.02.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    the debug stuff
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   20.10.96 : added the external debug modes
  15.  1.2   21.10.96 : changed debug totally
  16.  1.3   01.01.97 : changed output a bit - "XpkM before stuff - find in lots
  17.      of other debuf stuff"
  18.  1.4   09.03.97 : output contained 0 byte - removed
  19.  1.5   01.04.97 : little changes
  20.  1.6   12.04.97 : added TagList output, therefor changed XPKDEBUG contents
  21.  1.7   21.02.98 : uses new style register definition
  22. */
  23.  
  24. #include <exec/types.h>
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/utility.h>
  28. #include <utility/tagitem.h>
  29. #include <dos/var.h>
  30. #include <xpk/xpk.h>
  31. #include "xpkmaster.h"
  32.  
  33. typedef void (*putchtype) ();
  34.  
  35. #define FLAG_ERROR    (1<<0)
  36. #define FLAG_RUNTIME    (1<<1)
  37. #define FLAG_TAGLIST    (1<<2)
  38.  
  39. #if defined(__MAXON__) || defined(__STORM__)
  40.   #define __stdargs
  41. #endif
  42.  
  43. extern LONG __stdargs KPutChar(LONG);
  44. extern LONG __stdargs DPutChar(LONG);
  45. extern void DoDebug(UBYTE mode, STRPTR fmt, APTR data);
  46.  
  47. static ASM(void) serfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  48. { if(c) KPutChar(c); }
  49.  
  50. static ASM(void) parfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  51. { if(c) DPutChar(c); }
  52.  
  53. static ASM(void) normfunc(REG(d0, UBYTE c), REG(a3, ULONG pd))
  54. {
  55.   UBYTE d = c;
  56.   if(c)
  57.     Write(pd, &d, 1);
  58. }
  59.  
  60. void DebugTagList(STRPTR fmt, struct TagItem *taglist)
  61. {
  62.   DoDebug(FLAG_TAGLIST, fmt, taglist);
  63. }
  64.  
  65. void DebugError(STRPTR format, ...)
  66. {
  67.   DoDebug(FLAG_RUNTIME, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  68. }
  69.  
  70. void DebugRunTime(STRPTR format, ...)
  71. {
  72.   DoDebug(FLAG_ERROR, format, (APTR)((ULONG)(&format)+sizeof(STRPTR)));
  73. }
  74.  
  75. void DoDebug(UBYTE mode, STRPTR fmt, APTR data)
  76. {
  77.   ULONG fh = 0, i, Flags = 0;
  78.   UBYTE Mode[5] = "";
  79.   ASM(void) (*function)(REG(d0, UBYTE), REG(a3, ULONG)) = 0;
  80.  
  81.   Forbid();
  82.  
  83.   GetVar("XPKDEBUG", (STRPTR) &Mode, 5, GVF_GLOBAL_ONLY);
  84.  
  85.   for(i=1; Mode[i] && i < 5; ++i)
  86.   {
  87.     switch(Mode[i])
  88.     {
  89.       case 'E': Flags |= FLAG_ERROR; break;
  90.       case 'R': Flags |= FLAG_RUNTIME; break;
  91.       case 'T': Flags |= FLAG_TAGLIST; break;
  92.     }
  93.   }
  94.  
  95.   mode &= Flags;
  96.  
  97.   if(mode)
  98.   {
  99.     switch(Mode[0])
  100.     {
  101.     case 'S': function = serfunc; break;
  102.     case 'P': function = parfunc; break;
  103.     case 'F':
  104.       if((fh = Open("T:XpkMasterOut", MODE_READWRITE)))
  105.       {
  106.         Seek(fh, 0, OFFSET_END);
  107.         function = normfunc;
  108.       }
  109.       break;
  110.     }
  111.     if(function)
  112.     {
  113.       i = (ULONG) FindTask(0);
  114.       RawDoFmt("XpkM(%08lx):", &i, (putchtype) function, (APTR) fh);
  115.  
  116.       RawDoFmt(fmt, data, (putchtype) function, (APTR) fh);
  117.       RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  118.  
  119.       if(mode & FLAG_TAGLIST)
  120.       {
  121.         struct TagItem *ti;
  122.         while((ti = NextTagItem((struct TagItem **) &data)))
  123.         {
  124.           RawDoFmt("   %08lx, %lu", ti, (putchtype) function, (APTR) fh);
  125.           if((ti->ti_Tag == XPK_InName) || (ti->ti_Tag == XPK_OutName) ||
  126.           (ti->ti_Tag == XPK_FileName) || (ti->ti_Tag == XPK_Password) ||
  127.           (ti->ti_Tag == XPK_PackMethod))
  128.             RawDoFmt(" (%s)", &ti->ti_Data, (putchtype) function, (APTR) fh);
  129.           RawDoFmt("\n", 0, (putchtype) function, (APTR) fh);
  130.         }
  131.       }
  132.     }
  133.  
  134.     if(fh)
  135.       Close(fh);
  136.   }
  137.  
  138.   Permit();
  139. }
  140.  
  141. #endif /* XPKMASTER_DEBUG_C */
  142.