home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / comm / revrdist.sit / RevRdist / RevRdist src / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-26  |  4.2 KB  |  179 lines  |  [TEXT/KAHL]

  1. /*
  2.  * debug.c - routines to help with debugging
  3.  */
  4.  
  5. #include "RevRdist.h"
  6. #include <TransSkelProto.h>
  7.  
  8. static DialogPtr        dbgDialog;
  9. static Boolean            saveflags = false;    /* true to save Flags */
  10.  
  11. static void dbgEvent (Integer, EventRecord *);
  12. static void dbgClose (void);
  13. static void dbgClobber (void);
  14. static void dbgWatch (void);
  15.  
  16. /*
  17.  *=========================================================================
  18.  * setDebug () - set debug flags via modeless dialog
  19.  * entry:    SkelInit called, but not SkelMain
  20.  * exit:    Flags set
  21.  *=========================================================================
  22.  */
  23. void
  24. setDebug ()
  25. {
  26.     register Integer itemNo;        /* index to dialog items */
  27.     Integer            itemType;        /* for GetDItem call */
  28.     Handle            item;            /* " */
  29.     Rect            r;                /* " */
  30.     Integer            val;            /* value of individual flag bits */
  31.  
  32.     saveflags = false;
  33.     dbgDialog = GetNewDialog (RSRC_BASE+WIND_DFLAGS, nil, (WindowPtr) -1L);
  34.     if (dbgDialog == nil)
  35.         return;
  36.     SkelDialog (dbgDialog, dbgEvent, dbgClose, dbgClobber);
  37.     /*
  38.      * Preset check boxes based on current Flag bit settings
  39.      */
  40.     for (itemNo = 3; itemNo < 3 + 31; itemNo++)
  41.     {
  42.         itemType = -1;
  43.         GetDItem (dbgDialog, itemNo, &itemType, &item, &r);
  44.         if (itemType == (chkCtrl | ctrlItem))
  45.         {
  46.             val = (Flags >> (itemNo - 3)) & 1;
  47.             SetCtlValue ((ControlHandle) item, val);
  48.         }
  49.     }
  50.     ShowWindow ((WindowPtr) dbgDialog);
  51.     SkelBackground (dbgWatch);
  52.     SkelMain ();
  53. }
  54.  
  55.  
  56.  
  57. /*
  58.  *=========================================================================
  59.  * dbgClobber () - get rid of the debug dialog resources
  60.  *=========================================================================
  61.  */
  62. void
  63. dbgClobber ()
  64. {
  65.     if (dbgDialog)
  66.         DisposDialog (dbgDialog);
  67.     dbgDialog = nil;
  68.     SkelWhoa ();
  69. }
  70.  
  71.  
  72. /*
  73.  *=========================================================================
  74.  * dbgClose () - exit the debug dialog
  75.  * entry:    saveflags true if Flags final value should be rewritten to
  76.  *                resource in ourselves.
  77.  * exit:    Flags set based on final control setting in dialog
  78.  *=========================================================================
  79.  */
  80. void
  81. dbgClose ()
  82. {
  83.     Handle            h;                /* ptr to flags resource */
  84.     Integer            itemNo;            /* dialog item number */
  85.     Integer            itemType;        /* dialog item type */
  86.     Handle            item;            /* dialog item */
  87.     Rect            r;                /* needed for GetDItem */
  88.     Integer            val;
  89.  
  90.     Flags = 0;
  91.     for (itemNo = 3; itemNo < 3 + 31; itemNo++)
  92.     {
  93.         itemType = -1;
  94.         GetDItem (dbgDialog, itemNo, &itemType, &item, &r);
  95.         if (itemType == (chkCtrl | ctrlItem))
  96.         {
  97.             val = GetCtlValue ((ControlHandle) item);
  98.             Flags |= val << (itemNo - 3);
  99.         }
  100.     }
  101.     SkelRmveDlog (dbgDialog);
  102.     if (saveflags)
  103.     {
  104.         UseResFile (Ap_refNum);
  105.         h = Get1Resource (TYPE_LONG, FLAG_PARM);
  106.         if (h)
  107.         {
  108.             if (GetHandleSize (h) >= sizeof (Flags))
  109.             {
  110.                 BlockMove ((Ptr) &Flags, *h, sizeof (Flags));
  111.                 ChangedResource (h);
  112.                 WriteResource (h);
  113.             }
  114.             ReleaseResource (h);
  115.         }
  116.         saveflags = false;
  117.     }
  118. }
  119.  
  120.  
  121. /*
  122.  *=========================================================================
  123.  * dbgEvent (itemNo, theEvent) - handle events in debug dialog
  124.  * entry:    itemNo = the item number in dialog
  125.  *            theEvent = ptr to event record significant to dialog
  126.  *=========================================================================
  127.  */
  128. void
  129. dbgEvent (itemNo, theEvent)
  130.     Integer            itemNo;
  131.     EventRecord *    theEvent;
  132. {
  133.     Integer            itemType;        /* dialog item type */
  134.     Handle            item;            /* dialog item structure */
  135.     Rect            r;                /* needed for GetDItem */
  136.     Integer            val;            /* control value */
  137.     Longint            l;                /* temp long value */
  138.  
  139.     saveflags = (itemNo == 2);
  140.     if (itemNo == 1 || itemNo == 2)
  141.     {
  142.         /*
  143.          * Okay button pushed, close dialog
  144.          */
  145.         dbgClose ();
  146.         return;
  147.     }
  148.     /*
  149.      * The only other thing we are interested in is mouse downs in
  150.      * controls
  151.      */
  152.     if (theEvent->what == mouseDown && itemNo > 1)
  153.     {
  154.         itemType = -1;
  155.         GetDItem (dbgDialog, itemNo, &itemType, &item, &r);
  156.         if (itemType == (chkCtrl | ctrlItem))
  157.         {
  158.             val = GetCtlValue ((ControlHandle) item);
  159.             SetCtlValue ((ControlHandle) item, !val);
  160.         }
  161.     }
  162. }
  163.  
  164.  
  165. /*
  166.  *=========================================================================
  167.  * dbgWatch () - watch for Quit
  168.  *=========================================================================
  169.  */
  170. void
  171. dbgWatch ()
  172. {
  173.     if (Quit)
  174.     {
  175.         SkelBackground (nil);
  176.         dbgClose ();
  177.     }
  178. }
  179.