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

📄 tintinparse.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			case ttTickset:
			{
				DoTickSet();
				break;
			}

			case ttTicksize:
			{
				DoTickSize( strArgs );
				break;
			}

			case ttTogglesub:
			{
				ToggleSub();
				break;
			}

			case ttTolower:
			{
				DoChangeCase( strArgs, false );
				break;
			}

			case ttToupper:
			{
				DoChangeCase( strArgs, true );
				break;
			}

			case ttUnaction:
			{
				DoUnaction( strArgs );
				break;
			}

			case ttUnalias:
			{
				DoUnalias( strArgs );
				break;
			}

			case ttUngag:
			{
				DoUnsubstitute( strArgs, true );
				break;
			}

			case ttUnpath:
			{
				DoUnpath();
				break;
			}

			case ttUnsubstitute:
			{
				DoUnsubstitute( strArgs, false );
				break;
			}

			case ttUnvariable:
			{
				DoUnvariable( strArgs );
				break;
			}

			case ttVariable:
			{
				DoVariable( strArgs );
				break;
			}

			case ttVersion:
			{
				DoVersion();
				break;
			}

			case ttWizlist:
			{
				DoWizList();
				break;
			}

			case ttWrite:
			{
				DoWrite( strArgs );
				break;
			}

			case ttZap:
			{
				DoZap();
				break;
			}

			default:
			{
				boolProcessed = false;
				break;
			}
		}

		if (!boolProcessed)
		{
			ChWorldMainInfo*	pWorldMainInfo;
			ChCore*				pCore = GetMainInfo()->GetCore();

			if (pWorldMainInfo =
					(ChWorldMainInfo*)pCore->GetMainInfo( CH_MODULE_WORLD,
															strCommand ))
			{
				if (strArgs.IsEmpty())
				{							/* If there are no args, then just
												activate the frame */

					pCore->ActivateFrame( strCommand );
				}
				else
				{
					if (pWorldMainInfo->IsConnected())
					{
											/* If there are args, then send
												them to the frame */

						GetArgWithSpaces( strArgs, strArgs );
						pWorldMainInfo->GetTinTin()->ParseInput( strArgs );
					}
					else
					{
						string		strFormat;
						string		strMessage;

						LOADSTRING( IDS_TINTIN_SESSION_NOT_CONNECTED,
											strFormat );
						strMessage.Format( strFormat,
											(const char*)strCommand );
						ErrMessage( strMessage );
					}
				}
			}
			else
			{
				string		strFormat;
				string		strMessage;

				LOADSTRING( IDS_TINTIN_UNKNOWN_CMD, strFormat );
				strMessage.Format( strFormat, (const char*)strCommand );
				ErrMessage( strMessage );
			}
		}
	}

	#if 0

//	else if (IsAbrev( strCommand, "antisubstitute" ))
//	{
//		parse_antisub( strArgs );
//	}
//	else if (IsAbrev( strCommand, "boss" ))
//	{
//		boss_strCommand();
//	}
//	else if (IsAbrev( strCommand, "highlight" ))
//	{
//		parse_high( strArgs );
//	}
//	else if (IsAbrev( strCommand, "history" ))
//	{
//		history_strCommand();
//	}
//	else if (IsAbrev( strCommand, "presub" ))
//	{
//		presub_strCommand();
//	}
//	else if (IsAbrev( strCommand, "retab" ))
//	{
//		read_complete();
//	}
//	else if (IsAbrev( strCommand, "tablist" ))
//	{
//		tablist( complete_head );
//	}
//	else if (IsAbrev( strCommand, "tabadd" ))
//	{
//		tab_add( strArgs );
//	}
//	else if (IsAbrev( strCommand, "tabdelete" ))
//	{
//		tab_delete(strArgs);
//	}
//	else if (IsAbrev( strCommand, "togglesubs" ))
//	{
//		togglesubs_strCommand();
//	}
//	else if (IsAbrev( strCommand, "unantisubstitute" ))
//	{
//		unantisubstitute_strCommand( strArgs );
//	}
//	else if (IsAbrev( strCommand, "unhighlight" ))
//	{
//		unhighlight_strCommand( strArgs );
//	}

	#endif
}


/*----------------------------------------------------------------------------
	TinTin::IsSpeedwalkDirective
				Returns true if command consists only of the letters
				[n,s,e,w,u,d] or digits followed by those letters.
----------------------------------------------------------------------------*/

bool TinTin::IsSpeedwalkDirective( const char* pstrCmd )
{
	bool	boolSpeedWalk = false;

	while (*pstrCmd)
	{
		if ((*pstrCmd != 'n') && (*pstrCmd != 'e') && (*pstrCmd != 's') &&
			(*pstrCmd != 'w') && (*pstrCmd != 'u') && (*pstrCmd != 'd') &&
			!isdigit( *pstrCmd ))
		{
			return false;
		}

		if (!isdigit( *pstrCmd ))
		{
			boolSpeedWalk = TRUE;
		}

		pstrCmd++;
	}

	return boolSpeedWalk;
}


/*----------------------------------------------------------------------------
	TinTin::DoSpeedwalk
				This function will interpret and perform a speedwalk
				command.
----------------------------------------------------------------------------*/

void TinTin::DoSpeedwalk( const char* pstrCmd )
{
	while (*pstrCmd)
	{
		const char*	pstrStart = pstrCmd;
		bool		boolMultiple = false;
		char		cDirection;
		int			iCount;

		while (isdigit( *pstrCmd ))
		{
			pstrCmd++;
			boolMultiple = true;
		}

		if (boolMultiple && *pstrCmd)
		{
			if (2 == sscanf( pstrStart, "%d%c", &iCount, &cDirection ))
			{
				for (int iLoop = 0; iLoop < iCount; iLoop++)
				{
					Send( cDirection );
				}
			}
		}
		else if (*pstrCmd)
		{
			Send( *pstrCmd );
		}

		if (*pstrCmd)
		{
			pstrCmd++;
		}
	}
}


/*----------------------------------------------------------------------------
	TinTin::GetArgStopAtSpaces
				Get all arguments - don't remove double-quotes or
				back-slashes.
----------------------------------------------------------------------------*/

const char* TinTin::GetArgAll( const char* pstrText, string& strArg )
{
	int		iNestLevel = 0;

	strArg = "";
	pstrText = SpaceOut( pstrText );

	while (*pstrText)
	{
		if (*pstrText == '\\')
		{									/* Next character is quoted,
												so leave it in to be
												processed later */
			strArg += *pstrText++;
			if (*pstrText)
			{
				strArg += *pstrText++;
			}
		}
		else if ((*pstrText == ';') && (0 == iNestLevel))
		{
											// Semicolon ends the command...
			break;
		}
		else if (*pstrText == DEF_OPEN)
		{									// Open argument
			iNestLevel++;
			strArg += *pstrText++;
		}
		else if (*pstrText == DEF_CLOSE)
		{									// Close argument
			if (0 > --iNestLevel)
			{
				iNestLevel = 0;
			}
			strArg += *pstrText++;
		}
		else
		{									// Copy the character
			strArg += *pstrText++;
		}
	}

	return pstrText;
}


/*----------------------------------------------------------------------------
	TinTin::GetArgInBraces
				Get the argument.  If the argument is bracketed with
				curly braces, just get that part.
----------------------------------------------------------------------------*/

const char* TinTin::GetArgInBraces( const char* pstrText, string& strArg,
									bool boolIncludeSpaces )
{
	int			iNestLevel = 0;
	const char*	pstrTemp;
	string		strResult;

	pstrText = SpaceOut( pstrText );

	pstrTemp = pstrText;

	if (*pstrText != DEF_OPEN)
	{										// This isn't bracketed in braces
		if (boolIncludeSpaces)
		{
			pstrText = GetArgWithSpaces( pstrText, strArg );
		}
		else
		{
			pstrText = GetArgStopAtSpaces( pstrText, strArg );
		}

		return pstrText;
	}

	pstrText++;

	while (*pstrText && !((*pstrText == DEF_CLOSE) && (iNestLevel == 0)))
	{
		if (*pstrText == DEF_OPEN)
		{
			iNestLevel++;
		}
		else if (*pstrText == DEF_CLOSE)
		{
			iNestLevel--;
		}

		strResult += *pstrText++;
	}

	strArg = strResult;

	if (!*pstrText)
	{										/* There should be a '}' still
												in the buffer */

		ErrMessage( "# Unmatched braces error!" );
	}
	else
	{										// Skip the close brace
		pstrText++;
	}

	return pstrText;
}


/*----------------------------------------------------------------------------
	TinTin::GetArgStopAtSpaces
				Gets a single argument, stopping at spaces and removing
				quotes.
----------------------------------------------------------------------------*/

const char* TinTin::GetArgStopAtSpaces( const char* pstrText, string& strArg )
{
	strArg = "";
	pstrText = SpaceOut( pstrText );

	while (*pstrText)
	{
		if (*pstrText == '\\')
		{									// Next character is quoted
			if (*++pstrText)
			{
				strArg += *pstrText++;
			}
		}
		else if (*pstrText == ';')
		{
											// Semicolon ends the command...
			break;
		}
		else if (*pstrText == ' ')
		{									// End at a space...
			break;
		}
		else
		{									// Copy the character
			strArg += *pstrText++;
		}
	}

	return pstrText;
}


/*----------------------------------------------------------------------------
	TinTin::GetArgWithSpaces
				Gets the entire argument, including spaces,
				removing quotes.

				For example:
					In:		"this is it" way way hmmm;
					Out:	this is it way way hmmm
----------------------------------------------------------------------------*/

const char* TinTin::GetArgWithSpaces( const char* pstrText, string& strArg )
{
	int			iNestLevel = 0;
	string		strTemp;

	pstrText = SpaceOut( pstrText );

	while (*pstrText)
	{
		if (*pstrText == '\\')
		{
			if (*++pstrText)
			{
				strTemp += *pstrText++;
			}
			else
			{
				strTemp += '\\';
			}
		}
		else if ((*pstrText == ';') && (0 == iNestLevel))
		{
			break;
		}
		else if (*pstrText == DEF_OPEN)
		{
			iNestLevel++;
			strTemp += *pstrText++;
		}
		else if(*pstrText == DEF_CLOSE)
		{
			strTemp += *pstrText++;
			iNestLevel--;
		}
		else
		{
			strTemp += *pstrText++;
		}
	}

	strArg = strTemp;
	return pstrText;
}


/*----------------------------------------------------------------------------
	TinTin::SpaceOut

			Advances point to next non-space.
----------------------------------------------------------------------------*/

const char* TinTin::SpaceOut( const char* pstrText )
{
	while (isspace( *pstrText ))
	{
		pstrText++;
	}

	return pstrText;
}

⌨️ 快捷键说明

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