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

📄 tintinparse.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	TinTin class main & parsing methods.  Originally modified from TinTin++,
	(T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t, originally coded by
	Peter Unold 1992.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/TinTinParse.cpp,v 2.32 1996/09/12 19:10:20 pritham Exp $

#include "headers.h"
#if !defined(CH_PUEBLO_PLUGIN)
#include "resource.h"
#else
#include "vwrres.h"
#endif

#include <ChCore.h>

#include "TinTin.h"
#include "World.h"


/*----------------------------------------------------------------------------
	TinTin protected methods
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
	TinTin::ParseInput
				Checks for TinTin commands and aliases.
----------------------------------------------------------------------------*/

void TinTin::ParseInput( const string& strInput )
{
	string			strWorking( strInput );
	const char*		pstrTemp;
	const char*		pstrStart;
	const char*		pstrWorking = strWorking;
	TinTinListNode*	pNode;
	string			strCommand;
	const char*		pstrCommand;
	string			strArgs;

	if (++m_iRecurseLevel > MAX_RECURSE)
	{
		string		strMessage;

		LOADSTRING( IDS_TINTIN_RECURSE_ERR, strMessage );
		ErrMessage( strMessage );
	}
	else if (strWorking.IsEmpty())
	{										// Empty line
		Send( strWorking );
	}
	else
	{
		pstrTemp = GetArgStopAtSpaces( strWorking, strCommand );
		pstrStart = strCommand;

		if ((*pstrStart == GetTinTinChar()) &&
				IsAbrev( pstrStart + 1, "verbatim" ))
		{
											// Toggle verbatim status

			pstrTemp = GetArgInBraces( pstrTemp, strArgs, true );

			ToggleVerbatim( strArgs );
		}
		else if (IsVerbatim())
		{
			Send( strWorking );
		}
		else if (*pstrWorking == GetVerbatimChar())
		{									/* Line starts with verbatim
												escape, so send it 'as is'
												to the world */
			strWorking = ++pstrWorking;
			Send( strWorking );
		}
		else
		{
			SubstituteMyVars( strWorking, strWorking );

			pstrWorking = strWorking;
			while (*pstrWorking)
			{
				if (*pstrWorking == ';')
				{
					pstrWorking++;
				}

				pstrWorking = GetArgStopAtSpaces( pstrWorking, strCommand );
				pstrWorking = GetArgAll( pstrWorking, strArgs );

				pstrCommand = strCommand;

				if (*pstrCommand == GetTinTinChar())
				{
					ParseTinTinCommand( pstrCommand + 1, strArgs );
				}
				else if (pNode = GetListAliases()->SearchBegin( strCommand ))
				{
											// Alias found
					int			iLoop;
					const char*	pstrBeginArg;
					const char*	pstrEndArg;
					char		cEnd;
					string		strNewCommand;
											// Strip out the arguments
					m_strVars[0] = strArgs;
					for (iLoop = 1, pstrBeginArg = strArgs; iLoop < 10; iLoop++)
					{
						string		strTemp;
											// Find the beginning of the arg

						while (*pstrBeginArg == ' ')
						{
							pstrBeginArg++;
						}
											// Find the end of the argument

						cEnd = (*pstrBeginArg == '{') ? '}' : ' ';
						pstrBeginArg = (*pstrBeginArg == '{') ?
											pstrBeginArg + 1 : pstrBeginArg;
						for (pstrEndArg = pstrBeginArg;
								*pstrEndArg && (*pstrEndArg != cEnd); pstrEndArg++)
							;
											// Chop out the argument
						strTemp = pstrBeginArg;
						m_strVars[iLoop] = strTemp.Left( pstrEndArg - pstrBeginArg );

											// Move to the next argument

						pstrBeginArg = (*pstrEndArg) ? pstrEndArg + 1 : pstrEndArg;
					}

					PrepareActionAlias( pNode->GetRight(), strNewCommand );

					if(!strcmp( pNode->GetRight(), strNewCommand ) &&
						!strArgs.IsEmpty())
					{						// Append arguments
						strNewCommand += " ";
						strNewCommand += strArgs;
					}

					ParseInput( strNewCommand );
				}
				else if (IsSpeedwalk() && strArgs.IsEmpty() &&
							IsSpeedwalkDirective( strCommand ))
				{
					DoSpeedwalk( strCommand );
				}
				else
				{
					GetArgWithSpaces( strArgs, strArgs );
					Send( strCommand, strArgs );
				}
			}
		}
	}

	m_iRecurseLevel--;
}


void TinTin::Send( const string& strCmd )
{
	CheckInsertPath( strCmd );
	SendToWorld( strCmd );
}


void TinTin::Send( const string& strCmd, const string& strArgs )
{
	string	strTemp( strCmd );

	if (!strArgs.IsEmpty())
	{
		strTemp += ' ' + strArgs;
	}

	Send( strTemp );
}


/*----------------------------------------------------------------------------
	TinTin::ParseTinTinCommand
				Parses and processes most of the TinTin commands.
----------------------------------------------------------------------------*/

void TinTin::ParseTinTinCommand( const string& strCommand, string& strArgs )
{
	const char*			pstrCommand = strCommand;

	if (isdigit( *pstrCommand ))
	{
		int		iCount = atoi( pstrCommand );

		if (iCount > 0)
		{
			GetArgInBraces( strArgs, strArgs );

			while (iCount-- > 0)
			{								// Recurse to process the strCommand
				ParseInput( strArgs );
			}
		}
		else
		{
			ErrMessage( "# Yeah right!  Go repeat that yourself dude." );
		}
	}
	else
	{
		bool		boolProcessed = true;
		TTCommand	cmd;

		cmd = ParseTinTinCmd( strCommand );

		switch( cmd )
		{
			case ttAction:
			{
				DoAction( strArgs );
				break;
			}

			case ttAlert:
			{
				DoAlert();
				break;
			}

			case ttAlias:
			{
				DoAlias( strArgs );
				break;
			}

			case ttAll:
			{
				DoAll( strArgs );
				break;
			}

			case ttBell:
			{
				DoBell();
				break;
			}

			case ttChar:
			{
				DoChar( strArgs );
				break;
			}

			case ttCr:
			{
				DoCR();
				break;
			}

			case ttEcho:
			{
				ToggleEcho();
				break;
			}

			case ttEnd:
			{
				DoEnd( strCommand );
				break;
			}

			case ttGag:
			{
				if (strArgs[0] != DEF_OPEN)
				{
					string		strTemp( strArgs );

					strArgs = DEF_OPEN + strTemp + DEF_CLOSE;
				}
				
				strArgs += " .";

				DoSubstitute( strArgs );
				break;
			}

			case ttHelp:
			{
				DoHelp( strArgs );
				break;
			}

			case ttIf:
			{
				DoIf( strArgs );
				break;
			}

			case ttIgnore:
			{
				ToggleIgnore();
				break;
			}

			case ttInfo:
			{
				DoInfo();
				break;
			}

			case ttKillall:
			{
				DoKillAll( false );
				break;
			}

			case ttLog:
			{
				DoLog( strArgs );
				break;
			}

			case ttLoop:
			{
				DoLoop( strArgs );
				break;
			}

			case ttMap:
			{
				DoMap( strArgs );
				break;
			}

			case ttMark:
			{
				DoMark();
				break;
			}

			case ttMath:
			{
				DoMath( strArgs );
				break;
			}

			case ttMbox:
			{
				DoMbox( strArgs );
				break;
			}

			case ttMessage:
			{
				DoMessage( strArgs );
				break;
			}

			case ttName:
			{
				DoName( strArgs );
				break;
			}

			case ttNop:
			{
				break;
			}

			case ttPath:
			{
				DoPath();
				break;
			}

			case ttPathdir:
			{
				DoPathdir( strArgs );
				break;
			}

			case ttPlaySound:
			{
				DoPlaySound( strArgs );
				break;
			}

			case ttRandom:
			{
				DoRandom( strArgs );
				break;
			}

			case ttRead:
			{
				DoRead( strArgs, true );
				break;
			}

			case ttReturn:
			{
				DoReturn();
				break;
			}

			case ttSavepath:
			{
				DoSavepath( strArgs );
				break;
			}

			case ttSession:
			{
				DoSession( strArgs );
				break;
			}

			case ttShowme:
			{
				DoShowMe( strArgs );
				break;
			}

			case ttSpeedwalk:
			{
				ToggleSpeedwalk();
				break;
			}

			case ttSplit:
			{
				DoSplit( strArgs );
				break;
			}

			case ttSubstitute:
			{
				DoSubstitute( strArgs );
				break;
			}

			case ttTextin:
			{
				DoRead( strArgs, true );
				break;
			}

			case ttTick:
			{
				DoTick();
				break;
			}

			case ttTickkey:
			{
				DoTickKey( strArgs );
				break;
			}

			case ttTickoff:
			{
				DoTickOff();
				break;
			}

			case ttTickon:
			{
				DoTickOn();
				break;
			}

⌨️ 快捷键说明

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