home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / module.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  3.6 KB  |  175 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 <exec/memory.h>
  10. #include <dos/dostags.h>
  11. /*#include <graphics/displayinfo.h>*/
  12. #include <strings.h>
  13.  
  14. #include "includes.h"
  15. #include "libraries.h"
  16. #include "protos/protos.h"
  17.  
  18. struct Screen *ServerScr;
  19. struct Window *Wnd;
  20.  
  21. VOID InternalBlank( VOID )
  22. {
  23.     if( !ServerScr )
  24.     {
  25.         ServerScr = OpenScreenTags( 0L, SA_DisplayID, getTopScreenMode(),
  26.                                    SA_Depth, 1, SA_Behind, 1, TAG_END );
  27.         if( ServerScr )
  28.         {
  29.             Wnd = BlankMousePointer( ServerScr );
  30.             SetRGB4(&( ServerScr->ViewPort ), 0, 0, 0, 0 );
  31.             ScreenToFront( ServerScr );
  32.             Blanking = TRUE;
  33.         }
  34.     }
  35. }
  36.  
  37. VOID MessageModule( LONG Type )
  38. {
  39.     struct MsgPort *ClientPort;
  40.     BlankMsg *ClientMsg;
  41.     
  42.     if( ClientPort = FindPort( "GarshneClient" ))
  43.     {
  44.         if( Type == BM_DOBLANK )
  45.         {
  46.             TimeOutIO->tr_node.io_Command = TR_ADDREQUEST;
  47.             TimeOutIO->tr_time.tv_secs = 2;
  48.             TimeOutIO->tr_time.tv_micro = 0;
  49.             SendIO(( struct IORequest * )TimeOutIO );
  50.         }
  51.         
  52.         if( ClientMsg = AllocVec( sizeof( BlankMsg ), MEMF_CLEAR|MEMF_PUBLIC ))
  53.         {
  54.             ClientMsg->bm_Mess.mn_ReplyPort = ServerPort;
  55.             ClientMsg->bm_Mess.mn_Length = sizeof( BlankMsg );
  56.             /* Stealthimania */
  57.             ClientMsg->bm_Mess.mn_Node.ln_Name = ( UBYTE * )( &Blanking );
  58.             ClientMsg->bm_Type = Type;
  59.             PutMsg( ClientPort, ( struct Message * )ClientMsg );
  60.             return;
  61.         }
  62.     }
  63.     
  64.     if( Type == BM_DOBLANK )
  65.         InternalBlank();
  66. }
  67.  
  68. VOID LoadModule( STRPTR Dir, STRPTR Module )
  69. {
  70.     BPTR in = Open( "NIL:", MODE_OLDFILE );
  71.     BPTR out = Open( "NIL:", MODE_OLDFILE );
  72.     BYTE Path[256];
  73.     
  74.     if( !Stricmp( Module, "Random" ))
  75.         Module = RandomModule();
  76.     strcpy( Path, Dir );
  77.     AddPart( Path, Module, 256 );
  78.     
  79.     if( in && out )
  80.         if( SystemTags( Path, NP_Priority, -5, SYS_Asynch, TRUE, SYS_Input, in,
  81.                        SYS_Output, out, TAG_END ) != -1 )
  82.             return;
  83.     
  84.     if( in )
  85.         Close( in );
  86.     if( out )
  87.         Close( out );
  88. }
  89.  
  90. BlankerEntry *NewBlankerEntry( STRPTR Path, STRPTR Name )
  91. {
  92.     BlankerEntry *New = AllocVec( sizeof( BlankerEntry ), MEMF_CLEAR );
  93.  
  94.     if( New )
  95.     {
  96.         strcpy( New->be_Path, Path );
  97.         AddPart( New->be_Path, Name, 128 );
  98.         New->be_Name = FilePart( New->be_Path );
  99.         New->be_Node.ln_Name = New->be_Name;
  100.     }
  101.  
  102.     return New;
  103. }
  104.  
  105. LONG FileIsModule( STRPTR Path, STRPTR Name )
  106. {
  107.     LONG Length = strlen( Name );
  108.     
  109.     if(!( Stricmp(&( Name[Length-5] ), ".info" )))
  110.         return FALSE;
  111.     
  112.     if(!( Stricmp(&( Name[Length-6] ), ".prefs" )))
  113.         return FALSE;
  114.     
  115.     if(!( Stricmp(&( Name[Length-4] ), ".txt" )))
  116.         return FALSE;
  117.     
  118.     return TRUE;
  119. }
  120.  
  121. VOID FreeBlankerEntries( struct List *Entries )
  122. {
  123.     BlankerEntry *FreeMe;
  124.  
  125.     if( !Entries )
  126.         return;
  127.  
  128.     while( FreeMe = ( BlankerEntry * )RemHead( Entries ))
  129.         FreeVec( FreeMe );
  130.  
  131.     FreeVec( Entries );
  132. }
  133.  
  134. struct List *LoadBlankerEntries( STRPTR Path )
  135. {
  136.     struct FileInfoBlock *Blk;
  137.     struct List *Entries;
  138.     BPTR DirLock;
  139.  
  140.     if(!( Entries = AllocVec( sizeof( struct List ), MEMF_CLEAR )))
  141.         return 0L;
  142.     else
  143.         NewList( Entries );
  144.  
  145.     if( DirLock = Lock( Path, ACCESS_READ ))
  146.     {
  147.         if(( Blk = AllocDosObject( DOS_FIB, 0L ))&&( Examine( DirLock, Blk )))
  148.         {
  149.             BlankerEntry *New;
  150.  
  151.             while( ExNext( DirLock, Blk ))
  152.             {
  153.                 if(( Blk->fib_FileName )&&
  154.                    ( FileIsModule( Path, Blk->fib_FileName )))
  155.                 {
  156.                     if( New = NewBlankerEntry( Path, Blk->fib_FileName ))
  157.                     {
  158.                         New->be_Node.ln_Pri = 128 -
  159.                             (( New->be_Name[0] == '{' ? New->be_Name[1] :
  160.                               New->be_Name[0] ) - 'a' );
  161.                         Enqueue( Entries, ( struct Node * )New );
  162.                     }
  163.                 }
  164.             }
  165.             FreeDosObject( DOS_FIB, Blk );
  166.  
  167.             if( New = NewBlankerEntry( ":", "Random" ))
  168.                 AddTail( Entries, ( struct Node * )New );
  169.         }
  170.         UnLock( DirLock );
  171.     }
  172.     
  173.     return Entries;
  174. }
  175.