380 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			380 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| //
 | |
| // WILDOS2.CPP
 | |
| //
 | |
| //  Source file for ArchiveLib 2.0
 | |
| //
 | |
| //  Copyright (c) Greenleaf Software, Inc. 1994-1996
 | |
| //  All Rights Reserved
 | |
| //
 | |
| // CONTENTS
 | |
| //
 | |
| //  ALWildCardExpander::ConstructOsData()
 | |
| //  ALWildCardExpander::DestroyOsData()
 | |
| //  ALWildCardExpander::GetNextFile()
 | |
| //
 | |
| // DESCRIPTION
 | |
| //
 | |
| //  This file contains the OS specific routines need to expand
 | |
| //  wild card file names.  Different versions of these three functions
 | |
| //  exist for DOS, Win95, and OS/2.
 | |
| //
 | |
| // REVISION HISTORY
 | |
| //
 | |
| //   February 14, 1996  2.0A : New release
 | |
| //
 | |
| 
 | |
| #include "arclib.h"
 | |
| #if !defined( AL_IBM )
 | |
| #pragma hdrstop
 | |
| #endif
 | |
| 
 | |
| #define INCL_DOSFILEMGR
 | |
| #include <os2.h>
 | |
| 
 | |
| #include "wildcard.h"
 | |
| 
 | |
| struct ALWildCardOsData {  /* Tag internal class */
 | |
|     HDIR mHandle;
 | |
| };
 | |
| 
 | |
| //
 | |
| // NAME
 | |
| //
 | |
| //  ALWildCardExpander::ConstructOsData()
 | |
| //
 | |
| // PLATFORMS/ENVIRONMENTS
 | |
| //
 | |
| //  OS/2
 | |
| //  C++
 | |
| //
 | |
| // SHORT DESCRIPTION
 | |
| //
 | |
| //  Allocate space for a wildcard search under the OS/2 file system.
 | |
| //
 | |
| // C++ SYNOPSIS
 | |
| //
 | |
| //  #include "arclib.h"
 | |
| //  #include "wildcard
 | |
| //
 | |
| //  void ALWildCardExpander::ConstructOsData();
 | |
| //
 | |
| // C SYNOPSIS
 | |
| //
 | |
| //  No C translation for this internal protected function.
 | |
| //
 | |
| // VB SYNOPSIS
 | |
| //
 | |
| //  No VB translation for this internal protected function.
 | |
| //
 | |
| // DELPHI SYNOPSIS
 | |
| //
 | |
| //  No Delphi translation for this internal protected function.
 | |
| //
 | |
| // ARGUMENTS
 | |
| //
 | |
| //  None.
 | |
| //
 | |
| // DESCRIPTION
 | |
| //
 | |
| //  The process of wild card file expansion differs drastically for
 | |
| //  all the different environments we support.  Since each system
 | |
| //  is going to have different data requirements, we don't try to
 | |
| //  allocate any specialized data in the base class.  Instead, we just keep a
 | |
| //  pointer to the data, and allocate it in this member function.  Different
 | |
| //  versions of this member function show up in different directories, and the
 | |
| //  BUILD.INI file directs the compiler as to which to include.
 | |
| //
 | |
| //  This module supports the OS/2 file system.  The OS/2 wild card
 | |
| //  expansion state is stored in an HDIR handle.  We allocate that
 | |
| //  structure here, and store a pointer to it in the mpOsData member
 | |
| //  of the ALWildCardExpander structure.  Note that the HDIR data
 | |
| //  isn't initialized yet, we have just allocated some space for it.
 | |
| //
 | |
| // RETURNS
 | |
| //
 | |
| //  Nothing.
 | |
| //
 | |
| // EXAMPLE
 | |
| //
 | |
| // SEE ALSO
 | |
| //
 | |
| // REVISION HISTORY
 | |
| //
 | |
| //   February 14, 1996  2.0A : New release.
 | |
