home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Mailcheck Source / init src / mmc_drvr_find.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-18  |  2.6 KB  |  91 lines  |  [TEXT/KAHL]

  1. /*
  2.  * install the mac mail watch driver
  3.  * by Aaron Wohl (aw0g+@andrew.cmu.edu) jul 1990
  4.  * Carnegie-Mellon University
  5.  * Special Projects
  6.  * Pittsburgh, PA 15213-3890
  7.  * (412)-268-5032
  8.  *
  9.  * special thanks to Luni and Rich Brown @ Dartmouth
  10.  *
  11.  * Luni wrote the MacTCP emulator for macmach from which this file
  12.  * borrows liberaly.
  13.  *
  14.  * Rich Brown provided the source to Dartmouth's BlitzNotify installer
  15.  * which was a big help.
  16.  *
  17.  * Unlike other MailCheck source files which are for THINK C compilation
  18.  * only, this module compiles with MPW c also.  This lets macmail use it
  19.  * to find MailCheck.  So be carefull about sizeof(int) in THINK == 2
  20.  * and sizeof(int) in MPW == 4 if you make any changes.
  21.  *
  22.  */
  23.  
  24. /*
  25.  * returns the refnum of the passed driverName
  26.  * or zero if it isn't installed.  If no driver
  27.  * is found free_ref_num returns
  28.  * a refnum that is free both in the
  29.  * unit table and in the system file and any open
  30.  * resource forks.  if there are no free driver slots
  31.  * free_ref_num returns zero
  32.  * if a driver is found the value returned in free_ref_num
  33.  * is indeterminant
  34.  * The ref num free_ref_num returns is currently the largest free
  35.  * Only ref nums less than -12 are considered
  36.  */
  37.  
  38. #include "mmc_drvr_find.h"
  39.  
  40. short mmc_drvr_find(driverName,free_ref_num)
  41. unsigned char *driverName;
  42. short *free_ref_num;
  43. {
  44. #define drvrName 18        /*length byte and name of driver [string]*/
  45.   short negCount;
  46.   short dRef;
  47.   DCtlHandle     dCtl;
  48.   char        *drivePtr;
  49.   short result=0;
  50.   char **handle;
  51.  
  52.   if(free_ref_num!=0)
  53.     *free_ref_num=0;        /*assume no free slots*/
  54.   negCount = -UnitNtryCnt; /*get -(table size)*/
  55.         
  56.   /*Check to see that driver is installed, obtain refNum.*/
  57.   /*Assumes that an Open was done previously -- probably by an INIT.*/
  58.   /*Driver doesn't have to be open now, though.*/
  59.         
  60.   SetResLoad(FALSE);
  61.   /*we'll start with driver refnum == -12, right after .ATP entry*/
  62.   /*Look through unit table until we find the driver or reach the end.*/
  63.   for(dRef = -12;(dRef != negCount);dRef--) {
  64.  
  65.     dCtl = GetDCtlEntry(dRef); /*get handle to DCE*/
  66.  
  67.     if (dCtl == 0L) {
  68.       if(free_ref_num!=0)
  69.         if((handle=GetResource('DRVR',(-dRef)-1))==0)
  70.           *free_ref_num=dRef;
  71.         else
  72.           ReleaseResource(handle);
  73.     } else if (( (**dCtl).dCtlDriver != 0L) ) {
  74.       if ((**dCtl).dCtlFlags & dRAMBased)
  75.         drivePtr = *(Handle) (**dCtl).dCtlDriver;
  76.       else
  77.         drivePtr = (**dCtl).dCtlDriver;
  78.             
  79.       if ((drivePtr != 0L) &&  
  80.         (EqualString((void *)(drivePtr + drvrName),(void*)driverName,0,0))) {
  81.          result=dRef;
  82.          break;
  83.       }
  84.       
  85.    }
  86.   }
  87.         
  88.   SetResLoad(TRUE);
  89.   return result; /*can't find driver*/
  90. }
  91.