home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************
- FindFile
-
- An AmigaDOS Release 2 Commodity
-
- Code By : Russell R. Steffen
-
- Home Address : 11551 Sherman Rd.
- Cedarburg WI, 53012
- USA
- ( Stable )
-
- Email Address : STEFFENR@UWSTOUT.EDU
- ( Valid ubtil May 1993 )
-
- School Address : 318 Callahan Hall
- Menomonie, WI 54751
- USA
- ( Valid until May 1993 )
-
-
- Purpose -- To Emulate the FindFile Desk Accessory of the Macintosh.
-
- Legal -- This code is copyrighted by the author. However permission is
- granted for private use. Commercial use is prohibited without
- written consent of the author. This program is distrbuted
- WITHOUT ANY WARRANTY or IMPLIED WARRANTY of MERCHANTABILTY
- or FITNESS FOR A PARTICULAR PURPOSE.
-
-
- CopyRight ⌐ 1992 -- Russell R. Steffen. All rights reserved.
-
- History
- -----------------------------------------------------------------------------
- 29 JUN 1992 | File Creation, Inital Version
- -----------------------------------------------------------------------------
- 26 JUL 1992 | Competetion of Inital Version 1.00
- | Implemented ToolTypes : CX_POPKEY, CX_PRIORITY, CX_POPUP,
- | DEF_PATTERN, CENTERWINDOW, IGNOREICONS
- -----------------------------------------------------------------------------
- 30 JUL 1992 | Optimizations and cleanups. Added SORTLIST Tooltype
- | Version 1.00a
- -----------------------------------------------------------------------------
- 31 JUL 1992 | Added key command for found-list gadget. Version 1.00b
- | Fixed bug in ScanDir(), wasn't honoring a user quit request
- | properly.
- -----------------------------------------------------------------------------
- 04 NOV 1992 | Fixed another bug in ScanDir() with a near total rewrite.
- | Now works properly when launched from Workbench.
- | Fixed Window opening routine to use WA_InnerWidth and
- | and WA_InnerHeight. Window was a bit to small when the
- | prefs screen font was larger than 8 point.
- | Fixed problem with 'D' key, wasn't wraping around on
- | the device list.
- | Version 1.00c
- -----------------------------------------------------------------------------
-
- **********************************************************************************/
-
- #include "FindFile.h"
-
- /***************************** Global Constants **********************************/
-
- #define _VERSION "1.00c"
- #define DATE "(04.10.92)"
- #define NAME "FindFile"
- #define MAXSTR 256
- #define MAXPAT ( MAXSTR * 2 ) + 4
- #define OPEN_WINDOW 1
- #define FF_WIDTH 310
- #define FF_HEIGHT 165
-
- /*#define DEBUG*/
- #ifdef DEBUG
- #define DB( x ) printf("%s():",__FUNC__ );puts( x );
- #define DBf( x , y ) printf("%s():",__FUNC__ );printf( x , y );
- #else
- #define DB( x )
- #define DBf( x , y )
- #endif
-
- /** Gadget ID's **/
-
- enum { ID_PATGAD,ID_DEVGAD,ID_FOUNDLIST,ID_PATHLIST,ID_SEARCH,ID_HIDE,ID_QUIT };
-
- /***************************** Structure Defs ************************************/
-
- struct foundNode {
- struct Node fn_Node;
- struct MinList fn_PathList;
- UBYTE fn_Name[MAXSTR];
- };
-
- struct pathNode {
- struct Node pn_Node;
- UBYTE pn_Name[MAXSTR];
- };
-
- struct controlPanel {
- struct Window *ffWindow;
- SHORT lastX,
- lastY;
- BOOL centerWindow;
- BOOL ignoreIcons;
- BOOL sortList;
- UBYTE ignoreIconsPat[MAXPAT];
- struct VisualInfo *ffWinVi;
- struct Gadget *ffWinGadList;
- struct {
- struct Gadget *searchPatGad,
- *searchDevGad,
- *foundListGad,
- *pathListGad,
- *searchButton,
- *hideButton,
- *quitButton;
- } ffWinGads;
- UBYTE searchString[MAXSTR];
- UBYTE searchPattern[MAXPAT];
- UWORD searchDev;
- WORD numDevs;
- STRPTR *devList;
- struct MinList foundList;
- UWORD numFound;
- UWORD currFound;
- struct {
- struct MsgPort *cxPort;
- CxObj *ffBroker;
- UBYTE cxHotKeyString[MAXSTR];
- LONG cxPriority;
- } cxInterface;
- };
-
- /***************************** Function Prototypes *******************************/
-
- void Init( struct controlPanel * );
- void SetUp( struct controlPanel * , int , char ** );
- void Shutdown( struct controlPanel * , int );
-
- ULONG GetWaitMask( struct controlPanel * );
-
- void OpenFFWindow( struct controlPanel * );
- void CloseFFWindow( struct controlPanel * );
- void HandleFFWindowCommand( struct controlPanel * );
-
- void CreateFFGadgets( struct controlPanel *, STRPTR *, int , BYTE);
- void CenterWindow( struct Screen *, WORD *, WORD * );
- struct foundNode *NodeAddress( struct MinList * , UWORD );
- BOOL QuitCheck( struct controlPanel * );
-
- void Bstrcpy( UBYTE * , BSTR );
- STRPTR *GetDevList( struct controlPanel * );
- void FreeDevList( STRPTR * );
- BOOL ScanDir( STRPTR , struct controlPanel * , struct MinList * );
- BOOL MatchFile( struct controlPanel *, STRPTR );
-
- void AddPathNode( struct MinList * , UBYTE * );
- void DeletePathNode( struct MinList * );
- struct foundNode *AddFoundNode( struct MinList *, UBYTE * , BOOL );
- void DeleteFoundList( struct MinList * );
- void AddFoundFile( struct controlPanel *, STRPTR, struct MinList * );
-
- void OpenCxInterface( struct controlPanel * );
- void CloseCxInterface( struct controlPanel * );
- void HandleCxCommand( struct controlPanel * );
-
- void CMD_Show( struct controlPanel * );
- void CMD_Hide( struct controlPanel * );
- void CMD_Search( struct controlPanel * );
- void CMD_Quit( struct controlPanel * );
-
- /***************************** Global Vars ***************************************/
-
- struct Library *IntuitionBase;
- struct Library *GadToolsBase;
- struct Library *CxBase;
- struct Library *IconBase;
-
- extern int Enable_Abort; /* needed to disable Aztec C's ^C checking */
-
- static const UBYTE *verTag = "\0$VER: " NAME " " _VERSION " " DATE;
-
- /** This TextAttr should be gone in a future release. I want to
- write the window code to be Prefs font sensitive, eventually :) **/
-
- struct TextAttr DefaultFont = {
- (UBYTE *)"topaz.font",
- 8,
- FS_NORMAL,
- FPF_ROMFONT
- };
-
- /**************************** Code Starts Here ***********************************/
-
- struct Process;
- struct WBStartup;
-
- /*
- void
- _wb_parse( struct Process *pp, struct WBStartup *wbm )
- {
- }
- */
-
- void
- main(int argc, char **argv)
- {
- struct controlPanel *cp;
-
- Enable_Abort = 0; /* turn off auto CTRL-C handling */
-
- cp = AllocVec( sizeof( struct controlPanel ) , MEMF_PUBLIC | MEMF_CLEAR );
-
- Init( cp );
-
- SetUp( cp , argc , argv );
-
- FOREVER
- {
- ULONG mask;
-
- mask = GetWaitMask( cp );
-
- mask = Wait( mask );
-
- if( mask & SIGBREAKF_CTRL_C )
- CMD_Quit( cp );
-
- if( cp->ffWindow )
- if( mask & 1 << cp->ffWindow->UserPort->mp_SigBit )
- HandleFFWindowCommand( cp );
-
- if( cp->cxInterface.cxPort )
- if( mask & 1 << cp->cxInterface.cxPort->mp_SigBit )
- HandleCxCommand( cp );
- }
-
- }
-
- void
- SetUp( struct controlPanel *cp, int argc, char **argv )
- {
- UBYTE **toolTypes;
- STRPTR strTemp;
- BOOL openWindow=FALSE;
-
-
-
- /**** Parse WB & CLI Options ***************/
-
- toolTypes = ArgArrayInit( argc, argv );
-
- cp->cxInterface.cxPriority = ArgInt( toolTypes, "CX_PRIORITY", 0 );
-
- strTemp = ArgString( toolTypes, "CX_POPKEY", "LCommand help" );
- strncpy( cp->cxInterface.cxHotKeyString , strTemp, MAXSTR );
-
- strTemp = ArgString( toolTypes, "CX_POPUP", "NO" );
- if( ! strnicmp( strTemp, "YES" , MAXSTR ) )
- openWindow = TRUE;
-
- strTemp = ArgString( toolTypes, "DEF_PATTERN", "#?" );
- strncpy( cp->searchString , strTemp , MAXSTR );
-
- strTemp = ArgString( toolTypes, "CENTERWINDOW", "YES" );
- if( ! strnicmp( strTemp, "YES", MAXSTR ) )
- cp->centerWindow = TRUE;
-
- strTemp = ArgString( toolTypes, "IGNOREICONS" , "NO" );
- if( ! strnicmp( strTemp, "YES", MAXSTR ) )
- {
- cp->ignoreIcons = TRUE;
- ParsePatternNoCase( "#?.info" , cp->ignoreIconsPat, MAXPAT );
- }
- else
- ParsePatternNoCase( "#?" , cp->ignoreIconsPat, MAXPAT );
-
- strTemp = ArgString( toolTypes, "SORTLIST", "YES" );
- if( ! stricmp( strTemp, "YES" , MAXSTR ) )
- cp->sortList = TRUE;
-
- ArgArrayDone();
-
- OpenCxInterface( cp );
-
- cp->lastX = cp->lastY = -1L;
-
- NewList( (struct List *)&(cp->foundList) );
-
- if( openWindow )
- OpenFFWindow( cp );
-
- }
-
- void
- Init( struct controlPanel *cp )
- {
-
- if( ! ( IntuitionBase = OpenLibrary( "intuition.library", 37L ) ) )
- Shutdown( cp , 20 );
-
- if( ! ( GadToolsBase = OpenLibrary( "gadtools.library", 37L ) ) )
- Shutdown( cp , 20 );
-
- if( ! ( CxBase = OpenLibrary( "commodities.library" , 37L ) ) )
- Shutdown( cp , 20 );
-
- if( ! ( IconBase = OpenLibrary( "icon.library", 37L ) ) )
- Shutdown( cp , 20 );
-
- }
-
- ULONG
- GetWaitMask( struct controlPanel *cp )
- {
- ULONG mask;
-
- mask = SIGBREAKF_CTRL_C;
-
- if( cp->ffWindow )
- mask |= 1 << cp->ffWindow->UserPort->mp_SigBit;
-
- if( cp->cxInterface.cxPort )
- mask |= 1 << cp->cxInterface.cxPort->mp_SigBit;
-
- return( mask );
- }
-
- /******************************** FindFile Window Management **********************/
-
- void
- OpenFFWindow( struct controlPanel *cp )
- {
- struct Screen *defScreen;
- WORD left,
- top;
-
-
-
- if( cp->ffWindow )
- {
- WindowToFront( cp->ffWindow );
- ActivateWindow( cp->ffWindow );
- return;
- }
-
- if( !( defScreen = (struct Screen *)LockPubScreen( NULL )))
- Shutdown( cp, 20 );
-
- if( !(cp->ffWinVi = GetVisualInfo( defScreen, TAG_DONE )))
- Shutdown( cp, 20 );
-
- if( !( cp->devList = GetDevList(cp) ) )
- Shutdown( cp, 20 );
-
- CreateFFGadgets( cp, cp->devList , ( defScreen->WBorTop + defScreen->Font->ta_YSize+1 ),
- defScreen->WBorLeft );
-
- if( (cp->centerWindow) || cp->lastX == -1 || cp->lastY == -1 )
- CenterWindow( defScreen, &left, &top );
- else
- {
- left = cp->lastX;
- top = cp->lastY;
- }
-
- cp->ffWindow = OpenWindowTags( NULL, WA_Left , left,
- WA_Top, top,
- WA_InnerWidth, FF_WIDTH,
- WA_InnerHeight, FF_HEIGHT,
- WA_Activate, TRUE,
- WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
- WFLG_CLOSEGADGET |
- WFLG_SMART_REFRESH,
- WA_IDCMP, STRINGIDCMP|CYCLEIDCMP|
- BUTTONIDCMP|LISTVIEWIDCMP|
- IDCMP_CLOSEWINDOW|
- IDCMP_VANILLAKEY|
- IDCMP_REFRESHWINDOW|
- IDCMP_DISKINSERTED|
- IDCMP_DISKREMOVED,
- WA_PubScreen, defScreen,
- WA_Title, NAME " " _VERSION,
- WA_Gadgets, cp->ffWinGadList,
- TAG_DONE );
-
- GT_RefreshWindow( cp->ffWindow, NULL );
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, (&cp->foundList),
- GTLV_Selected, ~0L,
- TAG_DONE );
-
- UnlockPubScreen( NULL , defScreen );
-
- }
-
- void
- CloseFFWindow( struct controlPanel *cp )
- {
-
- cp->lastX = cp->ffWindow->LeftEdge;
- cp->lastY = cp->ffWindow->TopEdge;
-
- CloseWindow( cp->ffWindow );
- cp->ffWindow = NULL;
-
- FreeVisualInfo( cp->ffWinVi );
- cp->ffWinVi = NULL;
-
- FreeGadgets( cp->ffWinGadList );
- cp->ffWinGadList = NULL;
-
- cp->ffWinGads.searchPatGad = NULL;
- cp->ffWinGads.searchDevGad = NULL;
- cp->ffWinGads.pathListGad = NULL;
- cp->ffWinGads.searchButton = NULL;
- cp->ffWinGads.hideButton = NULL;
- cp->ffWinGads.quitButton = NULL;
-
- FreeDevList( cp->devList );
- cp->devList = NULL;
- }
-
- void
- HandleFFWindowCommand( struct controlPanel *cp )
- {
- struct IntuiMessage *msg;
-
- while( msg = GT_GetIMsg( cp->ffWindow->UserPort ) )
- {
- struct Gadget *gad;
- ULONG class;
- UWORD code,
- qualifier;
-
- gad = (struct Gadget *)msg->IAddress;
- class = msg->Class;
- code = msg->Code;
- qualifier = msg->Qualifier;
-
- GT_ReplyIMsg( msg );
-
- switch( class )
- {
- case IDCMP_CLOSEWINDOW : CMD_Hide( cp );
- break;
-
- case IDCMP_VANILLAKEY : switch( code )
- {
- case 'p' :
- case 'P' : ActivateGadget(cp->ffWinGads.searchPatGad,
- cp->ffWindow, NULL );
- break;
-
- case 'D' : cp->searchDev = ((cp->searchDev)-1) % cp->numDevs;
- GT_SetGadgetAttrs( cp->ffWinGads.searchDevGad,
- cp->ffWindow, NULL ,
- GTCY_Active,cp->searchDev,
- TAG_END );
- break;
- case 'd' : cp->searchDev = (++(cp->searchDev)) % cp->numDevs;
- GT_SetGadgetAttrs( cp->ffWinGads.searchDevGad,
- cp->ffWindow, NULL ,
- GTCY_Active,cp->searchDev,
- TAG_END );
- break;
-
- case 'F' : if( cp->currFound != ~0 )
- cp->currFound = cp->currFound == 0 ?
- 0 :
- (--(cp->currFound)) % cp->numFound;
- { struct foundNode *fn;
- fn = NodeAddress( &cp->foundList, cp->currFound );
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Selected, cp->currFound,
- GTLV_Top, cp->currFound,
- TAG_END );
- GT_SetGadgetAttrs( cp->ffWinGads.pathListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, &fn->fn_PathList,
- GTLV_Top, 0L,
- TAG_END );
- }
- break;
- case 'f' : if( cp->currFound == ~0 )
- cp->currFound = 0;
- else
- cp->currFound = cp->currFound == (cp->numFound-1) ?
- cp->currFound :
- (++cp->currFound) % cp->numFound;
-
- { struct foundNode *fn;
- fn = NodeAddress( &cp->foundList, cp->currFound );
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Selected, cp->currFound,
- GTLV_Top, cp->currFound,
- TAG_END );
- GT_SetGadgetAttrs( cp->ffWinGads.pathListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, &fn->fn_PathList,
- GTLV_Top, 0L,
- TAG_END );
- }
- break;
- case 'h' :
- case 'H' : CMD_Hide( cp );
- break;
-
- case 's' :
- case 'S' : CMD_Search( cp );
- break;
-
- case 'q' :
- case 'Q' : CMD_Quit( cp );
- break;
-
- }
- break;
-
- case IDCMP_DISKINSERTED :
- case IDCMP_DISKREMOVED : {
- STRPTR *newDevList;
-
- if( !( newDevList = GetDevList(cp) ) )
- Shutdown( cp , 20 );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchDevGad ,
- cp->ffWindow , NULL ,
- GTCY_Labels , newDevList,
- GTCY_Active , 0,
- TAG_END );
-
- cp->searchDev = 0;
-
- if( cp->devList )
- {
- FreeDevList( cp->devList );
- cp->devList = newDevList;
- }
-
- }
-
- break;
-
- case IDCMP_REFRESHWINDOW : GT_BeginRefresh(cp->ffWindow);
- GT_EndRefresh(cp->ffWindow,TRUE);
- break;
-
- case IDCMP_GADGETUP : switch( gad->GadgetID )
- {
- case ID_PATGAD : strncpy( cp->searchString ,
- ((struct StringInfo *)
- cp->ffWinGads.searchPatGad
- ->SpecialInfo)->Buffer ,
- MAXSTR );
- break;
-
- case ID_DEVGAD : cp->searchDev = code;
- break;
-
- case ID_FOUNDLIST : if(!IsListEmpty((struct List *)
- &(cp->foundList)))
- {
- struct foundNode *fn;
- fn=NodeAddress(&(cp->foundList),
- code),
- GT_SetGadgetAttrs(
- cp->ffWinGads.pathListGad,
- cp->ffWindow,
- NULL,
- GTLV_Labels, &(fn->fn_PathList),
- GTLV_Top, 0L,
- TAG_END );
- cp->currFound = code;
- }
- break;
-
- case ID_SEARCH : CMD_Search( cp );
- break;
-
- case ID_HIDE : CMD_Hide( cp );
- break;
-
- case ID_QUIT : CMD_Quit( cp );
- break;
-
- }
- break;
- }
- if( ! cp->ffWindow )
- break;
- }
- }
-
- void
- CreateFFGadgets( struct controlPanel *cp, STRPTR *devList, int topEdge , BYTE leftEdge)
- {
- struct Gadget *gadget;
- struct NewGadget ng;
-
-
-
- cp->ffWinGadList = NULL;
-
- if( ! ( gadget = CreateContext( &(cp->ffWinGadList) ) ) )
- Shutdown( cp , 20 );
-
- ng.ng_Width = 162;
- ng.ng_Height = 16;
- ng.ng_GadgetText = "Search _Pattern :";
- ng.ng_TextAttr = &DefaultFont;
- ng.ng_VisualInfo = cp->ffWinVi;
- ng.ng_GadgetID = ID_PATGAD;
- ng.ng_Flags = 0;
- ng.ng_LeftEdge = ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
- ng.ng_TopEdge = 5 + topEdge;
-
- cp->ffWinGads.searchPatGad = gadget = CreateGadget( STRING_KIND, gadget, &ng,
- GT_Underscore, '_',
- GTST_MaxChars, MAXSTR,
- GTST_String, cp->searchString,
- TAG_DONE );
-
- ng.ng_GadgetID = ID_DEVGAD;
- ng.ng_GadgetText = "_Device to Search :";
- ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
- ng.ng_LeftEdge = ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
- ng.ng_Width = 145;
- ng.ng_Height = 18;
-
-
- cp->ffWinGads.searchDevGad = gadget = CreateGadget( CYCLE_KIND, gadget, &ng,
- GT_Underscore, '_',
- GTCY_Labels, devList,
- TAG_DONE );
-
-
-
-
- ng.ng_GadgetID = ID_FOUNDLIST;
- ng.ng_GadgetText = "_Files Found :";
- ng.ng_TopEdge += ng.ng_Height + 16;
- ng.ng_LeftEdge = leftEdge + 5;
- ng.ng_Width = 160;
- ng.ng_Height = 76;
-
- cp->ffWinGads.foundListGad = gadget = CreateGadget( LISTVIEW_KIND, gadget, &ng,
- GTLV_ShowSelected, NULL,
- GT_Underscore, '_',
- TAG_DONE );
-
-
- ng.ng_GadgetID = ID_PATHLIST;
- ng.ng_GadgetText = "Path :";
- ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
- ng.ng_Width = 131;
-
- cp->ffWinGads.pathListGad = gadget = CreateGadget( LISTVIEW_KIND, gadget, &ng,
- GTLV_ReadOnly, TRUE,
- TAG_DONE );
-
-
- ng.ng_GadgetID = ID_SEARCH;
- ng.ng_GadgetText = "_Search";
- ng.ng_LeftEdge = leftEdge + 5L;
- ng.ng_TopEdge += ng.ng_Height + 4;
- ng.ng_Width = 94;
- ng.ng_Height = 20;
-
- cp->ffWinGads.searchButton = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
- GT_Underscore, '_',
- TAG_DONE );
-
-
- ng.ng_GadgetID = ID_HIDE;
- ng.ng_GadgetText = "_Hide";
- ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
-
- cp->ffWinGads.hideButton = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
- GT_Underscore, '_',
- TAG_DONE );
-
-
- ng.ng_GadgetID = ID_QUIT;
- ng.ng_GadgetText = "_Quit";
- ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
-
- cp->ffWinGads.quitButton = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
- GT_Underscore, '_',
- TAG_DONE );
-
- }
-
- void
- CenterWindow( struct Screen *sc, WORD *leftEdge, WORD *topEdge )
- {
- (*leftEdge) = sc->MouseX - (FF_WIDTH >> 1);
- (*topEdge) = sc->MouseY - (FF_HEIGHT >> 1);
-
- while((*leftEdge) + FF_WIDTH > sc->Width)
- (*leftEdge)--;
-
- while((*leftEdge) < 0)
- (*leftEdge)++;
-
- while((*topEdge) + FF_HEIGHT > sc->Height)
- (*topEdge)--;
-
- while((*topEdge) < 0)
- (*topEdge)++;
- }
-
- struct foundNode *
- NodeAddress( struct MinList *fl , UWORD ord )
- {
- struct foundNode *fn;
-
- fn = (struct foundNode *)fl->mlh_Head;
-
- while( ord-- )
- {
- fn = (struct foundNode *)fn->fn_Node.ln_Succ;
- }
-
- return( fn );
- }
-
- BOOL
- QuitCheck( struct controlPanel *cp )
- {
- struct IntuiMessage *msg;
- BOOL quit = FALSE;
-
- while( msg = GT_GetIMsg( cp->ffWindow->UserPort ) )
- {
- struct Gadget *gad;
- ULONG class;
- UWORD code;
-
- gad = msg->IAddress;
- class = msg->Class;
- code = msg->Code;
-
- GT_ReplyIMsg( msg );
-
- if( class == IDCMP_GADGETUP )
- {
- if( gad->GadgetID == ID_QUIT )
- {
- quit = TRUE;
- }
- }
- else
- if( class == IDCMP_VANILLAKEY )
- {
- if( code == 'q' || code == 'Q' )
- {
- quit = TRUE;
- }
- }
- else
- if( class == IDCMP_REFRESHWINDOW )
- {
- GT_BeginRefresh(cp->ffWindow);
- GT_EndRefresh(cp->ffWindow , TRUE);
- }
-
- }
-
- return( quit );
-
- }
-
- /*********************************************************************************/
-
- /******************************** DOS Interfacing Routines ***********************/
-
- /**********************************************************
- Copy a BSTR to CSTR. Equivalent to strcpy().
- **********************************************************/
-
- void
- Bstrcpy( UBYTE *dest , BSTR bsrc )
- {
- UBYTE *src = ( UBYTE *)BADDR( bsrc );
- SHORT pos;
- UBYTE len;
-
- len = *src++;
-
- for ( pos = 0; pos < len; pos++ )
- *dest++ = *src++;
-
- *dest++ = ':';
- *dest = '\0';
-
- }
-
- STRPTR *
- GetDevList( struct controlPanel *cp )
- {
- struct DosList *dList,
- *sdList;
- STRPTR *devList;
- int numVols = 0;
-
- dList = LockDosList( LDF_VOLUMES|LDF_READ );
-
- sdList = dList;
-
- while( dList = NextDosEntry( dList , LDF_VOLUMES|LDF_READ ) )
- numVols++;
-
- cp->numDevs = numVols;
-
- if( !( devList = AllocVec( (numVols + 1) * sizeof( STRPTR ) , MEMF_ANY|MEMF_CLEAR )))
- goto exitgdl;
-
- numVols = 0;
-
- while( sdList = NextDosEntry( sdList , LDF_VOLUMES|LDF_READ ) )
- {
- if( !( devList[numVols] = AllocVec( MAXSTR , MEMF_ANY|MEMF_CLEAR )))
- goto exitgdl;
-
- Bstrcpy( devList[numVols++] , sdList->dol_Name );
- }
-
- exitgdl:
-
- UnLockDosList( LDF_VOLUMES|LDF_READ );
-
- return( devList );
- }
-
- void
- FreeDevList( STRPTR *devList )
- {
- int loc = 0;
-
- while( devList[loc] )
- FreeVec( devList[loc++] );
-
- FreeVec( devList );
-
- }
-
- BOOL
- ScanDir( STRPTR dirName , struct controlPanel *cp , struct MinList *pathList )
- {
- BPTR currentDir,
- parentDir;
- struct FileInfoBlock *fib;
- BOOL cont = FALSE,
- done = FALSE;
-
-
- if(!(fib = AllocDosObject( DOS_FIB, NULL ) ) )
- return( FALSE );
-
-
- currentDir = Lock( dirName, ACCESS_READ );
-
- Examine( currentDir, fib );
-
- AddPathNode( pathList, fib->fib_FileName );
-
- parentDir = CurrentDir( currentDir );
-
- while( !done )
- {
- if( !ExNext( currentDir, fib ) )
- break;
-
- if( fib->fib_DirEntryType >= 0 )
- cont = ScanDir( fib->fib_FileName, cp, pathList );
- else
- {
- if( MatchFile( cp, fib->fib_FileName ) )
- {
- AddFoundFile( cp, fib->fib_FileName, pathList );
-
- /* Gadget Work */
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, (&cp->foundList),
- GTLV_Selected, 0L,
- TAG_DONE );
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, ~0L,
- TAG_DONE );
-
- }
- }
-
- if( cont )
- {
- done = QuitCheck( cp );
- }
- }
-
- currentDir = CurrentDir( parentDir );
-
- UnLock( currentDir );
-
- if( done == FALSE && IoErr() == ERROR_NO_MORE_ENTRIES )
- cont = TRUE;
- else
- cont = FALSE;
-
- DeletePathNode( pathList );
-
- FreeDosObject( DOS_FIB, fib );
-
- return( cont );
-
- }
-
- BOOL
- MatchFile( struct controlPanel *cp, STRPTR fileName )
- {
- if( MatchPatternNoCase( cp->ignoreIconsPat, fileName ) )
- {
- if( MatchPatternNoCase( cp->searchPattern, fileName ) )
- {
- return( TRUE );
- }
- }
- return( FALSE );
-
- }
-
- /******************************** Custom List Mgmt *******************************/
-
- void
- AddPathNode( struct MinList *list , UBYTE *pathName )
- {
- struct pathNode *pn;
-
- pn = AllocVec( sizeof( struct pathNode ) , MEMF_ANY|MEMF_CLEAR );
-
- pn->pn_Node.ln_Name = pn->pn_Name;
-
- strcpy( pn->pn_Name , pathName );
-
- AddTail( (struct List *)list , &pn->pn_Node );
- }
-
- void
- DeletePathNode( struct MinList *list )
- {
- struct pathNode *pn;
-
- pn = ( struct pathNode *)RemTail( (struct List *)list );
-
- FreeVec( pn );
-
- }
-
- struct foundNode *
- AddFoundNode( struct MinList *list , UBYTE *foundName , BOOL sort )
- {
- struct foundNode *fn;
- struct Node *node,
- *pred;
-
- fn = AllocVec( sizeof( struct foundNode ) , MEMF_ANY|MEMF_CLEAR );
-
- fn->fn_Node.ln_Name = fn->fn_Name;
-
- strcpy( fn->fn_Name , foundName );
-
- NewList( (struct List *)&fn->fn_PathList );
-
- if( sort )
- {
- pred = NULL;
-
- for( node = (struct Node *)list->mlh_Head ; node->ln_Succ ; node = node->ln_Succ )
- {
- if( stricmp( node->ln_Name , foundName ) > 0 )
- break;
- pred = node;
- }
-
- }
- else
- pred = (struct Node *)&list->mlh_Tail;
-
- Insert( (struct List *)list, (struct Node *)fn, pred );
-
- return( fn );
-
- }
-
- void
- DeleteFoundList( struct MinList *list )
- {
- while( ! IsListEmpty( (struct List *)list ))
- {
- struct foundNode *fn;
- struct pathNode *pn;
-
- fn = (struct foundNode *)RemHead( (struct List *)list );
- while(! IsListEmpty( (struct List *)&fn->fn_PathList ) )
- {
- pn = (struct pathNode *)RemHead( (struct List *)&fn->fn_PathList );
- FreeVec( pn );
- }
- FreeVec( fn );
- }
- }
-
- void
- AddFoundFile( struct controlPanel *cp, STRPTR fileName,
- struct MinList *pathList )
- {
- struct foundNode *fn;
- struct Node *pn;
-
- fn = AddFoundNode(&cp->foundList, fileName, cp->sortList );
- if( !IsListEmpty((struct List *)pathList ))
- {
- for( pn = (struct Node *)pathList->mlh_Head; pn->ln_Succ; pn = pn->ln_Succ )
- AddPathNode( &fn->fn_PathList, pn->ln_Name );
- }
- ++(cp->numFound);
- }
-
- /******************************** Commodities Exchange Handling Routines *********/
-
- void
- OpenCxInterface( struct controlPanel *cp )
- {
- struct NewBroker nb = {
- NB_VERSION,
- ( BYTE *)NAME,
- ( BYTE *)NAME " " _VERSION,
- ( BYTE *)"Searches a volume for a file",
- NBU_UNIQUE | NBU_NOTIFY,
- COF_SHOW_HIDE,
- 0,
- NULL,
- 0
- };
-
-
- nb.nb_Pri = cp->cxInterface.cxPriority;
-
-
- /******* Allocate And Initialize MessagePort *********/
- if( !( cp->cxInterface.cxPort = CreateMsgPort() ) )
- Shutdown( cp, 20 );
-
-
- nb.nb_Port = cp->cxInterface.cxPort;
-
- /******* Create Main Broker CxObj ********************/
-
- if( !( cp->cxInterface.ffBroker = CxBroker( &nb, NULL ) ) )
- Shutdown( cp, 20 );
-
-
- /******* Create HotKey CxObj *************************/
-
- AttachCxObj( cp->cxInterface.ffBroker, HotKey( cp->cxInterface.cxHotKeyString,
- cp->cxInterface.cxPort,
- OPEN_WINDOW ));
-
- /******* If all went well, activate the Broker *******/
-
- if( ! CxObjError( cp->cxInterface.ffBroker ) )
- ActivateCxObj( cp->cxInterface.ffBroker , TRUE );
- else
- Shutdown( cp , 20 );
-
- }
-
- void
- CloseCxInterface( struct controlPanel *cp )
- {
- if( cp->cxInterface.cxPort )
- {
- struct Message *msg;
-
- if( cp->cxInterface.ffBroker )
- DeleteCxObjAll( cp->cxInterface.ffBroker );
- cp->cxInterface.ffBroker = NULL;
-
- while( msg = GetMsg( cp->cxInterface.cxPort ) )
- ReplyMsg( msg );
-
- DeleteMsgPort( cp->cxInterface.cxPort );
- cp->cxInterface.cxPort = NULL;
-
- }
- }
-
- void
- HandleCxCommand( struct controlPanel *cp )
- {
- CxMsg *msg;
-
- while( msg = ( CxMsg *)GetMsg( cp->cxInterface.cxPort ) )
- {
- ULONG messageID;
- ULONG messageType;
-
- messageID = CxMsgID( msg );
- messageType = CxMsgType( msg );
-
- ReplyMsg( ( struct Message *)msg );
-
- switch( messageType )
- {
- case CXM_IEVENT : switch( messageID )
- {
- case OPEN_WINDOW : CMD_Show( cp );
- break;
- }
- break;
-
- case CXM_COMMAND : switch( messageID )
- {
- case CXCMD_DISABLE : ActivateCxObj( cp->cxInterface.ffBroker,
- FALSE );
- break;
- case CXCMD_ENABLE : ActivateCxObj( cp->cxInterface.ffBroker,
- TRUE );
- break;
-
- case CXCMD_APPEAR :
- case CXCMD_UNIQUE : CMD_Show( cp );
- break;
-
- case CXCMD_DISAPPEAR : CMD_Hide( cp );
- break;
-
- case CXCMD_KILL : CMD_Quit( cp );
- break;
- }
- break;
- }
- }
- }
-
- /**********************************************************************************/
-
- /*************** Command functions start here ************************************/
-
- void
- CMD_Show( struct controlPanel *cp )
- {
- OpenFFWindow( cp );
- }
-
- void
- CMD_Hide( struct controlPanel *cp )
- {
- CloseFFWindow( cp );
- }
-
- void
- CMD_Search( struct controlPanel *cp )
- {
- struct foundNode *fn;
- struct pathNode *pn;
- struct MinList pathList;
-
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchPatGad,
- cp->ffWindow, NULL,
- GA_Disabled, TRUE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchDevGad,
- cp->ffWindow, NULL,
- GA_Disabled, TRUE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchButton,
- cp->ffWindow, NULL,
- GA_Disabled, TRUE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.hideButton,
- cp->ffWindow, NULL,
- GA_Disabled, TRUE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, NULL,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.pathListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, NULL,
- TAG_END );
-
- DeleteFoundList( &cp->foundList );
-
- cp->numFound = 0;
- cp->currFound = ~0;
-
- NewList( (struct List *)&pathList );
-
- if( ParsePatternNoCase( cp->searchString , cp->searchPattern , MAXPAT ) == -1 )
- return;
-
- ScanDir( cp->devList[cp->searchDev] , cp , &pathList );
-
- /** Forget about the return from ScanDir(). It is only
- used as an abort code for the recursion, and meaningful
- only inside that func. ScanDir() will return a valid, but
- not complete list even if the user aborted the search **/
-
- GT_SetGadgetAttrs( cp->ffWinGads.foundListGad,
- cp->ffWindow, NULL,
- GTLV_Labels, (&cp->foundList),
- GTLV_Selected, ~0L,
- TAG_DONE );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchPatGad,
- cp->ffWindow, NULL,
- GA_Disabled, FALSE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchDevGad,
- cp->ffWindow, NULL,
- GA_Disabled, FALSE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.searchButton,
- cp->ffWindow, NULL,
- GA_Disabled, FALSE,
- TAG_END );
-
- GT_SetGadgetAttrs( cp->ffWinGads.hideButton,
- cp->ffWindow, NULL,
- GA_Disabled, FALSE,
- TAG_END );
-
- }
-
- void
- CMD_Quit( struct controlPanel *cp )
- {
- Shutdown( cp , 0 );
- }
-
- /**********************************************************************************/
-
- /*************** Comprehensive Shutdown Code *************************************/
- void
- Shutdown( struct controlPanel *cp , int retCode )
- {
-
- if( cp )
- {
-
- /*************************** Close Cx port and interface ************************/
-
- if( cp->cxInterface.cxPort )
- {
- CloseCxInterface( cp );
- }
-
- /*************************** Get Rid of Window and Related GadTools Stuff *******/
-
- if( cp->ffWindow )
- {
- CloseFFWindow( cp );
- cp->ffWindow = NULL;
- }
-
- if( cp->ffWinGadList )
- {
- FreeGadgets( cp->ffWinGadList );
- cp->ffWinGadList = NULL;
- }
-
- if( cp->ffWinVi );
- {
- FreeVisualInfo( cp->ffWinVi );
- cp->ffWinGadList = NULL;
- }
-
- DeleteFoundList( &cp->foundList );
-
- if( cp->devList )
- {
- FreeDevList( cp->devList );
- cp->devList = NULL;
- }
-
- FreeVec( cp );
-
- }
- /******************************* Close Libraries & exit ************************/
-
- if( IntuitionBase )
- CloseLibrary( IntuitionBase );
-
- if( GadToolsBase )
- CloseLibrary( GadToolsBase );
-
- if( IconBase )
- CloseLibrary( IconBase );
-
- if( CxBase )
- CloseLibrary( CxBase );
-
- exit( retCode );
-
- }
- /********************************************************************************/
-
-