| //
 | |
| 
 | |
| void AL_PROTO
 | |
| ALWildCardExpander::ConstructOsData()  /* Tag protected function */
 | |
| {
 | |
|     mpOsData = new ALWildCardOsData;
 | |
|     if ( mpOsData )
 | |
|         mpOsData->mHandle = 0xffffffff;
 | |
| }
 | |
| 
 | |
| //
 | |
| // NAME
 | |
| //
 | |
| //  ALWildCardExpander::DestroyOsData()
 | |
| //
 | |
| // PLATFORMS/ENVIRONMENTS
 | |
| //
 | |
| //  OS/2
 | |
| //  C++
 | |
| //
 | |
| // SHORT DESCRIPTION
 | |
| //
 | |
| //  Destroy the space allocated for the wildcard search under OS/2.
 | |
| //
 | |
| // C++ SYNOPSIS
 | |
| //
 | |
| //  #include "arclib.h"
 | |
| //  #include "wildcard
 | |
| //
 | |
| //  void ALWildCardExpander::DestroyOsData();
 | |
| //
 | |
| // C SYNOPSIS
 | |
| //
 | |
| //  No C translation for this internal protected function.
 | |
| //
 | |
| // VB SYNOPSIS
 | |
| //
 | |
| //  No VB translation for this internal protected function.
 | |
| //
 | |
| // DELPHI SYNOPSIS
 | |
| //
 | |
| //  No Delphi translation for this internal protected function.
 | |
| //
 | |
| // ARGUMENTS
 | |
| //
 | |
| //  None.
 | |
| //
 | |
| // DESCRIPTION
 | |
| //
 | |
| //  The process of wild card file expansion differs drastically for
 | |
| //  all the different environments we support.  Since each system
 | |
| //  is going to have different data requirements, we don't try to
 | |
| //  allocate system-specific data in the base class.  Instead, we just keep a
 | |
| //  pointer to the data, and allocate it in the member function
 | |
| //  ConstructOsData().
 | |
| //
 | |
| //  If we are constructing something when the search starts, it makes sense
 | |
| //  that we need to destroy it when the search is over.  That's what this
 | |
| //  guy does.
 | |
| //
 | |
| // RETURNS
 | |
| //
 | |
| //  Nothing.
 | |
| //
 | |
| // EXAMPLE
 | |
| //
 | |
| // SEE ALSO
 | |
| //
 | |
| // REVISION HISTORY
 | |
| //
 | |
| //   February 14, 1996  2.0A : New release.
 | |
| //
 | |
| 
 | |
| void AL_PROTO
 | |
| ALWildCardExpander::DestroyOsData()  /* Tag protected function */
 | |
| {
 | |
|     if ( mpOsData != 0 ) {
 | |
|         if ( mpOsData->mHandle != 0xffffffff )
 | |
|             DosFindClose( mpOsData->mHandle );
 | |
|         delete mpOsData;
 | |
|     }
 | |
|     mpOsData = 0;
 | |
| }
 | |
| 
 | |
| //
 | |
| // NAME
 | |
| //
 | |
| //  ALWildCardExpander::GetNextFile()
 | |
| //
 | |
| // PLATFORMS/ENVIRONMENTS
 | |
| //
 | |
| //  OS/2
 | |
| //  C++  C
 | |
| //
 | |
| // SHORT DESCRIPTION
 | |
| //
 | |
| //  Search for an additional file in the wildcard expansion.
 | |
| //
 | |
| // C++ SYNOPSIS
 | |
| //
 | |
| //  #include "arclib.h"
 | |
| //  #include "wildcard.h"
 | |
| //
 | |
| //  char *ALWildCardExpander::GetNextFile();
 | |
| //
 | |
| // C SYNOPSIS
 | |
| //
 | |
| //  #include "arclib.h"
 | |
| //  #include "wildcard.h"
 | |
