home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / Sysmon / src / ExcptTest.c < prev    next >
C/C++ Source or Header  |  2000-08-02  |  3KB  |  88 lines

  1. /*
  2. **    $RCSfile: ExcptTest.c,v $
  3. **    $Filename: ExcptTest.c $
  4. **    $Revision: 1.0 $
  5. **    $Date: 2000/08/01 15:25:03 $
  6. **
  7. **    sysmon.library silly Exception Test program (version 1.0)
  8. **    
  9. **    (C) Copyright 2000 by Etienne Vogt
  10. */
  11.  
  12. #define __USE_SYSBASE
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include "sysmon.h"
  18. #include "sysmon_protos.h"
  19. #include "sysmon_pragmas.h"
  20.  
  21. struct SysmonBase *SysmonBase;
  22.  
  23. /* Global variables shared with exception code */
  24. struct Process *myproc;
  25. volatile BOOL done = FALSE;    /* Don't optimize this, please */
  26. APTR oldexcept;
  27.  
  28. /* Prototypes */
  29. int main(void);
  30. static void cleanexit(int rc);
  31. static ULONG __saveds __asm myexcept(register __d0 ULONG excptsigs, register __a1 APTR excptdata);
  32.  
  33. static UBYTE version[] = "$VER: ExcptTest 1.0 (2.8.2000)";
  34.  
  35. int main(void)
  36.   SysmonBase = NULL;
  37.   myproc = (struct Process *)FindTask(NULL);
  38.  
  39.   if ((SysmonBase = (struct SysmonBase *)OpenLibrary("sysmon.library",1)) == NULL)
  40.   { PutStr("ExcptTest: Couldn't open sysmon.library V1\n");
  41.     cleanexit(20);
  42.   }
  43.  
  44.   smDisallowExcept();            /* Block exceptions for now */
  45.   oldexcept = myproc->pr_Task.tc_ExceptCode;
  46.   myproc->pr_Task.tc_ExceptCode = (APTR)myexcept;    /* Set our exception code */
  47.   SetExcept(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F); /* Activate CTRL_C and CTRL_F as exception signals */
  48.   smAllowExcept();            /* Exceptions now allowed */
  49.  
  50.   PutStr("Sleeping, Type CTRL_C or CTRL_F to quit\n");
  51.  
  52.   while (!done) smHibernate();        /* Rrrrr... Pffffff.... */
  53.  
  54.   PutStr("Woken up by CTRL_F, exiting\n");
  55.  
  56.   smDisallowExcept();        /* Block exceptions again for cleanup */
  57.   SetExcept(0, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F);    /* Deactivate exception signals */
  58.   myproc->pr_Task.tc_ExceptCode = oldexcept;    /* Restore old exception code */
  59.   smAllowExcept();
  60.  
  61.   cleanexit(0);
  62. }
  63.  
  64. static ULONG __saveds __asm myexcept(register __d0 ULONG excptsigs, register __a1 APTR excptdata)
  65. {
  66.   if (excptsigs & SIGBREAKF_CTRL_F)    /* CTRL_F received */
  67.   { done = TRUE;    /* Tell the main code it's time to exit */
  68.     smWakeUp((struct Task*)myproc);
  69.   }
  70.   if (excptsigs & SIGBREAKF_CTRL_C)    /* CTRL_C received */
  71.   { PutStr("BREAK\n");
  72.     smEndExcept(FALSE);        /* Prepare for exit, does an implicit smDisallowExcept() */
  73.     SetExcept(0, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F);    /* Deactivate exception signals */
  74.     myproc->pr_Task.tc_ExceptCode = oldexcept;        /* Restore old exception code */
  75.     smAllowExcept();        /* Don't forget this one */
  76.     cleanexit(5);        /* byebye... */
  77.   }
  78.  
  79.   return excptsigs;    /* for compatibility with exec */
  80. }
  81.  
  82. static void cleanexit(int rc)
  83. {
  84.   if (SysmonBase) CloseLibrary((struct Library *)SysmonBase);
  85.   exit(rc);
  86. }
  87.