home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / source / _cxbrk.c next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  3.7 KB  |  131 lines

  1. /***
  2. *
  3. *          Copyright © 1992  SAS Institute, Inc.
  4. *
  5. * name             _CXBRK  -  default signal handler for SIGINT
  6. *
  7. * synopsis         _CXBRK(sig)
  8. *                  sig             signal which caused the abort request
  9. *
  10. *
  11. * description      _CXBRK is the default signal handler used to handle
  12. *                  the SIGINT signal.  It puts up a requester asking
  13. *                  the user if he really wants to abort program execution.
  14. *                  If yes, this routine aborts the program, otherwise the
  15. *                  routine returns to normal program execution.
  16. *
  17. ***/
  18.  
  19. #include <string.h>
  20. #include <signal.h>
  21. #include <stdlib.h>
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <libraries/dosextens.h>
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/intuition.h>
  28.  
  29.  
  30. void _CXBRK(int);
  31.  
  32. static struct IntuiText Text2 = {
  33.            (unsigned char)-1, 
  34.            (unsigned char)-1,                /* pen numbers */
  35.            0,                                /* draw mode */
  36.            14, 14,                           /* starting offsets */
  37.            NULL,                             /* text attribute pointer */
  38.            "** User Abort Requested **",
  39.            NULL
  40. };
  41.  
  42. static struct IntuiText BodyText = {
  43.            (unsigned char)-1, 
  44.            (unsigned char)-1,                /* pen numbers */
  45.            0,                                /* draw mode */
  46.            4, 4,                             /* starting offsets */
  47.            NULL,                             /* text attribute pointer */
  48.            NULL,
  49.            &Text2
  50. };
  51.  
  52. static struct IntuiText ContinueText = {
  53.            (unsigned char)-1, 
  54.            (unsigned char)-1,                /* pen numbers */
  55.            0,                                /* draw mode */
  56.            4, 4,                             /* starting offsets */
  57.            NULL,                             /* text attribute pointer */
  58.            "CONTINUE",
  59.            NULL
  60. };
  61.  
  62. static struct IntuiText AbortText = {
  63.            (unsigned char)-1, 
  64.            (unsigned char)-1,                /* pen numbers */
  65.            0,                                /* draw mode */
  66.            4, 4,                             /* starting offsets */
  67.            NULL,                             /* text attribute pointer */
  68.            "ABORT",
  69.            NULL
  70. };
  71.  
  72. extern char *_ProgramName;
  73.  
  74.  
  75. void _CXBRK(sig)
  76.     int  sig;
  77. {
  78.     char   temp[81];
  79.     int    len;
  80.     struct Process *us;
  81.     BPTR   fh;
  82.     struct CommandLineInterface  *cli;
  83.     struct IntuitionBase         *IntuitionBase;
  84.  
  85.  
  86.     /*   Build the program name into temp   */
  87.  
  88.     len = _ProgramName[-1];
  89.     if (len > 79)
  90.         len = 79;
  91.     memcpy(temp, _ProgramName, len);
  92.     temp[len] = '\0';
  93.  
  94.  
  95.     /* Now see if we were invoked from CLI or from WorkBench */
  96.  
  97.     us = (struct Process *) FindTask(0L);
  98.     if (us->pr_CLI != NULL) {
  99.         cli = (struct CommandLineInterface *) (((long) (us->pr_CLI)) << 2);
  100.         fh = cli->cli_StandardOutput;
  101.         if (fh == NULL)
  102.             fh = us->pr_COS;
  103.         if (fh != NULL) {
  104.             Write(fh, "*** Break: ", 11L);
  105.             temp[len++] = '\n';
  106.             Write(fh, temp, (long) len);
  107.             __sigfunc[SIGINT] = SIG_IGN;
  108.             __exit(20);
  109.     }
  110.     }
  111.  
  112.     IntuitionBase = (struct IntuitionBase *)
  113.                            OpenLibrary("intuition.library",0);
  114.     if (IntuitionBase == NULL) {
  115.         __sigfunc[SIGINT] = SIG_IGN;
  116.         __exit(20);
  117.     }
  118.  
  119.     BodyText.IText = temp;
  120.  
  121.     if (AutoRequest(NULL, &BodyText, &ContinueText, &AbortText,
  122.                                   0L, 0L, 250L, 60L) != TRUE) {
  123.         __sigfunc[SIGINT] = SIG_IGN;
  124.         __exit(20);
  125.     }
  126.  
  127.     __sigfunc[sig] = _CXBRK;
  128.  
  129.     return;
  130. }
  131.