| //
 | |
| //  char * ALExpanderGetNextFile( hALExpander this_object );
 | |
| //
 | |
| // VB SYNOPSIS
 | |
| //
 | |
| //  None, at least not for OS/2.
 | |
| //
 | |
| // DELPHI SYNOPSIS
 | |
| //
 | |
| //  None, at least not for OS/2.
 | |
| //
 | |
| // ARGUMENTS
 | |
| //
 | |
| //  this_object  :  A reference or pointer to the ALWildCardExpander that
 | |
| //                  is performing the expansion.  Note that the C++ member
 | |
| //                  version of this call doesn't have an explicit argument
 | |
| //                  here, since it has access to 'this' implicitly.
 | |
| //
 | |
| // DESCRIPTION
 | |
| //
 | |
| //  The ALWildCardExpander has what amounts to six different internal
 | |
| //  states.  They are:
 | |
| //
 | |
| //              Searching subdirectories, using another object
 | |
| //
 | |
| //              Extracting the next wild spec from the input line
 | |
| //
 | |
| //              Expanding the wild card to get the first matching file
 | |
| //
 | |
| //              Expanding the wild card to get the next matching file
 | |
| //
 | |
| //              Looking for the first subdirectory
 | |
| //
 | |
| //              Looking for the next subdirectory
 | |
| //
 | |
| //  For the most part, we keep track of the state using the mState
 | |
| //  variable.  However, we keep track of whether we are searching
 | |
| //  subdirectories by examining the pointer to the next expander.  If
 | |
| //  it is non-null, it means we are in that state.
 | |
| //
 | |
| // RETURNS
 | |
| //
 | |
| //  In the event that this routine is able to come up with a new
 | |
| //  file name, it returns a character pointer to the name, which
 | |
| //  is kept in member variable mResultFileName.  If no new file
 | |
| //  name could be cooked up, we return a 0, which means you are
 | |
| //  done.
 | |
| //
 | |
| // EXAMPLE
 | |
| //
 | |
| // SEE ALSO
 | |
| //
 | |
| // REVISION HISTORY
 | |
| //
 | |
| //   February 14, 1996  2.0A : New release.
 | |
| //
 | |
| 
 | |
| char AL_DLL_FAR * AL_PROTO
 | |
| ALWildCardExpander::GetNextFile()  /* Tag public function */
 | |
