⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsentity.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
字号:
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Base/FSEntity.cpp,v $
 * $Date: 2003/05/13 18:41:55 $
 *
 Description:
\*____________________________________________________________________________*/
//$SourceTop:$

#include "FSEntity.h"

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
FileSystemEntity::FileSystemEntity( const FileSystemEntity &tFSE )
:	tFSType( tFSE.tFSType ),
	pName( 0 ),
	pExtension( 0 ),
	sPath( tFSE.sPath ),
	sPathRoot( tFSE.sPathRoot )
{
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
FileSystemEntity::FileSystemEntity( 
		const FileSysType &tTheFSType,
		const PIString &sFullPath )
:	tFSType( tTheFSType ),
	pName( 0 ),
	pExtension( 0 ),
	sPath( sFullPath ),
	sPathRoot()
{
	/* ---
	strip trailing directory seperator characters from
	sPath
	--- */
	int iLen = sPath.Len();
	if ( iLen )
		{
		const char *pPath = sPath;
		int i = iLen-1;
		for(; i>=0 && 
			InternalIsDirectorySeperatorCharacter( pPath[i] ); i--);
		if ( i < (iLen-1) )
			{
			i++;
			char *pTmp = DuplicateString( sPath );
			if ( i<0 )
				{ i=0; };
			pTmp[i]='\0';
			sPath = pTmp;
			PI_DELETE( pTmp );
			};
		};
	InternalPathRootFromPath( 
		sPathRoot, 
		sPath, 
		sPath.Len() );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:	protected constructor
 Description:
\*____________________________________________________________________________*/
FileSystemEntity::FileSystemEntity(
	const PIString &sTheRootPath,
	const FileSysType &tFSTheType
	)
:	tFSType( tFSTheType ),
	pName( 0 ),
	pExtension( 0 ),
	sPath(),
	sPathRoot( sTheRootPath )
{
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	This function attempts to rename internal data structures to point
	to a sibling file in the same directory as the original file.
\*____________________________________________________________________________*/
void FileSystemEntity::NewFileInSamePathRoot( const char *pFileName )
{
	assert( pFileName );
	sPath=sPathRoot;
	sPath.Concatenate( InternalDirectorySeperatorCharacter() );
	sPath.Concatenate( pFileName );
	pName=pExtension=0;
	ExpireFileInformation();
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	Add a file to the end of the path. The current path then becomes
	the directory above the file.
	This method will take no special action if the filename to be
	concatentated has zero length. This will have the effect of 
	concatenating the directory sperator character for this file system
	to the end of the path.
\*____________________________________________________________________________*/
bool FileSystemEntity::ConcatenateFileToPath( const PIString &sFileName )
{
	PIString sTmp;
	tFSType.NormaliseFileName( sFileName, sTmp );

	sPathRoot=sPath;
	sPath.Concatenate( InternalDirectorySeperatorCharacter() );
	sPath.Concatenate( sTmp );

	pName=0;
	pExtension=0;
	InternalExpireFileInformation(); //? undefined when called from constructor
	return true;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const char *FileSystemEntity::GetName()
{
	if ( !pName )
		{
		int iPathLen = sPath.Len();
		int iPathRootLen = sPathRoot.Len();
		assert( iPathLen>=iPathRootLen );
		const char *pPath = sPath;
		if ( iPathLen == iPathRootLen )
			{
			pName = pPath;
			}
		else
			{	
			pName = &( pPath[ iPathRootLen ] );
			if ( iPathRootLen )
				{ pName++; };
			};
		};
	return pName;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const char *FileSystemEntity::GetExtension()
{
	if ( !pExtension )
		{
		pExtension=tFSType.GetExtension( GetName() );
		};

	return pExtension;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
void FileSystemEntity::SetPath( const PIString &sNewPath )
{
	sPath=sNewPath;
	InternalPathRootFromPath( sPathRoot, sPath,
		sPath.Len() );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:	static, protected
 Description:
	Truncate filepath pPath to directory level assuming directory seperator
	character cSeperator. Store result in sRoot	
	Given a full file path, its length and the directory seperator
	character for this file system, generate the directory this file
	exists in.
	If the path is a directory (its ends with the directory seperator
	character) then this the directory itself is the result of the
	function.
\*____________________________________________________________________________*/
void FileSystemEntity::InternalPathRootFromPath( 
	PIString &sRoot, const char *pPath, int iPathLen )
{
	if ( !pPath )
		{ sRoot=PIString::Empty(); return; };
	char *pC=DuplicateString( pPath, iPathLen );
	assert( pC );
	for( int i=iPathLen-1; i>=0; i--)
		{
		if ( InternalIsDirectorySeperatorCharacter( pC[i] ) )
			{ pC[i]='\0'; break; };
		};

	sRoot=pC;
	PI_DELETE( [] pC );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -