home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 171.lha / SupLib / openlibs.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  93 lines

  1.  
  2. #include <local/xmisc.h>
  3.  
  4. static long OpenMask = 0;
  5.  
  6. long GfxBase;
  7. long IntuitionBase;
  8. long ExpansionBase;
  9. long DiskfontBase;
  10. long TranslatorBase;
  11. long IconBase;
  12. long MathBase;
  13. long MathTransBase;
  14. long MathIeeeDoubBasBase;
  15. long MathIeeeSingBasBase;
  16. long LayersBase;
  17. long ClistBase;
  18. long PotgoBase;
  19. long TimerBase;
  20. long DResBase;
  21. long xfiller15;
  22.  
  23. struct OLI {
  24.     char *name;
  25.     long *var;
  26. };
  27.  
  28. struct OLI strvar[] = {
  29.   "graphics",           &GfxBase,
  30.   "intuition",          &IntuitionBase,
  31.   "expansion",          &ExpansionBase,
  32.   "diskfont",           &DiskfontBase,
  33.   "translator",         &TranslatorBase,
  34.   "icon",               &IconBase,
  35.   "mathffp",            &MathBase,
  36.   "mathtrans",          &MathTransBase,
  37.   "mathieeedoubbas",    &MathIeeeDoubBasBase,
  38.   "mathieeesingbas",    &MathIeeeSingBasBase,
  39.   "layers",             &LayersBase,
  40.   "clist",              &ClistBase,
  41.   "potgo",              &PotgoBase,
  42.   "timer",              &TimerBase,
  43.   "dres",               &DResBase,
  44.   "x15",                &xfiller15
  45. };
  46.  
  47.  
  48. openlibs(mask)
  49. unsigned short mask;
  50. {
  51.     register struct OLI *sv;
  52.     register short i;
  53.     char buf[64];
  54.  
  55.     for (i = 0; i < sizeof(strvar)/sizeof(strvar[0]); ++i) {
  56.     sv = strvar + i;
  57.     if (mask & (1 << i)) {
  58.         strcpy(buf, sv->name);
  59.         strcat(buf, ".library");
  60.         if (*sv->var == 0 && (*sv->var = OpenLibrary(buf, 0L)) == 0) {
  61.         closelibs(mask);
  62.         return(0);
  63.         }
  64.         OpenMask |= 1 << i;
  65.     }
  66.     }
  67.     return(1);
  68. }
  69.  
  70. /*
  71.  * CLOSELIBS(mask)
  72.  *
  73.  *    Close the indicated libraries.    Does not close libraries which
  74.  *    have not been openned with OPENLIBS()
  75.  */
  76.  
  77. closelibs(mask)
  78. unsigned short mask;
  79. {
  80.     register struct OLI *sv;
  81.     register short i;
  82.  
  83.     for (i = 0; i < sizeof(strvar)/sizeof(strvar[0]); ++i) {
  84.     sv = strvar + i;
  85.     if ((mask & (1 << i)) && *sv->var && (OpenMask & (1 << i))) {
  86.         CloseLibrary(*sv->var);
  87.         *sv->var = 0L;
  88.         OpenMask &= ~(1 << i);
  89.     }
  90.     }
  91. }
  92.  
  93.