| {
 | |
|     FILEFINDBUF3 buffer = { 0 };
 | |
|     ULONG count;
 | |
| 
 | |
|     if ( mpOsData == 0 )
 | |
|         return 0;
 | |
|     for ( ; ; ) {
 | |
|         if ( mpNextExpander ) {
 | |
|             char *p = mpNextExpander->GetNextFile();
 | |
|             if ( p )
 | |
|                 return p;
 | |
|             delete mpNextExpander;
 | |
|             mpNextExpander = 0;
 | |
|         }
 | |
|         switch ( mState ) {
 | |
|             case GET_NEXT_WILD_NAME :
 | |
|                 if ( GetNextWildName() == 0 )
 | |
|                     return 0;
 | |
|                 mWildPathOnly = mFullWildName;
 | |
|                 mWildPathOnly.StripFileName();
 | |
|                 mWildNameOnly = mFullWildName;
 | |
|                 mWildNameOnly.StripPath();
 | |
|                 mState = GET_FIRST_FILE_NAME;
 | |
|                 break;
 | |
|             case GET_FIRST_FILE_NAME :
 | |
|                 if ( mpOsData->mHandle != 0xffffffff ) {
 | |
|                     DosFindClose( mpOsData->mHandle );
 | |
|                     mpOsData->mHandle = 0xffffffff;
 | |
|                 }
 | |
|                 count = 1;
 | |
|                 if ( DosFindFirst( (PSZ) (char *) mFullWildName,
 | |
|                                    &mpOsData->mHandle,
 | |
|                                    FILE_READONLY,
 | |
|                                    (PVOID) &buffer,
 | |
|                                    sizeof( buffer ),
 | |
|                                    &count,
 | |
|                                    FIL_STANDARD ) || count == 0 ) { //Don't want to exclude RO files
 | |
|                     if ( miTraverseFlag )
 | |
|                         mState = GET_FIRST_DIRECTORY;
 | |
|                     else
 | |
|                         mState = GET_NEXT_WILD_NAME;
 | |
|                     break;
 | |
|                 }
 | |
|                 mState = GET_NEXT_FILE_NAME;
 | |
|                 mResultFileName = ALName( mWildPathOnly + buffer.achName );
 | |
|                 return mResultFileName;
 | |
|             case GET_NEXT_FILE_NAME :
 | |
|                 count = 1;
 | |
|                 if ( DosFindNext( mpOsData->mHandle,
 | |
|                                   (PVOID) &buffer,
 | |
|                                   sizeof( buffer ),
 | |
|                                   &count ) || count == 0 ) {
 | |
|                     if ( miTraverseFlag )
 | |
|                         mState = GET_FIRST_DIRECTORY;
 | |
|                     else
 | |
|                         mState = GET_NEXT_WILD_NAME;
 | |
|                     break;
 | |
|                 }
 | |
|                 mResultFileName = mWildPathOnly + buffer.achName;
 | |
|                 return mResultFileName;
 | |
|             case GET_FIRST_DIRECTORY :
 | |
|                 count = 1;
 | |
|                 if ( mpOsData->mHandle != 0xffffffff ) {
 | |
|                     DosFindClose( mpOsData->mHandle );
 | |
|                     mpOsData->mHandle = 0xffffffff;
 | |
|                 }
 | |
|                 if ( DosFindFirst( (PSZ)(char *)( mWildPathOnly + "*.*" ),
 | |
|                                    &mpOsData->mHandle,
 | |
|                                    MUST_HAVE_DIRECTORY,
 | |
|                                    (PVOID) &buffer,
 | |
|                                    sizeof( buffer ),
 | |
|                                    &count,
 | |
|                                    FIL_STANDARD ) || count == 0 ) { //Don't want to exclude RO files
 | |
|                     mState = GET_NEXT_WILD_NAME;
 | |
|                     break;
 | |
|                 }
 | |
|                 mState = GET_NEXT_DIRECTORY;
 | |
|                 if ( strcmp( buffer.achName, ".." ) == 0 )
 | |
|                     break;
 | |
|                 if ( strcmp( buffer.achName, "." ) == 0 )
 | |
|                     break;
 | |
|                 mpNextExpander = new ALWildCardExpander( mWildPathOnly + buffer.achName + "\\" + (char *) mWildNameOnly, 1, mCase );
 | |
|                 break;
 | |
| //
 | |
| // This is just like GET_FIRST_DIRECTORY, except it gets to call
 | |
| // _dos_findnext() instead of _dos_findfirst().
 | |
| //
 | |
|             case GET_NEXT_DIRECTORY :
 | |
|                 count = 1;
 | |
|                 if ( DosFindNext( mpOsData->mHandle,
 | |
|                                   (PVOID) &buffer,
 | |
|                                   sizeof( buffer ),
 | |
|                                   &count ) || count == 0 ) {
 | |
|                     mState = GET_NEXT_WILD_NAME;
 | |
|                     break;
 | |
|                 }
 | |
|                 if ( strcmp( buffer.achName, ".." ) == 0 )
 | |
|                     break;
 | |
|                 if ( strcmp( buffer.achName, "." ) == 0 )
 | |
|                     break;
 | |
|                 mpNextExpander = new ALWildCardExpander( mWildPathOnly + buffer.achName + "\\" + (char *) mWildNameOnly, 1 );
 | |
|                 break;
 | |
|             default :
 | |
|                 return 0;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 |