home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / xlib / libs.c < prev    next >
C/C++ Source or Header  |  1987-12-07  |  2KB  |  135 lines

  1. /*
  2.     Shared library support.
  3.     written October, 1987
  4.     by Preston L. Bannister
  5. */
  6.  
  7. #include <osbind.h>
  8. #include <bios.h>
  9. #include <basepage.h>
  10. #include <debug.h>
  11. #define LIBSUPPORT_IMPLEMENTATION
  12. #include "libs.h"
  13.  
  14. LibLink *Libraries;
  15.  
  16.  
  17. /*===== entry points =====*/
  18.  
  19.  
  20. /*
  21.     Add a new library to the list of installed libraries.
  22. */
  23.  
  24. void
  25. AddLibrary (lib)
  26.   LibLink *lib;        /* IN a new library link */
  27. {
  28.   ENTER(AddLibrary);
  29.   lib->next = Libraries;
  30.   Libraries = lib;
  31.   LEAVE(AddLibrary);
  32. }
  33.  
  34.  
  35. /*
  36.     Find an installed library to match the given name and version.
  37.     Returns a NULL pointer if the library was not found or if the
  38.     entrance routine of the library itself decided it was not 
  39.     compatible with the given version.
  40. */
  41.  
  42. Library
  43. FindLibrary (name,version)
  44.   char *name;        /* IN name of the library to find */
  45.   int version;        /* IN version number of library */
  46. {
  47.   LibLink *p = Libraries;
  48.   ENTER(FindLibrary);
  49.   DEBUG(("Looking for '%s'\n",name));
  50.   for (p=Libraries; p; p=p->next)
  51.   {
  52.     DEBUG(("Examining '%s'\n",p->name));
  53.     if (strcmp(name,p->name)==0)
  54.     {
  55.       LEAVE(FindLibrary:FoundIt);
  56.       return ((*p->entrance)(version));
  57.     }
  58.   }
  59.   LEAVE(FindLibrary:NotFound);
  60.   return 0L;
  61. }
  62.  
  63.  
  64. /*
  65.     For each installed library, call the given procedure with a pointer 
  66.     to the given data and a pointer to the library link structure.
  67. */
  68.  
  69. void
  70. ForEachLibrary (proc,data)
  71.   int (*proc)();
  72.   int *data;
  73. {
  74.   LibLink *p = Libraries;
  75.   ENTER(ForEachLibrary);
  76.   for (p=Libraries; p; p=p->next)
  77.   {
  78.     if ((*proc)(data,p))
  79.       break;
  80.   }
  81.   LEAVE(ForEachLibrary);
  82. }
  83.  
  84.  
  85. /*===== =====*/
  86.  
  87.  
  88. Procedure LibSupportBase[] = {
  89.   AddLibrary,
  90.   FindLibrary,
  91.   ForEachLibrary
  92. };
  93.  
  94.  
  95. /* Called when client finds this library */
  96.  
  97. Library
  98. Entrance (version)
  99.   int version;
  100. {
  101.   DEBUG(("In LibSupport Entrance\n"));
  102.   switch (version)
  103.   {
  104.     case LIBSUPPORT_VERSION:
  105.       return LibSupportBase;
  106.   }
  107.   return 0L;
  108. }
  109.  
  110.  
  111. LibLink LibSupport = {
  112.   0L,
  113.   LIBSUPPORT_NAME,
  114.   LIBSUPPORT_VERSION,
  115.   Entrance
  116. };
  117.  
  118.  
  119. main ()
  120. {
  121.   extern int end[];
  122.  
  123.   DEBUG(("\nInstalling LibSupport\n"));
  124.   Libraries = &LibSupport;
  125.   Setexc(LIB_FIND_VECTOR,FindLibrary);
  126.   DEBUG(("LibSupport vector 0x%04x set to 0x%08X FindLibrary\n",
  127.           LIB_FIND_VECTOR,FindLibrary));
  128.   Setexc(LIB_ADD_VECTOR,AddLibrary);
  129.   DEBUG(("LibSupport vector 0x%04x set to 0x%08X AddLibrary\n",
  130.           LIB_ADD_VECTOR,AddLibrary));
  131.   Ptermres((long)end-(long)BP,0);
  132.   DEBUG(("LibSupport installation failed!\n"));
  133.   return 1;
  134. }
  135.