home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sherlock.zip / DISPATCH.C < prev    next >
C/C++ Source or Header  |  1994-06-29  |  3KB  |  137 lines

  1. /*
  2. **  Sherlock - Copyright 1992, 1993, 1994
  3. **    Harfmann Software
  4. **    Compuserve: 73147,213
  5. **    All rights reserved
  6. */
  7. /*
  8. **  Dispatch a command.  If we have a module loaded, get the
  9. */
  10. #include    <stdlib.h>
  11. #include    <stdio.h>
  12. #include    <sys/stat.h>
  13. #define     INCL_DOSSESMGR
  14. #define     INCL_DOSPROCESS
  15. #include    <os2.h>
  16. #include    "debug.h"
  17.  
  18. #include    "Debugger.h"
  19. #include    "SrcInter.h"
  20. #include    "Source.h"
  21.  
  22. /*
  23. ** Global variables.
  24. */
  25. int FlipScreen = 1;
  26.  
  27. /*
  28. ** Static variables.
  29. */
  30. static int nest = 0;
  31.  
  32. /*
  33. ** Dispatch a command and handle it properly.
  34. */
  35. int _System DispatchCommand(int command)
  36. {
  37. int keepGoing = 1;
  38. int status;
  39. int tmp, active;
  40.  
  41.     if(command == DBG_C_Go ||
  42.        command == DBG_C_SStep ||
  43.        command == DBG_C_RangeStep ||
  44.        command == DBG_C_XchgOpcode)
  45.     active = 1;
  46.     else
  47.     active = 0;
  48.  
  49.     debugBuffer.Cmd = command;
  50.     if(FlipScreen && active)
  51.     DosSelectSession(debugInfo.session);
  52.     while(keepGoing) {
  53.     fflush(logFile);
  54.     if((status = DosDebug(&debugBuffer)) != 0) {
  55.         fprintf(logFile, "COMMAND %d ERROR!: %d\n", command, status);
  56.         exit(1);
  57.     }
  58.     switch(debugBuffer.Cmd) {
  59.             case DBG_N_ModuleLoad:  /* Module loaded    */
  60.         tmp = FlipScreen;
  61.         FlipScreen = 0;
  62.         LoadDebuggeeModule(debugBuffer.Value);
  63.         DispatchCommand(DBG_C_Stop);
  64.         debugBuffer.Cmd = command;
  65.         FlipScreen = tmp;
  66.         break;
  67.  
  68.             case DBG_N_ModuleFree:  /* Module freed     */
  69.         tmp = FlipScreen;
  70.         FlipScreen = 0;
  71.         FreeDebuggeeModule(debugBuffer.Value);
  72.         DispatchCommand(DBG_C_Stop);
  73.         debugBuffer.Cmd = command;
  74.         FlipScreen = tmp;
  75.         break;
  76.  
  77.             case DBG_N_Success:     /* Successful command completion    */
  78.         keepGoing = 0;
  79.                 break;
  80.  
  81.             case DBG_N_Error:       /* Error detected during command    */
  82.                 keepGoing = 0;
  83.                 break;
  84.  
  85.             case DBG_N_ProcTerm:    /* Process termination - DosExitList done   */
  86.                 keepGoing = 0;
  87.                 break;
  88.  
  89.             case DBG_N_Exception:   /* Exception detected               */
  90.                 keepGoing = 0;
  91.         break;
  92.  
  93.             case DBG_N_CoError:     /* Coprocessor not in use error     */
  94.                 keepGoing = 0;
  95.                 break;
  96.  
  97.             case DBG_N_ThreadTerm:  /* Thread termination - not in DosExitList  */
  98.                 keepGoing = 0;
  99.                 break;
  100.  
  101.             case DBG_N_AsyncStop:   /* Async Stop detected              */
  102.                 keepGoing = 0;
  103.                 break;
  104.  
  105.             case DBG_N_NewProc:     /* New Process started      */
  106.                 keepGoing = 0;
  107.                 break;
  108.  
  109.             case DBG_N_AliasFree:   /* Alias needs to be freed  */
  110.                 keepGoing = 0;
  111.                 break;
  112.  
  113.             case DBG_N_Watchpoint:  /* Watchpoint hit           */
  114.                 keepGoing = 0;
  115.                 break;
  116.  
  117.             case DBG_N_ThreadCreate:    /* Thread creation      */
  118.                 keepGoing = 0;
  119.                 break;
  120.  
  121.             case DBG_N_RangeStep:   /* Range Step detected      */
  122.                 keepGoing = 0;
  123.                 break;
  124.         }
  125.     }
  126.  
  127.     /*
  128.     ** Restore the screen if needed.
  129.     */
  130. #ifndef SHERLOCK
  131.     if(FlipScreen && active)
  132.     DosSelectSession(0);
  133. #endif
  134.     nest--;
  135.     return debugBuffer.Cmd;
  136. }
  137.