You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dm...@apache.org on 2004/05/26 19:39:21 UTC

cvs commit: xml-xalan/c/src/xalanc/PlatformSupport DirectoryEnumerator.hpp

dmitryh     2004/05/26 10:39:21

  Modified:    c/Tests  Makefile.in
               c/Tests/Harness FileUtility.cpp
               c/src/xalanc/PlatformSupport DirectoryEnumerator.hpp
  Log:
  Patch for  Bugzilla 24630  -  Porting Conf executable to Unix platforms
  
  Revision  Changes    Path
  1.8       +1 -1      xml-xalan/c/Tests/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/Tests/Makefile.in,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Makefile.in	6 Apr 2004 15:08:45 -0000	1.7
  +++ Makefile.in	26 May 2004 17:39:20 -0000	1.8
  @@ -48,7 +48,7 @@
   
   all: Tests
   
  -tests : ThreadTest
  +tests : ThreadTest Conf
   
   Tests:   ThreadTest Conf
   
  
  
  
  1.58      +46 -6     xml-xalan/c/Tests/Harness/FileUtility.cpp
  
  Index: FileUtility.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/Tests/Harness/FileUtility.cpp,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- FileUtility.cpp	14 Apr 2004 02:04:01 -0000	1.57
  +++ FileUtility.cpp	26 May 2004 17:39:20 -0000	1.58
  @@ -38,7 +38,8 @@
   #define DIR_MODE_BITS 509
   #include <dirent.h>
   #include <unistd.h>
  -extern "C" int mkdir(const char*, mode_t mode);
  +
  +#include <sys/stat.h>
   #endif
   
   
  @@ -420,6 +421,9 @@
               const XalanDOMString&   relDir,
               bool                    useDirPrefix)
   {
  +	char buffer3[PATH_MAX];
  +    getcwd(buffer3, PATH_MAX);
  +
       const XalanDOMString    searchSuffix(XALAN_STATIC_UCODE_STRING("*.xsl"));
       XalanDOMString  searchSpecification;
   
  @@ -439,6 +443,8 @@
       FileNameVectorType  theFiles;
       theEnumerator(searchSpecification, theFiles);
   
  +	chdir(buffer3);
  +
       return theFiles;
   }
   
  @@ -450,11 +456,16 @@
   FileUtility::FileNameVectorType
   FileUtility::getDirectoryNames(const XalanDOMString&        rootDirectory)
   {
  +	char buffer2[PATH_MAX];
  +	getcwd(buffer2, PATH_MAX);
  +
       const XalanDOMString    dirSpec(XALAN_STATIC_UCODE_STRING("*"));
   
       DirectoryEnumeratorFunctor<FileNameVectorType, XalanDOMString, DirectoryFilterPredicate> theEnumerator;
       FileNameVectorType  theFiles;
       theEnumerator(XalanDOMString(rootDirectory), XalanDOMString(dirSpec), theFiles);
  +	
  +	chdir(buffer2);
   
       return theFiles;
   }
  @@ -986,13 +997,14 @@
                   data.actual = XalanDOMString("<![CDATA[") + XalanDOMString(rline) + XalanDOMString("]]>");
                   data.currentNode = XalanDOMString("Line: ") + XalanDOMString(temp);
                   data.fail += 1;
  +			fclose(result); 	fclose(gold);
                   return false;
               }
           }
   
           lineNum += 1;
       }
  -
  +			fclose(result); 	fclose(gold);
       return true;
   }
   
  @@ -1842,12 +1854,36 @@
       XalanDOMString paramValue;
       bool    fileStatus;
   
  +#if defined(AIX) || defined(SOLARIS) || defined(LINUX) || defined(HPUX)
  +
  +	bool	pathStatus;
  +	CharVectorType     withPath;
  +	TranscodeToLocalCodePage(resultsFile, withPath, false);
  +	if (withPath[0] == '/')
  +		pathStatus=true;
  +	else
  +		pathStatus=false;
  +	
  +	char buffer5[PATH_MAX];
  +	XalanDOMString resultPath= XalanDOMString(getcwd(buffer5, PATH_MAX));
  +	append(resultPath, s_pathSep);
  +#endif
  +	
  +
       // Pass the results .xml file as a parameter to the stylesheet.  It must be wrapped in single
       // quotes so that it is not considered an expression.
       //
  -    assign(paramValue, XalanDOMString("'"));
  -    append(paramValue, resultsFile);
  -    append(paramValue, XalanDOMString("'"));
  +  #if defined (AIX) || defined(SOLARIS) || defined(LINUX) || defined(HPUX)
  +	assign(paramValue, XalanDOMString("\'"));
  +	if ( !pathStatus )
  +		append(paramValue, resultPath);
  +	append(paramValue, resultsFile);
  +	append(paramValue, XalanDOMString("\'"));
  +  #else	
  +	assign(paramValue, XalanDOMString("'"));
  +    	append(paramValue, resultsFile);
  +    	append(paramValue, XalanDOMString("'"));
  +  #endif
   
       // Set the parameter
       //
  @@ -1882,7 +1918,11 @@
   
       if (result == 0)
       {
  -        system(c_str(TranscodeToLocalCodePage(theHTMLFile)));
  +	#if defined(_MSC_VER)
  +		system(c_str(TranscodeToLocalCodePage(theHTMLFile)));
  +	#else
  +		cout << "The HTML output: " << theHTMLFile << " was created" << endl;
  +	#endif
       }
       else 
       {
  
  
  
  1.9       +97 -13    xml-xalan/c/src/xalanc/PlatformSupport/DirectoryEnumerator.hpp
  
  Index: DirectoryEnumerator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/PlatformSupport/DirectoryEnumerator.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DirectoryEnumerator.hpp	6 Apr 2004 15:08:45 -0000	1.8
  +++ DirectoryEnumerator.hpp	26 May 2004 17:39:21 -0000	1.9
  @@ -26,7 +26,13 @@
   #if defined(_MSC_VER)
   #include <io.h>
   #else
  +#include <unistd.h>
   #include <dirent.h>
  +#include <sys/stat.h>
  +#include <errno.h>
  +
  +extern int 	errno;
  +
   #endif
   
   
  @@ -35,7 +41,7 @@
   #include <iterator>
   
   
  -
  +#include <xalanc/PlatformSupport/XalanFileOutputStream.hpp>
   #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
   #include <xalanc/PlatformSupport/XalanUnicode.hpp>
   
  @@ -137,8 +143,30 @@
   	 */
   	bool isDirectory() const
   	{
  -#if defined(AIX) || defined(HPUX) || defined(SOLARIS) || defined(OS390) || defined(OS400) || defined(TRU64)  || defined(CYGWIN)
  +#if defined(OS390) || defined(OS400) || defined(TRU64)
   		return false;
  +
  +#elif defined(AIX) || defined(SOLARIS) || defined(LINUX) || defined(HPUX) || defined(CYGWIN)
  +
  +	struct	stat stat_Info;
  +	int	retCode = stat (d_name, &stat_Info);
  + 
  +	if ( retCode == -1 )
  +	{
  +		typedef	XalanFileOutputStream::XalanFileOutputStreamOpenException XalanStatDirectoryException;
  +		throw	XalanStatDirectoryException( XalanDOMString(d_name), errno );
  +	}
  +
  +	if ( S_ISDIR(stat_Info.st_mode) == 1 )
  +	{   
  +		return true;
  +	}
  +	else 
  +	{   
  +		return false;
  +	}
  +
  +
   #else		
   		if (d_type == DT_DIR || d_type == DT_UNKNOWN)
   		{
  @@ -154,7 +182,7 @@
   	bool
   	isSelfOrParent() const
   	{
  -#if defined(AIX) || defined(HPUX) || defined(SOLARIS) || defined(OS390) || defined(OS400) || defined(TRU64)
  +#if defined(OS390) || defined(OS400) || defined(TRU64)
   		return false;
   #else		
   		if (isDirectory() == false)
  @@ -240,8 +268,14 @@
   {
   #if defined(_MSC_VER)
   	FindFileStruct 		theFindData;
  +	
  +	#ifdef _WIN64
  +		typedef	intptr_t	theHandleType;
  +	#else
  +		typedef	long	theHandleType;
  +	#endif
   
  -	long	theSearchHandle = _wfindfirst(const_cast<wchar_t*>(theConversionFunction(theFullSearchSpec)),
  +	theHandleType	theSearchHandle = _wfindfirst(const_cast<wchar_t*>(theConversionFunction(theFullSearchSpec)),
   										  &theFindData);
   
   	if (theSearchHandle != -1)
  @@ -269,36 +303,67 @@
   		_findclose(theSearchHandle);
   	}
   
  -	
  -#elif defined(LINUX)
  +
  +#elif defined(AIX) || defined(SOLARIS) || defined(LINUX) || defined(HPUX) || defined(CYGWIN)	
   
   	CharVectorType	theTargetVector;
   
   	TranscodeToLocalCodePage(theFullSearchSpec, theTargetVector, false);
   
   	const CharVectorType::size_type		theSize = theTargetVector.size();
  +	int  indexSuffix=0, indexName=0;
  +	bool target_Dir = false; 
   
   	if (theSize > 0)
   	{
   		if (theTargetVector.back() == '*')
   		{
  +			target_Dir = true;
   			theTargetVector.pop_back();
   
   			if (theSize == 1)
   			{
   				theTargetVector.push_back('.');
   			}
  +		
   		}
  +		else
  +        {
  +			target_Dir = false;
  +
  +			while(theTargetVector.back() != '*')
  +			{
  +				theTargetVector.pop_back();
  +				indexSuffix++;
  +			}
  +
  +			theTargetVector.pop_back();
  +			while(theTargetVector.back() != '/')
  +			{ 
  +				theTargetVector.pop_back();
  +				indexName++;
  +			}
  +		}      
   
   		theTargetVector.push_back('\0');
   
   		const char* const	theSpec = c_str(theTargetVector);
   		assert(theSpec != 0);
  +		
  +		XalanDOMString		theName;
  +		XalanDOMString		theSuffix;
  +		if ( !target_Dir )
  +		{
  +			int lenSpec = strlen(theSpec); 
  +			theName = theFullSearchSpec.substr(lenSpec, indexName); 
  +			theSuffix = theFullSearchSpec.substr(lenSpec+indexName+1, indexSuffix);
  +		}
   
   		DIR* const	theDirectory = opendir(theSpec);
   
   		if (theDirectory != 0)
   		{
  +			chdir(theSpec);
   			try
   			{
   				const FindFileStruct*	theEntry =
  @@ -306,22 +371,41 @@
   	
   				while(theEntry != 0)
   				{
  -					if ((fIncludeSelfAndParent == true || theEntry->isSelfOrParent() == false) &&
  -						theFilterPredicate(*theEntry) == true)
  +					if ((fIncludeSelfAndParent == true || theEntry->isSelfOrParent() == false))
   					{
  -						*theOutputIterator = StringType(theEntry->getName());
  +						if (theFilterPredicate(*theEntry) == true)
  +						{
  +							if( target_Dir )
  +							{
  +								*theOutputIterator = StringType(theEntry->getName());
  +							}
  +							else
  +							{
  +								XalanDOMString	Getname = StringType(theEntry->getName());
  +								int	Check_1 = Getname.compare(theName);
  +								XalanDOMString	GetnameSuffix = Getname.substr(length(Getname)-indexSuffix, indexSuffix);            
  +								int Check_2 = GetnameSuffix.compare(theSuffix);
  +								if ( Check_1 == 1 && (!Check_2) )
  +								{
  +									*theOutputIterator = Getname;
  +								}
  +							}
  +						}
   					}
  -
   					theEntry = (FindFileStruct*)readdir(theDirectory);
  -				}
  -			}
  +				} //while
  +			}//try
  +
   			catch(...)
   			{
   				closedir(theDirectory);
   
   				throw;
   			}
  -
  +			if( target_Dir )
  +                           chdir("..");
  +                         else
  +                           chdir("../..");
   			closedir(theDirectory);
   		}
   	}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org