AppleWin/source/Debugger_Parser.h

238 lines
5.9 KiB
C
Raw Normal View History

2006-02-26 06:26:56 +00:00
#ifndef DEBUGGER_PARSER_H
#define DEBUGGER_PARSER_H
#define CHAR_LF '\x0D'
#define CHAR_CR '\x0A'
#define CHAR_SPACE ' '
#define CHAR_TAB '\t'
#define CHAR_QUOTED '"'
#define CHAR_ESCAPE '\x1B'
// Globals __________________________________________________________________
extern int g_nArgRaw;
extern Arg_t g_aArgRaw[ MAX_ARGS ]; // pre-processing
extern Arg_t g_aArgs [ MAX_ARGS ]; // post-processing
extern const TCHAR * g_pConsoleFirstArg; // = 0; // points to first arg
extern const TokenTable_t g_aTokens[ NUM_TOKENS ];
extern const TCHAR TCHAR_LF ;//= 0x0D;
extern const TCHAR TCHAR_CR ;//= 0x0A;
extern const TCHAR TCHAR_SPACE ;//= TEXT(' ');
extern const TCHAR TCHAR_TAB ;//= TEXT('\t');
extern const TCHAR TCHAR_QUOTED;//= TEXT('"' );
// Prototypes _______________________________________________________________
// Arg - Command Processing
Update_t Help_Arg_1( int iCommandHelp );
int _Arg_1 ( int nValue );
int _Arg_1 ( LPTSTR pName );
int _Arg_Shift ( int iSrc, int iEnd, int iDst = 0 );
void ArgsClear ();
bool ArgsGetValue ( Arg_t *pArg, WORD * pAddressValue_, const int nBase = 16 );
bool ArgsGetImmediateValue ( Arg_t *pArg, WORD * pAddressValue_ );
int ArgsGet ( TCHAR * pInput );
bool ArgsGetRegisterValue ( Arg_t *pArg, WORD * pAddressValue_ );
void ArgsRawParse ( void );
int ArgsCook ( const int nArgs, const int bProcessMask ); // ArgsRawCook
2006-02-26 06:26:56 +00:00
// Token
const char * ParserFindToken( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
// Text Util
/*
inline const char* SkipEOL ( const char *pSrc )
{
while (pSrc && ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR)))
if (pSrc)
{
pSrc++;
}
return pSrc;
}
*/
2006-02-28 16:36:51 +00:00
2006-02-26 06:26:56 +00:00
inline const char* EatEOL ( const char *pSrc )
{
2006-02-28 16:36:51 +00:00
if (pSrc)
{
if (*pSrc == CHAR_LF)
pSrc++;
if (*pSrc == CHAR_CR)
pSrc++;
}
return pSrc;
2006-02-26 06:26:56 +00:00
}
2006-02-28 16:36:51 +00:00
2006-02-26 06:26:56 +00:00
inline const char* SkipWhiteSpace ( const char *pSrc )
{
2006-02-28 16:36:51 +00:00
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)))
{
pSrc++;
}
return pSrc;
2006-02-26 06:26:56 +00:00
}
2006-02-28 16:36:51 +00:00
2006-02-26 06:26:56 +00:00
inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
2006-02-28 16:36:51 +00:00
while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) && (pSrc > pStart))
{
pSrc--;
}
return pSrc;
2006-02-26 06:26:56 +00:00
}
inline const char* SkipUntilChar ( const char *pSrc, const char nDelim )
2006-02-28 16:36:51 +00:00
{
while (pSrc && (*pSrc))
{
if (*pSrc == nDelim)
break;
pSrc++;
}
return pSrc;
}
2006-02-26 06:26:56 +00:00
inline const char* SkipUntilEOL ( const char *pSrc )
{
2006-02-28 16:36:51 +00:00
// EOL delims: NULL, LF, CR
while (pSrc && (*pSrc))
2006-02-26 06:26:56 +00:00
{
2006-02-28 16:36:51 +00:00
if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR))
{
break;
}
pSrc++;
2006-02-26 06:26:56 +00:00
}
2006-02-28 16:36:51 +00:00
return pSrc;
2006-02-26 06:26:56 +00:00
}
inline const char* SkipUntilTab ( const char *pSrc)
{
2006-02-28 16:36:51 +00:00
while (pSrc && (*pSrc))
2006-02-26 06:26:56 +00:00
{
2006-02-28 16:36:51 +00:00
if (*pSrc == CHAR_TAB)
{
break;
}
pSrc++;
2006-02-26 06:26:56 +00:00
}
2006-02-28 16:36:51 +00:00
return pSrc;
2006-02-26 06:26:56 +00:00
}
inline const char* SkipUntilToken ( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ )
{
2006-02-28 16:36:51 +00:00
if ( pToken_)
*pToken_ = NO_TOKEN;
2006-02-26 06:26:56 +00:00
while (pSrc && (*pSrc))
{
2006-02-28 16:36:51 +00:00
if (ParserFindToken( pSrc, aTokens, nTokens, pToken_ ))
return pSrc;
2006-02-26 06:26:56 +00:00
pSrc++;
}
return pSrc;
}
2006-02-28 16:36:51 +00:00
inline const char* SkipUntilWhiteSpace ( const char *pSrc )
{
while (pSrc && (*pSrc))
{
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc++;
}
return pSrc;
}
2006-02-26 06:26:56 +00:00
inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pStart )
{
2006-02-28 16:36:51 +00:00
while (pSrc && (pSrc > pStart))
2006-02-26 06:26:56 +00:00
{
2006-02-28 16:36:51 +00:00
if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))
{
break;
}
pSrc--;
2006-02-26 06:26:56 +00:00
}
2006-02-28 16:36:51 +00:00
return pSrc;
2006-02-26 06:26:56 +00:00
}
/*
const TCHAR* SkipEOL ( const TCHAR *pSrc );
const TCHAR* SkipWhiteSpace ( const TCHAR *pSrc );
const TCHAR* SkipWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart );
const TCHAR* SkipUntilChar ( const TCHAR *pSrc, const TCHAR nDelim );
const TCHAR* SkipUntilEOL ( const TCHAR *pSrc );
const TCHAR* SkipUntilToken ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ );
const TCHAR* SkipUntilWhiteSpace ( const TCHAR *pSrc );
const TCHAR* SkipUntilWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart );
const TCHAR* SkipUntilTab ( const TCHAR *pSrc);
*/
const TCHAR * FindTokenOrAlphaNumeric ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ );
// TextRemoveWhiteSpaceReverse
int RemoveWhiteSpaceReverse ( char *pSrc );
// TextExpandTabsToSpaces
void TextConvertTabsToSpaces( TCHAR *pDeTabified_, LPCTSTR pText, const int nDstSize, int nTabStop = 0 );
2006-02-28 16:36:51 +00:00
/** Assumes text are valid hex digits!
//=========================================================================== */
inline BYTE TextConvert2CharsToByte ( char *pText )
{
BYTE n = ((pText[0] <= '@') ? (pText[0] - '0') : (pText[0] - 'A' + 10)) << 4;
n += ((pText[1] <= '@') ? (pText[1] - '0') : (pText[1] - 'A' + 10)) << 0;
return n;
}
//===========================================================================
inline bool TextIsHexChar( char nChar )
{
if ((nChar >= '0') && (nChar <= '9'))
return true;
if ((nChar >= 'A') && (nChar <= 'F'))
return true;
if ((nChar >= 'a') && (nChar <= 'f'))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexByte( char *pText )
{
if (TextIsHexChar( pText[0] ) &&
TextIsHexChar( pText[1] ))
return true;
return false;
}
//===========================================================================
inline bool TextIsHexString ( LPCSTR pText )
{
while (*pText)
{
if (! TextIsHexChar( *pText ))
return false;
pText++;
}
return true;
}
2006-02-26 06:26:56 +00:00
#endif