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

📄 _piprog.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/Pi2API/_PIProg.cpp,v $
 * $Date: 2003/05/13 18:42:09 $
 *
 Description:
	Implementation of program facilities.
\*____________________________________________________________________________*/
//$SourceTop:$

#include <fstream.h>
#include <assert.h>
#include "_PIBase.h"
#include "_PIDBKey.h"
#include "_PIProg.h"
#include "StrToken.h"
#include "AutoDel.h"
#include "ProgMain.h"
#include "PiAPI.h"

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PIDB *_PIProgram::initProgramDatabase( const char *pName, const char *pVersion,
	int iMajor, int iMinor, int iPatch )
{
	assert( pName && pVersion );
	if ( !pName || !pVersion )
		{ return 0; };
	_PIDB *pDB = PI_NEW( PIDBTree( 0 ) );
	PIString sTmp; const char *pTmp;
	pDB->Add( PIDBTYPE_STRING, PIDBKEY_PROGRAM, (void *)pName, 0 );
	pDB->Add( PIDBTYPE_STRING, PIDBKEY_VERSION, (void *)pVersion, 0 );
	pi_ltoa( iMajor, 10, sTmp ); pTmp = sTmp;
	pDB->Add( PIDBTYPE_STRING, PIDBKEY_VERSION_MAJOR, (void *)pTmp, 0 );
	pi_ltoa( iMinor, 10, sTmp ); pTmp = sTmp;
	pDB->Add( PIDBTYPE_STRING, PIDBKEY_VERSION_MINOR, (void *)pTmp, 0 );
	pi_ltoa( iPatch, 10, sTmp ); pTmp = sTmp; 
	pDB->Add( PIDBTYPE_STRING, PIDBKEY_VERSION_PATCH, (void *)pTmp, 0 );
	return pDB;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	Load the arguments straight into a new argument tree. The 
arguments will have been formatted on the commandline into 
	variable=value pairs.
\*____________________________________________________________________________*/
int _PIProgram::loadArguments( _PIDB * /* pDB*/, int /*iArgc*/,
		char * /*ppArgv*/[])
{
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
int _PIProgram::dbgDump( _PIDB *pDB, ostream &os )
{
	assert( pDB );
	pDB->Render( os );
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
void *_PIProgram::topLevelLookup( _PIDB *pDB, int iType, const char *pTopKey,
	const char *pKey )
{
	_PIDB *pTopLevelDB = (_PIDB *)pDB->Lookup( PIDBTYPE_TREE, pTopKey,
		PIDBFLAG_PROPAGATEUP );
	if ( !pTopLevelDB ) 
		{ return 0; };
	void *pV = pTopLevelDB->Lookup( iType, pKey, 0 );
	return pV;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static int iRet = PIAPI_COMPLETED;
PIProgramFn fnTheFn = 0;
void Internal_PlatformFn( void )
{
	_PIDB *pDB = ProgramDB_Init();
	if ( pDB )
		{
		PIPlatform_catchExceptions( (void (*)(void*))fnTheFn, pDB );
		ProgramDB_Cleanup( pDB );
		return;
		};
	iRet = PIAPI_ERROR;
}
PUBLIC_PIAPI int PIProgram_enter( const char *pProgram, int iVersion,
	PIProgramFn fnEnter )
{
	if ( iVersion != PIPROGRAM_VERSION_1_0 || !fnEnter )
		{ return PIAPI_EINVAL; };

	fnTheFn = fnEnter;
	int iRC = PIPlatform_enter( pProgram, iVersion, Internal_PlatformFn );
	return iRC==PIAPI_COMPLETED ? iRet : iRC;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIProgram_dbgDump( _PIDB *pDB, const char *pDumpFile )
{
	if ( !pDB )
		{ return PIAPI_EINVAL; };
	if ( pDumpFile )
		{
		ofstream ofs( pDumpFile, ios::app | ios::trunc );
		if ( !ofs.good() )
			{ return PIAPI_ERROR; };
		_PIProgram::dbgDump( pDB, ofs );
		}
	else
		{
		_PIProgram::dbgDump( pDB, cout );
		};
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI _PIDB *PIProgram_initProgramDatabase( const char *pName,
	const char *pVersion, int iMajor, int iMinor,
	int iPatch )
{
	if ( !pName || !pVersion ) { return 0; };
	return _PIProgram::initProgramDatabase( pName, pVersion, iMajor,
		iMinor, iPatch );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIProgram_loadArguments( _PIDB *pDB, int iArgc,
	char *ppArgv[] )
{
	if ( !pDB || (iArgc && !ppArgv) ) { return PIAPI_EINVAL; };
	return _PIProgram::loadArguments( pDB, iArgc, ppArgv );
}

⌨️ 快捷键说明

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