home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / main.c < prev    next >
C/C++ Source or Header  |  1994-10-13  |  3KB  |  143 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <dos/dos.h>
  10. #include <devices/timer.h>
  11.  
  12. #include "includes.h"
  13. #include "libraries.h"
  14. #include "protos/protos.h"
  15.  
  16. __far extern LONG RangeSeed;
  17.  
  18. STATIC const UBYTE VersTag[] = VERSTAG;
  19. LONG Blanking = FALSE, BlankAfterInit = FALSE;
  20. struct MsgPort *ServerPort = 0L, *TimerPort = 0L;
  21. struct List *BlankerEntries, *ActiveEntries;
  22. struct timerequest *TimeOutIO;
  23. struct Task *ServerTask;
  24. BlankerPrefs *Prefs;
  25.  
  26. VOID FreeResources( VOID )
  27. {
  28.     MessageModule( BM_DOQUIT );
  29.  
  30.     CloseBlankerWindow();
  31.     CloseDownScreen();
  32.  
  33.     FreeBlankerEntries( BlankerEntries );
  34.  
  35.     if( TimeOutIO )
  36.     {
  37.         if( TimeOutIO->tr_node.io_Device )
  38.             CloseDevice(( struct IORequest * )TimeOutIO );
  39.         DeleteExtIO(( struct IORequest * )TimeOutIO );
  40.     }
  41.  
  42.     if( TimerPort )
  43.         DeletePort( TimerPort );
  44.  
  45.     if( ServerPort )
  46.         DeletePort( ServerPort );
  47.  
  48.     ShutdownCX();
  49.     CloseLibraries();
  50. }
  51.  
  52. LONG AllocResources( VOID )
  53. {
  54.     if( OpenLibraries() == 1L )
  55.         return 1L;
  56.  
  57.     RangeSeed = ( LONG )( ServerTask = FindTask( 0L ));
  58.  
  59.     if( CheckCX() == QUIT )
  60.         return 1L;
  61.  
  62.     ServerPort = CreatePort( "GarshneServer", 0 );
  63.     TimerPort = CreatePort( 0L, 0 );
  64.     if( !ServerPort || !TimerPort )
  65.         return 1L;
  66.  
  67.     TimeOutIO = ( struct timerequest * )
  68.         CreateExtIO( TimerPort, sizeof( struct timerequest ));
  69.     if( !TimeOutIO )
  70.         return 1L;
  71.  
  72.     if( OpenDevice( "timer.device", UNIT_VBLANK,
  73.                    ( struct IORequest * )TimeOutIO, 0L ))
  74.         return 1L;
  75.  
  76.     return 0L;
  77. }
  78.  
  79. VOID main( int argc, char *argv[] )
  80. {
  81.     LONG sigs, retval;
  82.     
  83.     if( AllocResources() == 1L )
  84.     {
  85.         FreeResources();
  86.         return;
  87.     }
  88.  
  89.     Prefs = LoadDefaultPrefs();
  90.     BlankerEntries = LoadBlankerEntries( Prefs->bp_Dir );
  91.     if( !( Prefs->bp_Flags & BF_REPLACE ) ||
  92.        Stricmp( Prefs->bp_Blanker, "Random" ))
  93.         LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
  94.  
  95.     if( SetupCX() == QUIT )
  96.     {
  97.         FreeResources();
  98.         return;
  99.     }
  100.  
  101.     if( Prefs->bp_PopUp )
  102.         retval = openMainWindow();
  103.  
  104.     do
  105.     {
  106.         sigs = Wait( SIG_CX | SIG_SERVWIN | SIG_SERVPORT | SIG_TIMER |
  107.                     SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D );
  108.         
  109.         if( sigs & SIG_SERVPORT )
  110.             retval = HandleServerMsg();
  111.  
  112.         if( sigs & SIG_CX )
  113.             retval = HandleCxMess();
  114.  
  115.         if( sigs & SIG_SERVWIN )
  116.             retval = HandleBlankerIDCMP();
  117.  
  118.         if( sigs & SIGBREAKF_CTRL_C )
  119.             retval = 0L;
  120.  
  121.         if( sigs & SIGBREAKF_CTRL_D )
  122.             retval = HandleMouseCheck();
  123.                         
  124.         if( sigs & SIG_TIMER )
  125.         {
  126.             WaitIO(( struct IORequest * )TimeOutIO );
  127.             MessageModule( BM_UNBLANK );
  128.             InternalBlank();
  129.         }
  130.  
  131.         if( retval == CLOSEWIN )
  132.         {
  133.             Prefs->bp_Left = BlankerWnd->LeftEdge;
  134.             Prefs->bp_Top = BlankerWnd->TopEdge;
  135.             CloseBlankerWindow();
  136.             CloseDownScreen();
  137.         }
  138.     }
  139.     while( retval );
  140.  
  141.     FreeResources();
  142. }
  143.