home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / allocate_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  1.7 KB  |  65 lines

  1. /*
  2.  * Allocate_Misc.c
  3.  *
  4.  * Example of allocating a miscellaneous resource
  5.  * We will allocate the serial resource and wait till
  6.  * CTRL-C is pressed.  While we are waiting, the
  7.  * query_serial program should be run.  It will try
  8.  * to open the serial device and if unsuccessful, will
  9.  * return the name of the owner.  It will be us!
  10.  *
  11.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  12.  *
  13.  * Run from CLI only
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <resources/misc.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/misc_protos.h>
  23.  
  24. #include <stdio.h>
  25.  
  26. #ifdef LATTICE
  27. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  28. int chkabort(void) { return(0); }  /* really */
  29. #endif
  30.  
  31. struct Library *MiscBase = NULL;
  32.  
  33. void main(int argc, char **argv)
  34. {
  35. UBYTE *owner = NULL;       /* owner of misc resource */
  36.  
  37. if (!(MiscBase= (struct Library *)OpenResource(MISCNAME)))
  38.     printf("Cannot open %s\n",MISCNAME);
  39. else
  40.    {
  41.     /* Allocate both pieces of the serial hardware */
  42.     if ((owner = AllocMiscResource(MR_SERIALPORT,"Serial Port Hog")) == NULL)
  43.         {
  44.         if ((owner = AllocMiscResource(MR_SERIALBITS,"Serial Port Hog")) == NULL)
  45.             {
  46.             /* Wait for CTRL-C to be pressed */
  47.             printf("\nWaiting for CTRL-C...\n");
  48.             Wait(SIGBREAKF_CTRL_C);
  49.  
  50.             /* We're back */
  51.  
  52.             /* Deallocate the serial port register */
  53.             FreeMiscResource(MR_SERIALBITS);
  54.             }
  55.         else
  56.             printf("\nUnable to allocate MR_SERIALBITS because %s owns it\n",owner);
  57.  
  58.         /* Deallocate the serial port */
  59.         FreeMiscResource(MR_SERIALPORT);
  60.        }
  61.     else
  62.        printf("\nUnable to allocate MR_SERIALPORT because %s owns it\n",owner);
  63.    }
  64. }
  65.