📄 tintinparse.cpp
字号:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
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/ChText/TinTinParse.cpp,v 2.7 1996/02/17 02:17:53 coyote Exp $
#include <ChTypes.h>
#include <ctype.h>
#include <signal.h>
#include "TinTin.h"
/*----------------------------------------------------------------------------
TinTin class
----------------------------------------------------------------------------*/
TinTin::TinTin() :
m_cTinTin( DEF_TINTIN_CHAR ),
m_cVerbatim( DEF_VERBATIM_CHAR ),
m_boolOnline( true ),
m_boolDoActions( true ),
m_boolDoSubs( true ),
m_boolPresub( true ),
m_boolSpeedwalk( false ),
m_boolStartQuotes( false ),
m_boolVerbatim( true ),
m_iAliasCounter( 0 ),
m_iActionCounter( 0 ),
m_iSubCounter( 0 ),
m_iAntiSubCounter( 0 ),
m_iVarCounter( 0 ),
m_iHighlightCounter( 0 )
{
m_pListActions = new TinTinList( this );
m_pListAliases = new TinTinList( this );
m_pListHighlights = new TinTinList( this );
m_pListPath = new TinTinList( this );
m_pListPathDirs = new TinTinList( this );
m_pListSubs = new TinTinList( this );
m_pListAntiSubs = new TinTinList( this );
m_pListVars = new TinTinList( this );
m_boolDisplayMessages[msgIndexAliases] = true;
m_boolDisplayMessages[msgIndexActions] = true;
m_boolDisplayMessages[msgIndexSubstitutions] = true;
m_boolDisplayMessages[msgIndexAntiSub] = true;
m_boolDisplayMessages[msgIndexHilight] = true;
m_boolDisplayMessages[msgIndexVariable] = true;
m_boolDisplayMessages[msgIndexPathdir] = true;
}
TinTin::~TinTin()
{
if (m_pListActions)
{
delete m_pListActions;
m_pListActions = 0;
}
if (m_pListAliases)
{
delete m_pListAliases;
m_pListAliases = 0;
}
if (m_pListHighlights)
{
delete m_pListHighlights;
m_pListHighlights = 0;
}
if (m_pListPath)
{
delete m_pListPath;
m_pListPath = 0;
}
if (m_pListPathDirs)
{
delete m_pListPathDirs;
m_pListPathDirs = 0;
}
if (m_pListSubs)
{
delete m_pListSubs;
m_pListSubs = 0;
}
if (m_pListAntiSubs)
{
delete m_pListAntiSubs;
m_pListAntiSubs = 0;
}
if (m_pListVars)
{
delete m_pListVars;
m_pListVars = 0;
}
}
void TinTin::SendToWorld( const string& strOutput )
{
}
void TinTin::Display( const string& strOutput )
{
}
/*----------------------------------------------------------------------------
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 (strWorking.IsEmpty())
{ // Empty line
SendToWorld( strWorking );
}
pstrTemp = GetArgStopAtSpaces( strWorking, strCommand );
pstrStart = strCommand;
if ((*pstrStart == GetTinTinChar()) &&
IsAbrev( pstrStart + 1, "verbatim" ))
{
// Toggle verbatim status
pstrTemp = GetArgAll( pstrTemp, strArgs );
ToggleVerbatim( strArgs );
}
else if (IsVerbatim())
{
SendToWorld( strWorking );
}
else if (*pstrWorking == GetVerbatimChar())
{ /* Line starts with verbatim
escape, so send it 'as is'
to the world */
strWorking = pstrWorking++;
SendToWorld( strWorking );
}
else
{
SubstituteMyVars( strWorking, strWorking );
pstrWorking = strWorking;
while (*pstrWorking)
{
bool boolQuote;
if (*pstrWorking == ';')
{
pstrWorking++;
}
if (boolQuote = (!IsUsingStartQuotes() && ('"' == *pstrWorking)))
{
/* We're not processing quotes
at the start of a command, so
don't include the quote in
processing */
pstrWorking++;
}
pstrWorking = GetArgStopAtSpaces( pstrWorking, strCommand );
pstrWorking = GetArgAll( pstrWorking, strArgs );
if (boolQuote)
{ /* If we preserved a quote, add it
back to the beginning of the
string */
strCommand = '"' + strCommand;
}
pstrCommand = strCommand;
if (*pstrCommand == GetTinTinChar())
{
ParseTinTinCommand( pstrCommand + 1, strArgs );
}
else if (pNode = m_pListAliases->SearchBegin( strCommand, ALPHA ))
{
// 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 );
SendToWorld( strCommand, strArgs );
}
}
}
}
void TinTin::SendToWorld( const string& strCmd, const string& strArgs )
{
string strTemp( strCmd );
strTemp += ' ' + strArgs;
SendToWorld( 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
{
Display( "# Yeah right! Go repeat that yourself dude." );
}
}
else
{
TTCommand cmd;
cmd = ParseTinTinCmd( strCommand );
switch( cmd )
{
case ttAlias:
{
DoAlias( strArgs );
break;
}
case ttBell:
{
DoBell();
break;
}
case ttChar:
{
DoChar( strArgs );
break;
}
case ttCr:
{
DoCR();
break;
}
case ttHelp:
{
DoHelp( strArgs );
break;
}
case ttInfo:
{
DoInfo();
break;
}
case ttKillall:
{
DoKillAll( false );
break;
}
case ttNop:
{
break;
}
case ttRead:
{
DoRead( strArgs, true );
break;
}
case ttSpeedwalk:
{
ToggleSpeedwalk();
break;
}
case ttStartquotes:
{
ToggleStartQuotes();
break;
}
case ttUnalias:
{
DoUnalias( strArgs );
break;
}
case ttWizlist:
{
DoWizList();
break;
}
default:
{
string strFormat( "# Unknown command! ('%s')" );
string strStatus;
strStatus.Format( strFormat, (const char*)strCommand );
Display( strStatus );
break;
}
}
}
#if 0
// else if (IsAbrev( strCommand, "action" ))
// {
// action_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "antisubstitute" ))
// {
// parse_antisub( strArgs );
// }
// else if (IsAbrev( strCommand, "boss" ))
// {
// boss_strCommand();
// }
// else if (IsAbrev( strCommand, "echo" ))
// {
// echo_strCommand();
// }
// else if (IsAbrev( strCommand, "end" ))
// {
// end_strCommand( strCommand );
// }
// else if (IsAbrev( strCommand, "highlight" ))
// {
// parse_high( strArgs );
// }
// else if (IsAbrev( strCommand, "history" ))
// {
// history_strCommand();
// }
// else if (IsAbrev( strCommand, "if" ))
// {
// if_strCommand(strArgs, ses);
// }
// else if (IsAbrev( strCommand, "ignore" ))
// {
// ignore_strCommand();
// }
// else if (IsAbrev( strCommand, "log" ))
// {
// log_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "loop" ))
// {
// loop_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "map" ))
// {
// map_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "math" ))
// {
// math_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "mark" ))
// {
// mark_strCommand();
// }
// else if (IsAbrev( strCommand, "message" ))
// {
// message_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "path" ))
// {
// path_strCommand();
// }
// else if (IsAbrev( strCommand, "pathdir" ))
// {
// pathdir_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "presub" ))
// {
// presub_strCommand();
// }
// else if (IsAbrev( strCommand, "redraw" ))
// {
// redraw_strCommand();
// }
// else if (IsAbrev( strCommand, "retab" ))
// {
// read_complete();
// }
// else if (IsAbrev( strCommand, "return" ))
// {
// return_strCommand();
// }
// else if (IsAbrev( strCommand, "savepath" ))
// {
// savepath_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "session" ))
// {
// session_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "showme" ))
// {
// showme_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "snoop" ))
// {
// snoop_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "split" ))
// {
// split_strCommand( strArgs );
// }
// else if (IsAbrev( strCommand, "suspend" ))
// {
// tstphandler(SIGTSTP,0,NULL,NULL);
// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -