home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / ii-31 / signalnotification.c < prev   
C/C++ Source or Header  |  1996-01-30  |  4KB  |  121 lines

  1. ;/* SignalNotification.c.  Compiled with SAS/C 6.56
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=FAR IGNORE=73 SignalNotification.c
  3. slink from SignalNotification.o to SignalNotification lib lib:amiga.lib
  4. quit
  5.  
  6. Copyright (c) 1991 Commodore-Amiga, Inc.
  7.  
  8. This example is provided in electronic form by Commodore-Amiga,
  9. Inc. for use with the Amiga Mail Volume II technical publication.
  10. Amiga Mail Volume II contains additional information on the correct
  11. usage of the techniques and operating system functions presented in
  12. these examples.  The source and executable code of these examples may
  13. only be distributed in free electronic form, via bulletin board or
  14. as part of a fully non-commercial and freely redistributable
  15. diskette.  Both the source and executable code (including comments)
  16. must be included, without modification, in any copy.  This example
  17. may not be published in printed form or distributed with any
  18. commercial product. However, the programming techniques and support
  19. routines set forth in these examples may be used in the development
  20. of original executable software products for Commodore Amiga
  21. computers.
  22.  
  23. All other rights reserved.
  24.  
  25. This example is provided "as-is" and is subject to change; no
  26. warranties are made.  All use is at your own risk. No liability or
  27. responsibility is assumed.
  28. */
  29.  
  30.  
  31. #include <exec/types.h>
  32. #include <exec/memory.h>
  33. #include <dos/dos.h>
  34. #include <dos/dosasl.h>
  35. #include <dos/notify.h>
  36. #include <dos/rdargs.h>
  37.  
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40.  
  41. /* Use pragmas if you've got them */
  42.  
  43. static UBYTE   *VersTag = "\0$VER: SignalNotification 37.1 (09.07.91)";
  44. struct Library *DOSBase;
  45. struct ExecBase *SysBase;
  46.  
  47. VOID            main(VOID);
  48.  
  49. VOID
  50. main(VOID)
  51. {
  52.  
  53.     struct RDArgs  *readargs;
  54.     LONG            rargs[2];
  55.     struct NotifyRequest *notifyrequest;
  56.     UBYTE          *filename;
  57.     ULONG           signr, signal;
  58.  
  59.     /* To appease amiga.lib */
  60.     SysBase = (*((struct Library **) 4));
  61.  
  62.     /* Fail silently if < 37 */
  63.     if (DOSBase = OpenLibrary("dos.library", 37))
  64.     {
  65.         /* See the DOS Autodocs for more information about ReadArgs() */
  66.         if (readargs = ReadArgs("Filename/A", rargs, NULL))
  67.         {
  68.             filename = (UBYTE *) (rargs[0]);
  69.  
  70.             /* Allocate a NotifyRequest structure */
  71.             if (notifyrequest = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))
  72.             {
  73.                 /* And allocate a signalbit */
  74.                 if ((signr = AllocSignal(-1L)) != -1)
  75.                 {
  76.  
  77.                     /* Initialize notifcation request */
  78.                     notifyrequest->nr_Name = filename;
  79.                     notifyrequest->nr_Flags = NRF_SEND_SIGNAL | NRF_NOTIFY_INITIAL;
  80.                     /* Signal this task */
  81.                     notifyrequest->nr_stuff.nr_Signal.nr_Task =
  82.                             (struct Task *) FindTask(NULL);
  83.                     /* with this signal bit */
  84.                     notifyrequest->nr_stuff.nr_Signal.nr_SignalNum = signr;
  85.  
  86.                     if ((StartNotify(notifyrequest)) == DOSTRUE)
  87.                     {
  88.                         /* Loop until Ctrl-C to exit */
  89.                         for (;;)
  90.                         {
  91.                             signal = Wait(1L << signr | SIGBREAKF_CTRL_C);
  92.                             if (signal & (1L << signr))
  93.                                 VFPrintf(Output(), "Notification signal!\n", NULL);
  94.                             if (signal & SIGBREAKF_CTRL_C)
  95.                             {
  96.                                 EndNotify(notifyrequest);
  97.                                 PrintFault(ERROR_BREAK, NULL);
  98.                                 break;
  99.                             }
  100.                         }
  101.                     }
  102.                     else
  103.                         PrintFault(ERROR_NOT_IMPLEMENTED, NULL);    /* most logical */
  104.  
  105.                     FreeSignal(signr);
  106.                 }
  107.                 else
  108.                     VFPrintf(Output(), "No signal available\n", NULL);
  109.                 FreeMem(notifyrequest, sizeof(struct NotifyRequest));
  110.             }
  111.             else
  112.                 PrintFault(ERROR_NO_FREE_STORE, NULL);
  113.  
  114.             FreeArgs(readargs);
  115.         }
  116.         else
  117.             PrintFault(IoErr(), NULL);
  118.         CloseLibrary(DOSBase);
  119.     }
  120. }
  121.