home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / prefnotify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  2.6 KB  |  84 lines

  1. ;/* prefnotify.c.  - Execute me to compile me with SAS/C 5.10
  2. lc -cfistq -v -y -j73 prefnotify.c
  3. blink from LIB:c.o,prefnotify.o to prefnotify lib LIB:LC.lib LIB:amiga.lib
  4. quit
  5.  
  6. ** prefnotify.c - notified if serial prefs change
  7. */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <dos/dos.h>
  12. #include <dos/notify.h>
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18.  
  19. #ifdef LATTICE
  20. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  21. int chkabort(void) { return(0); }  /* really */
  22. #endif
  23.  
  24. #define PREFSFILENAME "ENV:sys/serial.prefs"
  25.  
  26. static UBYTE   *VersTag = "\0$VER: prefnot 37.1 (09.07.91)";
  27.  
  28. extern struct Library *DOSBase;
  29.  
  30.  
  31. void main(int argc, char **argv)
  32. {
  33. BOOL done=FALSE;
  34. struct NotifyRequest *notifyrequest;
  35. UBYTE          *filename;
  36. LONG           signum;
  37. ULONG          signals;
  38.  
  39. /* We need at least V37 for notification */
  40. if (DOSBase->lib_Version >= 37)
  41.     {
  42.     /* Allocate a NotifyRequest structure */
  43.     if (notifyrequest = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))
  44.         {
  45.         /* And allocate a signalsbit */
  46.         if ((signum = AllocSignal(-1L)) != -1)
  47.             {
  48.             /* Initialize notification request */
  49.             filename = PREFSFILENAME;
  50.             notifyrequest->nr_Name = filename;
  51.             notifyrequest->nr_Flags = NRF_SEND_SIGNAL;
  52.             /* Signal this task */
  53.             notifyrequest->nr_stuff.nr_Signal.nr_Task = (struct Task *) FindTask(NULL);
  54.             /* with this signals bit */
  55.             notifyrequest->nr_stuff.nr_Signal.nr_SignalNum = signum;
  56.  
  57.             if ((StartNotify(notifyrequest)) == DOSTRUE)
  58.                 {
  59.                 printf("Select Serial Prefs SAVE or USE to notify this program\n");
  60.                 printf("CTRL-C to exit\n\n");
  61.                 /* Loop until Ctrl-C to exit */
  62.                 while(!done)
  63.                     {
  64.                     signals = Wait(  (1L << signum) | SIGBREAKF_CTRL_C  );
  65.                     if (signals & (1L << signum))
  66.                         printf("Notification signal received.\n");
  67.                     if (signals & SIGBREAKF_CTRL_C)
  68.                         {
  69.                         EndNotify(notifyrequest);
  70.                         done=TRUE;
  71.                         }
  72.                     }
  73.                 }
  74.             else printf("Can't start notification\n");
  75.             FreeSignal(signum);
  76.             }
  77.         else printf("No signals available\n");
  78.         FreeMem(notifyrequest, sizeof(struct NotifyRequest));
  79.         }
  80.     else printf("Not enough memory for NotifyRequest.\n");
  81.     }
  82. else printf("Requires at least V37 dos.library\n");
  83. }
  84.