home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / GimmeLib / stdstuff.c < prev    next >
C/C++ Source or Header  |  1988-12-27  |  3KB  |  150 lines

  1. /*
  2.  *  FILE: stdstuff.c
  3.  *  Support routines for creating and dealing with standard libraries
  4.  *  and devices.
  5.  *
  6.  *  Public Domain, but keep my name in it as the original author.
  7.  *  30-Sep-88    Jan Sven Trabandt   added to gimme.lib
  8.  *  31-Oct-88    Jan Sven Trabandt   added new options
  9.  *                    made getRidOfStdStuff more controllable
  10.  */
  11.  
  12.  
  13. #define I_AM_STDSTUFF
  14. #include "gimmelib/gimmefuncs.h"
  15. #include "gimmelib/stdstuff.h"
  16.  
  17. #ifdef AZTEC_C
  18. extern int Enable_Abort;
  19. #endif AZTEC_C
  20.  
  21. struct IntuitionBase    *IntuitionBase = NULL;
  22. struct GfxBase        *GfxBase = NULL;
  23. struct DiskfontBase    *DiskfontBase = NULL;
  24. struct Device        *TimerBase = NULL;
  25.  
  26. struct MsgPort        *gimTimerPort = NULL;
  27. struct timerequest  *gimMasterTR = NULL;
  28. struct timerequest  *gimSlaveTR = NULL;
  29.  
  30. struct MsgPort        *gimMainPort = NULL;
  31. SHORT            gimSubTasks = 0;
  32.  
  33. void            *gimChainMem = NULL;
  34.  
  35.  
  36. ULONG gimmeStdStuff( myflags, rev )
  37.     ULONG   myflags;
  38.     SHORT   rev;
  39. {
  40.     if( myflags & GSS_DISABLEABORT ) {
  41. #ifdef AZTEC_C
  42.     Enable_Abort = 0;
  43. #endif
  44.     }
  45.     if( myflags & GSS_INTUITION ) {
  46.     if( !(IntuitionBase = (struct IntuitionBase *)
  47.                 OpenLibrary("intuition.library", (long) rev)) ) {
  48.         return( GSS_INTUITION );
  49.     }
  50.     }
  51.     if( myflags & GSS_GFX ) {
  52.     if( !(GfxBase = (struct GfxBase *)
  53.                 OpenLibrary("graphics.library", (long) rev)) ) {
  54.         return( GSS_GFX );
  55.     }
  56.     }
  57.     if( myflags & GSS_CLOSEWBENCH ) {
  58.     if( CloseWorkBench() ) {
  59.         return( GSS_CLOSEWBENCH );
  60.     }
  61.     }
  62.     if( myflags & GSS_DISKFONT ) {
  63.     if( !(DiskfontBase = (struct DiskfontBase *)
  64.                 OpenLibrary("diskfont.library", (long) rev)) ) {
  65.         return( GSS_DISKFONT );
  66.     }
  67.     }
  68.     if( myflags & GSS_TIMER ) {
  69.     if( !(gimMasterTR = accessTimer(UNIT_MICROHZ, &gimTimerPort)) ) {
  70.         return( GSS_TIMER );
  71.     }
  72.     if( !(gimSlaveTR = gimmeTimeRequest(gimMasterTR)) ) {
  73.         return( GSS_TIMER );
  74.     }
  75.     }
  76.     if( myflags & GSS_SUBTASK ) {
  77.     if( initSubTasker(&gimSubTasks, &gimMainPort) ) {
  78.         return( GSS_SUBTASK );
  79.     }
  80.     }
  81.     return( 0L );
  82. } /* gimmeStdStuff */
  83.  
  84.  
  85. ULONG getRidOfStdStuff( myflags )
  86.     ULONG   myflags;
  87. {
  88.     if( myflags & GSS_MEMCHAIN ) {
  89.     if( gimChainMem ) {
  90.         chainFreeMem( gimChainMem );
  91.         gimChainMem = NULL;
  92.     }
  93.     }
  94.     if( myflags & GSS_SUBTASK ) {
  95.     if( gimMainPort ) {
  96.         handleSpecialSubTaskMsg( &gimSubTasks, &gimMainPort );
  97.         if( doneSubTasker(&gimSubTasks, &gimMainPort)
  98.             && !(myflags & GSS_RUTHLESS) ) {
  99.         return( GSS_SUBTASK );
  100.         }
  101.         gimSubTasks = 0;
  102.         gimMainPort = NULL;
  103.     }
  104.     }
  105.     if( myflags & GSS_TIMER ) {
  106.     if( gimSlaveTR ) {
  107.         if( getRidOfTimeRequest(gimSlaveTR) && !(myflags & GSS_RUTHLESS) ) {
  108.         return( GSS_TIMER );
  109.         }
  110.         gimSlaveTR = NULL;
  111.     }
  112.     if( gimMasterTR ) {
  113.         if( releaseTimer(gimMasterTR, NULL) && !(myflags & GSS_RUTHLESS) ) {
  114.         return( GSS_TIMER );
  115.         }
  116.         gimMasterTR = NULL;
  117.         gimTimerPort = NULL;
  118.     }
  119.     }
  120.     if( myflags & GSS_DISKFONT ) {
  121.     if( DiskfontBase ) {
  122.         CloseLibrary( DiskfontBase );
  123.         DiskfontBase = NULL;
  124.     }
  125.     }
  126.     if( myflags & GSS_OPENWBENCH ) {
  127.     if( OpenWorkBench() && !(myflags & GSS_RUTHLESS) ) {
  128.         return( GSS_OPENWBENCH );
  129.     }
  130.     }
  131.     if( myflags & GSS_GFX ) {
  132.     if( GfxBase ) {
  133.         CloseLibrary( GfxBase );
  134.         GfxBase = NULL;
  135.     }
  136.     }
  137.     if( myflags & GSS_INTUITION ) {
  138.     if( IntuitionBase ) {
  139.         CloseLibrary( IntuitionBase );
  140.         IntuitionBase = NULL;
  141.     }
  142.     }
  143.     if( myflags & GSS_ENABLEABORT ) {
  144. #ifdef AZTEC_C
  145.     Enable_Abort = 1;
  146. #endif
  147.     }
  148.     return( 0L );
  149. } /* getRidOfStdStuff */
  150.